mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:15:09 +00:00
SoundPlayer: Start working on a GUI sound player application
This can play anything that AWavLoader can load (so obviously only WAV files at the moment.) It works by having a timer that wakes up every 100ms and tries to send a sample buffer to the AudioServer. If our server-side queue is full then we wait until the next timer iteration and try again. We display the most recently enqueued sample buffer in a nice little widget that just plots the samples in green-on-black. :^)
This commit is contained in:
parent
6693e56603
commit
1188a036e9
6 changed files with 148 additions and 0 deletions
45
Applications/SoundPlayer/SampleWidget.cpp
Normal file
45
Applications/SoundPlayer/SampleWidget.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "SampleWidget.h"
|
||||
#include <LibAudio/ABuffer.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
||||
SampleWidget::SampleWidget(GWidget* parent)
|
||||
: GFrame(parent)
|
||||
{
|
||||
set_frame_shape(FrameShape::Container);
|
||||
set_frame_shadow(FrameShadow::Sunken);
|
||||
set_frame_thickness(2);
|
||||
}
|
||||
|
||||
SampleWidget::~SampleWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void SampleWidget::paint_event(GPaintEvent& event)
|
||||
{
|
||||
GFrame::paint_event(event);
|
||||
GPainter painter(*this);
|
||||
painter.add_clip_rect(event.rect());
|
||||
|
||||
painter.fill_rect(frame_inner_rect(), Color::Black);
|
||||
|
||||
if (!m_buffer)
|
||||
return;
|
||||
|
||||
// FIXME: Right now we only display as many samples from the buffer as we can fit
|
||||
// in the frame_inner_rect(). Maybe scale the samples or something?
|
||||
int samples_to_draw = min(m_buffer->sample_count(), frame_inner_rect().width());
|
||||
for (int x = 0; x < samples_to_draw; ++x) {
|
||||
// FIXME: This might look nicer if drawn as lines.
|
||||
auto& sample = m_buffer->samples()[x];
|
||||
Point p = { x, frame_inner_rect().center().y() + (int)(sample.left * frame_inner_rect().height()) };
|
||||
painter.set_pixel(p, Color::Green);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleWidget::set_buffer(ABuffer* buffer)
|
||||
{
|
||||
if (m_buffer == buffer)
|
||||
return;
|
||||
m_buffer = buffer;
|
||||
update();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue