chore: format

This commit is contained in:
🪞👃🪞 2024-07-04 14:35:41 +03:00
parent a3c21fa192
commit 4aadc712b8
4 changed files with 109 additions and 97 deletions

View file

@ -1,10 +1,17 @@
use crate::{core::*, model::*}; use crate::{core::*, model::*};
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> { pub fn handle (state: &mut Plugin, event: &AppEvent) -> Usually<bool> {
handle_keymap(s, event, keymap!(Plugin { handle_keymap(state, event, KEYMAP)
}
[Up, NONE, "cursor_up", "move cursor up", pub const KEYMAP: &'static [KeyBinding<Plugin>] = keymap!(Plugin {
|s: &mut Plugin|{ [Up, NONE, "cursor_up", "move cursor up", cursor_up],
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
[Char(','), NONE, "decrement", "decrement value", decrement],
[Char('.'), NONE, "increment", "increment value", increment],
});
fn cursor_up (s: &mut Plugin) -> Usually<bool> {
if s.selected > 0 { if s.selected > 0 {
s.selected = s.selected - 1 s.selected = s.selected - 1
} else { } else {
@ -14,10 +21,9 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
} }
} }
Ok(true) Ok(true)
}], }
[Down, NONE, "cursor_down", "move cursor down", fn cursor_down (s: &mut Plugin) -> Usually<bool> {
|s: &mut Plugin|{
s.selected = s.selected + 1; s.selected = s.selected + 1;
match &s.plugin { match &s.plugin {
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => { Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => {
@ -28,10 +34,9 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
_ => {} _ => {}
} }
Ok(true) Ok(true)
}], }
[Char(','), NONE, "decrement", "decrement value", fn decrement (s: &mut Plugin) -> Usually<bool> {
|s: &mut Plugin|{
match s.plugin.as_mut() { match s.plugin.as_mut() {
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
let index = port_list[s.selected].index; let index = port_list[s.selected].index;
@ -42,10 +47,9 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
_ => {} _ => {}
} }
Ok(true) Ok(true)
}], }
[Char('.'), NONE, "increment", "increment value", fn increment (s: &mut Plugin) -> Usually<bool> {
|s: &mut Plugin|{
match s.plugin.as_mut() { match s.plugin.as_mut() {
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
let index = port_list[s.selected].index; let index = port_list[s.selected].index;
@ -56,14 +60,4 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
_ => {} _ => {}
} }
Ok(true) Ok(true)
}],
[Char('m'), NONE, "toggle_midi_map", "toggle midi map mode",
|s: &mut Plugin|{
s.mapping = !s.mapping;
Ok(true)
}]
}))
} }

View file

