docs: add more doc strings

This commit is contained in:
🪞👃🪞 2024-07-12 20:21:07 +03:00
parent 317547c6b2
commit 107e38278e
15 changed files with 40 additions and 16 deletions

View file

@ -7,6 +7,7 @@ use std::fs::{File, create_dir_all};
const CONFIG_FILE_NAME: &'static str = "tek.toml"; const CONFIG_FILE_NAME: &'static str = "tek.toml";
const PROJECT_FILE_NAME: &'static str = "project.toml"; const PROJECT_FILE_NAME: &'static str = "project.toml";
/// Filesystem locations of things.
pub struct AppPaths { pub struct AppPaths {
config_dir: PathBuf, config_dir: PathBuf,
config_file: 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<Arc<XdgApp>>, pub bool); pub struct SetupModal(pub Option<Arc<XdgApp>>, pub bool);
render!(SetupModal |self, buf, area| { render!(SetupModal |self, buf, area| {

View file

@ -2,7 +2,7 @@
use crate::{core::*, handle, App, AppFocus}; 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!{ handle!{
App |self, e| { App |self, e| {
@ -16,10 +16,10 @@ handle!{
} }
Ok(if self.entered { Ok(if self.entered {
handle_focused(self, e)? handle_focused(self, e)?
|| handle_keymap(self, e, KEYMAP)? || handle_keymap(self, e, KEYMAP_GLOBAL)?
|| handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)? || handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)?
} else { } else {
handle_keymap(self, e, KEYMAP)? handle_keymap(self, e, KEYMAP_GLOBAL)?
|| handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)? || handle_keymap(self, e, crate::control::focus::KEYMAP_FOCUS)?
|| handle_focused(self, e)? || handle_focused(self, e)?
}) })
@ -51,7 +51,8 @@ fn handle_device (state: &mut App, e: &AppEvent) -> Usually<bool> {
.map(|x|x.unwrap_or(false)) .map(|x|x.unwrap_or(false))
} }
pub const KEYMAP: &'static [KeyBinding<App>] = keymap!(App { /// Global key bindings.
pub const KEYMAP_GLOBAL: &'static [KeyBinding<App>] = keymap!(App {
[Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| { [Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| {
app.transport.toggle_play()?; app.transport.toggle_play()?;
Ok(true) Ok(true)

View file

@ -1,5 +1,6 @@
use crate::{core::*, model::App}; use crate::{core::*, model::App};
/// Key bindings for arranger section.
pub const KEYMAP_ARRANGER: &'static [KeyBinding<App>] = keymap!(App { pub const KEYMAP_ARRANGER: &'static [KeyBinding<App>] = keymap!(App {
[Char('`'), NONE, "arranger_mode_switch", "switch the display mode", |app: &mut App| { [Char('`'), NONE, "arranger_mode_switch", "switch the display mode", |app: &mut App| {
app.arranger_mode = !app.arranger_mode; app.arranger_mode = !app.arranger_mode;

View file

@ -1,5 +1,6 @@
use crate::{core::*, model::App}; use crate::{core::*, model::App};
/// Key bindings for chain section.
pub const KEYMAP_CHAIN: &'static [KeyBinding<App>] = keymap!(App { pub const KEYMAP_CHAIN: &'static [KeyBinding<App>] = keymap!(App {
[Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut App| { [Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut App| {
Ok(true) Ok(true)

View file

@ -1,5 +1,6 @@
use crate::{core::*, model::{App, AppFocus}}; use crate::{core::*, model::{App, AppFocus}};
/// Generic key bindings for views that support focus.
pub const KEYMAP_FOCUS: &'static [KeyBinding<App>] = keymap!(App { pub const KEYMAP_FOCUS: &'static [KeyBinding<App>] = keymap!(App {
[Char(';'), NONE, "command", "open command palette", |app: &mut App| { [Char(';'), NONE, "command", "open command palette", |app: &mut App| {
app.modal = Some(Box::new(crate::view::HelpModal::new())); app.modal = Some(Box::new(crate::view::HelpModal::new()));

View file

@ -10,7 +10,7 @@ use crate::{core::*, model::*};
//("Ins/Del", "Add/remove track"), //("Ins/Del", "Add/remove track"),
//]; //];
pub fn handle (state: &mut Mixer, event: &AppEvent) -> Usually<bool> { pub fn handle_mixer (state: &mut Mixer, event: &AppEvent) -> Usually<bool> {
if let AppEvent::Input(crossterm::event::Event::Key(event)) = event { if let AppEvent::Input(crossterm::event::Event::Key(event)) = event {
match event.code { match event.code {

View file

@ -1,10 +1,11 @@
use crate::{core::*, model::*}; use crate::{core::*, model::*};
pub fn handle (state: &mut Plugin, event: &AppEvent) -> Usually<bool> { pub fn handle_plugin (state: &mut Plugin, event: &AppEvent) -> Usually<bool> {
handle_keymap(state, event, KEYMAP) handle_keymap(state, event, KEYMAP_PLUGIN)
} }
pub const KEYMAP: &'static [KeyBinding<Plugin>] = keymap!(Plugin { /// Key bindings for plugin device.
pub const KEYMAP_PLUGIN: &'static [KeyBinding<Plugin>] = keymap!(Plugin {
[Up, NONE, "cursor_up", "move cursor up", |s: &mut Plugin|{ [Up, NONE, "cursor_up", "move cursor up", |s: &mut Plugin|{
s.selected = s.selected.saturating_sub(1); s.selected = s.selected.saturating_sub(1);
Ok(true) Ok(true)

View file

@ -1,10 +1,11 @@
use crate::{core::*, model::*}; use crate::{core::*, model::*};
pub fn handle (state: &mut Sampler, event: &AppEvent) -> Usually<bool> { pub fn handle_sampler (state: &mut Sampler, event: &AppEvent) -> Usually<bool> {
handle_keymap(state, event, KEYMAP) handle_keymap(state, event, KEYMAP_SAMPLER)
} }
pub const KEYMAP: &'static [KeyBinding<Sampler>] = keymap!(Sampler { /// Key bindings for sampler device.
pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
[Up, NONE, "cursor_up", "move cursor up", cursor_up], [Up, NONE, "cursor_up", "move cursor up", cursor_up],
[Down, NONE, "cursor_down", "move cursor down", cursor_down], [Down, NONE, "cursor_down", "move cursor down", cursor_down],
[Char('t'), NONE, "sample_play", "play current sample", trigger], [Char('t'), NONE, "sample_play", "play current sample", trigger],

View file

@ -1,5 +1,6 @@
use crate::{core::*, model::App}; use crate::{core::*, model::App};
/// Key bindings for phrase editor.
pub const KEYMAP_SEQUENCER: &'static [KeyBinding<App>] = keymap!(App { pub const KEYMAP_SEQUENCER: &'static [KeyBinding<App>] = keymap!(App {
[Up, NONE, "seq_cursor_up", "move cursor up", |app: &mut App| { [Up, NONE, "seq_cursor_up", "move cursor up", |app: &mut App| {
app.note_cursor = app.note_cursor.saturating_sub(1); app.note_cursor = app.note_cursor.saturating_sub(1);

View file

@ -1,5 +1,6 @@
use crate::{core::*, model::{App, TransportFocus}}; use crate::{core::*, model::{App, TransportFocus}};
/// Key bindings for transport toolbar.
pub const KEYMAP_TRANSPORT: &'static [KeyBinding<App>] = keymap!(App { pub const KEYMAP_TRANSPORT: &'static [KeyBinding<App>] = keymap!(App {
[Left, NONE, "transport_prev", "select previous control", |app: &mut App| Ok({ [Left, NONE, "transport_prev", "select previous control", |app: &mut App| Ok({
app.transport.selected.prev(); app.transport.selected.prev();

View file

@ -1,9 +1,23 @@
//! Project file format. //! 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 crate::{core::*, model::*, App};
use clojure_reader::{edn::{read, Edn}, error::Error as EdnError}; use clojure_reader::{edn::{read, Edn}, error::Error as EdnError};
/// EDN parsing helper.
macro_rules! edn { macro_rules! edn {
($edn:ident { $($pat:pat => $expr:expr),* $(,)? }) => { ($edn:ident { $($pat:pat => $expr:expr),* $(,)? }) => {
match $edn { $($pat => $expr),* } match $edn { $($pat => $expr),* }

View file

@ -7,7 +7,7 @@ pub struct Mixer {
pub selected_column: usize, pub selected_column: usize,
} }
//render!(Mixer = crate::view::mixer::render); //render!(Mixer = crate::view::mixer::render);
handle!(Mixer = crate::control::mixer::handle); handle!(Mixer = crate::control::handle_mixer);
process!(Mixer = process); process!(Mixer = process);
impl Mixer { impl Mixer {

View file

@ -15,7 +15,7 @@ pub struct Plugin {
pub ports: JackPorts, pub ports: JackPorts,
} }
render!(Plugin = crate::view::plugin::render); render!(Plugin = crate::view::plugin::render);
handle!(Plugin = crate::control::plugin::handle); handle!(Plugin = crate::control::handle_plugin);
process!(Plugin = Plugin::process); process!(Plugin = Plugin::process);
pub enum PluginKind { pub enum PluginKind {

View file

@ -41,7 +41,7 @@ render!(Sampler |self, buf, area| {
Ok(Rect { x, y, width: (width as u16).min(area.width), height }) 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); process!(Sampler = Sampler::process);
impl Sampler { impl Sampler {

View file

@ -48,11 +48,11 @@ render!(HelpModal |self, buf, area|{
let y = y + 1; let y = y + 1;
for i in 0..height-3 { for i in 0..height-3 {
let y = y + i; 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()))?; 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.2.blit(buf, x + 11, y, Some(Style::default().white().bold()))?;
command.3.blit(buf, x + 26, y, Some(Style::default().white().dim()))?; 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()))?; 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.2.blit(buf, x + 11, y, Some(Style::default().white().bold()))?;
command.3.blit(buf, x + 26, y, Some(Style::default().white().dim()))?; command.3.blit(buf, x + 26, y, Some(Style::default().white().dim()))?;