Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Vertical guidelines #91

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions neothesia-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ColorSchema>,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -111,6 +115,10 @@ fn default_play_along() -> bool {
false
}

fn default_vertical_guidelines() -> bool {
false
}

fn default_color_schema() -> Vec<ColorSchema> {
vec![
ColorSchema {
Expand Down
28 changes: 28 additions & 0 deletions neothesia-core/src/render/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ pub struct KeyboardRenderer {
should_reupload: bool,

layout: piano_math::KeyboardLayout,
vertical_guidelines: bool,
}

impl KeyboardRenderer {
pub fn new(
gpu: &Gpu,
transform_uniform: &Uniform<TransformUniform>,
layout: piano_math::KeyboardLayout,
vertical_guidelines: bool,
) -> Self {
let quad_pipeline = QuadPipeline::new(gpu, transform_uniform);
let key_states: Vec<KeyState> = layout
Expand All @@ -45,6 +47,7 @@ impl KeyboardRenderer {
should_reupload: false,

layout,
vertical_guidelines,
}
}

Expand Down Expand Up @@ -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));
}

Expand Down
29 changes: 25 additions & 4 deletions neothesia/src/scene/menu_scene/iced_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -31,6 +33,7 @@ pub enum Message {

SelectOutput(OutputDescriptor),
SelectInput(InputDescriptor),
VerticalGuidelines(bool),

OpenMidiFilePicker,
MidiFileLoaded(Option<(midi_file::MidiFile, PathBuf)>),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),]
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion neothesia/src/scene/playing_scene/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading