notes selection UI works

Still need to update all cells to actually use the new selections...
main
Elijah Voigt 2 weeks ago
parent 1c0f5ef623
commit 69673ac9c0

@ -6,8 +6,7 @@ use bevy::{
feathers::{containers::*, theme::ThemeProps}, feathers::{containers::*, theme::ThemeProps},
ui::{Checked, InteractionDisabled}, ui::{Checked, InteractionDisabled},
ui_widgets::{ ui_widgets::{
ActivateOnPress, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, slider_self_update
slider_self_update,
}, },
}; };
use engine::*; use engine::*;
@ -177,12 +176,15 @@ fn update_pitch_map_resource_ui(
fn the_ui() -> impl Scene { fn the_ui() -> impl Scene {
fn toggle_note( fn toggle_note(
this: On<Activate>, change: On<ValueChange<bool>>,
notes: Query<&Note, With<UiButton>>, notes: Query<&Note, With<Checkbox>>,
mut pitch_map: ResMut<PitchMap>, mut pitch_map: ResMut<PitchMap>,
) { ) {
let this_note = notes.get(this.entity).unwrap(); if change.is_final {
pitch_map.toggle(this_note); let this_note = notes.get(change.source).unwrap();
pitch_map.set_note(this_note, change.value);
info!("(note {:?}) Updated pitch map: {:#?}", this_note, pitch_map);
}
} }
bsn! { bsn! {
@ -342,6 +344,7 @@ fn the_ui() -> impl Scene {
on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| { on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| {
if value_change.is_final { if value_change.is_final {
pitch_map.octaves_up = value_change.value as usize; pitch_map.octaves_up = value_change.value as usize;
info!("(octave up) Updated pitch map: {:#?}", pitch_map);
} }
}) })
on(slider_self_update), on(slider_self_update),
@ -351,6 +354,7 @@ fn the_ui() -> impl Scene {
on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| { on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| {
if value_change.is_final { if value_change.is_final {
pitch_map.octaves_down = value_change.value as usize; pitch_map.octaves_down = value_change.value as usize;
info!("(octave down) Updated pitch map: {:#?}", pitch_map);
} }
}) })
on(slider_self_update), on(slider_self_update),
@ -610,7 +614,7 @@ fn new_cell(
let playback_settings = PlaybackSettings::ONCE.with_volume(volume); let playback_settings = PlaybackSettings::ONCE.with_volume(volume);
info!("using coordinates {:?}", c); debug!("using coordinates {:?}", c);
bsn! { bsn! {
Cell Cell
@ -962,10 +966,10 @@ impl Default for PitchMap {
} }
impl PitchMap { impl PitchMap {
fn toggle(&mut self, n: &Note) { fn set_note(&mut self, n: &Note, value: bool) {
if let Some(idx) = self.notes.iter().position(|v| v == n) { if !value && let Some(idx) = self.notes.iter().position(|v| v == n) {
self.notes.swap_remove(idx); self.notes.swap_remove(idx);
} else { } else if value {
self.notes.push(n.clone()); self.notes.push(n.clone());
} }
} }
@ -980,12 +984,12 @@ impl PitchMap {
let octave: isize = { let octave: isize = {
let num_octaves: usize = self.octaves_up + self.octaves_down + 1; let num_octaves: usize = self.octaves_up + self.octaves_down + 1;
let y_coord: usize = c.y.strict_abs() as usize; // TODO: shift first or something let y_coord: usize = c.y.strict_abs() as usize; // TODO: shift first or something
info!("num_octaves: {:?}", num_octaves); debug!("num_octaves: {:?}", num_octaves);
info!("y_coord: {:?}", y_coord); debug!("y_coord: {:?}", y_coord);
(y_coord % num_octaves) as isize - 5 (y_coord % num_octaves) as isize - 5
}; };
let cp = CellPitch { note, octave }; let cp = CellPitch { note, octave };
info!("Cell Pitch: {:?}", cp); debug!("Cell Pitch: {:?}", cp);
cp cp
} }
} }

Loading…
Cancel
Save