From d3ade502bfae2d9eb19d315492d18ee3dcfd2e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Mary=C5=84czak?= Date: Thu, 28 Sep 2023 22:54:37 +0200 Subject: [PATCH] WIP Horizontal guidelines (#91) * WIP Horizontal guidelines * Add guidelines config * Use new guidelines config in render --- neothesia-cli/src/main.rs | 7 ++++- neothesia-core/src/config.rs | 8 +++++ neothesia-core/src/render/keyboard/mod.rs | 28 ++++++++++++++++++ .../src/scene/menu_scene/iced_menu/mod.rs | 29 ++++++++++++++++--- neothesia/src/scene/playing_scene/keyboard.rs | 7 ++++- 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/neothesia-cli/src/main.rs b/neothesia-cli/src/main.rs index fafbe4c1..2f2d4587 100644 --- a/neothesia-cli/src/main.rs +++ b/neothesia-cli/src/main.rs @@ -72,7 +72,12 @@ impl Recorder { let keyboard_layout = get_layout(width as f32, height as f32); - let mut keyboard = KeyboardRenderer::new(&gpu, &transform_uniform, keyboard_layout.clone()); + let mut keyboard = KeyboardRenderer::new( + &gpu, + &transform_uniform, + keyboard_layout.clone(), + config.vertical_guidelines, + ); keyboard.position_on_bottom_of_parent(height as f32); diff --git a/neothesia-core/src/config.rs b/neothesia-core/src/config.rs index 56614e93..e7cce1ac 100644 --- a/neothesia-core/src/config.rs +++ b/neothesia-core/src/config.rs @@ -23,6 +23,9 @@ pub struct Config { #[serde(skip_serializing)] pub play_along: bool, + #[serde(default = "default_vertical_guidelines")] + pub vertical_guidelines: bool, + #[serde(default = "default_color_schema")] pub color_schema: Vec, @@ -66,6 +69,7 @@ impl Config { animation_speed: default_animation_speed(), playback_offset: default_playback_offset(), play_along: default_play_along(), + vertical_guidelines: default_vertical_guidelines(), color_schema: default_color_schema(), background_color: Default::default(), output: default_output(), @@ -111,6 +115,10 @@ fn default_play_along() -> bool { false } +fn default_vertical_guidelines() -> bool { + false +} + fn default_color_schema() -> Vec { vec![ ColorSchema { diff --git a/neothesia-core/src/render/keyboard/mod.rs b/neothesia-core/src/render/keyboard/mod.rs index 9a7a6a14..021348fb 100644 --- a/neothesia-core/src/render/keyboard/mod.rs +++ b/neothesia-core/src/render/keyboard/mod.rs @@ -21,6 +21,7 @@ pub struct KeyboardRenderer { should_reupload: bool, layout: piano_math::KeyboardLayout, + vertical_guidelines: bool, } impl KeyboardRenderer { @@ -28,6 +29,7 @@ impl KeyboardRenderer { gpu: &Gpu, transform_uniform: &Uniform, layout: piano_math::KeyboardLayout, + vertical_guidelines: bool, ) -> Self { let quad_pipeline = QuadPipeline::new(gpu, transform_uniform); let key_states: Vec = layout @@ -45,6 +47,7 @@ impl KeyboardRenderer { should_reupload: false, layout, + vertical_guidelines, } } @@ -114,6 +117,31 @@ impl KeyboardRenderer { let id = key.id(); let color = self.key_states[id].color(); + if self.vertical_guidelines { + // Horizontal guides + // TODO: Does not really fit in keyboard renderer + if key.note_id() == 0 || key.note_id() == 5 { + let x = self.pos.x + key.x(); + let y = 0.0; + + let w = 1.0; + let h = f32::MAX; + + let color = if key.note_id() == 0 { + [0.2, 0.2, 0.2, 1.0] + } else { + [0.05, 0.05, 0.05, 1.0] + }; + + instances.push(QuadInstance { + position: [x, y], + size: [w, h], + color, + border_radius: [0.0, 0.0, 0.0, 0.0], + }); + } + } + instances.push(key_state::to_quad(key, color, self.pos)); } diff --git a/neothesia/src/scene/menu_scene/iced_menu/mod.rs b/neothesia/src/scene/menu_scene/iced_menu/mod.rs index a68d3781..994af126 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/mod.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/mod.rs @@ -4,11 +4,13 @@ use super::Renderer; use iced_core::{ alignment::{Horizontal, Vertical}, image::Handle as ImageHandle, + text::LineHeight, Alignment, Length, Padding, }; use iced_runtime::Command; use iced_widget::{ - button, checkbox, column as col, container, image, pick_list, row, text, vertical_space, + button, checkbox, column as col, container, image, pick_list, row, text, toggler, + vertical_space, }; use crate::{ @@ -31,6 +33,7 @@ pub enum Message { SelectOutput(OutputDescriptor), SelectInput(InputDescriptor), + VerticalGuidelines(bool), OpenMidiFilePicker, MidiFileLoaded(Option<(midi_file::MidiFile, PathBuf)>), @@ -152,6 +155,9 @@ impl Program for AppUi { Message::PlayAlongCheckbox(v) => { target.config.play_along = v; } + Message::VerticalGuidelines(v) => { + target.config.vertical_guidelines = v; + } Message::Tick => { self.data.outputs = target.output_manager.borrow().outputs(); self.data.inputs = target.input_manager.inputs(); @@ -257,7 +263,7 @@ impl<'a> Step { match self { Self::Exit => Self::exit(), Self::Main => Self::main(data, target), - Self::Settings => Self::settings(data), + Self::Settings => Self::settings(data, target), Self::TrackSelection => Self::track_selection(data, target), } } @@ -349,7 +355,7 @@ impl<'a> Step { center_x(content).into() } - fn settings(data: &'a Data) -> Element<'a, Message> { + fn settings(data: &'a Data, target: &Target) -> Element<'a, Message> { let output_list = { let outputs = &data.outputs; let selected_output = data.selected_output.clone(); @@ -400,6 +406,21 @@ impl<'a> Step { .spacing(10) }; + let guidelines = { + let title = text("Guidelines:") + .vertical_alignment(Vertical::Center) + .height(Length::Fixed(30.0)); + + let toggler = toggler( + Some("Vertical".to_string()), + target.config.vertical_guidelines, + Message::VerticalGuidelines, + ) + .text_line_height(LineHeight::Absolute(30.0.into())); + + row![title, toggler].spacing(10) + }; + let buttons = row![neo_button("Back") .on_press(Message::GoToPage(Step::Main)) .width(Length::Fill),] @@ -408,7 +429,7 @@ impl<'a> Step { let column = col![ image(data.logo_handle.clone()), - col![output_list, input_list].spacing(10), + col![output_list, input_list, guidelines].spacing(10), buttons, ] .spacing(40) diff --git a/neothesia/src/scene/playing_scene/keyboard.rs b/neothesia/src/scene/playing_scene/keyboard.rs index b83de251..7b574f7c 100644 --- a/neothesia/src/scene/playing_scene/keyboard.rs +++ b/neothesia/src/scene/playing_scene/keyboard.rs @@ -25,7 +25,12 @@ impl Keyboard { target.window_state.logical_size.height, ); - let mut renderer = KeyboardRenderer::new(&target.gpu, &target.transform, layout); + let mut renderer = KeyboardRenderer::new( + &target.gpu, + &target.transform, + layout, + target.config.vertical_guidelines, + ); renderer.position_on_bottom_of_parent(target.window_state.logical_size.height); Self { renderer }