diff options
author | William McPherson <willmcpherson2@gmail.com> | 2020-06-15 15:33:53 +1000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-18 16:42:37 +0200 |
commit | ee52572ca1bc382e6ccaf8e59e02db2b15157ac8 (patch) | |
tree | 4b106893b9343cba066a076c9a943cc2a714e410 /Applications/Piano/RollWidget.cpp | |
parent | db5b28b78ef64ab28eee7bc3f237241223e31f20 (diff) | |
download | serenity-ee52572ca1bc382e6ccaf8e59e02db2b15157ac8.zip |
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.
Diffstat (limited to 'Applications/Piano/RollWidget.cpp')
-rw-r--r-- | Applications/Piano/RollWidget.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Applications/Piano/RollWidget.cpp b/Applications/Piano/RollWidget.cpp index d9968225d9..738bef8f9e 100644 --- a/Applications/Piano/RollWidget.cpp +++ b/Applications/Piano/RollWidget.cpp @@ -26,7 +26,7 @@ */ #include "RollWidget.h" -#include "AudioEngine.h" +#include "TrackManager.h" #include <LibGUI/Painter.h> #include <LibGUI/ScrollBar.h> #include <math.h> @@ -37,8 +37,8 @@ constexpr int roll_height = note_count * note_height; constexpr int horizontal_scroll_sensitivity = 20; constexpr int max_zoom = 1 << 8; -RollWidget::RollWidget(AudioEngine& audio_engine) - : m_audio_engine(audio_engine) +RollWidget::RollWidget(TrackManager& track_manager) + : m_track_manager(track_manager) { set_should_hide_unnecessary_scrollbars(true); set_content_size({ 0, roll_height }); @@ -117,7 +117,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event) painter.translate(horizontal_note_offset_remainder, note_offset_remainder); for (int note = note_count - (note_offset + notes_to_paint); note <= (note_count - 1) - note_offset; ++note) { - for (auto roll_note : m_audio_engine.roll_notes(note)) { + for (auto roll_note : m_track_manager.current_track().roll_notes(note)) { int x = m_roll_width * (static_cast<double>(roll_note.on_sample) / roll_length); int width = m_roll_width * (static_cast<double>(roll_note.length()) / roll_length); if (x + width < x_offset || x > x_offset + widget_inner_rect().width()) @@ -134,7 +134,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event) } } - int x = m_roll_width * (static_cast<double>(m_audio_engine.time()) / roll_length); + int x = m_roll_width * (static_cast<double>(m_track_manager.time()) / roll_length); if (x > x_offset && x <= x_offset + widget_inner_rect().width()) painter.draw_line({ x, 0 }, { x, roll_height }, Gfx::Color::Black); @@ -164,7 +164,7 @@ void RollWidget::mousedown_event(GUI::MouseEvent& event) int note = (note_count - 1) - y; u32 on_sample = roll_length * (static_cast<double>(x) / m_num_notes); u32 off_sample = (roll_length * (static_cast<double>(x + 1) / m_num_notes)) - 1; - m_audio_engine.set_roll_note(note, on_sample, off_sample); + m_track_manager.current_track().set_roll_note(note, on_sample, off_sample); update(); } |