diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 2d4e1f3e..1f202f03 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,7 +1,7 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline}, + render::{QuadInstance, QuadPipeline, TextInstance, TextPipeline}, // Move text types to same level as Quad types utils::Point, }; @@ -13,6 +13,7 @@ pub struct GuidelineRenderer { horizontal_guidelines: bool, cache: Vec, + text_cache: Vec, measures: Arc<[Duration]>, } @@ -30,6 +31,7 @@ impl GuidelineRenderer { vertical_guidelines, horizontal_guidelines, cache: Vec::new(), + text_cache: Vec::new(), measures, } } @@ -37,11 +39,13 @@ impl GuidelineRenderer { pub fn set_pos(&mut self, pos: Point) { self.pos = pos; self.cache.clear(); + self.text_cache.clear(); } pub fn set_layout(&mut self, layout: piano_layout::KeyboardLayout) { self.layout = layout; self.cache.clear(); + self.text_cache.clear(); } /// Reupload instances to GPU @@ -74,6 +78,42 @@ impl GuidelineRenderer { color, border_radius: [0.0, 0.0, 0.0, 0.0], }); + + // Add text instance for note label + self.text_cache.push(TextInstance { + position: [x, y], + text: key.note_id().to_string(), + color: [1.0, 1.0, 1.0, 1.0], + scale: 1.0, + }); + } + } + + // Helper method to convert key index to note name + fn get_note_name(key_index: usize) -> &'static str { + const NOTE_NAMES: [&str; 12] = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]; + NOTE_NAMES[key_index % 12] + } + + #[profiling::function] + fn update_vertical_guidelines(&mut self, quads: &mut QuadPipeline, layer: usize) { + for key in self.layout.keys.iter() { + let x = self.pos.x + key.x(); + let y = self.pos.y; + + quads.instances(layer).push(QuadInstance { + position: [x, y], + size: [2.0, self.layout.height], // Use height field directly + color: [0.2, 0.2, 0.2, 0.5], + border_radius: [0.0, 0.0, 0.0, 0.0], + }); + + self.text_cache.push(TextInstance { + position: [x + 2.0, y + 2.0], + text: Self::get_note_name(key.note_id() as usize).to_string(), + color: [1.0, 1.0, 1.0, 1.0], + scale: 0.8, + }); } } @@ -113,6 +153,7 @@ impl GuidelineRenderer { pub fn update( &mut self, quads: &mut QuadPipeline, + texts: &mut TextPipeline, layer: usize, animation_speed: f32, time: f32, @@ -128,5 +169,10 @@ impl GuidelineRenderer { for quad in self.cache.iter() { quads.instances(layer).push(*quad); } + + for text in self.text_cache.iter() { + texts.instances(layer).push(*text); + } } } + diff --git a/note_names.rs b/note_names.rs new file mode 100644 index 00000000..4f514e76 --- /dev/null +++ b/note_names.rs @@ -0,0 +1,2 @@ +pub fn get_note_name(midi_note: u8) -> String { + const NOTE_NAMES: [&str; \ No newline at end of file