Commit graph

3205 commits

Author SHA1 Message Date
Andreas Kling
b2e502e533 Kernel: Add Thread::block_until(Condition).
Replace the class-based snooze alarm mechanism with a per-thread callback.
This makes it easy to block the current thread on an arbitrary condition:

    void SomeDevice::wait_for_irq() {
        m_interrupted = false;
        current->block_until([this] { return m_interrupted; });
    }
    void SomeDevice::handle_irq() {
        m_interrupted = true;
    }

Use this in the SB16 driver, and in NetworkTask :^)
2019-07-14 14:54:54 +02:00
Andreas Kling
e8d61bb8c0 CEventLoop: Oops, I had the pipe reader/writer fd's mixed up. 2019-07-14 14:28:24 +02:00
Andreas Kling
4c0c93ce09 LibCore: Oops, fix infinite recursion in LogStream << CSocketAddress. 2019-07-14 14:24:37 +02:00
Andreas Kling
3073ea7d84 Kernel: Add support for the WSTOPPED flag to the waitpid() syscall.
This makes waitpid() return when a child process is stopped via a signal.
Use this in Shell to catch stopped children and return control to the
command line. :^)

Fixes #298.
2019-07-14 11:35:49 +02:00
Andreas Kling
de03b72979 LibC: Add WIFSTOPPED() macro in <sys/wait.h>. 2019-07-14 11:31:53 +02:00
Andreas Kling
c9ee481cdf LibCore: Port CSocket over to using dbg().
Also added a LogStream operator<< for CSocketAddress.
2019-07-14 11:02:40 +02:00
Andreas Kling
b4329a8eec CObject: Add LogStream operator<< for CObject. 2019-07-14 10:59:26 +02:00
Andreas Kling
2a9b627ae9 Piano: Use CObject::custom_event() to simplify PianoWidget a bit. 2019-07-14 10:28:10 +02:00
Andreas Kling
a634fab3c4 CObject: Add custom_event() virtual.
This way you can just override custom_event() to catch CCustomEvent instead
of having to filter the entire event stream with event(). :^)
2019-07-14 10:27:27 +02:00
Andreas Kling
1ecb7462b7 Piano: Use CEventLoop::wake() to trigger repaint from sound thread.
In order to repaint the GUI after the sound thread has produced some sweet
new waves, we post a CCustomEvent to the main thread's event loop and then
wake up that event loop via CEventLoop::wake().
2019-07-14 10:22:28 +02:00
Andreas Kling
17ee548bcd CEventLoop: Add wake(), a mechanism for waking up when blocked in select().
This patch generalizes the concept used in Piano to wake up the event loop
so it can react to something happening on a secondary thread.
Basically, there's a pipe who is always part of the file descriptor set we
pass to select(), and calling wake() simply writes a little to that pipe.
2019-07-14 10:20:57 +02:00
Andreas Kling
f1d6a37d5d LibCore: Add CThread, a simple thread abstraction object.
Currently this is only a simple wrapper around create_thread() that
remembers the thread ID of the spawned thread.
2019-07-14 10:19:51 +02:00
Andreas Kling
ad7ec2bbc7 Kernel: Make the create_thread() syscall return the new thread ID. 2019-07-14 10:17:58 +02:00
Robin Burchell
0a1bd03f1d WindowServer: Add a custom window type for Launcher
This keeps it out of the taskbar window list.
The stacking order is a little gnarly, but it seems to work OK still.
2019-07-14 00:06:47 +02:00
Robin Burchell
bee4544192 WSEventLoop: Treat invalid window types the same as unknown window types
And forcefully disconnect the client in both cases.
2019-07-14 00:06:47 +02:00
Andreas Kling
559a999852 Piano: Use a fixed-width font in the UI to align things nicely. 2019-07-13 23:14:00 +02:00
Andreas Kling
9197cfc62f Piano: Add 16x16 window icon. 2019-07-13 23:12:40 +02:00
Andreas Kling
3eeb0734ba Piano: Remove some unused code. 2019-07-13 23:02:07 +02:00
Andreas Kling
173edcc5ae Piano: Add to Launcher with a new 32x32 icon. :^) 2019-07-13 23:01:47 +02:00
Andreas Kling
69bafd1043 Build: Make sure we build LibAudio before AudioServer :^) 2019-07-13 22:58:36 +02:00
Robin Burchell
ffa8cb668f AudioServer: Assorted infrastructure work
* Add a LibAudio, and move WAV file parsing there (via AWavFile and AWavLoader)
* Add CLocalSocket, and CSocket::connect() variant for local address types.
  We make some small use of this in WindowServer (as that's where we
  modelled it from), but don't get too invasive as this PR is already
  quite large, and the WS I/O is a bit carefully done
