mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
it even works with the edn_content
This commit is contained in:
parent
9cd6e9f195
commit
c9677c87d8
1 changed files with 59 additions and 99 deletions
158
tek/src/lib.rs
158
tek/src/lib.rs
|
|
@ -82,7 +82,7 @@ edn_view!(TuiOut: |self: App| self.size.of(EdnView::from_source(self, self.edn.a
|
|||
Selection {};
|
||||
Arc<RwLock<MidiClip>> {};
|
||||
Option<Arc<RwLock<MidiClip>>> {};
|
||||
|
||||
// Provide sizes:
|
||||
u16 {
|
||||
":sidebar-w" => self.sidebar_w(),
|
||||
":sample-h" => if self.compact() { 0 } else { 5 },
|
||||
|
|
@ -91,7 +91,7 @@ edn_view!(TuiOut: |self: App| self.size.of(EdnView::from_source(self, self.edn.a
|
|||
":pool-w" => if self.compact() { 5 } else {
|
||||
let w = self.size.w();
|
||||
if w > 60 { 20 } else if w > 40 { 15 } else { 10 } } };
|
||||
|
||||
// Provide components:
|
||||
Box<dyn Render<TuiOut> + 'a> {
|
||||
":editor" => (&self.editor).boxed(),
|
||||
":pool" => self.pool.as_ref().map(|pool|PoolView(self.compact(), pool)).boxed(),
|
||||
|
|
@ -104,37 +104,6 @@ edn_view!(TuiOut: |self: App| self.size.of(EdnView::from_source(self, self.edn.a
|
|||
":outputs" => self.row(self.w(), 3, self.output_header(), self.output_cells()).boxed(),
|
||||
":scenes" => self.row(self.w(), self.size.h().saturating_sub(9) as u16,
|
||||
self.scene_header(), self.scene_cells(self.is_editing())).boxed() }});
|
||||
|
||||
//content!(TuiOut:|self: App|self.size.of(EdnView::from_source(self, self.edn.as_ref())));
|
||||
//edn_provide!(bool: |self: App| { _ => return None });
|
||||
//edn_provide!(usize: |self: App| { _ => return None });
|
||||
//edn_provide!(isize: |self: App| { _ => return None });
|
||||
//edn_provide!(Color: |self: App| { _ => return None });
|
||||
//edn_provide!(Selection: |self: App| { _ => return None });
|
||||
//edn_provide!(Arc<RwLock<MidiClip>>: |self: App| { _ => return None });
|
||||
//edn_provide!(Option<Arc<RwLock<MidiClip>>>: |self: App| { _ => return None });
|
||||
//edn_provide!('a: Box<dyn Render<TuiOut> + 'a>: |self: App|{
|
||||
//":editor" => (&self.editor).boxed(),
|
||||
//":pool" => self.pool.as_ref().map(|pool|PoolView(self.compact(), pool)).boxed(),
|
||||
//":sample" => self.view_sample(self.is_editing()).boxed(),
|
||||
//":sampler" => self.view_sampler(self.is_editing(), &self.editor).boxed(),
|
||||
//":status" => self.editor.as_ref().map(|e|Bsp::e(e.clip_status(), e.edit_status())).boxed(),
|
||||
//":toolbar" => ClockView::new(true, &self.clock).boxed(),
|
||||
//":tracks" => self.row(self.w(), 3, self.track_header(), self.track_cells()).boxed(),
|
||||
//":inputs" => self.row(self.w(), 3, self.input_header(), self.input_cells()).boxed(),
|
||||
//":outputs" => self.row(self.w(), 3, self.output_header(), self.output_cells()).boxed(),
|
||||
//":scenes" => self.row(self.w(), self.size.h().saturating_sub(9) as u16,
|
||||
//self.scene_header(), self.scene_cells(self.is_editing())).boxed() });
|
||||
//edn_provide!(u16: |self: App|{
|
||||
//":sidebar-w" => self.sidebar_w(),
|
||||
//":sample-h" => if self.compact() { 0 } else { 5 },
|
||||
//":samples-w" => if self.compact() { 4 } else { 11 },
|
||||
//":samples-y" => if self.compact() { 1 } else { 0 },
|
||||
//":pool-w" => if self.compact() { 5 } else {
|
||||
//let w = self.size.w();
|
||||
//if w > 60 { 20 } else if w > 40 { 15 } else { 10 }
|
||||
//}
|
||||
//});
|
||||
impl App {
|
||||
pub fn sequencer (
|
||||
jack: &Arc<RwLock<JackConnection>>, pool: MidiPool, editor: MidiEditor,
|
||||
|
|
@ -366,7 +335,6 @@ impl App {
|
|||
}
|
||||
handle!(TuiIn: |self: App, input| Ok(None));
|
||||
#[derive(Clone, Debug)] pub enum AppCommand {
|
||||
Clear,
|
||||
Clip(ClipCommand),
|
||||
Clock(ClockCommand),
|
||||
Color(ItemPalette),
|
||||
|
|
@ -383,7 +351,6 @@ handle!(TuiIn: |self: App, input| Ok(None));
|
|||
Zoom(Option<usize>),
|
||||
}
|
||||
edn_command!(AppCommand: |state: App| {
|
||||
("clear" [] Self::Clear)
|
||||
("stop-all" [] Self::StopAll)
|
||||
("compact" [c: bool ] Self::Compact(c))
|
||||
("color" [c: Color] Self::Color(c.map(ItemPalette::from).unwrap_or_default()))
|
||||
|
|
@ -400,66 +367,28 @@ edn_command!(AppCommand: |state: App| {
|
|||
("sampler" [a, ..b] Self::Sampler(SamplerCommand::from_edn(state.sampler.as_ref().expect("no sampler"), &a.to_ref(), b)))
|
||||
});
|
||||
command!(|self: AppCommand, state: App|match self {
|
||||
Self::Clear => { todo!() },
|
||||
Self::Zoom(_) => { todo!(); },
|
||||
Self::History(delta) => { todo!("undo/redo") },
|
||||
Self::Select(s) => { state.selected = s; None },
|
||||
Self::Clock(cmd) => cmd.delegate(state, Self::Clock)?,
|
||||
Self::Scene(cmd) => match cmd {
|
||||
SceneCommand::Add => { state.scene_add(None, None)?; None }
|
||||
SceneCommand::Del(index) => { state.scene_del(index); None },
|
||||
SceneCommand::SetColor(index, color) => {
|
||||
let old = state.scenes[index].color;
|
||||
state.scenes[index].color = color;
|
||||
Some(SceneCommand::SetColor(index, old))
|
||||
},
|
||||
SceneCommand::Enqueue(scene) => {
|
||||
for track in 0..state.tracks.len() {
|
||||
state.tracks[track].player.enqueue_next(state.scenes[scene].clips[track].as_ref());
|
||||
}
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
}.map(Self::Scene),
|
||||
Self::Track(cmd) => match cmd {
|
||||
TrackCommand::Add => { state.track_add(None, None)?; None },
|
||||
TrackCommand::Del(index) => { state.track_del(index); None },
|
||||
TrackCommand::Stop(track) => { state.tracks[track].player.enqueue_next(None); None },
|
||||
TrackCommand::SetColor(index, color) => {
|
||||
let old = state.tracks[index].color;
|
||||
state.tracks[index].color = color;
|
||||
Some(TrackCommand::SetColor(index, old))
|
||||
},
|
||||
_ => None
|
||||
}.map(Self::Track),
|
||||
Self::Clip(cmd) => match cmd {
|
||||
ClipCommand::Get(track, scene) => { todo!() },
|
||||
ClipCommand::Put(track, scene, clip) => {
|
||||
let old = state.scenes[scene].clips[track].clone();
|
||||
state.scenes[scene].clips[track] = clip;
|
||||
Some(ClipCommand::Put(track, scene, old))
|
||||
},
|
||||
ClipCommand::Enqueue(track, scene) => {
|
||||
state.tracks[track].player.enqueue_next(state.scenes[scene].clips[track].as_ref());
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
}.map(Self::Clip),
|
||||
Self::Editor(cmd) =>
|
||||
state.editor.as_mut().map(|editor|cmd.delegate(editor, Self::Editor)).transpose()?.flatten(),
|
||||
Self::Sampler(cmd) =>
|
||||
state.sampler.as_mut().map(|sampler|cmd.delegate(sampler, Self::Sampler)).transpose()?.flatten(),
|
||||
Self::Enqueue(clip) =>
|
||||
state.player.as_mut().map(|player|{player.enqueue_next(clip.as_ref());None}).flatten(),
|
||||
Self::StopAll => {
|
||||
for track in 0..state.tracks.len() { state.tracks[track].player.enqueue_next(None); }
|
||||
None
|
||||
},
|
||||
Self::Select(s) => { state.selected = s; None },
|
||||
Self::Clock(cmd) => cmd.delegate(state, Self::Clock)?,
|
||||
Self::Scene(cmd) => cmd.delegate(state, Self::Scene)?,
|
||||
Self::Track(cmd) => cmd.delegate(state, Self::Track)?,
|
||||
Self::Clip(cmd) => cmd.delegate(state, Self::Clip)?,
|
||||
Self::Editor(cmd) => state.editor.as_mut()
|
||||
.map(|editor|cmd.delegate(editor, Self::Editor)).transpose()?.flatten(),
|
||||
Self::Sampler(cmd) => state.sampler.as_mut()
|
||||
.map(|sampler|cmd.delegate(sampler, Self::Sampler)).transpose()?.flatten(),
|
||||
Self::Enqueue(clip) => state.player.as_mut()
|
||||
.map(|player|{player.enqueue_next(clip.as_ref());None}).flatten(),
|
||||
Self::Color(palette) => {
|
||||
let old = state.color;
|
||||
state.color = palette;
|
||||
Some(Self::Color(old))
|
||||
},
|
||||
Self::StopAll => {
|
||||
for track in 0..state.tracks.len(){state.tracks[track].player.enqueue_next(None);}
|
||||
None
|
||||
},
|
||||
Self::Pool(cmd) => if let Some(pool) = state.pool.as_mut() {
|
||||
let undo = cmd.clone().delegate(pool, Self::Pool)?;
|
||||
if let Some(editor) = state.editor.as_mut() {
|
||||
|
|
@ -560,14 +489,8 @@ has_clock!(|self: Track|self.player.clock());
|
|||
has_player!(|self: Track|self.player);
|
||||
impl Track {
|
||||
const MIN_WIDTH: usize = 9;
|
||||
fn width_inc (&mut self) {
|
||||
self.width += 1;
|
||||
}
|
||||
fn width_dec (&mut self) {
|
||||
if self.width > Track::MIN_WIDTH {
|
||||
self.width -= 1;
|
||||
}
|
||||
}
|
||||
fn width_inc (&mut self) { self.width += 1; }
|
||||
fn width_dec (&mut self) { if self.width > Track::MIN_WIDTH { self.width -= 1; } }
|
||||
}
|
||||
#[derive(Clone, Debug)] pub enum TrackCommand {
|
||||
Add,
|
||||
|
|
@ -587,7 +510,17 @@ edn_command!(TrackCommand: |state: App| {
|
|||
("stop" [a: usize] Self::Stop(a.unwrap()))
|
||||
("swap" [a: usize, b: usize] Self::Swap(a.unwrap(), b.unwrap()))
|
||||
});
|
||||
command!(|self: TrackCommand, state: App|match self { _ => todo!("track command") });
|
||||
command!(|self: TrackCommand, state: App|match self {
|
||||
Self::Add => { state.track_add(None, None)?; None },
|
||||
Self::Del(index) => { state.track_del(index); None },
|
||||
Self::Stop(track) => { state.tracks[track].player.enqueue_next(None); None },
|
||||
Self::SetColor(index, color) => {
|
||||
let old = state.tracks[index].color;
|
||||
state.tracks[index].color = color;
|
||||
Some(Self::SetColor(index, old))
|
||||
},
|
||||
_ => None
|
||||
});
|
||||
impl HasTracks for App {
|
||||
fn midi_ins (&self) -> &Vec<JackPort<MidiIn>> { &self.midi_ins }
|
||||
fn midi_outs (&self) -> &Vec<JackPort<MidiOut>> { &self.midi_outs }
|
||||
|
|
@ -763,7 +696,22 @@ edn_command!(SceneCommand: |state: App| {
|
|||
("enqueue" [a: usize] Self::Enqueue(a.unwrap()))
|
||||
("swap" [a: usize, b: usize] Self::Swap(a.unwrap(), b.unwrap()))
|
||||
});
|
||||
command!(|self: SceneCommand, state: App|match self { _ => todo!("scene command") });
|
||||
command!(|self: SceneCommand, state: App|match self {
|
||||
Self::Add => { state.scene_add(None, None)?; None }
|
||||
Self::Del(index) => { state.scene_del(index); None },
|
||||
Self::SetColor(index, color) => {
|
||||
let old = state.scenes[index].color;
|
||||
state.scenes[index].color = color;
|
||||
Some(Self::SetColor(index, old))
|
||||
},
|
||||
Self::Enqueue(scene) => {
|
||||
for track in 0..state.tracks.len() {
|
||||
state.tracks[track].player.enqueue_next(state.scenes[scene].clips[track].as_ref());
|
||||
}
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
});
|
||||
impl HasScenes for App {
|
||||
fn scenes (&self) -> &Vec<Scene> { &self.scenes }
|
||||
fn scenes_mut (&mut self) -> &mut Vec<Scene> { &mut self.scenes }
|
||||
|
|
@ -850,7 +798,19 @@ edn_command!(ClipCommand: |state: App| {
|
|||
("color" [a: usize, b: usize]
|
||||
Self::SetColor(a.unwrap(), b.unwrap(), ItemPalette::random()))
|
||||
});
|
||||
command!(|self: ClipCommand, state: App|match self { _ => todo!("clip command") });
|
||||
command!(|self: ClipCommand, state: App|match self {
|
||||
Self::Get(track, scene) => { todo!() },
|
||||
Self::Put(track, scene, clip) => {
|
||||
let old = state.scenes[scene].clips[track].clone();
|
||||
state.scenes[scene].clips[track] = clip;
|
||||
Some(Self::Put(track, scene, old))
|
||||
},
|
||||
Self::Enqueue(track, scene) => {
|
||||
state.tracks[track].player.enqueue_next(state.scenes[scene].clips[track].as_ref());
|
||||
None
|
||||
},
|
||||
_ => None
|
||||
});
|
||||
audio!(|self: App, client, scope|{
|
||||
// Start profiling cycle
|
||||
let t0 = self.perf.get_t0();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue