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

Loading…
Cancel
Save