diff options
author | William McPherson <willmcpherson2@gmail.com> | 2020-02-08 17:04:05 +1100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-10 14:04:27 +0100 |
commit | 9997b0dbf59557687a7a9fb4103dd001387e134f (patch) | |
tree | a458ec19658143849f5249c6ff0249bfc0e7bf4e /Applications/Piano/MainWidget.cpp | |
parent | 591870c7b428ed9e268f64607202611b75313ffa (diff) | |
download | serenity-9997b0dbf59557687a7a9fb4103dd001387e134f.zip |
Piano: Add sampler
This commit adds basic support for importing, viewing and playing WAV
samples at different pitches.
Naming issues:
- We are using the Sample struct from Music.h, but also the Sample
struct from LibAudio (Audio::Sample). This is a little confusing.
set_recorded_sample() finds the peak sample and then divides all the
samples by that peak to get a guaranteed min/max of -1/1. This is nice
because our other waves are also bound between these values and we can
just do the same stuff. This is why we're using Audio::Sample, because
it uses floats, whereas Music.h's Sample uses i16s. It's a little
annoying that we have to use a mixture of floats and doubles though.
For playback at lower frequencies, we're calculating in-between samples,
rather than just playing samples multiple times. Basically, you get the
current sample and add the difference between the current sample and the
next sample multiplied by the distance from the current sample. This is
like drawing the hypotenuse of a right-angled triangle.
Diffstat (limited to 'Applications/Piano/MainWidget.cpp')
-rw-r--r-- | Applications/Piano/MainWidget.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Applications/Piano/MainWidget.cpp b/Applications/Piano/MainWidget.cpp index c1db1e21a3..a119769f78 100644 --- a/Applications/Piano/MainWidget.cpp +++ b/Applications/Piano/MainWidget.cpp @@ -30,8 +30,10 @@ #include "KeysWidget.h" #include "KnobsWidget.h" #include "RollWidget.h" +#include "SamplerWidget.h" #include "WaveWidget.h" #include <LibGUI/BoxLayout.h> +#include <LibGUI/TabWidget.h> MainWidget::MainWidget(AudioEngine& audio_engine) : m_audio_engine(audio_engine) @@ -45,10 +47,16 @@ MainWidget::MainWidget(AudioEngine& audio_engine) m_wave_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_wave_widget->set_preferred_size(0, 100); - m_roll_widget = RollWidget::construct(this, audio_engine); + m_roll_widget = RollWidget::construct(nullptr, audio_engine); m_roll_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); m_roll_widget->set_preferred_size(0, 300); + m_sampler_widget = SamplerWidget::construct(nullptr, audio_engine); + + m_tab_widget = GUI::TabWidget::construct(this); + m_tab_widget->add_widget("Piano Roll", m_roll_widget); + m_tab_widget->add_widget("Sampler", m_sampler_widget); + m_keys_and_knobs_container = GUI::Widget::construct(this); m_keys_and_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_keys_and_knobs_container->layout()->set_spacing(2); |