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,69 +1,63 @@
use crate::{core::*, model::*};
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
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<bool> {
handle_keymap(state, event, KEYMAP)
}
pub const KEYMAP: &'static [KeyBinding<Plugin>] = 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<bool> {
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<bool> {
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<bool> {
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<bool> {
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)
}

View file

@ -1,7 +1,7 @@
use crate::{core::*, model::*};
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 {

View file

@ -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<Arc<XdgApp>>,
/// Main JACK client.
pub jack: Option<DynamicAsyncClient>,
pub grid_mode: bool,
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,
/// Main MIDI controller.
pub midi_in: Option<Port<MidiIn>>,
/// Main audio outputs.
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,
/// 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<Scene>,
/// Focused track+1, 0 is scene list
pub track_cursor: usize,
/// Collection of tracks
pub tracks: Vec<Track>,
}
process!(App |self, _client, scope| {

View file

@ -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 {