@ -1,7 +1,7 @@
use crate::{core::*, model::*}; use crate::{core::*, model::*};
pub fn handle (state: &mut Sampler, event: &AppEvent) -> Usually<bool> { pub fn handle (state: &mut Sampler, event: &AppEvent) -> Usually<bool> {
Ok(handle_keymap(state, event, KEYMAP)?) handle_keymap(state, event, KEYMAP)
} }
pub const KEYMAP: &'static [KeyBinding<Sampler>] = keymap!(Sampler { pub const KEYMAP: &'static [KeyBinding<Sampler>] = keymap!(Sampler {

View file

@ -72,20 +72,20 @@ pub fn main () -> Usually<()> {
]))?, ]))?,
]; ];
state.tracks[0].sequence = Some(0);
state.tracks[1].sequence = Some(0);
state.track_cursor = 1;
state.scene_cursor = 1;
state.note_start = 12;
//for track in state.tracks.iter() { //for track in state.tracks.iter() {
//if let Some(port) = track.midi_ins()?.get(0) { //if let Some(port) = track.midi_ins()?.get(0) {
//client.connect_ports(&track.midi_out, port)?; //client.connect_ports(&track.midi_out, port)?;
//} //}
//} //}
state.tracks[0].sequence = Some(0);
state.tracks[1].sequence = Some(0);
state.track_cursor = 1;
state.scene_cursor = 1;
state.note_start = 12;
state.time_zoom = 12;
state.midi_in = Some(client.register_port("midi-in", MidiIn)?); state.midi_in = Some(client.register_port("midi-in", MidiIn)?);
state.transport = Some(client.transport()); state.transport = Some(client.transport());
state.playing = Some(TransportState::Stopped); state.playing = Some(TransportState::Stopped);
state.time_zoom = 12;
state.jack = Some(jack); state.jack = Some(jack);
Ok(()) Ok(())
})) }))
@ -93,36 +93,54 @@ pub fn main () -> Usually<()> {
#[derive(Default)] #[derive(Default)]
pub struct App { pub struct App {
/// Paths to user directories
pub xdg: Option<Arc<XdgApp>>, pub xdg: Option<Arc<XdgApp>>,
/// Main JACK client.
pub jack: Option<DynamicAsyncClient>, pub jack: Option<DynamicAsyncClient>,
pub grid_mode: bool, /// Main MIDI controller.
pub chain_mode: bool,
pub seq_mode: bool,
pub scenes: Vec<Scene>,
pub scene_cursor: usize,
pub tracks: Vec<Track>,
pub track_cursor: usize,
pub frame: usize,
pub modal: Option<Box<dyn Component>>,
pub section: usize,
pub entered: bool,
pub playing: Option<TransportState>,
pub transport: Option<Transport>,
pub timebase: Arc<Timebase>,
pub playhead: usize,
pub midi_in: Option<Port<MidiIn>>, pub midi_in: Option<Port<MidiIn>>,
/// Main audio outputs.
pub audio_outs: Option<Vec<Port<AudioOut>>>, pub audio_outs: Option<Vec<Port<AudioOut>>>,
/// JACK transport handle.
pub transport: Option<Transport>,
/// Transport status
pub playing: Option<TransportState>,
/// Current transport position
pub playhead: usize,
/// Current sample rate and tempo.
pub timebase: Arc<Timebase>,
/// Display mode of grid section
pub grid_mode: bool,
/// Display mode of chain section
pub chain_mode: bool,
/// Display mode of sequencer seciton
pub seq_mode: bool,
/// Optional modal dialog
pub modal: Option<Box<dyn Component>>,
/// Currently focused section
pub section: usize,
/// Whether the section is focused
pub entered: bool,
/// Current frame
pub metronome: bool, pub metronome: bool,
/// Display position of cursor within note range
pub note_cursor: usize,
/// Range of notes to display /// Range of notes to display
pub note_start: usize, pub note_start: usize,
/// Position of cursor within note range /// Display position of cursor within time range
pub note_cursor: usize, pub time_cursor: usize,
/// PPQ per display unit /// PPQ per display unit
pub time_zoom: usize, pub time_zoom: usize,
/// Range of time steps to display /// Range of time steps to display
pub time_start: usize, pub time_start: usize,
/// Position of cursor within time range /// Focused scene+1, 0 is track list
pub time_cursor: usize, pub scene_cursor: usize,
/// Collection of scenes
pub scenes: Vec<Scene>,
/// Focused track+1, 0 is scene list
pub track_cursor: usize,
/// Collection of tracks
pub tracks: Vec<Track>,
} }
process!(App |self, _client, scope| { process!(App |self, _client, scope| {

View file

@ -45,7 +45,7 @@ render!(App |self, buf, area| {
ChainView { focused: self.section == 1, track: Some(track) } ChainView { focused: self.section == 1, track: Some(track) }
.render(buf, Rect { x, y: y + height - height / 3 - 1, width, height: height / 3 })?.height; .render(buf, Rect { x, y: y + height - height / 3 - 1, width, height: height / 3 })?.height;
y = y + SequencerView { SequencerView {
focused: self.section == 2, focused: self.section == 2,
ppq: self.timebase.ppq() as usize, ppq: self.timebase.ppq() as usize,
now: self.timebase.frames_pulses(self.playhead as f64) as usize, now: self.timebase.frames_pulses(self.playhead as f64) as usize,
@ -55,7 +55,7 @@ render!(App |self, buf, area| {
time_zoom: self.time_zoom, time_zoom: self.time_zoom,
note_cursor: self.note_cursor, note_cursor: self.note_cursor,
note_start: self.note_start, note_start: self.note_start,
}.render(buf, Rect { x, y, width, height: height - height / 3 })?.height; }.render(buf, Rect { x, y, width, height: height - height / 3 })?;
} }
if let Some(ref modal) = self.modal { if let Some(ref modal) = self.modal {