diff --git a/src/control/plugin.rs b/src/control/plugin.rs index 21286a19..4fbbdde4 100644 --- a/src/control/plugin.rs +++ b/src/control/plugin.rs @@ -1,69 +1,63 @@ use crate::{core::*, model::*}; -pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually { - handle_keymap(s, event, keymap!(Plugin { - - [Up, NONE, "cursor_up", "move cursor up", - |s: &mut Plugin|{ - if s.selected > 0 { - s.selected = s.selected - 1 - } else { - s.selected = match &s.plugin { - Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1, - _ => 0 - } - } - Ok(true) - }], - - [Down, NONE, "cursor_down", "move cursor down", - |s: &mut Plugin|{ - s.selected = s.selected + 1; - match &s.plugin { - Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => { - if s.selected >= port_list.len() { - s.selected = 0; - } - }, - _ => {} - } - Ok(true) - }], - - [Char(','), NONE, "decrement", "decrement value", - |s: &mut Plugin|{ - match s.plugin.as_mut() { - Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { - let index = port_list[s.selected].index; - if let Some(value) = instance.control_input(index) { - instance.set_control_input(index, value - 0.01); - } - }, - _ => {} - } - Ok(true) - }], - - [Char('.'), NONE, "increment", "increment value", - |s: &mut Plugin|{ - match s.plugin.as_mut() { - Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { - let index = port_list[s.selected].index; - if let Some(value) = instance.control_input(index) { - instance.set_control_input(index, value + 0.01); - } - }, - _ => {} - } - Ok(true) - }], - - [Char('m'), NONE, "toggle_midi_map", "toggle midi map mode", - |s: &mut Plugin|{ - s.mapping = !s.mapping; - Ok(true) - }] - - })) +pub fn handle (state: &mut Plugin, event: &AppEvent) -> Usually { + handle_keymap(state, event, KEYMAP) } +pub const KEYMAP: &'static [KeyBinding] = keymap!(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 { + if s.selected > 0 { + s.selected = s.selected - 1 + } else { + s.selected = match &s.plugin { + Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1, + _ => 0 + } + } + Ok(true) +} + +fn cursor_down (s: &mut Plugin) -> Usually { + s.selected = s.selected + 1; + match &s.plugin { + Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => { + if s.selected >= port_list.len() { + s.selected = 0; + } + }, + _ => {} + } + Ok(true) +} + +fn decrement (s: &mut Plugin) -> Usually { + match s.plugin.as_mut() { + Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { + let index = port_list[s.selected].index; + if let Some(value) = instance.control_input(index) { + instance.set_control_input(index, value - 0.01); + } + }, + _ => {} + } + Ok(true) +} + +fn increment (s: &mut Plugin) -> Usually { + match s.plugin.as_mut() { + Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => { + let index = port_list[s.selected].index; + if let Some(value) = instance.control_input(index) { + instance.set_control_input(index, value + 0.01); + } + }, + _ => {} + } + Ok(true) +} diff --git a/src/control/sampler.rs b/src/control/sampler.rs index 611eb610..efac93e7 100644 --- a/src/control/sampler.rs +++ b/src/control/sampler.rs @@ -1,7 +1,7 @@ use crate::{core::*, model::*}; pub fn handle (state: &mut Sampler, event: &AppEvent) -> Usually { - Ok(handle_keymap(state, event, KEYMAP)?) + handle_keymap(state, event, KEYMAP) } pub const KEYMAP: &'static [KeyBinding] = keymap!(Sampler { diff --git a/src/main.rs b/src/main.rs index 0afdf40a..ae9f793d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,57 +72,75 @@ 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() { //if let Some(port) = track.midi_ins()?.get(0) { //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.transport = Some(client.transport()); state.playing = Some(TransportState::Stopped); - state.time_zoom = 12; - state.jack = Some(jack); + state.jack = Some(jack); Ok(()) })) } #[derive(Default)] pub struct App { + /// Paths to user directories pub xdg: Option>, + /// Main JACK client. pub jack: Option, - pub grid_mode: bool, - pub chain_mode: bool, - pub seq_mode: bool, - pub scenes: Vec, - pub scene_cursor: usize, - pub tracks: Vec, - pub track_cursor: usize, - pub frame: usize, - pub modal: Option>, - pub section: usize, - pub entered: bool, - pub playing: Option, - pub transport: Option, - pub timebase: Arc, - pub playhead: usize, + /// Main MIDI controller. pub midi_in: Option>, + /// Main audio outputs. pub audio_outs: Option>>, + /// JACK transport handle. + pub transport: Option, + /// Transport status + pub playing: Option, + /// Current transport position + pub playhead: usize, + /// Current sample rate and tempo. + pub timebase: Arc, + /// 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>, + /// Currently focused section + pub section: usize, + /// Whether the section is focused + pub entered: bool, + /// Current frame pub metronome: bool, + /// Display position of cursor within note range + pub note_cursor: usize, /// Range of notes to display - pub note_start: usize, - /// Position of cursor within note range - pub note_cursor: usize, + pub note_start: usize, + /// Display position of cursor within time range + pub time_cursor: usize, /// PPQ per display unit - pub time_zoom: usize, + pub time_zoom: usize, /// Range of time steps to display - pub time_start: usize, - /// Position of cursor within time range - pub time_cursor: usize, + pub time_start: usize, + /// Focused scene+1, 0 is track list + pub scene_cursor: usize, + /// Collection of scenes + pub scenes: Vec, + /// Focused track+1, 0 is scene list + pub track_cursor: usize, + /// Collection of tracks + pub tracks: Vec, } process!(App |self, _client, scope| { diff --git a/src/view.rs b/src/view.rs index 1dddb07e..524a9ea8 100644 --- a/src/view.rs +++ b/src/view.rs @@ -45,7 +45,7 @@ render!(App |self, buf, area| { ChainView { focused: self.section == 1, track: Some(track) } .render(buf, Rect { x, y: y + height - height / 3 - 1, width, height: height / 3 })?.height; - y = y + SequencerView { + SequencerView { focused: self.section == 2, ppq: self.timebase.ppq() 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, note_cursor: self.note_cursor, 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 {