summaryrefslogtreecommitdiff
path: root/Applications/Piano/PianoWidget.h
diff options
context:
space:
mode:
authorWilliam McPherson <willmcpherson2@gmail.com>2019-12-23 20:46:15 +1100
committerAndreas Kling <awesomekling@gmail.com>2019-12-23 15:08:15 +0100
commit7c8bbea995d9e2a5580c66cca7e8a56f65329fc2 (patch)
treef6a15da45b6379bbeb8668fd04529ffb9c2414ed /Applications/Piano/PianoWidget.h
parentebaadda6bd44cc68b2b96eb4afe990c9b2e7b993 (diff)
downloadserenity-7c8bbea995d9e2a5580c66cca7e8a56f65329fc2.zip
Piano: Add piano roll
m_roll_notes[] is an array of 2 bools, pressed and playing. A roll note is highlighted if it is pressed or in the currently playing column, but the note is only actually played if the roll note is both pressed and playing. We change columns every m_tick which is currently 10 frames. The delay is synchronised with this. change_roll_column() tracks the previous column and current column to be played. Each roll note in the previous column is set to "not playing" and the underlying audio note is turned off if it was pressed. For the current column, each roll note is set to playing and the underlying audio note is turned on if pressed.
Diffstat (limited to 'Applications/Piano/PianoWidget.h')
-rw-r--r--Applications/Piano/PianoWidget.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/Applications/Piano/PianoWidget.h b/Applications/Piano/PianoWidget.h
index f8c1679df7..9e15607409 100644
--- a/Applications/Piano/PianoWidget.h
+++ b/Applications/Piano/PianoWidget.h
@@ -28,13 +28,24 @@ private:
double w_triangle(size_t);
double w_noise();
+ struct RollNote {
+ bool pressed;
+ bool playing;
+ };
+
Rect define_piano_key_rect(int index, PianoKey) const;
PianoKey find_key_for_relative_position(int x, int y) const;
+ Rect define_roll_note_rect(int column, int row) const;
+ RollNote* find_roll_note_for_relative_position(int x, int y);
void render_piano_key(GPainter&, int index, PianoKey, const StringView&);
void render_piano(GPainter&);
void render_knobs(GPainter&);
void render_knob(GPainter&, const Rect&, bool state, const StringView&);
+ void render_roll_note(GPainter&, int column, int row, PianoKey);
+ void render_roll(GPainter&);
+
+ void change_roll_column();
enum SwitchNote {
Off,
@@ -73,4 +84,9 @@ private:
PianoKey m_piano_key_under_mouse { K_None };
bool m_mouse_pressed { false };
+
+ RollNote m_roll_notes[20][32] { { false, false } };
+
+ int m_time { 0 };
+ int m_tick { 10 };
};