* Add an AClientConnection which will eventually be used to talk to
  AudioServer (and make use of it in Piano, though right now it really
  doesn't do anything except connect, using our new CLocalSocket...)
2019-07-13 22:57:24 +02:00
Andreas Kling
983245113a SB16: Write the correct DMA buffer offset for 16-bit samples.
Also switch to using single-cycle mode for now. It would be nice to add
support for auto-initialized mode but this works okay at the moment.
2019-07-13 21:28:35 +02:00
Andreas Kling
ec7b98f079 Piano: Take down the baseline "volume" from 3000 to 1800.
I have no idea what a good value for this would be. This seems to do better
when playing many notes at once.
2019-07-13 20:54:16 +02:00
Andreas Kling
02c3c737f6 SB16: IRQ handler should send 0xd5 to pause 16-bit playback.
We were sending 0xd0 to pause 8-bit playback. Not sure if this actually
makes any difference but it seems like the correct thing to do.
Also update 'm_interrupted' *after* handling things.
2019-07-13 20:43:38 +02:00
Andreas Kling
eec9666735 Piano: Use a secondary thread to write the audio stream.
This frees up the main thread to draw the GUI. The secondary thread uses
a pipe to trick the main thread's event loop to break out of select() and
update() the PianoWidget. :^)
2019-07-13 20:20:08 +02:00
Andreas Kling
dcfa93e71f SB16: Use a snooze alarm to block the current thread while playing. 2019-07-13 20:15:17 +02:00
Andreas Kling
54e79a4640 Kernel: Make it easier to add Thread block states in the future. 2019-07-13 20:14:39 +02:00
Andreas Kling
302cae5c2f CEventLoop: When asked to exit the event loop, exit right away.
Don't process any more events. We already prepend the remaining events in
this loop to the outer loop if needed.

If there were any more events queued after the exit request, the iteration
code would make an invalid access into 'queued_events'.

Fixes #300.
2019-07-13 19:54:57 +02:00
Albert Gafiyatullin
f5a9b27f3f chmod: Add understanding of simple permission strings. (#295)
Fixes #162.
2019-07-13 19:36:02 +02:00
Andreas Kling
cf1afcafbc LibC: Protect the malloc heap with a basic lock. 2019-07-13 18:36:19 +02:00
Andreas Kling
debc587ce2 LibCore: Add CCustomEvent, a custom CEvent for arbitrary use.
For convenience it includes an int, and a void*. Interpretation of the
contents is up to the client.
2019-07-13 18:35:13 +02:00
Andreas Kling
b51f0f7bfa SB16: Put debug spam behind SB16_DEBUG. 2019-07-13 17:55:48 +02:00
Andreas Kling
48bde0393e SB16: Use Stereo samples by default. 2019-07-13 17:51:36 +02:00
Andreas Kling
d63b6e624e SB16: Send (sample count, less 1) to the DSP, not the number of bytes.
This worked fine when we were using 8-bit samples but broke on 16-bit.
2019-07-13 17:47:57 +02:00
Andreas Kling
781a28f3ed SB16: Switch to signed 16-bit 44100 Hz Mono by default.
We should switch to Stereo but I'm having some trouble with that locally..
Since we intend to mix everything through SoundServer, let's just put the
card into 16-bit mode right away.
2019-07-13 17:12:33 +02:00
Andreas Kling
c962c54610 Piano: Start working on a desktop piano.
The idea here is to implement a simple synhesizer that allows you to play
music with your keyboard. :^)

