mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
Piano: Allow multiple tracks internally
This commit adds multi-track functionality without exposing it to the user. All I really did was rename AudioEngine to Track and allow more than one Track in TrackManager. A lot of the changes are just changing widgets to take a TrackManager and use current_track(). The TrackManager creates Tracks and gives them a read-only reference to the global time value. When the TrackManager wants to fill a sample in the buffer (in fill_buffer()), it calls fill_sample() on each Track. The delay code is slightly different - a Track will fill its m_delay_buffer with the sample it just created rather than the most recent sample in the buffer (which used to be the same thing). TrackManager manages the current octave. Other than those few things, this is a pretty basic separation of concerns.
This commit is contained in:
parent
db5b28b78e
commit
ee52572ca1
18 changed files with 371 additions and 247 deletions
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "SamplerWidget.h"
|
||||
#include "AudioEngine.h"
|
||||
#include "TrackManager.h"
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/FilePicker.h>
|
||||
|
@ -33,8 +33,8 @@
|
|||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
||||
WaveEditor::WaveEditor(AudioEngine& audio_engine)
|
||||
: m_audio_engine(audio_engine)
|
||||
WaveEditor::WaveEditor(TrackManager& track_manager)
|
||||
: m_track_manager(track_manager)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ void WaveEditor::paint_event(GUI::PaintEvent& event)
|
|||
GUI::Painter painter(*this);
|
||||
painter.fill_rect(frame_inner_rect(), Color::Black);
|
||||
|
||||
auto recorded_sample = m_audio_engine.recorded_sample();
|
||||
auto recorded_sample = m_track_manager.current_track().recorded_sample();
|
||||
if (recorded_sample.is_empty())
|
||||
return;
|
||||
|
||||
|
@ -88,8 +88,8 @@ void WaveEditor::paint_event(GUI::PaintEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
|
||||
: m_audio_engine(audio_engine)
|
||||
SamplerWidget::SamplerWidget(TrackManager& track_manager)
|
||||
: m_track_manager(track_manager)
|
||||
{
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
layout()->set_margins({ 10, 10, 10, 10 });
|
||||
|
@ -111,7 +111,7 @@ SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
|
|||
Optional<String> open_path = GUI::FilePicker::get_open_filepath();
|
||||
if (!open_path.has_value())
|
||||
return;
|
||||
String error_string = m_audio_engine.set_recorded_sample(open_path.value());
|
||||
String error_string = m_track_manager.current_track().set_recorded_sample(open_path.value());
|
||||
if (!error_string.is_empty()) {
|
||||
GUI::MessageBox::show(String::format("Failed to load WAV file: %s", error_string.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
|
@ -123,7 +123,7 @@ SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
|
|||
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 = add<WaveEditor>(m_audio_engine);
|
||||
m_wave_editor = add<WaveEditor>(m_track_manager);
|
||||
m_wave_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_wave_editor->set_preferred_size(0, 100);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue