Skip to content

Commit

Permalink
Settings & Config for horizontal guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Jan 14, 2024
1 parent b792ad9 commit 569d5d0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
1 change: 1 addition & 0 deletions neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Recorder {
keyboard.layout().clone(),
*keyboard.pos(),
config.vertical_guidelines,
config.horizontal_guidelines,
midi.mesures.clone(),
);

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 @@ -22,6 +22,9 @@ pub struct Config {
#[serde(default = "default_vertical_guidelines")]
pub vertical_guidelines: bool,

#[serde(default = "default_horizontal_guidelines")]
pub horizontal_guidelines: bool,

#[serde(default = "default_color_schema")]
pub color_schema: Vec<ColorSchema>,

Expand Down Expand Up @@ -68,6 +71,7 @@ impl Config {
animation_speed: default_animation_speed(),
playback_offset: default_playback_offset(),
vertical_guidelines: default_vertical_guidelines(),
horizontal_guidelines: default_horizontal_guidelines(),
color_schema: default_color_schema(),
background_color: Default::default(),
output: default_output(),
Expand Down Expand Up @@ -122,6 +126,10 @@ fn default_vertical_guidelines() -> bool {
false
}

fn default_horizontal_guidelines() -> bool {
false
}

fn default_color_schema() -> Vec<ColorSchema> {
vec![
ColorSchema {
Expand Down
22 changes: 18 additions & 4 deletions neothesia-core/src/render/guidelines.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{time::Duration, sync::Arc};
use std::{sync::Arc, time::Duration};

use crate::{
render::{QuadInstance, QuadPipeline},
Expand All @@ -10,6 +10,7 @@ pub struct GuidelineRenderer {

layout: piano_math::KeyboardLayout,
vertical_guidelines: bool,
horizontal_guidelines: bool,

cache: Vec<QuadInstance>,
mesures: Arc<[Duration]>,
Expand All @@ -20,12 +21,14 @@ impl GuidelineRenderer {
layout: piano_math::KeyboardLayout,
pos: Point<f32>,
vertical_guidelines: bool,
horizontal_guidelines: bool,
mesures: Arc<[Duration]>,
) -> Self {
Self {
pos,
layout,
vertical_guidelines,
horizontal_guidelines,
cache: Vec::new(),
mesures,
}
Expand Down Expand Up @@ -74,8 +77,17 @@ impl GuidelineRenderer {
}
}

fn update_horizontal_guidelines(&mut self, quads: &mut QuadPipeline, animation_speed: f32, time: f32) {
for mesure in self.mesures.iter().skip_while(|bar| bar.as_secs_f32() < time) {
fn update_horizontal_guidelines(
&mut self,
quads: &mut QuadPipeline,
animation_speed: f32,
time: f32,
) {
for mesure in self
.mesures
.iter()
.skip_while(|bar| bar.as_secs_f32() < time)
{
let x = 0.0;
let y = self.pos.y - (mesure.as_secs_f32() - time) * animation_speed;

Expand All @@ -96,7 +108,9 @@ impl GuidelineRenderer {
self.reupload();
}

self.update_horizontal_guidelines(quads, animation_speed, time);
if self.horizontal_guidelines {
self.update_horizontal_guidelines(quads, animation_speed, time);
}

for quad in self.cache.iter() {
quads.instances().push(*quad);
Expand Down
60 changes: 40 additions & 20 deletions neothesia/src/scene/menu_scene/iced_menu/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum SettingsMessage {
SelectOutput(OutputDescriptor),
SelectInput(InputDescriptor),
VerticalGuidelines(bool),
HorizontalGuidelines(bool),

OpenSoundFontPicker,
SoundFontFileLoaded(Option<PathBuf>),
Expand Down Expand Up @@ -69,6 +70,9 @@ pub(super) fn update(
SettingsMessage::VerticalGuidelines(v) => {
target.config.vertical_guidelines = v;
}
SettingsMessage::HorizontalGuidelines(v) => {
target.config.horizontal_guidelines = v;
}
SettingsMessage::OpenSoundFontPicker => {
data.is_loading = true;
return open_sound_font_picker(|res| {
Expand Down Expand Up @@ -108,11 +112,13 @@ pub(super) fn update(
Command::none()
}

fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, Message> {
fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, SettingsMessage> {
let output_settings = {
let output_list = pick_list(&data.outputs, data.selected_output.clone(), |v| {
SettingsMessage::SelectOutput(v).into()
})
let output_list = pick_list(
&data.outputs,
data.selected_output.clone(),
SettingsMessage::SelectOutput,
)
.style(theme::pick_list());

preferences_group::ActionRow::new()
Expand All @@ -134,7 +140,7 @@ fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, Message> {
.suffix(
iced_widget::button(centered_text("Select File"))
.style(theme::button())
.on_press(SettingsMessage::OpenSoundFontPicker.into()),
.on_press(SettingsMessage::OpenSoundFontPicker),
);

if let Some(subtitle) = subtitle {
Expand All @@ -151,14 +157,12 @@ fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, Message> {
.build()
}

fn input_group<'a>(data: &'a Data, _target: &Target) -> Element<'a, Message> {
fn input_group<'a>(data: &'a Data, _target: &Target) -> Element<'a, SettingsMessage> {
let inputs = &data.inputs;
let selected_input = data.selected_input.clone();

let input_list = pick_list(inputs, selected_input, |v| {
SettingsMessage::SelectInput(v).into()
})
.style(theme::pick_list());
let input_list =
pick_list(inputs, selected_input, SettingsMessage::SelectInput).style(theme::pick_list());

preferences_group::PreferencesGroup::new()
.title("Input")
Expand Down Expand Up @@ -198,17 +202,15 @@ fn counter<'a>(
.into()
}

fn note_range_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message> {
fn note_range_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, SettingsMessage> {
let start = counter(
*target.config.piano_range().start(),
SettingsMessage::RangeStart,
)
.map(Message::Settings);
);
let end = counter(
*target.config.piano_range().end(),
SettingsMessage::RangeEnd,
)
.map(Message::Settings);
);

preferences_group::PreferencesGroup::new()
.title("Note Range")
Expand All @@ -221,10 +223,19 @@ fn note_range_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message
.build()
}

fn guidelines_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message> {
let toggler = toggler(None, target.config.vertical_guidelines, |v| {
SettingsMessage::VerticalGuidelines(v).into()
})
fn guidelines_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, SettingsMessage> {
let vertical = toggler(
None,
target.config.vertical_guidelines,
SettingsMessage::VerticalGuidelines,
)
.style(theme::toggler());

let horizontal = toggler(
None,
target.config.horizontal_guidelines,
SettingsMessage::HorizontalGuidelines,
)
.style(theme::toggler());

preferences_group::PreferencesGroup::new()
Expand All @@ -233,7 +244,13 @@ fn guidelines_group<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message
preferences_group::ActionRow::new()
.title("Vertical Guidelines")
.subtitle("Display octave indicators")
.suffix(toggler),
.suffix(vertical),
)
.push(
preferences_group::ActionRow::new()
.title("Horizontal Guidelines")
.subtitle("Display mesure/bar indicators")
.suffix(horizontal),
)
.build()
}
Expand All @@ -256,6 +273,9 @@ pub(super) fn view<'a>(data: &'a Data, target: &Target) -> Element<'a, Message>
.width(Length::Fill)
.align_items(Alignment::Center);

let column: Element<SettingsMessage> = column.into();
let column: Element<Message> = column.map(Message::Settings);

let left = {
let back = NeoBtn::new(
icons::left_arrow_icon()
Expand Down
1 change: 1 addition & 0 deletions neothesia/src/scene/playing_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl PlayingScene {
keyboard_layout.clone(),
*keyboard.pos(),
target.config.vertical_guidelines,
target.config.horizontal_guidelines,
song.file.mesures.clone(),
);

Expand Down

0 comments on commit 569d5d0

Please sign in to comment.