mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
dsl_ns!
This commit is contained in:
parent
72975c861a
commit
525ed15466
5 changed files with 643 additions and 665 deletions
|
|
@ -41,6 +41,8 @@ use std::fmt::Write;
|
||||||
use ::tengri::tui::ratatui::prelude::Position;
|
use ::tengri::tui::ratatui::prelude::Position;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
mod app_view; pub use self::app_view::*;
|
mod app_view; pub use self::app_view::*;
|
||||||
|
mod app_ctrl; pub use self::app_ctrl::*;
|
||||||
|
mod app_jack; pub use self::app_jack::*;
|
||||||
#[cfg(test)] mod app_test;
|
#[cfg(test)] mod app_test;
|
||||||
/// Total state
|
/// Total state
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
@ -66,62 +68,6 @@ pub struct App {
|
||||||
/// Base color.
|
/// Base color.
|
||||||
pub color: ItemTheme,
|
pub color: ItemTheme,
|
||||||
}
|
}
|
||||||
macro_rules!dsl_expose(($Struct:ident { $($fn:ident: $ret:ty = |$self:ident|$body:expr);* $(;)? })=>{
|
|
||||||
#[tengri_proc::expose] impl $Struct { $(fn $fn (&$self) -> $ret { $body })* }
|
|
||||||
});
|
|
||||||
dsl_expose!(App {
|
|
||||||
_isize_stub: isize = |self|todo!();
|
|
||||||
_item_theme_stub: ItemTheme = |self|todo!();
|
|
||||||
w_sidebar: u16 = |self|self.project.w_sidebar(self.editor().is_some());
|
|
||||||
h_sample_detail: u16 = |self|6.max(self.height() as u16 * 3 / 9);
|
|
||||||
focus_editor: bool = |self|self.project.editor.is_some();
|
|
||||||
focus_dialog: bool = |self|!matches!(self.dialog, Dialog::None);
|
|
||||||
focus_message: bool = |self|matches!(self.dialog, Dialog::Message(..));
|
|
||||||
focus_add_device: bool = |self|matches!(self.dialog, Dialog::Device(..));
|
|
||||||
focus_browser: bool = |self|self.browser().is_some();
|
|
||||||
focus_clip: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::TrackClip{..});
|
|
||||||
focus_track: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Track(..));
|
|
||||||
focus_scene: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Scene(..));
|
|
||||||
focus_mix: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Mix);
|
|
||||||
focus_pool_import: bool = |self|matches!(self.pool.mode, Some(PoolMode::Import(..)));
|
|
||||||
focus_pool_export: bool = |self|matches!(self.pool.mode, Some(PoolMode::Export(..)));
|
|
||||||
focus_pool_rename: bool = |self|matches!(self.pool.mode, Some(PoolMode::Rename(..)));
|
|
||||||
focus_pool_length: bool = |self|matches!(self.pool.mode, Some(PoolMode::Length(..)));
|
|
||||||
dialog_none: Option<Dialog> = |self|None;
|
|
||||||
dialog_device: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
|
||||||
dialog_device_prev: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
|
||||||
dialog_device_next: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
|
||||||
dialog_help: Option<Dialog> = |self|Some(Dialog::Help(0));
|
|
||||||
dialog_menu: Option<Dialog> = |self|Some(Dialog::Menu(0));
|
|
||||||
dialog_save: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::SaveProject, Browser::new(None).unwrap()));
|
|
||||||
dialog_load: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::LoadProject, Browser::new(None).unwrap()));
|
|
||||||
dialog_import_clip: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ImportClip(Default::default()), Browser::new(None).unwrap()));
|
|
||||||
dialog_export_clip: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ExportClip(Default::default()), Browser::new(None).unwrap()));
|
|
||||||
dialog_import_sample: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ImportSample(Default::default()), Browser::new(None).unwrap()));
|
|
||||||
dialog_export_sample: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ExportSample(Default::default()), Browser::new(None).unwrap()));
|
|
||||||
dialog_options: Option<Dialog> = |self|Some(Dialog::Options);
|
|
||||||
editor_pitch: Option<u7> = |self|Some((self.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into());
|
|
||||||
scene_count: usize = |self|self.scenes().len();
|
|
||||||
scene_selected: Option<usize> = |self|self.selection().scene();
|
|
||||||
track_count: usize = |self|self.tracks().len();
|
|
||||||
track_selected: Option<usize> = |self|self.selection().track();
|
|
||||||
select_scene: Selection = |self|self.selection().select_scene(self.tracks().len());
|
|
||||||
select_scene_next: Selection = |self|self.selection().select_scene_next(self.scenes().len());
|
|
||||||
select_scene_prev: Selection = |self|self.selection().select_scene_prev();
|
|
||||||
select_track: Selection = |self|self.selection().select_track(self.tracks().len());
|
|
||||||
select_track_next: Selection = |self|self.selection().select_track_next(self.tracks().len());
|
|
||||||
select_track_prev: Selection = |self|self.selection().select_track_prev();
|
|
||||||
clip_selected: Option<Arc<RwLock<MidiClip>>> = |self|match self.selection() {
|
|
||||||
Selection::TrackClip { track, scene } => self.scenes()[*scene].clips[*track].clone(),
|
|
||||||
_ => None };
|
|
||||||
device_kind: usize = |self|if let Dialog::Device(index) = self.dialog {
|
|
||||||
index } else { 0 };
|
|
||||||
device_kind_next: usize = |self|if let Dialog::Device(index) = self.dialog {
|
|
||||||
(index + 1) % device_kinds().len() } else { 0 };
|
|
||||||
device_kind_prev: usize = |self|if let Dialog::Device(index) = self.dialog {
|
|
||||||
index.overflowing_sub(1).0.min(device_kinds().len().saturating_sub(1))
|
|
||||||
} else { 0 };
|
|
||||||
});
|
|
||||||
type ModuleMap<T> = Arc<RwLock<BTreeMap<Arc<str>, T>>>;
|
type ModuleMap<T> = Arc<RwLock<BTreeMap<Arc<str>, T>>>;
|
||||||
/// Configuration
|
/// Configuration
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
@ -263,7 +209,7 @@ pub enum Dialog {
|
||||||
Menu(usize),
|
Menu(usize),
|
||||||
Device(usize),
|
Device(usize),
|
||||||
Message(Arc<str>),
|
Message(Arc<str>),
|
||||||
Browser(BrowserTarget, Browser),
|
Browser(BrowserTarget, Arc<Browser>),
|
||||||
Options,
|
Options,
|
||||||
}
|
}
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -296,502 +242,10 @@ fn unquote (x: &str) -> &str {
|
||||||
//chars.next_back();
|
//chars.next_back();
|
||||||
chars.as_str()
|
chars.as_str()
|
||||||
}
|
}
|
||||||
impl ScenesView for App {
|
|
||||||
fn h_scenes (&self) -> u16 {
|
|
||||||
(self.height() as u16).saturating_sub(20)
|
|
||||||
}
|
|
||||||
fn w_side (&self) -> u16 {
|
|
||||||
20
|
|
||||||
}
|
|
||||||
fn w_mid (&self) -> u16 {
|
|
||||||
(self.width() as u16).saturating_sub(self.w_side())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl App {
|
|
||||||
fn handle_tui_key_with_history (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
|
||||||
panic!("{input:?}");
|
|
||||||
//Ok(if let Some(binding) = self.profile.as_ref()
|
|
||||||
//.map(|c|c.keys.dispatch(input.event())).flatten()
|
|
||||||
//{
|
|
||||||
//let binding = binding.clone();
|
|
||||||
//let undo = binding.command.clone().execute(self)?;
|
|
||||||
//// FIXME failed commands are not persisted in undo history
|
|
||||||
////self.history.push((binding.command.clone(), undo));
|
|
||||||
//Some(true)
|
|
||||||
//} else {
|
|
||||||
//None
|
|
||||||
//})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MaybeClip = Option<Arc<RwLock<MidiClip>>>;
|
|
||||||
macro_rules! ns { ($C:ty, $s:expr, $a:expr, $W:expr) => { <$C>::try_from_expr($s, $a).map($W) } }
|
|
||||||
macro_rules! cmd { ($cmd:expr) => {{ $cmd; None }}; }
|
|
||||||
macro_rules! cmd_todo { ($msg:literal) => {{ println!($msg); None }}; }
|
|
||||||
|
|
||||||
macro_rules!dsl_bind(($Command:ident: $State:ident {
|
|
||||||
$($fn:ident = |$state:ident $(, $arg:ident:$ty:ty)*|$body:expr);* $(;)?
|
|
||||||
})=>{
|
|
||||||
handle!(TuiIn: |self: $State, input|self.handle_tui_key_with_history(input));
|
|
||||||
#[tengri_proc::command(App)] impl $Command {
|
|
||||||
$(fn $fn ($state: &mut $State $(, $arg:$ty)*) -> Perhaps<Self> { $body })*
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dsl_bind!(AppCommand: App {
|
|
||||||
enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
|
|
||||||
history = |app, delta: isize| { todo!() };
|
|
||||||
zoom = |app, zoom: usize| { todo!() };
|
|
||||||
stop_all = |app| { app.tracks_stop_all(); Ok(None) };
|
|
||||||
//dialog = |app, command: DialogCommand|
|
|
||||||
//Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
|
|
||||||
project = |app, command: ArrangementCommand|
|
|
||||||
Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
|
|
||||||
clock = |app, command: ClockCommand|
|
|
||||||
Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
|
|
||||||
sampler = |app, command: SamplerCommand|
|
|
||||||
Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
|
||||||
.transpose()?.flatten());
|
|
||||||
pool = |app, command: PoolCommand| {
|
|
||||||
let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
|
|
||||||
// update linked editor after pool action
|
|
||||||
match command {
|
|
||||||
// autoselect: automatically load selected clip in editor
|
|
||||||
PoolCommand::Select { .. } |
|
|
||||||
// autocolor: update color in all places simultaneously
|
|
||||||
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => {
|
|
||||||
let clip = app.pool.clip().clone();
|
|
||||||
app.editor_mut().map(|editor|editor.set_clip(clip.as_ref()))
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
};
|
|
||||||
Ok(undo)
|
|
||||||
};
|
|
||||||
select = |app, selection: Selection| {
|
|
||||||
*app.project.selection_mut() = selection;
|
|
||||||
//todo!
|
|
||||||
//if let Some(ref mut editor) = app.editor_mut() {
|
|
||||||
//editor.set_clip(match selection {
|
|
||||||
//Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
|
|
||||||
//.project
|
|
||||||
//.scenes.get(scene)
|
|
||||||
//.map(|s|s.clips.get(track))
|
|
||||||
//=>
|
|
||||||
//Some(clip),
|
|
||||||
//_ =>
|
|
||||||
//None
|
|
||||||
//});
|
|
||||||
//}
|
|
||||||
Ok(None)
|
|
||||||
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
|
||||||
//(0, 0) => Self::Select(Selection::Mix),
|
|
||||||
//(t, 0) => Self::Select(Selection::Track(t)),
|
|
||||||
//(0, s) => Self::Select(Selection::Scene(s)),
|
|
||||||
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
|
||||||
// autoedit: load focused clip in editor.
|
|
||||||
};
|
|
||||||
//fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
|
||||||
//Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
|
||||||
//}
|
|
||||||
//fn launch (app: &mut App) -> Perhaps<Self> {
|
|
||||||
//app.project.launch();
|
|
||||||
//Ok(None)
|
|
||||||
//}
|
|
||||||
toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
|
|
||||||
editor = |app, command: MidiEditCommand| Ok(if let Some(editor) = app.editor_mut() {
|
|
||||||
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
|
||||||
// update linked sampler after editor action
|
|
||||||
app.project.sampler_mut().map(|sampler|match command {
|
|
||||||
// autoselect: automatically select sample in sampler
|
|
||||||
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
|
||||||
_ => {}
|
|
||||||
});
|
|
||||||
undo
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//take!(ClockCommand |state: App, iter|Take::take(state.clock(), iter));
|
|
||||||
//take!(MidiEditCommand |state: App, iter|Ok(state.editor().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
|
||||||
//take!(PoolCommand |state: App, iter|Take::take(&state.pool, iter));
|
|
||||||
//take!(SamplerCommand |state: App, iter|Ok(state.project.sampler().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
|
||||||
//take!(ArrangementCommand |state: App, iter|Take::take(&state.project, iter));
|
|
||||||
//take!(DialogCommand |state: App, iter|Take::take(&state.dialog, iter));
|
|
||||||
//has_editor!(|self: App|{
|
|
||||||
//editor = self.editor;
|
|
||||||
//editor_w = {
|
|
||||||
//let size = self.size.w();
|
|
||||||
//let editor = self.editor.as_ref().expect("missing editor");
|
|
||||||
//let time_len = editor.time_len().get();
|
|
||||||
//let time_zoom = editor.time_zoom().get().max(1);
|
|
||||||
//(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
|
|
||||||
//};
|
|
||||||
//editor_h = 15;
|
|
||||||
//is_editing = self.editor.is_some();
|
|
||||||
//});
|
|
||||||
impl Dialog {
|
impl Dialog {
|
||||||
fn menu_selected (&self) -> Option<usize> { todo!() }
|
fn menu_selected (&self) -> Option<usize> { todo!() }
|
||||||
fn device_selected (&self) -> Option<usize> { todo!() }
|
fn device_selected (&self) -> Option<usize> { todo!() }
|
||||||
fn message (&self) -> Option<&str> { todo!() }
|
fn message (&self) -> Option<&str> { todo!() }
|
||||||
fn browser (&self) -> Option<&Browser> { todo!() }
|
fn browser (&self) -> Option<&Arc<Browser>> { todo!() }
|
||||||
fn browser_target (&self) -> Option<&BrowserTarget> { todo!() }
|
fn browser_target (&self) -> Option<&BrowserTarget> { todo!() }
|
||||||
}
|
}
|
||||||
#[tengri_proc::command(Option<Dialog>)] impl DialogCommand {
|
|
||||||
fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
|
||||||
*dialog = Some(new);
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
|
||||||
*dialog = None;
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl HasJack<'static> for App {
|
|
||||||
fn jack (&self) -> &Jack<'static> {
|
|
||||||
&self.jack
|
|
||||||
}
|
|
||||||
}
|
|
||||||
audio!(
|
|
||||||
|self: App, client, scope|{
|
|
||||||
let t0 = self.perf.get_t0();
|
|
||||||
self.clock().update_from_scope(scope).unwrap();
|
|
||||||
let midi_in = self.project.midi_input_collect(scope);
|
|
||||||
if let Some(editor) = &self.editor() {
|
|
||||||
let mut pitch: Option<u7> = None;
|
|
||||||
for port in midi_in.iter() {
|
|
||||||
for event in port.iter() {
|
|
||||||
if let (_, Ok(LiveEvent::Midi {message: MidiMessage::NoteOn {ref key, ..}, ..}))
|
|
||||||
= event
|
|
||||||
{
|
|
||||||
pitch = Some(key.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(pitch) = pitch {
|
|
||||||
editor.set_note_pos(pitch.as_int() as usize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let result = self.project.process_tracks(client, scope);
|
|
||||||
self.perf.update_from_jack_scope(t0, scope);
|
|
||||||
result
|
|
||||||
};
|
|
||||||
|self, event|{
|
|
||||||
use JackEvent::*;
|
|
||||||
match event {
|
|
||||||
SampleRate(sr) => {
|
|
||||||
self.clock().timebase.sr.set(sr as f64);
|
|
||||||
},
|
|
||||||
PortRegistration(id, true) => {
|
|
||||||
//let port = self.jack().port_by_id(id);
|
|
||||||
//println!("\rport add: {id} {port:?}");
|
|
||||||
//println!("\rport add: {id}");
|
|
||||||
},
|
|
||||||
PortRegistration(id, false) => {
|
|
||||||
/*println!("\rport del: {id}")*/
|
|
||||||
},
|
|
||||||
PortsConnected(a, b, true) => { /*println!("\rport conn: {a} {b}")*/ },
|
|
||||||
PortsConnected(a, b, false) => { /*println!("\rport disc: {a} {b}")*/ },
|
|
||||||
ClientRegistration(id, true) => {},
|
|
||||||
ClientRegistration(id, false) => {},
|
|
||||||
ThreadInit => {},
|
|
||||||
XRun => {},
|
|
||||||
GraphReorder => {},
|
|
||||||
_ => { panic!("{event:?}"); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
impl App {
|
|
||||||
pub fn toggle_dialog (&mut self, mut dialog: Dialog) -> Dialog {
|
|
||||||
std::mem::swap(&mut self.dialog, &mut dialog);
|
|
||||||
dialog
|
|
||||||
}
|
|
||||||
pub fn toggle_editor (&mut self, value: Option<bool>) {
|
|
||||||
//FIXME: self.editing.store(value.unwrap_or_else(||!self.is_editing()), Relaxed);
|
|
||||||
let value = value.unwrap_or_else(||!self.editor().is_some());
|
|
||||||
if value {
|
|
||||||
// Create new clip in pool when entering empty cell
|
|
||||||
if let Selection::TrackClip { track, scene } = *self.selection()
|
|
||||||
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
|
||||||
&& let Some(slot) = scene.clips.get_mut(track)
|
|
||||||
&& slot.is_none()
|
|
||||||
&& let Some(track) = self.project.tracks.get_mut(track)
|
|
||||||
{
|
|
||||||
let (index, mut clip) = self.pool.add_new_clip();
|
|
||||||
// autocolor: new clip colors from scene and track color
|
|
||||||
let color = track.color.base.mix(scene.color.base, 0.5);
|
|
||||||
clip.write().unwrap().color = ItemColor::random_near(color, 0.2).into();
|
|
||||||
if let Some(ref mut editor) = &mut self.project.editor {
|
|
||||||
editor.set_clip(Some(&clip));
|
|
||||||
}
|
|
||||||
*slot = Some(clip.clone());
|
|
||||||
//Some(clip)
|
|
||||||
} else {
|
|
||||||
//None
|
|
||||||
}
|
|
||||||
} else if let Selection::TrackClip { track, scene } = *self.selection()
|
|
||||||
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
|
||||||
&& let Some(slot) = scene.clips.get_mut(track)
|
|
||||||
&& let Some(clip) = slot.as_mut()
|
|
||||||
{
|
|
||||||
// Remove clip from arrangement when exiting empty clip editor
|
|
||||||
let mut swapped = None;
|
|
||||||
if clip.read().unwrap().count_midi_messages() == 0 {
|
|
||||||
std::mem::swap(&mut swapped, slot);
|
|
||||||
}
|
|
||||||
if let Some(clip) = swapped {
|
|
||||||
self.pool.delete_clip(&clip.read().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn browser (&self) -> Option<&Browser> {
|
|
||||||
if let Dialog::Browser(_, ref b) = self.dialog { Some(b) } else { None }
|
|
||||||
}
|
|
||||||
pub fn device_pick (&mut self, index: usize) {
|
|
||||||
self.dialog = Dialog::Device(index);
|
|
||||||
}
|
|
||||||
pub fn add_device (&mut self, index: usize) -> Usually<()> {
|
|
||||||
match index {
|
|
||||||
0 => {
|
|
||||||
let name = self.jack.with_client(|c|c.name().to_string());
|
|
||||||
let midi = self.project.track().expect("no active track").sequencer.midi_outs[0].port_name();
|
|
||||||
let track = self.track().expect("no active track");
|
|
||||||
let port = format!("{}/Sampler", &track.name);
|
|
||||||
let connect = Connect::exact(format!("{name}:{midi}"));
|
|
||||||
let sampler = if let Ok(sampler) = Sampler::new(
|
|
||||||
&self.jack, &port, &[connect], &[&[], &[]], &[&[], &[]]
|
|
||||||
) {
|
|
||||||
self.dialog = Dialog::None;
|
|
||||||
Device::Sampler(sampler)
|
|
||||||
} else {
|
|
||||||
self.dialog = Dialog::Message("Failed to add device.".into());
|
|
||||||
return Err("failed to add device".into())
|
|
||||||
};
|
|
||||||
let track = self.track_mut().expect("no active track");
|
|
||||||
track.devices.push(sampler);
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
1 => {
|
|
||||||
todo!();
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//#[derive(Clone, Debug)]
|
|
||||||
//pub enum DialogCommand {
|
|
||||||
//Open { dialog: Dialog },
|
|
||||||
//Close
|
|
||||||
//}
|
|
||||||
|
|
||||||
//impl Command<Option<Dialog>> for DialogCommand {
|
|
||||||
//fn execute (self, state: &mut Option<Dialog>) -> Perhaps<Self> {
|
|
||||||
//match self {
|
|
||||||
//Self::Open { dialog } => {
|
|
||||||
//*state = Some(dialog);
|
|
||||||
//},
|
|
||||||
//Self::Close => {
|
|
||||||
//*state = None;
|
|
||||||
//}
|
|
||||||
//};
|
|
||||||
//Ok(None)
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
||||||
//dsl!(DialogCommand: |self: Dialog, iter|todo!());
|
|
||||||
//Dsl::take(&mut self.dialog, iter));
|
|
||||||
|
|
||||||
//#[tengri_proc::command(Option<Dialog>)]//Nope.
|
|
||||||
//impl DialogCommand {
|
|
||||||
//fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
|
||||||
//*dialog = Some(new);
|
|
||||||
//Ok(None)
|
|
||||||
//}
|
|
||||||
//fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
|
||||||
//*dialog = None;
|
|
||||||
//Ok(None)
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|
|
|
||||||
//s.view_meters_input())
|
|
||||||
//}
|
|
||||||
//pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|
|
|
||||||
//s.view_meters_output())
|
|
||||||
//}
|
|
||||||
//pub fn view_history (&self) -> impl Content<TuiOut> {
|
|
||||||
//Fixed::y(1, Fill::x(Align::w(FieldH(self.color,
|
|
||||||
//format!("History ({})", self.history.len()),
|
|
||||||
//self.history.last().map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))))
|
|
||||||
//}
|
|
||||||
//pub fn view_status_h2 (&self) -> impl Content<TuiOut> {
|
|
||||||
//self.update_clock();
|
|
||||||
//let theme = self.color;
|
|
||||||
//let clock = self.clock();
|
|
||||||
//let playing = clock.is_rolling();
|
|
||||||
//let cache = clock.view_cache.clone();
|
|
||||||
////let selection = self.selection().describe(self.tracks(), self.scenes());
|
|
||||||
//let hist_len = self.history.len();
|
|
||||||
//let hist_last = self.history.last();
|
|
||||||
//Fixed::y(2, Stack::east(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
|
||||||
//add(&Fixed::x(5, Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
|
||||||
//Either::new(false, // TODO
|
|
||||||
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
|
||||||
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
|
||||||
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
|
||||||
//),
|
|
||||||
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
|
||||||
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
|
||||||
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
|
||||||
//)
|
|
||||||
//)
|
|
||||||
//)));
|
|
||||||
//add(&" ");
|
|
||||||
//{
|
|
||||||
//let cache = cache.read().unwrap();
|
|
||||||
//add(&Fixed::x(15, Align::w(Bsp::s(
|
|
||||||
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
|
||||||
//FieldH(theme, "Time", cache.time.view.clone()),
|
|
||||||
//))));
|
|
||||||
//add(&Fixed::x(13, Align::w(Bsp::s(
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
|
||||||
//))));
|
|
||||||
//add(&Fixed::x(12, Align::w(Bsp::s(
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "Buf", cache.buf.view.clone()))),
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "Lat", cache.lat.view.clone()))),
|
|
||||||
//))));
|
|
||||||
////add(&Bsp::s(
|
|
||||||
//////Fill::x(Align::w(FieldH(theme, "Selected", Align::w(selection)))),
|
|
||||||
////Fill::x(Align::w(FieldH(theme, format!("History ({})", hist_len),
|
|
||||||
////hist_last.map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))),
|
|
||||||
////""
|
|
||||||
////));
|
|
||||||
//////if let Some(last) = self.history.last() {
|
|
||||||
//////add(&FieldV(theme, format!("History ({})", self.history.len()),
|
|
||||||
//////Fill::x(Align::w(format!("{:?}", last.0)))));
|
|
||||||
//////}
|
|
||||||
//}
|
|
||||||
//}))
|
|
||||||
//}
|
|
||||||
//pub fn view_status_v (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.update_clock();
|
|
||||||
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
||||||
//let theme = self.color;
|
|
||||||
//let playing = self.clock().is_rolling();
|
|
||||||
//Tui::bg(theme.darker.rgb, Fixed::xy(20, 5, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
||||||
//col!(
|
|
||||||
//Fill::x(Align::w(Bsp::e(
|
|
||||||
//Align::w(Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
|
||||||
//Either::new(false, // TODO
|
|
||||||
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
|
||||||
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
|
||||||
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
|
||||||
//),
|
|
||||||
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
|
||||||
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
|
||||||
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
|
||||||
//)
|
|
||||||
//)
|
|
||||||
//)),
|
|
||||||
//Bsp::s(
|
|
||||||
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
|
||||||
//FieldH(theme, "Time", cache.time.view.clone()),
|
|
||||||
//),
|
|
||||||
//))),
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
|
||||||
//Fill::x(Align::w(FieldH(theme, "Buf", Bsp::e(cache.buf.view.clone(), Bsp::e(" = ", cache.lat.view.clone()))))),
|
|
||||||
//))))
|
|
||||||
//}
|
|
||||||
//pub fn view_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.update_clock();
|
|
||||||
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
||||||
//view_status(Some(self.project.selection.describe(self.tracks(), self.scenes())),
|
|
||||||
//cache.sr.view.clone(), cache.buf.view.clone(), cache.lat.view.clone())
|
|
||||||
//}
|
|
||||||
//pub fn view_transport (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.update_clock();
|
|
||||||
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
||||||
//view_transport(self.project.clock.is_rolling(),
|
|
||||||
//cache.bpm.view.clone(), cache.beat.view.clone(), cache.time.view.clone())
|
|
||||||
//}
|
|
||||||
//pub fn view_editor (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//let bg = self.editor()
|
|
||||||
//.and_then(|editor|editor.clip().clone())
|
|
||||||
//.map(|clip|clip.read().unwrap().color.darker)
|
|
||||||
//.unwrap_or(self.color.darker);
|
|
||||||
//Fill::xy(Tui::bg(bg.rgb, self.editor()))
|
|
||||||
//}
|
|
||||||
//pub fn view_editor_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.editor().map(|e|Fixed::x(20, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
||||||
//Fill::y(Align::n(Bsp::s(e.clip_status(), e.edit_status()))))))
|
|
||||||
//}
|
|
||||||
//pub fn view_midi_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_midi_ins_status(self.color)
|
|
||||||
//}
|
|
||||||
//pub fn view_midi_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_midi_outs_status(self.color)
|
|
||||||
//}
|
|
||||||
//pub fn view_audio_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_audio_ins_status(self.color)
|
|
||||||
//}
|
|
||||||
//pub fn view_audio_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_audio_outs_status(self.color)
|
|
||||||
//}
|
|
||||||
//pub fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//Bsp::e(
|
|
||||||
//Fixed::x(20, Align::nw(self.project.view_scenes_names())),
|
|
||||||
//self.project.view_scenes_clips(),
|
|
||||||
//)
|
|
||||||
//}
|
|
||||||
//pub fn view_scenes_names (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_scenes_names()
|
|
||||||
//}
|
|
||||||
//pub fn view_scenes_clips (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.view_scenes_clips()
|
|
||||||
//}
|
|
||||||
//pub fn view_tracks_inputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
//Fixed::y(1 + self.project.midi_ins.len() as u16,
|
|
||||||
//self.project.view_inputs(self.color))
|
|
||||||
//}
|
|
||||||
//pub fn view_tracks_outputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
//self.project.view_outputs(self.color)
|
|
||||||
//}
|
|
||||||
//pub fn view_tracks_devices <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
//Fixed::y(4, self.project.view_track_devices(self.color))
|
|
||||||
//}
|
|
||||||
//pub fn view_tracks_names <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
//Fixed::y(2, self.project.view_track_names(self.color))
|
|
||||||
//}
|
|
||||||
//pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//Fixed::x(20, Bsp::s(
|
|
||||||
//Fill::x(Align::w(FieldH(self.color, "Clip pool:", ""))),
|
|
||||||
//Fill::y(Align::n(Tui::bg(Rgb(0, 0, 0), Outer(true, Style::default().fg(Tui::g(96)))
|
|
||||||
//.enclose(PoolView(&self.pool)))))))
|
|
||||||
//}
|
|
||||||
//pub fn view_samples_keys (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|s.view_list(true, self.editor().unwrap()))
|
|
||||||
//}
|
|
||||||
//pub fn view_samples_grid (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|s.view_grid())
|
|
||||||
//}
|
|
||||||
//pub fn view_sample_viewer (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|s.view_sample(self.editor().unwrap().get_note_pos()))
|
|
||||||
//}
|
|
||||||
//pub fn view_sample_info (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|s.view_sample_info(self.editor().unwrap().get_note_pos()))
|
|
||||||
//}
|
|
||||||
//pub fn view_sample_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
//self.project.sampler().map(|s|Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
||||||
//Fill::y(Align::n(s.view_sample_status(self.editor().unwrap().get_note_pos())))))
|
|
||||||
//}
|
|
||||||
|
|
|
||||||
308
crates/app/app_ctrl.rs
Normal file
308
crates/app/app_ctrl.rs
Normal file
|
|
@ -0,0 +1,308 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
//handle!(TuiIn:|self: App, input|self.
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
fn handle_tui_key_with_history (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
||||||
|
panic!("{input:?}");
|
||||||
|
//Ok(if let Some(binding) = self.profile.as_ref()
|
||||||
|
//.map(|c|c.keys.dispatch(input.event())).flatten()
|
||||||
|
//{
|
||||||
|
//let binding = binding.clone();
|
||||||
|
//let undo = binding.command.clone().execute(self)?;
|
||||||
|
//// FIXME failed commands are not persisted in undo history
|
||||||
|
////self.history.push((binding.command.clone(), undo));
|
||||||
|
//Some(true)
|
||||||
|
//} else {
|
||||||
|
//None
|
||||||
|
//})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MaybeClip = Option<Arc<RwLock<MidiClip>>>;
|
||||||
|
|
||||||
|
macro_rules!dsl_expose(($Struct:ident { $($fn:ident: $ret:ty = |$self:ident|$body:expr);* $(;)? })=>{
|
||||||
|
#[tengri_proc::expose] impl $Struct { $(fn $fn (&$self) -> $ret { $body })* }
|
||||||
|
});
|
||||||
|
|
||||||
|
dsl_expose!(App {
|
||||||
|
_isize_stub: isize = |self|todo!();
|
||||||
|
_item_theme_stub: ItemTheme = |self|todo!();
|
||||||
|
w_sidebar: u16 = |self|self.project.w_sidebar(self.editor().is_some());
|
||||||
|
h_sample_detail: u16 = |self|6.max(self.height() as u16 * 3 / 9);
|
||||||
|
focus_editor: bool = |self|self.project.editor.is_some();
|
||||||
|
focus_dialog: bool = |self|!matches!(self.dialog, Dialog::None);
|
||||||
|
focus_message: bool = |self|matches!(self.dialog, Dialog::Message(..));
|
||||||
|
focus_add_device: bool = |self|matches!(self.dialog, Dialog::Device(..));
|
||||||
|
focus_browser: bool = |self|self.dialog.browser().is_some();
|
||||||
|
focus_clip: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::TrackClip{..});
|
||||||
|
focus_track: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Track(..));
|
||||||
|
focus_scene: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Scene(..));
|
||||||
|
focus_mix: bool = |self|!self.focus_editor() && matches!(self.selection(), Selection::Mix);
|
||||||
|
focus_pool_import: bool = |self|matches!(self.pool.mode, Some(PoolMode::Import(..)));
|
||||||
|
focus_pool_export: bool = |self|matches!(self.pool.mode, Some(PoolMode::Export(..)));
|
||||||
|
focus_pool_rename: bool = |self|matches!(self.pool.mode, Some(PoolMode::Rename(..)));
|
||||||
|
focus_pool_length: bool = |self|matches!(self.pool.mode, Some(PoolMode::Length(..)));
|
||||||
|
dialog_none: Option<Dialog> = |self|None;
|
||||||
|
dialog_device: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
||||||
|
dialog_device_prev: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
||||||
|
dialog_device_next: Option<Dialog> = |self|Some(Dialog::Device(0)); // TODO
|
||||||
|
dialog_help: Option<Dialog> = |self|Some(Dialog::Help(0));
|
||||||
|
dialog_menu: Option<Dialog> = |self|Some(Dialog::Menu(0));
|
||||||
|
dialog_save: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::SaveProject, Browser::new(None).unwrap().into()));
|
||||||
|
dialog_load: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::LoadProject, Browser::new(None).unwrap().into()));
|
||||||
|
dialog_import_clip: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ImportClip(Default::default()), Browser::new(None).unwrap().into()));
|
||||||
|
dialog_export_clip: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ExportClip(Default::default()), Browser::new(None).unwrap().into()));
|
||||||
|
dialog_import_sample: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ImportSample(Default::default()), Browser::new(None).unwrap().into()));
|
||||||
|
dialog_export_sample: Option<Dialog> = |self|Some(Dialog::Browser(BrowserTarget::ExportSample(Default::default()), Browser::new(None).unwrap().into()));
|
||||||
|
dialog_options: Option<Dialog> = |self|Some(Dialog::Options);
|
||||||
|
editor_pitch: Option<u7> = |self|Some((self.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into());
|
||||||
|
scene_count: usize = |self|self.scenes().len();
|
||||||
|
scene_selected: Option<usize> = |self|self.selection().scene();
|
||||||
|
track_count: usize = |self|self.tracks().len();
|
||||||
|
track_selected: Option<usize> = |self|self.selection().track();
|
||||||
|
select_scene: Selection = |self|self.selection().select_scene(self.tracks().len());
|
||||||
|
select_scene_next: Selection = |self|self.selection().select_scene_next(self.scenes().len());
|
||||||
|
select_scene_prev: Selection = |self|self.selection().select_scene_prev();
|
||||||
|
select_track: Selection = |self|self.selection().select_track(self.tracks().len());
|
||||||
|
select_track_next: Selection = |self|self.selection().select_track_next(self.tracks().len());
|
||||||
|
select_track_prev: Selection = |self|self.selection().select_track_prev();
|
||||||
|
clip_selected: Option<Arc<RwLock<MidiClip>>> = |self|match self.selection() {
|
||||||
|
Selection::TrackClip { track, scene } => self.scenes()[*scene].clips[*track].clone(),
|
||||||
|
_ => None };
|
||||||
|
device_kind: usize = |self|if let Dialog::Device(index) = self.dialog {
|
||||||
|
index } else { 0 };
|
||||||
|
device_kind_next: usize = |self|if let Dialog::Device(index) = self.dialog {
|
||||||
|
(index + 1) % device_kinds().len() } else { 0 };
|
||||||
|
device_kind_prev: usize = |self|if let Dialog::Device(index) = self.dialog {
|
||||||
|
index.overflowing_sub(1).0.min(device_kinds().len().saturating_sub(1))
|
||||||
|
} else { 0 };
|
||||||
|
});
|
||||||
|
|
||||||
|
macro_rules!dsl_bind(($Command:ident: $State:ident {
|
||||||
|
$($fn:ident = |$state:ident $(, $arg:ident:$ty:ty)*|$body:expr);* $(;)?
|
||||||
|
})=>{
|
||||||
|
handle!(TuiIn: |self: $State, input|self.handle_tui_key_with_history(input));
|
||||||
|
#[tengri_proc::command(App)] impl $Command {
|
||||||
|
$(fn $fn ($state: &mut $State $(, $arg:$ty)*) -> Perhaps<Self> { $body })*
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dsl_bind!(AppCommand: App {
|
||||||
|
enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
|
||||||
|
history = |app, delta: isize| { todo!() };
|
||||||
|
zoom = |app, zoom: usize| { todo!() };
|
||||||
|
stop_all = |app| { app.tracks_stop_all(); Ok(None) };
|
||||||
|
//dialog = |app, command: DialogCommand|
|
||||||
|
//Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
|
||||||
|
project = |app, command: ArrangementCommand|
|
||||||
|
Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
|
||||||
|
clock = |app, command: ClockCommand|
|
||||||
|
Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
|
||||||
|
sampler = |app, command: SamplerCommand|
|
||||||
|
Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
||||||
|
.transpose()?.flatten());
|
||||||
|
pool = |app, command: PoolCommand| {
|
||||||
|
let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
|
||||||
|
// update linked editor after pool action
|
||||||
|
match command {
|
||||||
|
// autoselect: automatically load selected clip in editor
|
||||||
|
PoolCommand::Select { .. } |
|
||||||
|
// autocolor: update color in all places simultaneously
|
||||||
|
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => {
|
||||||
|
let clip = app.pool.clip().clone();
|
||||||
|
app.editor_mut().map(|editor|editor.set_clip(clip.as_ref()))
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
Ok(undo)
|
||||||
|
};
|
||||||
|
select = |app, selection: Selection| {
|
||||||
|
*app.project.selection_mut() = selection;
|
||||||
|
//todo!
|
||||||
|
//if let Some(ref mut editor) = app.editor_mut() {
|
||||||
|
//editor.set_clip(match selection {
|
||||||
|
//Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
|
||||||
|
//.project
|
||||||
|
//.scenes.get(scene)
|
||||||
|
//.map(|s|s.clips.get(track))
|
||||||
|
//=>
|
||||||
|
//Some(clip),
|
||||||
|
//_ =>
|
||||||
|
//None
|
||||||
|
//});
|
||||||
|
//}
|
||||||
|
Ok(None)
|
||||||
|
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
||||||
|
//(0, 0) => Self::Select(Selection::Mix),
|
||||||
|
//(t, 0) => Self::Select(Selection::Track(t)),
|
||||||
|
//(0, s) => Self::Select(Selection::Scene(s)),
|
||||||
|
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
||||||
|
// autoedit: load focused clip in editor.
|
||||||
|
};
|
||||||
|
//fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
||||||
|
//Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
||||||
|
//}
|
||||||
|
//fn launch (app: &mut App) -> Perhaps<Self> {
|
||||||
|
//app.project.launch();
|
||||||
|
//Ok(None)
|
||||||
|
//}
|
||||||
|
toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
|
||||||
|
editor = |app, command: MidiEditCommand| Ok(if let Some(editor) = app.editor_mut() {
|
||||||
|
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
||||||
|
// update linked sampler after editor action
|
||||||
|
app.project.sampler_mut().map(|sampler|match command {
|
||||||
|
// autoselect: automatically select sample in sampler
|
||||||
|
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
||||||
|
_ => {}
|
||||||
|
});
|
||||||
|
undo
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//take!(ClockCommand |state: App, iter|Take::take(state.clock(), iter));
|
||||||
|
//take!(MidiEditCommand |state: App, iter|Ok(state.editor().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
||||||
|
//take!(PoolCommand |state: App, iter|Take::take(&state.pool, iter));
|
||||||
|
//take!(SamplerCommand |state: App, iter|Ok(state.project.sampler().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
||||||
|
//take!(ArrangementCommand |state: App, iter|Take::take(&state.project, iter));
|
||||||
|
//take!(DialogCommand |state: App, iter|Take::take(&state.dialog, iter));
|
||||||
|
//has_editor!(|self: App|{
|
||||||
|
//editor = self.editor;
|
||||||
|
//editor_w = {
|
||||||
|
//let size = self.size.w();
|
||||||
|
//let editor = self.editor.as_ref().expect("missing editor");
|
||||||
|
//let time_len = editor.time_len().get();
|
||||||
|
//let time_zoom = editor.time_zoom().get().max(1);
|
||||||
|
//(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
|
||||||
|
//};
|
||||||
|
//editor_h = 15;
|
||||||
|
//is_editing = self.editor.is_some();
|
||||||
|
//});
|
||||||
|
#[tengri_proc::command(Option<Dialog>)] impl DialogCommand {
|
||||||
|
fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
||||||
|
*dialog = Some(new);
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||||
|
*dialog = None;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn toggle_dialog (&mut self, mut dialog: Dialog) -> Dialog {
|
||||||
|
std::mem::swap(&mut self.dialog, &mut dialog);
|
||||||
|
dialog
|
||||||
|
}
|
||||||
|
pub fn toggle_editor (&mut self, value: Option<bool>) {
|
||||||
|
//FIXME: self.editing.store(value.unwrap_or_else(||!self.is_editing()), Relaxed);
|
||||||
|
let value = value.unwrap_or_else(||!self.editor().is_some());
|
||||||
|
if value {
|
||||||
|
// Create new clip in pool when entering empty cell
|
||||||
|
if let Selection::TrackClip { track, scene } = *self.selection()
|
||||||
|
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
||||||
|
&& let Some(slot) = scene.clips.get_mut(track)
|
||||||
|
&& slot.is_none()
|
||||||
|
&& let Some(track) = self.project.tracks.get_mut(track)
|
||||||
|
{
|
||||||
|
let (index, mut clip) = self.pool.add_new_clip();
|
||||||
|
// autocolor: new clip colors from scene and track color
|
||||||
|
let color = track.color.base.mix(scene.color.base, 0.5);
|
||||||
|
clip.write().unwrap().color = ItemColor::random_near(color, 0.2).into();
|
||||||
|
if let Some(ref mut editor) = &mut self.project.editor {
|
||||||
|
editor.set_clip(Some(&clip));
|
||||||
|
}
|
||||||
|
*slot = Some(clip.clone());
|
||||||
|
//Some(clip)
|
||||||
|
} else {
|
||||||
|
//None
|
||||||
|
}
|
||||||
|
} else if let Selection::TrackClip { track, scene } = *self.selection()
|
||||||
|
&& let Some(scene) = self.project.scenes.get_mut(scene)
|
||||||
|
&& let Some(slot) = scene.clips.get_mut(track)
|
||||||
|
&& let Some(clip) = slot.as_mut()
|
||||||
|
{
|
||||||
|
// Remove clip from arrangement when exiting empty clip editor
|
||||||
|
let mut swapped = None;
|
||||||
|
if clip.read().unwrap().count_midi_messages() == 0 {
|
||||||
|
std::mem::swap(&mut swapped, slot);
|
||||||
|
}
|
||||||
|
if let Some(clip) = swapped {
|
||||||
|
self.pool.delete_clip(&clip.read().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn browser (&self) -> Option<&Browser> {
|
||||||
|
if let Dialog::Browser(_, ref b) = self.dialog { Some(b) } else { None }
|
||||||
|
}
|
||||||
|
pub fn device_pick (&mut self, index: usize) {
|
||||||
|
self.dialog = Dialog::Device(index);
|
||||||
|
}
|
||||||
|
pub fn add_device (&mut self, index: usize) -> Usually<()> {
|
||||||
|
match index {
|
||||||
|
0 => {
|
||||||
|
let name = self.jack.with_client(|c|c.name().to_string());
|
||||||
|
let midi = self.project.track().expect("no active track").sequencer.midi_outs[0].port_name();
|
||||||
|
let track = self.track().expect("no active track");
|
||||||
|
let port = format!("{}/Sampler", &track.name);
|
||||||
|
let connect = Connect::exact(format!("{name}:{midi}"));
|
||||||
|
let sampler = if let Ok(sampler) = Sampler::new(
|
||||||
|
&self.jack, &port, &[connect], &[&[], &[]], &[&[], &[]]
|
||||||
|
) {
|
||||||
|
self.dialog = Dialog::None;
|
||||||
|
Device::Sampler(sampler)
|
||||||
|
} else {
|
||||||
|
self.dialog = Dialog::Message("Failed to add device.".into());
|
||||||
|
return Err("failed to add device".into())
|
||||||
|
};
|
||||||
|
let track = self.track_mut().expect("no active track");
|
||||||
|
track.devices.push(sampler);
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
todo!();
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//#[derive(Clone, Debug)]
|
||||||
|
//pub enum DialogCommand {
|
||||||
|
//Open { dialog: Dialog },
|
||||||
|
//Close
|
||||||
|
//}
|
||||||
|
|
||||||
|
//impl Command<Option<Dialog>> for DialogCommand {
|
||||||
|
//fn execute (self, state: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||||
|
//match self {
|
||||||
|
//Self::Open { dialog } => {
|
||||||
|
//*state = Some(dialog);
|
||||||
|
//},
|
||||||
|
//Self::Close => {
|
||||||
|
//*state = None;
|
||||||
|
//}
|
||||||
|
//};
|
||||||
|
//Ok(None)
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
//dsl!(DialogCommand: |self: Dialog, iter|todo!());
|
||||||
|
//Dsl::take(&mut self.dialog, iter));
|
||||||
|
|
||||||
|
//#[tengri_proc::command(Option<Dialog>)]//Nope.
|
||||||
|
//impl DialogCommand {
|
||||||
|
//fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
||||||
|
//*dialog = Some(new);
|
||||||
|
//Ok(None)
|
||||||
|
//}
|
||||||
|
//fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||||
|
//*dialog = None;
|
||||||
|
//Ok(None)
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
//
|
||||||
57
crates/app/app_jack.rs
Normal file
57
crates/app/app_jack.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
impl HasJack<'static> for App {
|
||||||
|
fn jack (&self) -> &Jack<'static> {
|
||||||
|
&self.jack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
audio!(
|
||||||
|
|self: App, client, scope|{
|
||||||
|
let t0 = self.perf.get_t0();
|
||||||
|
self.clock().update_from_scope(scope).unwrap();
|
||||||
|
let midi_in = self.project.midi_input_collect(scope);
|
||||||
|
if let Some(editor) = &self.editor() {
|
||||||
|
let mut pitch: Option<u7> = None;
|
||||||
|
for port in midi_in.iter() {
|
||||||
|
for event in port.iter() {
|
||||||
|
if let (_, Ok(LiveEvent::Midi {message: MidiMessage::NoteOn {ref key, ..}, ..}))
|
||||||
|
= event
|
||||||
|
{
|
||||||
|
pitch = Some(key.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(pitch) = pitch {
|
||||||
|
editor.set_note_pos(pitch.as_int() as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = self.project.process_tracks(client, scope);
|
||||||
|
self.perf.update_from_jack_scope(t0, scope);
|
||||||
|
result
|
||||||
|
};
|
||||||
|
|self, event|{
|
||||||
|
use JackEvent::*;
|
||||||
|
match event {
|
||||||
|
SampleRate(sr) => {
|
||||||
|
self.clock().timebase.sr.set(sr as f64);
|
||||||
|
},
|
||||||
|
PortRegistration(id, true) => {
|
||||||
|
//let port = self.jack().port_by_id(id);
|
||||||
|
//println!("\rport add: {id} {port:?}");
|
||||||
|
//println!("\rport add: {id}");
|
||||||
|
},
|
||||||
|
PortRegistration(id, false) => {
|
||||||
|
/*println!("\rport del: {id}")*/
|
||||||
|
},
|
||||||
|
PortsConnected(a, b, true) => { /*println!("\rport conn: {a} {b}")*/ },
|
||||||
|
PortsConnected(a, b, false) => { /*println!("\rport disc: {a} {b}")*/ },
|
||||||
|
ClientRegistration(id, true) => {},
|
||||||
|
ClientRegistration(id, false) => {},
|
||||||
|
ThreadInit => {},
|
||||||
|
XRun => {},
|
||||||
|
GraphReorder => {},
|
||||||
|
_ => { panic!("{event:?}"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -1,81 +1,71 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
pub(crate) use std::marker::PhantomData;
|
content!(TuiOut:|self: App|VIEW[":view"](self));//if let Ok(Some(view)) = VIEW[":view"] { view(self) } else { panic!() });
|
||||||
content!(TuiOut:|self: App|"kyp");//VIEW.content(self, "(bg :color/black (fill/xy (bsp/a overlay content)))"));
|
struct DslNs<'t, T: 't>(&'t [(&'t str, T)]);
|
||||||
struct DslView<'s, O: Output, T> {
|
type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
|
||||||
symbol: &'s str,
|
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
||||||
callback: Option<for<'t> fn (&'t T) -> Box<dyn Render<O> + 't>>,
|
type Output = DslCb;
|
||||||
next: Option<&'s Self>
|
fn index (&self, index: D) -> &Self::Output {
|
||||||
|
if let Ok(Some(symbol)) = index.src() {
|
||||||
|
for (key, value) in self.0.iter() {
|
||||||
|
if symbol == *key {
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
pub const VIEW: DslView<'static, TuiOut, App> = DslView::new()
|
|
||||||
.def("browser", view_browser)
|
|
||||||
.def("content", view_content)
|
|
||||||
.def("device", view_device)
|
|
||||||
.def("menu", view_menu)
|
|
||||||
//.def("options", view_options)
|
|
||||||
.def("overlay", view_overlay);
|
|
||||||
impl<'s, O: Output, T> DslView<'s, O, T> {
|
|
||||||
pub const fn new () -> Self {
|
|
||||||
DslView { symbol: "", callback: None, next: None }
|
|
||||||
}
|
}
|
||||||
pub const fn def (
|
|
||||||
&'static self,
|
|
||||||
symbol: &'static str,
|
|
||||||
callback: fn (&T) -> Box<dyn Render<O> + '_>
|
|
||||||
) -> Self {
|
|
||||||
DslView { symbol, callback: Some(callback), next: Some(self) }
|
|
||||||
}
|
}
|
||||||
pub fn content <'t> (
|
&(view_nil as DslCb)
|
||||||
&'static self, state: &'t T, src: impl Dsl) -> Usually<Box<dyn Render<O> + 't>> {
|
|
||||||
Ok(if src.sym()? == Some(self.symbol) && let Some(callback) = self.callback {
|
|
||||||
callback(&state)
|
|
||||||
} else if let Some(next) = self.next {
|
|
||||||
next.content(state, src)?
|
|
||||||
} else {
|
|
||||||
return Err("DslView::content: undefined".into())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
//fn render (&self, state: &T, output: &mut O, src: impl Dsl) -> Usually<()> {
|
|
||||||
//Ok(if src.sym()? == Some(self.0) && let Some(callback) = self.1 {
|
|
||||||
//let view = callback(&state);
|
|
||||||
//output.place(output.area(), &view)
|
|
||||||
//} else if let Some(next) = self.2 {
|
|
||||||
//next.render(state, output, src)?
|
|
||||||
//} else {
|
|
||||||
//return Err("DslView::render: undefined".into())
|
|
||||||
//})
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
pub const VIEW: DslNs<'static, DslCb> = DslNs(&[
|
||||||
|
(":view", |state|VIEW[":view/content"](state)),
|
||||||
fn view_content (app: &App) -> Box<dyn Render<TuiOut> + '_> {
|
(":view/content", |state|Fill::xy(ErrorBoundary::new(Ok(Some("·")))).boxed()),
|
||||||
Fill::xy(ErrorBoundary::new(Ok(Some("·")))).boxed()
|
(":view/overlay", |state|{
|
||||||
}
|
|
||||||
fn view_overlay <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
||||||
match &state.dialog {
|
match &state.dialog {
|
||||||
Dialog::Menu(_) => view_menu(state),
|
Dialog::Menu(_) => VIEW[":view/menu"](state),
|
||||||
Dialog::Device(_) => view_device(state),
|
Dialog::Device(_) => VIEW[":view/device"](state),
|
||||||
Dialog::Browser(_, _) => view_browser(state),
|
Dialog::Browser(_, _) => VIEW[":view/browser"](state),
|
||||||
//Dialog::Help(_) => view_help,
|
//Dialog::Help(_) => view_help,
|
||||||
//Dialog::Message(_) => view_message,
|
//Dialog::Message(_) => view_message,
|
||||||
//Dialog::Options => view_options,
|
//Dialog::Options => view_options,
|
||||||
_ => unimplemented!()
|
_ => unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
fn wrap_dialog <'s> (dialog: impl Content<TuiOut> + 's) -> impl Content<TuiOut> + 's {
|
(":view/browser", |state|{
|
||||||
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
let browser = state.dialog.browser().cloned().unwrap();
|
||||||
Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog))))
|
let target = state.dialog.browser_target().unwrap();
|
||||||
}
|
Box::new(Bsp::s(
|
||||||
fn wrap_dialog_menu <'a> (content: impl Content<TuiOut> + 'a) -> Box<dyn Render<TuiOut> + 'a> {
|
Padding::xy(3, 1, Fill::x(Align::w(FieldV(
|
||||||
|
Default::default(),
|
||||||
|
match target {
|
||||||
|
BrowserTarget::SaveProject => "Save project:",
|
||||||
|
BrowserTarget::LoadProject => "Load project:",
|
||||||
|
BrowserTarget::ImportSample(_) => "Import sample:",
|
||||||
|
BrowserTarget::ExportSample(_) => "Export sample:",
|
||||||
|
BrowserTarget::ImportClip(_) => "Import clip:",
|
||||||
|
BrowserTarget::ExportClip(_) => "Export clip:",
|
||||||
|
},
|
||||||
|
Shrink::x(3, Fixed::y(1, Tui::fg(Tui::g(96), RepeatH("🭻")))))))),
|
||||||
|
Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
|
.enclose(Fill::xy(browser))))
|
||||||
|
}),
|
||||||
|
(":view/device", |state|{
|
||||||
|
let selected = state.dialog.device_selected().unwrap();
|
||||||
|
Box::new(Bsp::s(Tui::bold(true, "Add device"), Map::south(1,
|
||||||
|
move||device_kinds().iter(),
|
||||||
|
move|label: &&'static str, i|{
|
||||||
|
let bg = if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) };
|
||||||
|
let lb = if i == selected { "[ " } else { " " };
|
||||||
|
let rb = if i == selected { " ]" } else { " " };
|
||||||
|
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name"))))
|
||||||
|
})))
|
||||||
|
}),
|
||||||
|
(":view/menu", |state|{
|
||||||
|
let views = state.config.views.clone();
|
||||||
|
let selected = state.dialog.menu_selected();
|
||||||
Box::new(Tui::bg(Rgb(0,0,0), Bsp::s(
|
Box::new(Tui::bg(Rgb(0,0,0), Bsp::s(
|
||||||
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))),
|
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))),
|
||||||
Bsp::n(
|
Bsp::n(
|
||||||
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Bsp::e(Tui::fg(Rgb(255,192,48), "[Enter]"), " new session")))),
|
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Bsp::e(Tui::fg(Rgb(255,192,48), "[Enter]"), " new session")))),
|
||||||
Fill::y(Align::n(Fill::x(content)))))))
|
Fill::y(Align::n(Fill::x(Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
||||||
}
|
|
||||||
fn view_menu <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
||||||
let views = state.config.views.clone();
|
|
||||||
let selected = state.dialog.menu_selected();
|
|
||||||
wrap_dialog_menu(Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
|
||||||
////let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
////let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
||||||
////let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
////let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
||||||
////Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|
////Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|
||||||
|
|
@ -88,40 +78,33 @@ fn view_menu <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
||||||
Fill::x(Align::w(Tui::fg(Rgb(224,192,128), name))),
|
Fill::x(Align::w(Tui::fg(Rgb(224,192,128), name))),
|
||||||
Fill::x(Align::e(Tui::fg(Rgb(224,128,32), &id)))
|
Fill::x(Align::e(Tui::fg(Rgb(224,128,32), &id)))
|
||||||
)),
|
)),
|
||||||
Fill::x(Align::w(info)))))); } }))
|
Fill::x(Align::w(info)))))); } }))))))))
|
||||||
|
}),
|
||||||
|
//(":view/options", view_options),
|
||||||
|
]);
|
||||||
|
fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
|
||||||
|
"nil".boxed()
|
||||||
}
|
}
|
||||||
fn view_browser <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
fn wrap_dialog (dialog: impl Content<TuiOut>) -> impl Content<TuiOut> {
|
||||||
let target = &state.dialog.browser_target().clone().unwrap();
|
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
||||||
Box::new(Bsp::s(
|
Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog))))
|
||||||
Padding::xy(3, 1, Fill::x(Align::w(FieldV(
|
}
|
||||||
Default::default(),
|
impl ScenesView for App {
|
||||||
match &target {
|
fn h_scenes (&self) -> u16 {
|
||||||
BrowserTarget::SaveProject => "Save project:",
|
(self.height() as u16).saturating_sub(20)
|
||||||
BrowserTarget::LoadProject => "Load project:",
|
}
|
||||||
BrowserTarget::ImportSample(_) => "Import sample:",
|
fn w_side (&self) -> u16 {
|
||||||
BrowserTarget::ExportSample(_) => "Export sample:",
|
20
|
||||||
BrowserTarget::ImportClip(_) => "Import clip:",
|
}
|
||||||
BrowserTarget::ExportClip(_) => "Export clip:",
|
fn w_mid (&self) -> u16 {
|
||||||
},
|
(self.width() as u16).saturating_sub(self.w_side())
|
||||||
Shrink::x(3, Fixed::y(1, Tui::fg(Tui::g(96), RepeatH("🭻")))))))),
|
|
||||||
Outer(true, Style::default().fg(Tui::g(96)))
|
|
||||||
.enclose(Fill::xy(state.dialog.browser()))))
|
|
||||||
}
|
}
|
||||||
fn view_device <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
||||||
let selected = state.dialog.device_selected().unwrap();
|
|
||||||
Box::new(Bsp::s(Tui::bold(true, "Add device"), Map::south(1,
|
|
||||||
move||device_kinds().iter(),
|
|
||||||
move|label: &&'static str, i|
|
|
||||||
Fill::x(Tui::bg(if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) },
|
|
||||||
Bsp::e(if i == state.dialog.device_selected().unwrap() { "[ " } else { " " },
|
|
||||||
Bsp::w(if i == state.dialog.device_selected().unwrap() { " ]" } else { " " },
|
|
||||||
"FIXME device name")))))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Bsp::s("",
|
//Bsp::s("",
|
||||||
//Map::south(1,
|
//Map::south(1,
|
||||||
//move||app.config.binds.layers.iter()
|
//move||state.config.binds.layers.iter()
|
||||||
//.filter_map(|a|(a.0)(app).then_some(a.1))
|
//.filter_map(|a|(a.0)(state).then_some(a.1))
|
||||||
//.flat_map(|a|a)
|
//.flat_map(|a|a)
|
||||||
//.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
|
//.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
|
||||||
//.skip(offset)
|
//.skip(offset)
|
||||||
|
|
@ -157,3 +140,179 @@ fn view_device <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
||||||
////Outer(true, Style::default().fg(Tui::g(96)))
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
////.enclose(Fill::xy(browser)))
|
////.enclose(Fill::xy(browser)))
|
||||||
//},
|
//},
|
||||||
|
//
|
||||||
|
//pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|
|
||||||
|
//s.view_meters_input())
|
||||||
|
//}
|
||||||
|
//pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|
|
||||||
|
//s.view_meters_output())
|
||||||
|
//}
|
||||||
|
//pub fn view_history (&self) -> impl Content<TuiOut> {
|
||||||
|
//Fixed::y(1, Fill::x(Align::w(FieldH(self.color,
|
||||||
|
//format!("History ({})", self.history.len()),
|
||||||
|
//self.history.last().map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))))
|
||||||
|
//}
|
||||||
|
//pub fn view_status_h2 (&self) -> impl Content<TuiOut> {
|
||||||
|
//self.update_clock();
|
||||||
|
//let theme = self.color;
|
||||||
|
//let clock = self.clock();
|
||||||
|
//let playing = clock.is_rolling();
|
||||||
|
//let cache = clock.view_cache.clone();
|
||||||
|
////let selection = self.selection().describe(self.tracks(), self.scenes());
|
||||||
|
//let hist_len = self.history.len();
|
||||||
|
//let hist_last = self.history.last();
|
||||||
|
//Fixed::y(2, Stack::east(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
||||||
|
//add(&Fixed::x(5, Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
||||||
|
//Either::new(false, // TODO
|
||||||
|
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
||||||
|
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
||||||
|
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
||||||
|
//),
|
||||||
|
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
||||||
|
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
||||||
|
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
||||||
|
//)
|
||||||
|
//)
|
||||||
|
//)));
|
||||||
|
//add(&" ");
|
||||||
|
//{
|
||||||
|
//let cache = cache.read().unwrap();
|
||||||
|
//add(&Fixed::x(15, Align::w(Bsp::s(
|
||||||
|
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
||||||
|
//FieldH(theme, "Time", cache.time.view.clone()),
|
||||||
|
//))));
|
||||||
|
//add(&Fixed::x(13, Align::w(Bsp::s(
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
||||||
|
//))));
|
||||||
|
//add(&Fixed::x(12, Align::w(Bsp::s(
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "Buf", cache.buf.view.clone()))),
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "Lat", cache.lat.view.clone()))),
|
||||||
|
//))));
|
||||||
|
////add(&Bsp::s(
|
||||||
|
//////Fill::x(Align::w(FieldH(theme, "Selected", Align::w(selection)))),
|
||||||
|
////Fill::x(Align::w(FieldH(theme, format!("History ({})", hist_len),
|
||||||
|
////hist_last.map(|last|Fill::x(Align::w(format!("{:?}", last.0))))))),
|
||||||
|
////""
|
||||||
|
////));
|
||||||
|
//////if let Some(last) = self.history.last() {
|
||||||
|
//////add(&FieldV(theme, format!("History ({})", self.history.len()),
|
||||||
|
//////Fill::x(Align::w(format!("{:?}", last.0)))));
|
||||||
|
//////}
|
||||||
|
//}
|
||||||
|
//}))
|
||||||
|
//}
|
||||||
|
//pub fn view_status_v (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.update_clock();
|
||||||
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
||||||
|
//let theme = self.color;
|
||||||
|
//let playing = self.clock().is_rolling();
|
||||||
|
//Tui::bg(theme.darker.rgb, Fixed::xy(20, 5, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
||||||
|
//col!(
|
||||||
|
//Fill::x(Align::w(Bsp::e(
|
||||||
|
//Align::w(Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
||||||
|
//Either::new(false, // TODO
|
||||||
|
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
||||||
|
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
||||||
|
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
||||||
|
//),
|
||||||
|
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
||||||
|
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
||||||
|
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
||||||
|
//)
|
||||||
|
//)
|
||||||
|
//)),
|
||||||
|
//Bsp::s(
|
||||||
|
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
||||||
|
//FieldH(theme, "Time", cache.time.view.clone()),
|
||||||
|
//),
|
||||||
|
//))),
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
||||||
|
//Fill::x(Align::w(FieldH(theme, "Buf", Bsp::e(cache.buf.view.clone(), Bsp::e(" = ", cache.lat.view.clone()))))),
|
||||||
|
//))))
|
||||||
|
//}
|
||||||
|
//pub fn view_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.update_clock();
|
||||||
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
||||||
|
//view_status(Some(self.project.selection.describe(self.tracks(), self.scenes())),
|
||||||
|
//cache.sr.view.clone(), cache.buf.view.clone(), cache.lat.view.clone())
|
||||||
|
//}
|
||||||
|
//pub fn view_transport (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.update_clock();
|
||||||
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
||||||
|
//view_transport(self.project.clock.is_rolling(),
|
||||||
|
//cache.bpm.view.clone(), cache.beat.view.clone(), cache.time.view.clone())
|
||||||
|
//}
|
||||||
|
//pub fn view_editor (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//let bg = self.editor()
|
||||||
|
//.and_then(|editor|editor.clip().clone())
|
||||||
|
//.map(|clip|clip.read().unwrap().color.darker)
|
||||||
|
//.unwrap_or(self.color.darker);
|
||||||
|
//Fill::xy(Tui::bg(bg.rgb, self.editor()))
|
||||||
|
//}
|
||||||
|
//pub fn view_editor_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.editor().map(|e|Fixed::x(20, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
||||||
|
//Fill::y(Align::n(Bsp::s(e.clip_status(), e.edit_status()))))))
|
||||||
|
//}
|
||||||
|
//pub fn view_midi_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_midi_ins_status(self.color)
|
||||||
|
//}
|
||||||
|
//pub fn view_midi_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_midi_outs_status(self.color)
|
||||||
|
//}
|
||||||
|
//pub fn view_audio_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_audio_ins_status(self.color)
|
||||||
|
//}
|
||||||
|
//pub fn view_audio_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_audio_outs_status(self.color)
|
||||||
|
//}
|
||||||
|
//pub fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Bsp::e(
|
||||||
|
//Fixed::x(20, Align::nw(self.project.view_scenes_names())),
|
||||||
|
//self.project.view_scenes_clips(),
|
||||||
|
//)
|
||||||
|
//}
|
||||||
|
//pub fn view_scenes_names (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_scenes_names()
|
||||||
|
//}
|
||||||
|
//pub fn view_scenes_clips (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.view_scenes_clips()
|
||||||
|
//}
|
||||||
|
//pub fn view_tracks_inputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
//Fixed::y(1 + self.project.midi_ins.len() as u16,
|
||||||
|
//self.project.view_inputs(self.color))
|
||||||
|
//}
|
||||||
|
//pub fn view_tracks_outputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
//self.project.view_outputs(self.color)
|
||||||
|
//}
|
||||||
|
//pub fn view_tracks_devices <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
//Fixed::y(4, self.project.view_track_devices(self.color))
|
||||||
|
//}
|
||||||
|
//pub fn view_tracks_names <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
//Fixed::y(2, self.project.view_track_names(self.color))
|
||||||
|
//}
|
||||||
|
//pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Fixed::x(20, Bsp::s(
|
||||||
|
//Fill::x(Align::w(FieldH(self.color, "Clip pool:", ""))),
|
||||||
|
//Fill::y(Align::n(Tui::bg(Rgb(0, 0, 0), Outer(true, Style::default().fg(Tui::g(96)))
|
||||||
|
//.enclose(PoolView(&self.pool)))))))
|
||||||
|
//}
|
||||||
|
//pub fn view_samples_keys (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|s.view_list(true, self.editor().unwrap()))
|
||||||
|
//}
|
||||||
|
//pub fn view_samples_grid (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|s.view_grid())
|
||||||
|
//}
|
||||||
|
//pub fn view_sample_viewer (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|s.view_sample(self.editor().unwrap().get_note_pos()))
|
||||||
|
//}
|
||||||
|
//pub fn view_sample_info (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|s.view_sample_info(self.editor().unwrap().get_note_pos()))
|
||||||
|
//}
|
||||||
|
//pub fn view_sample_status (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//self.project.sampler().map(|s|Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
||||||
|
//Fill::y(Align::n(s.view_sample_status(self.editor().unwrap().get_note_pos())))))
|
||||||
|
//}
|
||||||
|
|
|
||||||
2
deps/tengri
vendored
2
deps/tengri
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4515d2cc6f9d8d67782c175ebc5b560923295314
|
Subproject commit 24ac52d8079140b2b9f363d1568597bb5600a166
|
||||||
Loading…
Add table
Add a link
Reference in a new issue