diff --git a/Applications/Piano/Music.h b/Applications/Piano/Music.h index c2736c067e..3a150944ec 100644 --- a/Applications/Piano/Music.h +++ b/Applications/Piano/Music.h @@ -208,6 +208,21 @@ constexpr int beats_per_bar = 4; constexpr int notes_per_beat = 4; constexpr int roll_length = (sample_rate / (beats_per_minute / 60)) * beats_per_bar; +constexpr const char* note_names[] = { + "C", + "C#", + "D", + "D#", + "E", + "F", + "F#", + "G", + "G#", + "A", + "A#", + "B", +}; + // Equal temperament, A = 440Hz // We calculate note frequencies relative to A4: // 440.0 * pow(pow(2.0, 1.0 / 12.0), N) diff --git a/Applications/Piano/RollWidget.cpp b/Applications/Piano/RollWidget.cpp index 255c5d0cbe..d8d0aa670e 100644 --- a/Applications/Piano/RollWidget.cpp +++ b/Applications/Piano/RollWidget.cpp @@ -29,6 +29,7 @@ #include "TrackManager.h" #include #include +#include #include constexpr int note_height = 20; @@ -122,6 +123,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) { + int y = ((note_count - 1) - note) * note_height; for (auto roll_note : m_track_manager.current_track().roll_notes(note)) { int x = m_roll_width * (static_cast(roll_note.on_sample) / roll_length); int width = m_roll_width * (static_cast(roll_note.length()) / roll_length); @@ -130,13 +132,19 @@ void RollWidget::paint_event(GUI::PaintEvent& event) if (width < 2) width = 2; - int y = ((note_count - 1) - note) * note_height; int height = note_height; Gfx::IntRect rect(x, y, width, height); painter.fill_rect(rect, note_pressed_color); painter.draw_rect(rect, Color::Black); } + Gfx::IntRect note_name_rect(3, y, 1, note_height); + const char* note_name = note_names[note % notes_per_octave]; + + painter.draw_text(note_name_rect, note_name, Gfx::TextAlignment::CenterLeft); + note_name_rect.move_by(Gfx::Font::default_font().width(note_name) + 2, 0); + if (note % notes_per_octave == 0) + painter.draw_text(note_name_rect, String::formatted("{}", note / notes_per_octave + 1), Gfx::TextAlignment::CenterLeft); } int x = m_roll_width * (static_cast(m_track_manager.time()) / roll_length);