mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
chore: format
This commit is contained in:
parent
a3c21fa192
commit
4aadc712b8
4 changed files with 109 additions and 97 deletions
|
|
@ -1,69 +1,63 @@
|
||||||
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",
|
|
||||||
|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 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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
76
src/main.rs
76
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() {
|
//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(())
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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| {
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue