diff --git a/src/editor.rs b/src/editor.rs index ab610e3..946558c 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -7,6 +7,8 @@ use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; +// use crate::editor::action_trigger_derived_lenses::learned_notes; +// use crate::editor::data_derived_lenses::learned_notes; use crate::AtomicByteArray; use crate::Del2Params; use crate::DelayData; @@ -23,7 +25,17 @@ pub(crate) struct Data { pub learned_notes: Arc, } -impl Model for Data {} +impl Model for Data { + fn event(&mut self, cx: &mut EventContext, event: &mut Event) { + event.map(|event, meta| match event { + ActionTriggerEvent::LabelChange(learned_notes) => { + // self.set_label_string(); + println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + meta.consume(); + } + }); + } +} // Makes sense to also define this here, makes it a bit easier to keep track of pub fn default_state() -> Arc { @@ -87,9 +99,14 @@ pub fn create(editor_data: Data, editor_state: Arc) -> Option, label_string: String, + on_change: Option>, } impl ActionTrigger { pub fn new( @@ -553,6 +571,7 @@ impl ActionTrigger { own_index, learned_notes: learned_notes.get(cx), label_string: String::from("click to learn"), + on_change: None, } .build(cx, |cx| { Label::new(cx, Self::label_string).class("action-label"); @@ -623,7 +642,7 @@ impl View for ActionTrigger { Some("action-trigger") } - fn event(&mut self, cx: &mut EventContext, event: &mut Event) { + fn event(&mut self, _cx: &mut EventContext, event: &mut Event) { event.map(|window_event, meta| match window_event { // We don't need special double and triple click handling WindowEvent::MouseDown(MouseButton::Left) @@ -640,15 +659,31 @@ impl View for ActionTrigger { _ => {} }); } + fn draw(&self, draw_context: &mut DrawContext, canvas: &mut Canvas) { let bounds = draw_context.bounds(); let background_color: vg::Color = draw_context.background_color().into(); let border_color: vg::Color = draw_context.border_color().into(); - let outline_color: vg::Color = draw_context.outline_color().into(); - let selection_color: vg::Color = draw_context.selection_color().into(); + // let outline_color: vg::Color = draw_context.outline_color().into(); + // let selection_color: vg::Color = draw_context.selection_color().into(); let border_width = draw_context.border_width(); - let path_line_width = draw_context.outline_width(); + // let path_line_width = draw_context.outline_width(); self.draw_background(canvas, bounds, background_color, border_color, border_width); } } +pub trait ActionTriggerModifiers { + fn on_change(self, callback: F) -> Self; +} + +impl<'a> ActionTriggerModifiers for Handle<'a, ActionTrigger> { + fn on_change(self, callback: F) -> Self { + self.modify(|actiontrigger| actiontrigger.on_change = Some(Box::new(callback))) + } +} + +pub enum ActionTriggerEvent { + // LabelChange(AtomicByteArray, usize), + LabelChange(AtomicByteArray), + // ColorChange, +} diff --git a/src/lib.rs b/src/lib.rs index 18c5b61..ca17edf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,8 +25,11 @@ use array_init::array_init; use bit_mask_ring_buf::BMRingBuf; use nih_plug::prelude::*; +use nih_plug_vizia::vizia::binding::Lens; +use nih_plug_vizia::vizia::binding::LensExt; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::ViziaState; +use std::hash::{Hash, Hasher}; use std::simd::f32x4; use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; @@ -82,6 +85,7 @@ struct Del2 { delay_buffer_size: u32, counting_state: CountingState, should_update_filter: Arc, + learned_string: String, } // for use in graph @@ -461,6 +465,7 @@ impl Default for Del2 { delay_buffer_size: 0, counting_state: CountingState::TimeOut, should_update_filter, + learned_string: String::from("no trigger"), } } } @@ -1115,7 +1120,8 @@ impl Enum for MyLadderMode { }) } } -// #[derive(Debug)] + +#[derive(Debug)] pub struct AtomicByteArray { data: AtomicU64, } @@ -1141,5 +1147,31 @@ impl AtomicByteArray { } } +// impl Lens for AtomicByteArray { +// type Source = Self; // Adjust based on your actual source type +// type Target = Self; // Adjust based on your actual target type + +// fn view(&self, f: F) { +// // Implement logic how to view the lens +// f(self); +// } +// // Implement more logic here if necessary +// } + +// impl Hash for AtomicByteArray { +// fn hash(&self, state: &mut H) { +// // Hash the stored u64 value +// self.data.load(Ordering::SeqCst).hash(state); +// } +// } + +// impl Clone for AtomicByteArray { +// fn clone(&self) -> Self { +// AtomicByteArray { +// data: AtomicU64::new(self.data.load(Ordering::SeqCst)), +// } +// } +// } + nih_export_clap!(Del2); nih_export_vst3!(Del2);