Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
GatoImorrivel committed Nov 14, 2023
1 parent 48157f2 commit 726e9c4
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 26 deletions.
37 changes: 37 additions & 0 deletions fretcat_editor/src/components/effect_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ impl EffectHandle {
.width(Stretch(1.0));
}).overflow(Overflow::Hidden)
}

pub fn drag_handle(cx: &mut Context, effect: fretcat_effects::prelude::EffectHandle<dyn AudioEffect>) -> Handle<Self> {
Self {
active: effect.active(),
handle: effect.clone()
}.build(cx, |cx| {
HStack::new(cx, move |cx| {
VStack::new(cx, move |cx| {
Button::new(
cx,
move |_| {},
|cx| Label::new(cx, ""),
)
.class("delete-effect-btn")
.font_family(vec![FamilyOwned::Name("Symbols Nerd Font Mono".to_owned())]);
Button::new(
cx,
move |ex| ex.emit(EffectHandleEvent::Toggle),
|cx| Label::new(cx, Self::active.map(|active| if *active { "" } else { "" })),
)
.class("delete-effect-btn")
.font_family(vec![FamilyOwned::Name("Symbols Nerd Font Mono".to_owned())]);
})
.class("effect-bar")
.height(Stretch(1.0))
.width(Stretch(3.0));

VStack::new(cx, move |cx| effect.view(cx, effect.clone()))
.width(Stretch(100.0))
.height(Stretch(1.0))
.class("effect-container")
.disabled(true);
})
.class("effect-handle")
.width(Stretch(1.0));
}).overflow(Overflow::Hidden)
}
}

