diff --git a/src/config.rs b/src/config.rs index 3a9b062a..883eab99 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use std::fs::{File, create_dir_all}; const CONFIG_FILE_NAME: &'static str = "tek.toml"; const PROJECT_FILE_NAME: &'static str = "project.toml"; +/// Filesystem locations of things. pub struct AppPaths { config_dir: PathBuf, config_file: PathBuf, @@ -49,6 +50,7 @@ impl AppPaths { } } +/// Appears on first run (i.e. if state dir is missing). pub struct SetupModal(pub Option>, pub bool); render!(SetupModal |self, buf, area| { diff --git a/src/control.rs b/src/control.rs index 54ca57d2..d2507ae6 100644 --- a/src/control.rs +++ b/src/control.rs @@ -2,7 +2,7 @@ use crate::{core::*, handle, App, AppFocus}; -pubmod!{ arranger chain focus mixer plugin sampler sequencer transport } +submod!{ arranger chain focus mixer plugin sampler sequencer transport } handle!{ App |self, e| { @@ -16,10 +16,10 @@ handle!{ } Ok(if self.entered { handle_focused(self, e)? - || handle_keymap(self, e, KEYMAP)? + || handle_keymap(self, e, KEYMAP_GLOBAL)? || handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)? } else { - handle_keymap(self, e, KEYMAP)? + handle_keymap(self, e, KEYMAP_GLOBAL)? || handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)? || handle_focused(self, e)? }) @@ -51,7 +51,8 @@ fn handle_device (state: &mut App, e: &AppEvent) -> Usually { .map(|x|x.unwrap_or(false)) } -pub const KEYMAP: &'static [KeyBinding] = keymap!(App { +/// Global key bindings. +pub const KEYMAP_GLOBAL: &'static [KeyBinding] = keymap!(App { [Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| { app.transport.toggle_play()?; Ok(true) diff --git a/src/control/arranger.rs b/src/control/arranger.rs index 592e5998..2277d98d 100644 --- a/src/control/arranger.rs +++ b/src/control/arranger.rs @@ -1,5 +1,6 @@ use crate::{core::*, model::App}; +/// Key bindings for arranger section. pub const KEYMAP_ARRANGER: &'static [KeyBinding] = keymap!(App { [Char('`'), NONE, "arranger_mode_switch", "switch the display mode", |app: &mut App| { app.arranger_mode = !app.arranger_mode; diff --git a/src/control/chain.rs b/src/control/chain.rs index 280eefb0..f5f5e0d2 100644 --- a/src/control/chain.rs +++ b/src/control/chain.rs @@ -1,5 +1,6 @@ use crate::{core::*, model::App}; +/// Key bindings for chain section. pub const KEYMAP_CHAIN: &'static [KeyBinding] = keymap!(App { [Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut App| { Ok(true) diff --git a/src/control/focus.rs b/src/control/focus.rs index fa0fb71d..6a5b3f75 100644 --- a/src/control/focus.rs +++ b/src/control/focus.rs @@ -1,5 +1,6 @@ use crate::{core::*, model::{App, AppFocus}}; +/// Generic key bindings for views that support focus. pub const KEYMAP_FOCUS: &'static [KeyBinding] = keymap!(App { [Char(';'), NONE, "command", "open command palette", |app: &mut App| { app.modal = Some(Box::new(crate::view::HelpModal::new())); diff --git a/src/control/mixer.rs b/src/control/mixer.rs index 38909668..5ae4d241 100644 --- a/src/control/mixer.rs +++ b/src/control/mixer.rs @@ -10,7 +10,7 @@ use crate::{core::*, model::*}; //("Ins/Del", "Add/remove track"), //]; -pub fn handle (state: &mut Mixer, event: &AppEvent) -> Usually { +pub fn handle_mixer (state: &mut Mixer, event: &AppEvent) -> Usually { if let AppEvent::Input(crossterm::event::Event::Key(event)) = event { match event.code { diff --git a/src/control/plugin.rs b/src/control/plugin.rs index 5f9adafa..41fd9d87 100644 --- a/src/control/plugin.rs +++ b/src/control/plugin.rs @@ -1,10 +1,11 @@ use crate::{core::*, model::*}; -pub fn handle (state: &mut Plugin, event: &AppEvent) -> Usually { - handle_keymap(state, event, KEYMAP) +pub fn handle_plugin (state: &mut Plugin, event: &AppEvent) -> Usually { + handle_keymap(state, event, KEYMAP_PLUGIN) } -pub const KEYMAP: &'static [KeyBinding] = keymap!(Plugin { +/// Key bindings for plugin device. +pub const KEYMAP_PLUGIN: &'static [KeyBinding] = keymap!(Plugin { [Up, NONE, "cursor_up", "move cursor up", |s: &mut Plugin|{ s.selected = s.selected.saturating_sub(1); Ok(true) diff --git a/src/control/sampler.rs b/src/control/sampler.rs index bbdf51a4..97c8b492 100644 --- a/src/control/sampler.rs +++ b/src/control/sampler.rs @@ -1,10 +1,11 @@ use crate::{core::*, model::*}; -pub fn handle (state: &mut Sampler, event: &AppEvent) -> Usually { - handle_keymap(state, event, KEYMAP) +pub fn handle_sampler (state: &mut Sampler, event: &AppEvent) -> Usually { + handle_keymap(state, event, KEYMAP_SAMPLER) } -pub const KEYMAP: &'static [KeyBinding] = keymap!(Sampler { +/// Key bindings for sampler device. +pub const KEYMAP_SAMPLER: &'static [KeyBinding] = keymap!(Sampler { [Up, NONE, "cursor_up", "move cursor up", cursor_up], [Down, NONE, "cursor_down", "move cursor down", cursor_down], [Char('t'), NONE, "sample_play", "play current sample", trigger], diff --git a/src/control/sequencer.rs b/src/control/sequencer.rs index 73a309c0..20d08515 100644 --- a/src/control/sequencer.rs +++ b/src/control/sequencer.rs @@ -1,5 +1,6 @@ use crate::{core::*, model::App}; +/// Key bindings for phrase editor. pub const KEYMAP_SEQUENCER: &'static [KeyBinding] = keymap!(App { [Up, NONE, "seq_cursor_up", "move cursor up", |app: &mut App| { app.note_cursor = app.note_cursor.saturating_sub(1); diff --git a/src/control/transport.rs b/src/control/transport.rs index 2fa7dbe8..e279410f 100644 --- a/src/control/transport.rs +++ b/src/control/transport.rs @@ -1,5 +1,6 @@ use crate::{core::*, model::{App, TransportFocus}}; +/// Key bindings for transport toolbar. pub const KEYMAP_TRANSPORT: &'static [KeyBinding] = keymap!(App { [Left, NONE, "transport_prev", "select previous control", |app: &mut App| Ok({ app.transport.selected.prev(); diff --git a/src/edn.rs b/src/edn.rs index 87230f87..1e77b946 100644 --- a/src/edn.rs +++ b/src/edn.rs @@ -1,9 +1,23 @@ //! Project file format. +//! +//! This module `impl`s the `from_edn`, `load_edn`, etc. methods +//! of structs that are defined in other modules. See: +//! +//! * [App::from_edn] +//! * [App::load_edn] +//! * [App::load_edn_one] +//! * [Scene::load_edn] +//! * [Track::load_edn] +//! * [Phrase::load_edn] +//! * [Sampler::load_edn] +//! * [Sample::load_edn] +//! * [LV2Plugin::load_edn] use crate::{core::*, model::*, App}; use clojure_reader::{edn::{read, Edn}, error::Error as EdnError}; +/// EDN parsing helper. macro_rules! edn { ($edn:ident { $($pat:pat => $expr:expr),* $(,)? }) => { match $edn { $($pat => $expr),* } diff --git a/src/model/mixer.rs b/src/model/mixer.rs index f5bc7273..cd69ecdc 100644 --- a/src/model/mixer.rs +++ b/src/model/mixer.rs @@ -7,7 +7,7 @@ pub struct Mixer { pub selected_column: usize, } //render!(Mixer = crate::view::mixer::render); -handle!(Mixer = crate::control::mixer::handle); +handle!(Mixer = crate::control::handle_mixer); process!(Mixer = process); impl Mixer { diff --git a/src/model/plugin.rs b/src/model/plugin.rs index bbc2cfd2..26a00861 100644 --- a/src/model/plugin.rs +++ b/src/model/plugin.rs @@ -15,7 +15,7 @@ pub struct Plugin { pub ports: JackPorts, } render!(Plugin = crate::view::plugin::render); -handle!(Plugin = crate::control::plugin::handle); +handle!(Plugin = crate::control::handle_plugin); process!(Plugin = Plugin::process); pub enum PluginKind { diff --git a/src/model/sampler.rs b/src/model/sampler.rs index 57a3b8e9..fc0841a4 100644 --- a/src/model/sampler.rs +++ b/src/model/sampler.rs @@ -41,7 +41,7 @@ render!(Sampler |self, buf, area| { Ok(Rect { x, y, width: (width as u16).min(area.width), height }) }); -handle!(Sampler = crate::control::sampler::handle); +handle!(Sampler = crate::control::handle_sampler); process!(Sampler = Sampler::process); impl Sampler { diff --git a/src/view/help.rs b/src/view/help.rs index 6f17160d..a3d0799e 100644 --- a/src/view/help.rs +++ b/src/view/help.rs @@ -48,11 +48,11 @@ render!(HelpModal |self, buf, area|{ let y = y + 1; for i in 0..height-3 { let y = y + i; - if let Some(command) = crate::control::focus::KEYMAP_FOCUS.get(i as usize) { + if let Some(command) = crate::control::KEYMAP_FOCUS.get(i as usize) { format!("{:?}", command.0).blit(buf, x, y, Some(Style::default().white().bold()))?; command.2.blit(buf, x + 11, y, Some(Style::default().white().bold()))?; command.3.blit(buf, x + 26, y, Some(Style::default().white().dim()))?; - } else if let Some(command) = crate::control::KEYMAP.get((i as usize) - crate::control::focus::KEYMAP_FOCUS.len()) { + } else if let Some(command) = crate::control::KEYMAP.get((i as usize) - crate::control::KEYMAP_FOCUS.len()) { format!("{:?}", command.0).blit(buf, x, y, Some(Style::default().white().bold()))?; command.2.blit(buf, x + 11, y, Some(Style::default().white().bold()))?; command.3.blit(buf, x + 26, y, Some(Style::default().white().dim()))?;