From f1a93c1ce482198e42ca25b3bdce8d718c11aff7 Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 09:27:14 -0600 Subject: [PATCH 01/10] Add note labels to waterfall. --- neothesia-core/src/render/guidelines.rs | 19 ++++++++++++++++++- note_names.rs | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 note_names.rs diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 2d4e1f3e..b79e85af 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}, 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,14 @@ 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_name().to_string(), + color: [1.0, 1.0, 1.0, 1.0], + scale: 1.0, + }); } } @@ -113,6 +125,7 @@ impl GuidelineRenderer { pub fn update( &mut self, quads: &mut QuadPipeline, + texts: &mut TextPipeline, layer: usize, animation_speed: f32, time: f32, @@ -128,5 +141,9 @@ 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 From ff2185de478e07b23cc78eaf381bb4ce4bd268d5 Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:22:52 -0600 Subject: [PATCH 02/10] Add note labels to waterfall notes. --- neothesia-core/src/render/guidelines.rs | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index b79e85af..43ed8ccd 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -89,6 +89,36 @@ impl GuidelineRenderer { } } + // 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.white_keys().chain(self.layout.black_keys()) { + let x = self.pos.x + key.x(); + let y = self.pos.y; + + // Add the quad instance + quads.instances(layer).push(QuadInstance { + position: [x, y], // Position of the guideline + size: [2.0, self.layout.height()], // Thin width, full keyboard height + color: [0.2, 0.2, 0.2, 0.5], // Semi-transparent dark gray + border_radius: 0.0, // Sharp corners for guidelines + }); + + // Add text label + self.text_cache.push(TextInstance { + position: [x + 2.0, y + 2.0], // Slight offset from quad corner + text: Self::get_note_name(key.index()).to_string(), + color: [1.0, 1.0, 1.0, 1.0], // White text + scale: 0.8, + }); + } + } + #[profiling::function] fn update_horizontal_guidelines( &mut self, From dc66bd3e208988ef93f4a30a5c634259e7742f41 Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:29:37 -0600 Subject: [PATCH 03/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 43ed8ccd..f8ebd197 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,7 +1,8 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline, TextInstance}, + render::{QuadInstance, QuadPipeline}, + render::text::{TextInstance, TextPipeline}, // Move to text module utils::Point, }; @@ -82,7 +83,7 @@ impl GuidelineRenderer { // Add text instance for note label self.text_cache.push(TextInstance { position: [x, y], - text: key.note_name().to_string(), + text: key.note_id().to_string(), color: [1.0, 1.0, 1.0, 1.0], scale: 1.0, }); @@ -106,7 +107,7 @@ impl GuidelineRenderer { position: [x, y], // Position of the guideline size: [2.0, self.layout.height()], // Thin width, full keyboard height color: [0.2, 0.2, 0.2, 0.5], // Semi-transparent dark gray - border_radius: 0.0, // Sharp corners for guidelines + border_radius: [0.0, 0.0, 0.0, 0.0], // Fix: Use [f32; 4] instead of f32 }); // Add text label @@ -177,3 +178,18 @@ impl GuidelineRenderer { } } } + +impl KeyboardLayout { + pub fn white_keys(&self) -> impl Iterator { + self.keys.iter().filter(|k| !k.is_black()) + } + + pub fn black_keys(&self) -> impl Iterator { + self.keys.iter().filter(|k| k.is_black()) + } + + pub fn height(&self) -> f32 { + self.height + } +} + From 8a2d82159e376c2a8d2472f14abc8197eb38507c Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:32:11 -0600 Subject: [PATCH 04/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index f8ebd197..15ad4bcb 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -4,6 +4,7 @@ use crate::{ render::{QuadInstance, QuadPipeline}, render::text::{TextInstance, TextPipeline}, // Move to text module utils::Point, + piano_layout::{Key, KeyboardLayout}, }; pub struct GuidelineRenderer { @@ -51,7 +52,7 @@ impl GuidelineRenderer { /// Reupload instances to GPU fn reupload(&mut self) { - if !self.vertical_guidelines { + if (!self.vertical_guidelines) { return; } @@ -179,17 +180,3 @@ impl GuidelineRenderer { } } -impl KeyboardLayout { - pub fn white_keys(&self) -> impl Iterator { - self.keys.iter().filter(|k| !k.is_black()) - } - - pub fn black_keys(&self) -> impl Iterator { - self.keys.iter().filter(|k| k.is_black()) - } - - pub fn height(&self) -> f32 { - self.height - } -} - From b61d522ecda6246ab37eb5c880200b643fb43dad Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:36:50 -0600 Subject: [PATCH 05/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 15ad4bcb..6f5fb4e8 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,10 +1,8 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline}, - render::text::{TextInstance, TextPipeline}, // Move to text module + render::{QuadInstance, QuadPipeline, TextInstance, TextPipeline}, utils::Point, - piano_layout::{Key, KeyboardLayout}, }; pub struct GuidelineRenderer { @@ -52,7 +50,7 @@ impl GuidelineRenderer { /// Reupload instances to GPU fn reupload(&mut self) { - if (!self.vertical_guidelines) { + if !self.vertical_guidelines { return; } @@ -99,23 +97,21 @@ impl GuidelineRenderer { #[profiling::function] fn update_vertical_guidelines(&mut self, quads: &mut QuadPipeline, layer: usize) { - for key in self.layout.white_keys().chain(self.layout.black_keys()) { + for key in self.layout.keys.iter() { let x = self.pos.x + key.x(); let y = self.pos.y; - // Add the quad instance quads.instances(layer).push(QuadInstance { - position: [x, y], // Position of the guideline - size: [2.0, self.layout.height()], // Thin width, full keyboard height - color: [0.2, 0.2, 0.2, 0.5], // Semi-transparent dark gray - border_radius: [0.0, 0.0, 0.0, 0.0], // Fix: Use [f32; 4] instead of f32 + 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], }); - // Add text label self.text_cache.push(TextInstance { - position: [x + 2.0, y + 2.0], // Slight offset from quad corner + position: [x + 2.0, y + 2.0], text: Self::get_note_name(key.index()).to_string(), - color: [1.0, 1.0, 1.0, 1.0], // White text + color: [1.0, 1.0, 1.0, 1.0], scale: 0.8, }); } From f26e97f96bec52da17c34f4ce1ee9790e6a6a797 Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:39:09 -0600 Subject: [PATCH 06/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 6f5fb4e8..b5c1263c 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,7 +1,8 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline, TextInstance, TextPipeline}, + render::{QuadInstance, QuadPipeline}, + render::text::{Instance as TextInstance, Pipeline as TextPipeline}, utils::Point, }; @@ -110,7 +111,7 @@ impl GuidelineRenderer { self.text_cache.push(TextInstance { position: [x + 2.0, y + 2.0], - text: Self::get_note_name(key.index()).to_string(), + text: Self::get_note_name(key.note_id()).to_string(), color: [1.0, 1.0, 1.0, 1.0], scale: 0.8, }); From 7706418a30b9fac54b23f28b7d53afdf619689fd Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:40:49 -0600 Subject: [PATCH 07/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index b5c1263c..dae97268 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,8 +1,7 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline}, - render::text::{Instance as TextInstance, Pipeline as TextPipeline}, + render::{QuadInstance, QuadPipeline, text::TextInstance, text::TextPipeline}, utils::Point, }; @@ -111,7 +110,7 @@ impl GuidelineRenderer { self.text_cache.push(TextInstance { position: [x + 2.0, y + 2.0], - text: Self::get_note_name(key.note_id()).to_string(), + text: Self::get_note_name(key.note_id() as usize).to_string(), color: [1.0, 1.0, 1.0, 1.0], scale: 0.8, }); From 28a91457f0439025532549fcab18661e0454427b Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:43:30 -0600 Subject: [PATCH 08/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index dae97268..26cad423 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,7 +1,8 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline, text::TextInstance, text::TextPipeline}, + render::{QuadInstance, QuadPipeline}, + text::{TextInstance, TextPipeline}, // Fixed: moved to root text module utils::Point, }; From 21393eef6e629bb8a01b9abe9be8f16888a1eb36 Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:45:22 -0600 Subject: [PATCH 09/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 26cad423..6f9bfb9f 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration}; use crate::{ render::{QuadInstance, QuadPipeline}, - text::{TextInstance, TextPipeline}, // Fixed: moved to root text module + render::text::{TextInstance, TextPipeline}, // Fix: use render::text instead of text utils::Point, }; From a3266de29f3b0097fe762bcd3878efe2d70dd0bf Mon Sep 17 00:00:00 2001 From: Guy Chronister Date: Mon, 2 Dec 2024 16:47:29 -0600 Subject: [PATCH 10/10] Updated code. --- neothesia-core/src/render/guidelines.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neothesia-core/src/render/guidelines.rs b/neothesia-core/src/render/guidelines.rs index 6f9bfb9f..1f202f03 100644 --- a/neothesia-core/src/render/guidelines.rs +++ b/neothesia-core/src/render/guidelines.rs @@ -1,8 +1,7 @@ use std::{sync::Arc, time::Duration}; use crate::{ - render::{QuadInstance, QuadPipeline}, - render::text::{TextInstance, TextPipeline}, // Fix: use render::text instead of text + render::{QuadInstance, QuadPipeline, TextInstance, TextPipeline}, // Move text types to same level as Quad types utils::Point, };