impl View for EffectHandle {
Expand Down
20 changes: 15 additions & 5 deletions fretcat_editor/src/components/effect_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::sync::Arc;

use nih_plug::vizia::prelude::*;

use crate::{systems::{CardEvent, CardSystem}, common::{LIST_SPACING, LIST_SPACING_UNITS}};
use crate::{
common::{LIST_SPACING, LIST_SPACING_UNITS},
systems::{CardEvent, CardSystem},
};

use super::effect_handle::EffectHandle;
use fretcat_effects::{Chain, ChainCommand};
Expand All @@ -14,7 +17,7 @@ pub struct EffectList {
}

pub enum EffectListEvent {
DragChange(Option<usize>)
DragChange(Option<usize>),
}

impl EffectList {
Expand All @@ -24,10 +27,10 @@ impl EffectList {
update_counter: 0,
}
.build(cx, move |cx| {
cx.add_listener(|view: &mut EffectList, _cx, event| {
cx.add_listener(|view: &mut EffectList, cx, event| {
event.map::<ChainCommand, _>(|_, _| {
view.update_counter += 1;
})
});
});

ScrollView::new(cx, 0.0, 0.0, false, false, move |cx| {
Expand All @@ -38,7 +41,14 @@ impl EffectList {
VStack::new(cx, |cx| {
EffectHandle::new(cx, effect.clone(), index);
})
.height(Pixels(effect.height() + if effect.height() > 100.0 { LIST_SPACING } else { 0.0 }));
.height(Pixels(
effect.height()
+ if effect.height() > 100.0 {
LIST_SPACING
} else {
0.0
},
));
Element::new(cx).height(LIST_SPACING_UNITS);
}
VStack::new(cx, |cx| {
Expand Down
41 changes: 23 additions & 18 deletions fretcat_effects/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use indexmap::IndexMap;

use crate::effects::{Mono, Gain, NoiseGate};
use crate::effects::{Gain, Mono, NoiseGate};

pub use super::prelude::*;

Expand All @@ -11,7 +11,6 @@ pub const NUM_CHANNELS: usize = 2;
pub type Query<'a> = &'a EffectHandle<dyn AudioEffect>;
pub type QueryMut<'a> = &'a mut EffectHandle<dyn AudioEffect>;


#[derive(Debug, Lens, Clone)]
pub struct ChainData {
pub chain: Arc<Chain>,
Expand All @@ -31,7 +30,7 @@ impl ChainData {

impl Model for ChainData {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
let chain = unsafe { &mut *Arc::as_ptr(&self.chain).cast_mut() };
let chain = unsafe { Arc::as_ptr(&self.chain).cast_mut().as_mut().expect("CRASHED GUI") };
event.map(|event, _| match event {
ChainCommand::Insert(audio_effect) => {
chain.insert(audio_effect.clone());
Expand Down Expand Up @@ -78,24 +77,28 @@ pub struct Chain {

impl Chain {
#[inline]
pub fn process<'a>(&mut self, buffer: &mut [&'a mut [f32]], transport: &nih_plug::prelude::Transport) {
let mut frame = Frame::from(buffer);
pub fn process<'a>(
&mut self,
buffer: &mut [&'a mut [f32]],
transport: &nih_plug::prelude::Transport,
) {
let mut frame = Frame::from(buffer);

self.pre_fx
.iter_mut()
.for_each(|(_, fx)| fx.process(&mut frame, transport));
self.pre_fx
.iter_mut()
.for_each(|(_, fx)| fx.process(&mut frame, transport));

self.in_avg_amplitude = Self::get_rms(&frame);
self.in_avg_amplitude = Self::get_rms(&frame);

self.effects.iter_mut().for_each(|e| {
e.process_if_active(&mut frame, transport)
});
self.effects
.iter_mut()
.for_each(|e| e.process_if_active(&mut frame, transport));

self.post_fx
.iter_mut()
.for_each(|(_, fx)| fx.process(&mut frame, transport));
self.post_fx
.iter_mut()
.for_each(|(_, fx)| fx.process(&mut frame, transport));

self.out_avg_amplitude = Self::get_rms(&frame);
self.out_avg_amplitude = Self::get_rms(&frame);
}

#[inline]
Expand All @@ -118,7 +121,10 @@ impl Chain {

#[inline]
pub fn load(&mut self, effects: Vec<Arc<dyn AudioEffect>>) {
self.effects = effects.into_iter().map(|effect| EffectHandle::from(effect)).collect::<Vec<_>>();
self.effects = effects
.into_iter()
.map(|effect| EffectHandle::from(effect))
.collect::<Vec<_>>();
}

#[inline]
Expand Down Expand Up @@ -202,7 +208,6 @@ impl Default for Chain {
.pre_fx
.insert(PreFX("noise_gate"), Box::new(NoiseGate::default()));


chain
.post_fx
.insert(PostFX("out_gain"), Box::new(Gain::default()));
Expand Down
2 changes: 1 addition & 1 deletion fretcat_effects/src/common/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl AudioFilter {
.into_iter()
.zip(half)
.for_each(|(x, y)| {
points.push(Point::new(x as i32, y as i32));
points.push(Point::new(x as i32, (y * 1000.0).round() as i32));
});

points
Expand Down
2 changes: 1 addition & 1 deletion fretcat_effects/src/effects/dynamics/band_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Default for BandPass {
Self {
min_freq_hz,
max_freq_hz,
filter: [AudioFilter::new(crate::common::FilterMode::BandPass, 44100.0, min_freq_hz, 1.0); 2]
filter: [AudioFilter::new(crate::common::FilterMode::BandPass, 44100.0, (max_freq_hz + min_freq_hz) / 2.0, 1.0); 2]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fretcat_effects/src/effects/dynamics/high_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Default for HighPass {
filter: [AudioFilter::new(
crate::common::FilterMode::Highpass,
44100.0,
min_freq_hz,
max_freq_hz,
1.0,
); 2],
}
Expand Down
3 changes: 3 additions & 0 deletions fretcat_styles/editor/graph.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
graph:disabled {
color: #404040;
}
4 changes: 4 additions & 0 deletions fretcat_styles/effects/filter.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ band-pass .effect-title {
height: 1s;
background-color: transparent;
color: #e3e3e3;
}

.filter-graph:disabled {
color: #404040;
}
6 changes: 6 additions & 0 deletions fretcat_styles/fretcat-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ effect-list .new-effect-indicator > vstack {
effect-list .new-effect-indicator > vstack label {
font-size: 100;
color: #121212;
}graph:disabled {
color: #404040;
}labeled-knob knob {
width: 60px;
height: 60px;
Expand Down Expand Up @@ -477,6 +479,10 @@ band-pass .effect-title {
height: 1s;
background-color: transparent;
color: #e3e3e3;
}

.filter-graph:disabled {
color: #404040;
}.fuzz knob {
width: 100px;
height: 100px;
Expand Down

0 comments on commit 726e9c4

Please sign in to comment.