From 5dc014b26106259a03b16310da5d9f3cdf3a10c3 Mon Sep 17 00:00:00 2001 From: William McPherson Date: Thu, 6 Feb 2020 22:55:38 +1100 Subject: [PATCH] Piano: Fix roll playback at startup This is not a bug currently, since the first column immediately starts playing at startup and leaves no time for the user to put notes in it. However, this is needed for exporting. --- Applications/Piano/AudioEngine.cpp | 6 ++++++ Applications/Piano/AudioEngine.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Applications/Piano/AudioEngine.cpp b/Applications/Piano/AudioEngine.cpp index d91d0180ee..8eec8938d8 100644 --- a/Applications/Piano/AudioEngine.cpp +++ b/Applications/Piano/AudioEngine.cpp @@ -45,6 +45,9 @@ void AudioEngine::fill_buffer(FixedArray& buffer) { memset(buffer.data(), 0, buffer_size); + if (m_time == 0) + set_notes_from_roll(); + for (size_t i = 0; i < buffer.size(); ++i) { for (size_t note = 0; note < note_count; ++note) { switch (m_envelope[note]) { @@ -224,7 +227,10 @@ void AudioEngine::update_roll() m_current_column = 0; if (++m_previous_column == horizontal_notes) m_previous_column = 0; +} +void AudioEngine::set_notes_from_roll() +{ for (int note = 0; note < note_count; ++note) { if (m_roll_notes[note][m_previous_column] == On) set_note((note_count - 1) - note, Off); diff --git a/Applications/Piano/AudioEngine.h b/Applications/Piano/AudioEngine.h index 229c365f1a..e722e0cfd0 100644 --- a/Applications/Piano/AudioEngine.h +++ b/Applications/Piano/AudioEngine.h @@ -74,6 +74,7 @@ private: double noise() const; void update_roll(); + void set_notes_from_roll(); void set_sustain_impl(int sustain);