[ui] pianoroll

This commit is contained in:
2026-04-20 13:58:18 +03:00
parent ad8910ea19
commit 67b37dedc6
3 changed files with 274 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
use params::{ParamId, ParamStore};
use vizia::prelude::*;
use crate::widgets::piano::PianoKeyboard;
#[derive(Clone, Copy, Debug, PartialEq, Data)]
pub enum Panel {
Osc,
@@ -42,6 +44,8 @@ pub struct AppData {
pub host_bpm: f32,
#[lens(ignore)]
pub store: ParamStore,
pub held_notes: Vec<u8>,
pub octave: i32,
}
impl AppData {
@@ -57,6 +61,8 @@ impl AppData {
voice_count: 0,
cpu_load: 0.0,
host_bpm: 120.0,
held_notes: Vec::new(),
octave: 4,
}
}
}
@@ -66,10 +72,15 @@ pub enum AppEvent {
SetParam(ParamId, f32),
SetPanel(Panel),
UpdateMetrics { voices: u8, cpu: f32 },
NoteOn(u8, u8),
NoteOff(u8),
OctaveUp,
OctaveDown,
}
impl Model for AppData {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
event.map(|e: &AppEvent, _| match e {
AppEvent::SetParam(id, val) => {
let v = val.clamp(0.0, 1.0);
@@ -81,6 +92,17 @@ impl Model for AppData {
self.voice_count = *voices;
self.cpu_load = *cpu;
}
AppEvent::NoteOn(note, _vel) => {
if !self.held_notes.contains(note) {
self.held_notes.push(*note);
}
}
AppEvent::NoteOff(note) => self.held_notes.retain(|n| n != note),
AppEvent::OctaveUp => self.octave = (self.octave + 1).min(8),
AppEvent::OctaveDown => self.octave = (self.octave - 1).max(0),
});
event.map(|we: &WindowEvent, _| {
crate::widgets::piano::handle_kbd(cx, we, self.octave);
});
}
}
@@ -116,6 +138,7 @@ pub fn build_root(cx: &mut Context) {
crate::panels::macro_bar::build(cx);
})
.height(Stretch(1.0));
PianoKeyboard::new(cx);
})
.background_color(Color::rgb(18, 18, 28))
.width(Stretch(1.0))