somewhat working ui
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crossbeam_channel::Sender;
|
||||
use params::{ParamId, ParamStore};
|
||||
use vizia::prelude::*;
|
||||
|
||||
@@ -6,6 +7,13 @@ use crate::widgets::piano::PianoKeyboard;
|
||||
pub const MOD_NSRC: usize = 19;
|
||||
pub const MOD_NDST: usize = 11;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum MidiMsg {
|
||||
NoteOn(u8, u8),
|
||||
NoteOff(u8),
|
||||
AllNotesOff,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Data)]
|
||||
pub enum Panel {
|
||||
Voice,
|
||||
@@ -41,10 +49,12 @@ pub struct AppData {
|
||||
pub active_env: usize,
|
||||
pub active_lfo: usize,
|
||||
pub fx_selected: usize,
|
||||
#[lens(ignore)]
|
||||
pub midi_tx: Sender<MidiMsg>,
|
||||
}
|
||||
|
||||
impl AppData {
|
||||
pub fn new(store: ParamStore) -> Self {
|
||||
pub fn new(store: ParamStore, midi_tx: Sender<MidiMsg>) -> Self {
|
||||
let params = (0..ParamId::COUNT)
|
||||
.map(|i| store.get(unsafe { std::mem::transmute::<usize, ParamId>(i) }))
|
||||
.collect();
|
||||
@@ -63,6 +73,7 @@ impl AppData {
|
||||
active_env: 0,
|
||||
active_lfo: 0,
|
||||
fx_selected: 0,
|
||||
midi_tx,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,34 +107,45 @@ impl Model for AppData {
|
||||
self.params[*id as usize] = *val;
|
||||
self.store.set(*id, *val);
|
||||
}
|
||||
|
||||
AppEvent::SetPanel(p) => self.active_panel = *p,
|
||||
AppEvent::SelectEnv(i) => self.active_env = *i,
|
||||
AppEvent::SelectLfo(i) => self.active_lfo = *i,
|
||||
AppEvent::SelectFx(i) => self.fx_selected = *i,
|
||||
|
||||
AppEvent::UpdateMetrics { voices, cpu } => {
|
||||
self.voice_count = *voices;
|
||||
self.cpu_load = *cpu;
|
||||
}
|
||||
AppEvent::NoteOn(note, _) => {
|
||||
|
||||
AppEvent::NoteOn(note, vel) => {
|
||||
if !self.held_notes.contains(note) {
|
||||
self.held_notes.push(*note);
|
||||
}
|
||||
let _ = self.midi_tx.try_send(MidiMsg::NoteOn(*note, *vel));
|
||||
}
|
||||
AppEvent::NoteOff(note) => self.held_notes.retain(|n| n != note),
|
||||
AppEvent::NoteOff(note) => {
|
||||
self.held_notes.retain(|n| n != note);
|
||||
let _ = self.midi_tx.try_send(MidiMsg::NoteOff(*note));
|
||||
}
|
||||
|
||||
AppEvent::OctaveUp => self.octave = (self.octave + 1).min(8),
|
||||
AppEvent::OctaveDown => self.octave = (self.octave - 1).max(0),
|
||||
|
||||
AppEvent::SetModDepth { src, dst, depth } => {
|
||||
let idx = src * MOD_NDST + dst;
|
||||
if idx < self.mod_depths.len() {
|
||||
self.mod_depths[idx] = depth.clamp(-1.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
AppEvent::ToggleFx(s) => {
|
||||
if *s < self.fx_enabled.len() {
|
||||
self.fx_enabled[*s] = !self.fx_enabled[*s];
|
||||
}
|
||||
}
|
||||
AppEvent::SelectEnv(i) => self.active_env = *i,
|
||||
AppEvent::SelectLfo(i) => self.active_lfo = *i,
|
||||
AppEvent::SelectFx(i) => self.fx_selected = *i,
|
||||
});
|
||||
|
||||
event.map(|we: &WindowEvent, _| {
|
||||
crate::widgets::piano::handle_kbd(cx, we, self.octave);
|
||||
});
|
||||
@@ -158,3 +180,14 @@ pub fn build_root(cx: &mut Context) {
|
||||
.width(Stretch(1.0))
|
||||
.height(Stretch(1.0));
|
||||
}
|
||||
|
||||
fn tab_button(cx: &mut Context, p: Panel) {
|
||||
Binding::new(cx, AppData::active_panel, move |cx, active_lens| {
|
||||
let active = active_lens.get(cx) == p;
|
||||
Label::new(cx, p.label())
|
||||
.class("top-tab")
|
||||
.checked(active)
|
||||
.on_press(move |cx| cx.emit(AppEvent::SetPanel(p)))
|
||||
.height(Stretch(1.0));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user