mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
154 lines
5.9 KiB
Rust
154 lines
5.9 KiB
Rust
use crate::*;
|
|
|
|
pub fn tek_arc_str <'a> (_: &App, src: impl Language) -> Perhaps<Arc<str>> {
|
|
Ok(src.src()?.map(|x|x.into()))
|
|
}
|
|
|
|
pub fn tek_u16 <'a> (state: &App, src: impl Language) -> Perhaps<u16> {
|
|
Ok(Some(match src.word()? {
|
|
Some(":w/sidebar") => state.project.w_sidebar(state.editor().is_some()),
|
|
Some(":h/sample-detail") => 6.max(state.size.h() as u16 * 3 / 9),
|
|
_ => return try_to_u16(src)
|
|
}))
|
|
}
|
|
|
|
pub fn tek_usize <'a> (state: &App, src: impl Language) -> Perhaps<usize> {
|
|
Ok(Some(match src.word()? {
|
|
Some(":scene-count") => state.scenes().len(),
|
|
Some(":track-count") => state.tracks().len(),
|
|
Some(":device-kind") => state.dialog.device_kind().unwrap_or(0),
|
|
Some(":device-kind/next") => state.dialog.device_kind_next().unwrap_or(0),
|
|
Some(":device-kind/prev") => state.dialog.device_kind_prev().unwrap_or(0),
|
|
_ => return try_to_usize(src)
|
|
}))
|
|
}
|
|
|
|
pub fn tek_f64 <'a> (_state: &App, _src: impl Language) -> Perhaps<f64> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_bool <'a> (state: &App, src: impl Language) -> Perhaps<bool> {
|
|
src.word()?.map(|word|Ok(match word {
|
|
"Y" => true,
|
|
"N" => false,
|
|
":mode/editor" => state.project.editor.is_some(),
|
|
":focused/dialog" => !matches!(state.dialog, Dialog::None),
|
|
":focused/message" => matches!(state.dialog, Dialog::Message(..)),
|
|
":focused/add_device" => matches!(state.dialog, Dialog::Device(..)),
|
|
":focused/browser" => state.dialog.browser().is_some(),
|
|
//":focused/pool/import" => matches!(state.project.pool.mode, Some(PoolMode::Import(..))),
|
|
//":focused/pool/export" => matches!(state.project.pool.mode, Some(PoolMode::Export(..))),
|
|
//":focused/pool/rename" => matches!(state.project.pool.mode, Some(PoolMode::Rename(..))),
|
|
//":focused/pool/length" => matches!(state.project.pool.mode, Some(PoolMode::Length(..))),
|
|
":focused/clip" => matches!(state.selection(), Selection::TrackClip{..}),
|
|
":focused/track" => matches!(state.selection(), Selection::Track(..)),
|
|
":focused/scene" => matches!(state.selection(), Selection::Scene(..)),
|
|
":focused/mix" => matches!(state.selection(), Selection::Mix),
|
|
_ => return err!("not bool: {word}")
|
|
})).transpose()
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub fn tek_selection <'a> (state: &App, src: impl Language) -> Perhaps<Selection> {
|
|
src.word()?.map(|word|Ok(match word {
|
|
":select/scene" => state.selection().select_scene(state.tracks().len()),
|
|
":select/scene/next" => state.selection().select_scene_next(state.scenes().len()),
|
|
":select/scene/prev" => state.selection().select_scene_prev(),
|
|
":select/track" => state.selection().select_track(state.tracks().len()),
|
|
":select/track/next" => state.selection().select_track_next(state.tracks().len()),
|
|
":select/track/prev" => state.selection().select_track_prev(),
|
|
_ => return err!("not selection: {word}")
|
|
})).transpose()
|
|
}
|
|
|
|
pub fn tek_color <'a> (_: &App, src: impl Language) -> Perhaps<Color> {
|
|
if let Some(expr) = src.expr()? {
|
|
match (expr.head()?, expr.tail()?) {
|
|
(Some("g"), Some(tail)) => {
|
|
let n = try_to_u8(tail.head().map_err(Into::into))?
|
|
.ok_or(LanguageError::domain("not gray"))?;
|
|
Ok(Some(Color::Rgb(n, n, n)))
|
|
},
|
|
(Some("rgb"), Some(tail)) => {
|
|
let r = try_to_u8(tail.head().map_err(Into::into))?
|
|
.ok_or(LanguageError::domain("not red"))?;
|
|
let g = try_to_u8(tail.tail().head().map_err(Into::into))?
|
|
.ok_or(LanguageError::domain("not green"))?;
|
|
let b = try_to_u8(tail.tail().tail().head().map_err(Into::into))?
|
|
.ok_or(LanguageError::domain("not blue"))?;
|
|
Ok(Some(Color::Rgb(r, g, b)))
|
|
},
|
|
(Some(_), _) => return err!("not a color expression: {expr}"),
|
|
(None, _) => return err!("not a color expression: {expr}"),
|
|
}
|
|
} else if let Ok(Some(sym)) = src.word() {
|
|
Ok(match sym {
|
|
":color/bg" => Some(Color::Rgb(28, 32, 36)),
|
|
":color/fg" => Some(Color::Rgb(98, 92, 96)),
|
|
_ => return err!("not a color: {sym}")
|
|
})
|
|
} else {
|
|
return err!("not a color: {:?}", src.src()?)
|
|
}
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub fn tek_opt_u7 <'a> (state: &App, src: impl Language) -> Perhaps<Option<u7>> {
|
|
eval_word(src, |word|Ok(match word {
|
|
|
|
":editor/pitch" => Some((
|
|
state.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8
|
|
).into()),
|
|
|
|
_ => return err!("unknown midi note: {word}")
|
|
|
|
}))
|
|
}
|
|
|
|
pub fn tek_opt_usize <'a> (state: &App, src: impl Language) -> Perhaps<Option<usize>> {
|
|
eval_word(src, |word|Ok(match word {
|
|
|
|
":selected/scene" => state.selection().scene(),
|
|
":selected/track" => state.selection().track(),
|
|
|
|
_ => return err!("unknown opt<usize>: {word}")
|
|
|
|
}))
|
|
}
|
|
|
|
|
|
pub fn tek_opt_u16 <'a> (_: &App, _src: impl Language) -> Perhaps<Option<u16>> {
|
|
Ok(None)
|
|
}
|
|
|
|
pub fn tek_opt_u32 <'a> (_: &App, _src: impl Language) -> Perhaps<Option<u32>> {
|
|
Ok(None)
|
|
}
|
|
|
|
pub fn tek_opt_itemtheme <'a> (_: &App, _: impl Language) -> Perhaps<Option<ItemTheme>> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_opt_arc_array_connect <'a> (_: &App, _: impl Language) -> Perhaps<Option<Arc<[Connect]>>> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_arc_array_connect <'a> (_: &App, _: impl Language) -> Perhaps<Arc<[Connect]>> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_opt_arc_str <'a> (_: &App, _: impl Language) -> Perhaps<Option<Arc<str>>> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_opt_bool <'a> (_: &App, _: impl Language) -> Perhaps<Option<bool>> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_path_buf <'a> (_: &App, _: impl Language) -> Perhaps<PathBuf> {
|
|
todo!()
|
|
}
|
|
|
|
pub fn tek_vec_arc_str <'a> (_: &App, _: impl Language) -> Perhaps<Vec<Arc<str>>> {
|
|
todo!()
|
|
}
|