summaryrefslogtreecommitdiff
path: root/Applications/Piano
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-23 10:57:42 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-23 11:10:52 +0100
commit3d20da9ee451460b6e233f5efdf5a13e11525f97 (patch)
tree524b72d0874304c68036dbbc0514b632a4a08c59 /Applications/Piano
parent7ec758773cdd85755d91f52614f361e7e750c7e9 (diff)
downloadserenity-3d20da9ee451460b6e233f5efdf5a13e11525f97.zip
Userspace: Use Core::Object::add() when building interfaces
Diffstat (limited to 'Applications/Piano')
-rw-r--r--Applications/Piano/KeysWidget.cpp5
-rw-r--r--Applications/Piano/KeysWidget.h2
-rw-r--r--Applications/Piano/KnobsWidget.cpp53
-rw-r--r--Applications/Piano/KnobsWidget.h2
-rw-r--r--Applications/Piano/MainWidget.cpp14
-rw-r--r--Applications/Piano/RollWidget.cpp5
-rw-r--r--Applications/Piano/RollWidget.h2
-rw-r--r--Applications/Piano/SamplerWidget.cpp18
-rw-r--r--Applications/Piano/SamplerWidget.h4
-rw-r--r--Applications/Piano/WaveWidget.cpp5
-rw-r--r--Applications/Piano/WaveWidget.h2
11 files changed, 53 insertions, 59 deletions
diff --git a/Applications/Piano/KeysWidget.cpp b/Applications/Piano/KeysWidget.cpp
index c048c6eb15..9fd8779d5a 100644
--- a/Applications/Piano/KeysWidget.cpp
+++ b/Applications/Piano/KeysWidget.cpp
@@ -29,9 +29,8 @@
#include "AudioEngine.h"
#include <LibGUI/Painter.h>
-KeysWidget::KeysWidget(GUI::Widget* parent, AudioEngine& audio_engine)
- : GUI::Frame(parent)
- , m_audio_engine(audio_engine)
+KeysWidget::KeysWidget(AudioEngine& audio_engine)
+ : m_audio_engine(audio_engine)
{
set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken);
diff --git a/Applications/Piano/KeysWidget.h b/Applications/Piano/KeysWidget.h
index 2676bffe85..ee46e2b1a2 100644
--- a/Applications/Piano/KeysWidget.h
+++ b/Applications/Piano/KeysWidget.h
@@ -43,7 +43,7 @@ public:
void set_key(int key, Switch);
private:
- KeysWidget(GUI::Widget* parent, AudioEngine&);
+ explicit KeysWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
diff --git a/Applications/Piano/KnobsWidget.cpp b/Applications/Piano/KnobsWidget.cpp
index f817b58db3..c272ff80e8 100644
--- a/Applications/Piano/KnobsWidget.cpp
+++ b/Applications/Piano/KnobsWidget.cpp
@@ -32,9 +32,8 @@
#include <LibGUI/Label.h>
#include <LibGUI/Slider.h>
-KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWidget& main_widget)
- : GUI::Frame(parent)
- , m_audio_engine(audio_engine)
+KnobsWidget::KnobsWidget(AudioEngine& audio_engine, MainWidget& main_widget)
+ : m_audio_engine(audio_engine)
, m_main_widget(main_widget)
{
set_frame_thickness(2);
@@ -43,38 +42,38 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
set_layout(make<GUI::VerticalBoxLayout>());
set_fill_with_background_color(true);
- m_labels_container = GUI::Widget::construct(this);
+ m_labels_container = add<GUI::Widget>();
m_labels_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_labels_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_labels_container->set_preferred_size(0, 20);
- m_octave_label = GUI::Label::construct("Octave", m_labels_container);
- m_wave_label = GUI::Label::construct("Wave", m_labels_container);
- m_attack_label = GUI::Label::construct("Attack", m_labels_container);
- m_decay_label = GUI::Label::construct("Decay", m_labels_container);
- m_sustain_label = GUI::Label::construct("Sustain", m_labels_container);
- m_release_label = GUI::Label::construct("Release", m_labels_container);
- m_delay_label = GUI::Label::construct("Delay", m_labels_container);
+ m_octave_label = m_labels_container->add<GUI::Label>("Octave");
+ m_wave_label = m_labels_container->add<GUI::Label>("Wave");
+ m_attack_label = m_labels_container->add<GUI::Label>("Attack");
+ m_decay_label = m_labels_container->add<GUI::Label>("Decay");
+ m_sustain_label = m_labels_container->add<GUI::Label>("Sustain");
+ m_release_label = m_labels_container->add<GUI::Label>("Release");
+ m_delay_label = m_labels_container->add<GUI::Label>("Delay");
- m_values_container = GUI::Widget::construct(this);
+ m_values_container = add<GUI::Widget>();
m_values_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_values_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_values_container->set_preferred_size(0, 10);
- m_octave_value = GUI::Label::construct(String::number(m_audio_engine.octave()), m_values_container);
- m_wave_value = GUI::Label::construct(wave_strings[m_audio_engine.wave()], m_values_container);
- m_attack_value = GUI::Label::construct(String::number(m_audio_engine.attack()), m_values_container);
- m_decay_value = GUI::Label::construct(String::number(m_audio_engine.decay()), m_values_container);
- m_sustain_value = GUI::Label::construct(String::number(m_audio_engine.sustain()), m_values_container);
- m_release_value = GUI::Label::construct(String::number(m_audio_engine.release()), m_values_container);
- m_delay_value = GUI::Label::construct(String::number(m_audio_engine.delay() / m_audio_engine.tick()), m_values_container);
+ m_octave_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.octave()));
+ m_wave_value = m_values_container->add<GUI::Label>(wave_strings[m_audio_engine.wave()]);
+ m_attack_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.attack()));
+ m_decay_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.decay()));
+ m_sustain_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.sustain()));
+ m_release_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.release()));
+ m_delay_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.delay() / m_audio_engine.tick()));
- m_knobs_container = GUI::Widget::construct(this);
+ m_knobs_container = add<GUI::Widget>();
m_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>());
// FIXME: Implement vertical flipping in GSlider, not here.
- m_octave_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_octave_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_octave_knob->set_tooltip("Z: octave down, X: octave up");
m_octave_knob->set_range(octave_min - 1, octave_max - 1);
m_octave_knob->set_value((octave_max - 1) - (m_audio_engine.octave() - 1));
@@ -86,7 +85,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
m_octave_value->set_text(String::number(new_octave));
};
- m_wave_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_wave_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_wave_knob->set_tooltip("C: cycle through waveforms");
m_wave_knob->set_range(0, last_wave);
m_wave_knob->set_value(last_wave - m_audio_engine.wave());
@@ -98,7 +97,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
};
constexpr int max_attack = 1000;
- m_attack_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_attack_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_attack_knob->set_range(0, max_attack);
m_attack_knob->set_value(max_attack - m_audio_engine.attack());
m_attack_knob->set_step(100);
@@ -110,7 +109,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
};
constexpr int max_decay = 1000;
- m_decay_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_decay_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_decay_knob->set_range(0, max_decay);
m_decay_knob->set_value(max_decay - m_audio_engine.decay());
m_decay_knob->set_step(100);
@@ -122,7 +121,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
};
constexpr int max_sustain = 1000;
- m_sustain_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_sustain_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_sustain_knob->set_range(0, max_sustain);
m_sustain_knob->set_value(max_sustain - m_audio_engine.sustain());
m_sustain_knob->set_step(100);
@@ -134,7 +133,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
};
constexpr int max_release = 1000;
- m_release_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_release_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_release_knob->set_range(0, max_release);
m_release_knob->set_value(max_release - m_audio_engine.release());
m_release_knob->set_step(100);
@@ -146,7 +145,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
};
constexpr int max_delay = 8;
- m_delay_knob = GUI::VerticalSlider::construct(m_knobs_container);
+ m_delay_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_delay_knob->set_range(0, max_delay);
m_delay_knob->set_value(max_delay - (m_audio_engine.delay() / m_audio_engine.tick()));
m_delay_knob->on_value_changed = [this](int value) {
diff --git a/Applications/Piano/KnobsWidget.h b/Applications/Piano/KnobsWidget.h
index 853039fed5..315141144e 100644
--- a/Applications/Piano/KnobsWidget.h
+++ b/Applications/Piano/KnobsWidget.h
@@ -40,7 +40,7 @@ public:
void update_knobs();
private:
- KnobsWidget(GUI::Widget* parent, AudioEngine&, MainWidget&);
+ KnobsWidget(AudioEngine&, MainWidget&);
AudioEngine& m_audio_engine;
MainWidget& m_main_widget;
diff --git a/Applications/Piano/MainWidget.cpp b/Applications/Piano/MainWidget.cpp
index a119769f78..c70747d4c4 100644
--- a/Applications/Piano/MainWidget.cpp
+++ b/Applications/Piano/MainWidget.cpp
@@ -43,30 +43,30 @@ MainWidget::MainWidget(AudioEngine& audio_engine)
layout()->set_margins({ 2, 2, 2, 2 });
set_fill_with_background_color(true);
- m_wave_widget = WaveWidget::construct(this, audio_engine);
+ m_wave_widget = add<WaveWidget>(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(nullptr, audio_engine);
+ m_roll_widget = RollWidget::construct(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_sampler_widget = SamplerWidget::construct(audio_engine);
- m_tab_widget = GUI::TabWidget::construct(this);
+ m_tab_widget = add<GUI::TabWidget>();
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 = add<GUI::Widget>();
m_keys_and_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_keys_and_knobs_container->layout()->set_spacing(2);
m_keys_and_knobs_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_keys_and_knobs_container->set_preferred_size(0, 100);
m_keys_and_knobs_container->set_fill_with_background_color(true);
- m_keys_widget = KeysWidget::construct(m_keys_and_knobs_container, audio_engine);
+ m_keys_widget = m_keys_and_knobs_container->add<KeysWidget>(audio_engine);
- m_knobs_widget = KnobsWidget::construct(m_keys_and_knobs_container, audio_engine, *this);
+ m_knobs_widget = m_keys_and_knobs_container->add<KnobsWidget>(audio_engine, *this);
m_knobs_widget->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_knobs_widget->set_preferred_size(350, 0);
}
diff --git a/Applications/Piano/RollWidget.cpp b/Applications/Piano/RollWidget.cpp
index 6eb72573c6..8efb6dd671 100644
--- a/Applications/Piano/RollWidget.cpp
+++ b/Applications/Piano/RollWidget.cpp
@@ -33,9 +33,8 @@
constexpr int note_height = 20;
constexpr int roll_height = note_count * note_height;
-RollWidget::RollWidget(GUI::Widget* parent, AudioEngine& audio_engine)
- : ScrollableWidget(parent)
- , m_audio_engine(audio_engine)
+RollWidget::RollWidget(AudioEngine& audio_engine)
+ : m_audio_engine(audio_engine)
{
set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken);
diff --git a/Applications/Piano/RollWidget.h b/Applications/Piano/RollWidget.h
index 980ed70b76..e83597931a 100644
--- a/Applications/Piano/RollWidget.h
+++ b/Applications/Piano/RollWidget.h
@@ -38,7 +38,7 @@ public:
virtual ~RollWidget() override;
private:
- RollWidget(GUI::Widget* parent, AudioEngine&);
+ explicit RollWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent& event) override;
diff --git a/Applications/Piano/SamplerWidget.cpp b/Applications/Piano/SamplerWidget.cpp
index ce9d1f7f9c..ea227659b9 100644
--- a/Applications/Piano/SamplerWidget.cpp
+++ b/Applications/Piano/SamplerWidget.cpp
@@ -33,9 +33,8 @@
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
-WaveEditor::WaveEditor(GUI::Widget* parent, AudioEngine& audio_engine)
- : GUI::Frame(parent)
- , m_audio_engine(audio_engine)
+WaveEditor::WaveEditor(AudioEngine& audio_engine)
+ : m_audio_engine(audio_engine)
{
set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken);
@@ -92,9 +91,8 @@ void WaveEditor::paint_event(GUI::PaintEvent& event)
}
}
-SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine)
- : GUI::Frame(parent)
- , m_audio_engine(audio_engine)
+SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
+ : m_audio_engine(audio_engine)
{
set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken);
@@ -104,13 +102,13 @@ SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine)
layout()->set_spacing(10);
set_fill_with_background_color(true);
- m_open_button_and_recorded_sample_name_container = GUI::Widget::construct(this);
+ m_open_button_and_recorded_sample_name_container = add<GUI::Widget>();
m_open_button_and_recorded_sample_name_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_open_button_and_recorded_sample_name_container->layout()->set_spacing(10);
m_open_button_and_recorded_sample_name_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_open_button_and_recorded_sample_name_container->set_preferred_size(0, 24);
- m_open_button = GUI::Button::construct(m_open_button_and_recorded_sample_name_container);
+ m_open_button = m_open_button_and_recorded_sample_name_container->add<GUI::Button>();
m_open_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
m_open_button->set_preferred_size(24, 24);
m_open_button->set_focusable(false);
@@ -128,10 +126,10 @@ SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine)
m_wave_editor->update();
};
- m_recorded_sample_name = GUI::Label::construct("No sample loaded", m_open_button_and_recorded_sample_name_container);
+ m_recorded_sample_name = m_open_button_and_recorded_sample_name_container->add<GUI::Label>("No sample loaded");
m_recorded_sample_name->set_text_alignment(Gfx::TextAlignment::CenterLeft);
- m_wave_editor = WaveEditor::construct(this, m_audio_engine);
+ m_wave_editor = add<WaveEditor>(m_audio_engine);
m_wave_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_wave_editor->set_preferred_size(0, 100);
}
diff --git a/Applications/Piano/SamplerWidget.h b/Applications/Piano/SamplerWidget.h
index 1db504dbd2..11c4ec90db 100644
--- a/Applications/Piano/SamplerWidget.h
+++ b/Applications/Piano/SamplerWidget.h
@@ -36,7 +36,7 @@ public:
virtual ~WaveEditor() override;
private:
- WaveEditor(GUI::Widget* parent, AudioEngine&);
+ explicit WaveEditor(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override;
@@ -51,7 +51,7 @@ public:
virtual ~SamplerWidget() override;
private:
- SamplerWidget(GUI::Widget* parent, AudioEngine&);
+ explicit SamplerWidget(AudioEngine&);
AudioEngine& m_audio_engine;
diff --git a/Applications/Piano/WaveWidget.cpp b/Applications/Piano/WaveWidget.cpp
index 1d592b60d2..434f51cf4d 100644
--- a/Applications/Piano/WaveWidget.cpp
+++ b/Applications/Piano/WaveWidget.cpp
@@ -30,9 +30,8 @@
#include <LibGUI/Painter.h>
#include <limits>
-WaveWidget::WaveWidget(GUI::Widget* parent, AudioEngine& audio_engine)
- : GUI::Frame(parent)
- , m_audio_engine(audio_engine)
+WaveWidget::WaveWidget(AudioEngine& audio_engine)
+ : m_audio_engine(audio_engine)
{
set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken);
diff --git a/Applications/Piano/WaveWidget.h b/Applications/Piano/WaveWidget.h
index 0ead14fed9..41475eaa11 100644
--- a/Applications/Piano/WaveWidget.h
+++ b/Applications/Piano/WaveWidget.h
@@ -37,7 +37,7 @@ public:
virtual ~WaveWidget() override;
private:
- WaveWidget(GUI::Widget* parent, AudioEngine&);
+ explicit WaveWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override;