From 67ca1880816ba8ac2d1e9abda1638ed49f3f953c Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Wed, 23 Oct 2024 19:32:25 +0200 Subject: [PATCH] wip other triggers --- src/editor.rs | 85 +++++++++++++++++++++++++++++++++------------------ src/lib.rs | 18 ++++++----- src/style.css | 37 ++++++++++++++-------- 3 files changed, 90 insertions(+), 50 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 4c16994..b71d30d 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1,21 +1,20 @@ -use crate::util; +use std::sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Mutex, +}; + use nih_plug::prelude::{AtomicF32, Editor}; -use nih_plug_vizia::vizia::prelude::*; -use nih_plug_vizia::vizia::vg; -use nih_plug_vizia::widgets::*; -use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::{Arc, Mutex}; - -use crate::AtomicBoolArray; -use crate::AtomicByteArray; -use crate::Del2Params; -use crate::DelayData; -use crate::DelayDataOutput; -use crate::LastPlayedNotes; -use crate::LEARNING; -use crate::MUTE_OUT; -use crate::NO_LEARNED_NOTE; +use nih_plug_vizia::{ + assets, create_vizia_editor, + vizia::{prelude::*, vg}, + widgets::*, + ViziaState, ViziaTheming, +}; + +use crate::{ + util, AtomicBoolArray, AtomicByteArray, Del2Params, DelayData, DelayDataOutput, + LastPlayedNotes, LEARNING, MUTE_IN, MUTE_OUT, NO_LEARNED_NOTE, RESET_PATTERN, +}; #[derive(Lens, Clone)] pub(crate) struct Data { @@ -90,15 +89,43 @@ pub fn create(editor_data: Data, editor_state: Arc) -> Option, learning_index: Arc, - own_index: usize, learned_notes: Arc, last_played_notes: Arc, enabled_actions: Arc, + own_index: usize, } impl ActionTrigger { pub fn new( cx: &mut Context, is_learning: IsLearningL, learning_index: LearningIndexL, - own_index: usize, learned_notes: LearnedNotesL, last_played_notes: LastPlayedNotesL, enabled_actions: EnabledActionsL, + own_index: usize, ) -> Handle where IsLearningL: Lens>, @@ -556,10 +583,10 @@ impl ActionTrigger { Self { is_learning: is_learning.get(cx), learning_index: learning_index.get(cx), - own_index, learned_notes: learned_notes.get(cx), last_played_notes: last_played_notes.get(cx), enabled_actions: enabled_actions.get(cx), + own_index, } .build(cx, move |cx| { Label::new( diff --git a/src/lib.rs b/src/lib.rs index ef1cf0d..6b0f108 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,9 @@ const NO_LEARNED_NOTE: u8 = 128; const LEARNING: u8 = 129; // action trigger indexes // should be 0..7 because of AtomicByteArray size -const MUTE_OUT: usize = 0; +const MUTE_IN: usize = 0; +const MUTE_OUT: usize = 1; +const RESET_PATTERN: usize = 2; struct Del2 { params: Arc, @@ -621,7 +623,7 @@ impl Del2 { CountingState::TimeOut => { if is_delay_note { // If in TimeOut state, reset and start new counting phase - self.update_releasing(true); + self.mute_out(true); self.enabled_actions.store(MUTE_OUT, false); self.delay_data.current_tap = 0; self.timing_last_event = timing; @@ -704,10 +706,10 @@ impl Del2 { // Handle ActionTrigger events if self.is_playing_action(MUTE_OUT) { if self.enabled_actions.load(MUTE_OUT) { - self.update_releasing(false); + self.mute_out(false); self.enabled_actions.store(MUTE_OUT, false); } else { - self.update_releasing(true); + self.mute_out(true); self.enabled_actions.store(MUTE_OUT, true); } } @@ -722,16 +724,16 @@ impl Del2 { } } } - fn update_releasing(&mut self, releasing: bool) { - let time_value = if releasing { + fn mute_out(&mut self, mute: bool) { + let time_value = if mute { self.params.global.release_ms.value() } else { self.params.global.attack_ms.value() }; - let target_value = if releasing { 0.0 } else { 1.0 }; + let target_value = if mute { 0.0 } else { 1.0 }; for tap in 0..self.delay_data.current_tap { - self.releasings[tap] = releasing; + self.releasings[tap] = mute; self.amp_envelopes[tap].style = SmoothingStyle::Exponential(time_value); self.amp_envelopes[tap].set_target(self.sample_rate, target_value); } diff --git a/src/style.css b/src/style.css index 71c81ec..cc419cf 100644 --- a/src/style.css +++ b/src/style.css @@ -21,6 +21,7 @@ param-slider { height: 30px; + width: 171px; border-width: 1px; background-color: #4e4e4e; border-color: #fabdf0; @@ -114,8 +115,10 @@ delay-graph { } action-trigger { + width: 171px; height: 30px; - top: 100px; + top: 0px; + bottom: 0px; background-color: #4e4e4e; border-color: #5879af; outline-color: #e0ce91; @@ -123,31 +126,39 @@ action-trigger { border-width: 1px; transition: background-color 300ms; } +.action-name { + right: 9px; + top: 1s; + bottom: 3px; +} generic-ui { child-left: 0px; child-right: 0px; } -generic-ui .row { - col-between: 6px; - height: auto; - layout-type: row; -} +/* generic-ui .row { */ +/* col-between: 6px; */ +/* height: auto; */ +/* layout-type: row; */ +/* } */ .row { col-between: 6px; - height: auto; + height: 30px; layout-type: row; + background-color: #4e4e4e; } -generic-ui .column { - width: 269px; - height: auto; - left: 9px; - right: 0px; -} +/* generic-ui .column { */ +/* width: 269px; */ +/* height: auto; */ +/* left: 9px; */ +/* right: 0px; */ +/* } */ .column { width: 269px; height: auto; + row-between: 6px; + layout-type: column; } label { left: 1s;