Skip to content

Commit

Permalink
wip other triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Oct 23, 2024
1 parent 7a207bd commit 67ca188
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 50 deletions.
85 changes: 56 additions & 29 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -90,15 +89,43 @@ pub fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dy
});
});
});
ActionTrigger::new(
cx,
Data::is_learning,
Data::learning_index,
MUTE_OUT,
Data::learned_notes,
Data::last_played_notes,
Data::enabled_actions,
);

HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "mute in").class("action-name");
ActionTrigger::new(
cx,
Data::is_learning,
Data::learning_index,
Data::learned_notes,
Data::last_played_notes,
Data::enabled_actions,
MUTE_IN,
);
})
.class("row");
})
.class("column");
HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "mute out").class("action-name");
ActionTrigger::new(
cx,
Data::is_learning,
Data::learning_index,
Data::learned_notes,
Data::last_played_notes,
Data::enabled_actions,
MUTE_OUT,
);
})
.class("row");
}) // TODO: make into a class
.class("column");
})
// TODO: rename
.class("attack-release");

HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
Expand Down Expand Up @@ -531,20 +558,20 @@ fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context
pub struct ActionTrigger {
is_learning: Arc<AtomicBool>,
learning_index: Arc<AtomicUsize>,
own_index: usize,
learned_notes: Arc<AtomicByteArray>,
last_played_notes: Arc<LastPlayedNotes>,
enabled_actions: Arc<AtomicBoolArray>,
own_index: usize,
}
impl ActionTrigger {
pub fn new<IsLearningL, LearningIndexL, LearnedNotesL, LastPlayedNotesL, EnabledActionsL>(
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<Self>
where
IsLearningL: Lens<Target = Arc<AtomicBool>>,
Expand All @@ -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(
Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Del2Params>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down
37 changes: 24 additions & 13 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

param-slider {
height: 30px;
width: 171px;
border-width: 1px;
background-color: #4e4e4e;
border-color: #fabdf0;
Expand Down Expand Up @@ -114,40 +115,50 @@ delay-graph {
}

action-trigger {
width: 171px;
height: 30px;
top: 100px;
top: 0px;
bottom: 0px;
background-color: #4e4e4e;
border-color: #5879af;
outline-color: #e0ce91;
selection-color: #fabdf0;
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;
Expand Down

0 comments on commit 67ca188

Please sign in to comment.