It's a huge hack currently but we can improve upon this.
2019-07-13 17:05:16 +02:00
Andreas Kling
f712ead1fb AK: Add Queue::enqueue(const T&). 2019-07-13 17:00:30 +02:00
Andreas Kling
ecbf1b673a IRCClient: Implement "/msg <nick> ..." 2019-07-13 12:02:31 +02:00
Andreas Kling
5e6c1c6912 IRCClient: Open query window immediately when created by the user.
When handling "/query nick", we now immediately switch to the new query.
2019-07-13 11:54:01 +02:00
Andreas Kling
85674aa498 WindowServer: Don't deliver the same mouse event twice.
We were sometimes delivering the same mouse event twice to the active input
window. This happened because we had already delivered it via the automatic
cursor tracking mechanism.
2019-07-13 11:50:39 +02:00
Andreas Kling
f79f3f6b8c IRCClient: Make the channel and query mappings case-insensitive.
This allows us to send a message to "nickserv" and receive a response from
"NickServ" without getting confused. :^)
2019-07-13 11:05:30 +02:00
Andreas Kling
9a7b638743 IRCClient: Process incoming NOTICE messages like PRIVMSG.
They should be handled slightly differently, but at least now we're doing
*something* withthem.
2019-07-13 11:04:41 +02:00
Andreas Kling
d9d13f2445 AK: Support case-insensitive HashMap<String, T>.
We achieve this by allowing you to specify custom traits for the key type.
For convenience, we also provide a CaseInsensitiveStringTraits for String.
2019-07-13 11:00:29 +02:00
Andreas Kling
b425de18cc LibGUI: Add an auto-repeat interval to GAbstractButton.
Use this in GSpinBox to implement auto-increment / auto-decrement while you
are pressing down the respective buttons. :^)
2019-07-13 10:27:19 +02:00
Andreas Kling
c53f6a52e0 LibC: Fix make target dependency that was breaking parallel make sometimes. 2019-07-13 08:09:53 +02:00
Robin Burchell
6c4024c04a Kernel: First cut of a sb16 driver
Also add an AudioServer that (right now) doesn't do much.
It tries to open, parse, and play a wav file. In the future, it can do more.

My general thinking here here is that /dev/audio will be "owned" by AudioServer,
and we'll do mixing in software before passing buffers off to the kernel
to play, but we have to start somewhere.
2019-07-13 08:00:24 +02:00
Andreas Kling
6e671f78a8 Painter: Don't add line spacing after the very last line in draw_text().
This means that single-line draw_text() calls don't get any additional line
spacing added. Which makes things look right.
2019-07-12 19:54:10 +02:00
Andreas Kling
33466aba65 HelloWorld: Make the demo label say "Hello\nWorld!".
This is really just to show off multi-line GLabels :^)
2019-07-12 19:54:10 +02:00
Andreas Kling
ae6615d5a0 Painter: Implement multi-line support in Painter::draw_text().
This patch makes it possible to draw_text() things like "ABC\nDEF\nGHI".
It works by breaking the string into lines, then computing a bounding rect
for all the lines, and finally aligning each line appropriately within
the bounding rect and drawing them one by one.

Fixes #297.
2019-07-12 19:53:56 +02:00
Robin Burchell
8a1a9e78d7 WSWindowManager: Ensure that we pick a single window to deliver a full stream of events to
This is effectively a mouse grab except that we don't require any client
coordination to request it (which is probably OK, and certainly a lot
simpler to implement).

This prevents e.g. dragging the mouse cursor out of paint and over the
terminal from selecting text unexpectedly.
2019-07-12 18:19:45 +02:00