diff options
author | William McPherson <willmcpherson2@gmail.com> | 2020-02-06 19:13:25 +1100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-06 19:13:53 +0100 |
commit | 9a05bbaaced69d2c55f5aa9f0ecfa4ae21bd461a (patch) | |
tree | 30a1daaecfd8adfee19a971280d2dee01d3ad204 /Applications/Piano/RollWidget.cpp | |
parent | 82d17d2c79e8a680a211fbfd370fc257b6ea494a (diff) | |
download | serenity-9a05bbaaced69d2c55f5aa9f0ecfa4ae21bd461a.zip |
Piano: Move piano roll internals to AudioEngine
The piano roll data definitely belongs in AudioEngine along with the
note and time data. Now RollWidget only has GUI information, much like
the other widgets.
Note that this commit exacerbates issue #1158 which is caused by
RollWidget::paint_event().
Diffstat (limited to 'Applications/Piano/RollWidget.cpp')
-rw-r--r-- | Applications/Piano/RollWidget.cpp | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/Applications/Piano/RollWidget.cpp b/Applications/Piano/RollWidget.cpp index 8b2a8f93cd..12e5e9a9db 100644 --- a/Applications/Piano/RollWidget.cpp +++ b/Applications/Piano/RollWidget.cpp @@ -53,7 +53,7 @@ RollWidget::~RollWidget() void RollWidget::paint_event(GUI::PaintEvent& event) { int roll_width = widget_inner_rect().width(); - double note_width = static_cast<double>(roll_width) / m_horizontal_notes; + double note_width = static_cast<double>(roll_width) / horizontal_notes; set_content_size({ roll_width, roll_height }); @@ -74,7 +74,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event) for (int y = 0; y < notes_to_paint; ++y) { int y_pos = y * note_height; - for (int x = 0; x < m_horizontal_notes; ++x) { + for (int x = 0; x < horizontal_notes; ++x) { // This is needed to avoid rounding errors. You can't just use // note_width as the width. int x_pos = x * note_width; @@ -82,9 +82,9 @@ void RollWidget::paint_event(GUI::PaintEvent& event) int distance_to_next_x = next_x_pos - x_pos; Gfx::Rect rect(x_pos, y_pos, distance_to_next_x, note_height); - if (m_roll_notes[y + note_offset][x] == On) + if (m_audio_engine.roll_note(y + note_offset, x) == On) painter.fill_rect(rect, note_pressed_color); - else if (x == m_current_column) + else if (x == m_audio_engine.current_column()) painter.fill_rect(rect, column_playing_color); else if (key_pattern[key_pattern_index] == Black) painter.fill_rect(rect, Color::LightGray); @@ -108,7 +108,7 @@ void RollWidget::mousedown_event(GUI::MouseEvent& event) return; int roll_width = widget_inner_rect().width(); - double note_width = static_cast<double>(roll_width) / m_horizontal_notes; + double note_width = static_cast<double>(roll_width) / horizontal_notes; int y = (event.y() + vertical_scrollbar().value()) - frame_thickness(); y /= note_height; @@ -125,30 +125,7 @@ void RollWidget::mousedown_event(GUI::MouseEvent& event) ++x; x /= note_width; - if (m_roll_notes[y][x] == On) { - if (x == m_current_column) // If you turn off a note that is playing. - m_audio_engine.set_note((note_count - 1) - y, Off); - m_roll_notes[y][x] = Off; - } else { - m_roll_notes[y][x] = On; - } - - update(); -} - -void RollWidget::update_roll() -{ - if (++m_current_column == m_horizontal_notes) - m_current_column = 0; - if (++m_previous_column == m_horizontal_notes) - m_previous_column = 0; - - for (int note = 0; note < note_count; ++note) { - if (m_roll_notes[note][m_previous_column] == On) - m_audio_engine.set_note((note_count - 1) - note, Off); - if (m_roll_notes[note][m_current_column] == On) - m_audio_engine.set_note((note_count - 1) - note, On); - } + m_audio_engine.set_roll_note(y, x, m_audio_engine.roll_note(y, x) == On ? Off : On); update(); } |