From c7e7c9f68cf71e89cce3d4e6e9616ce01bfa7139 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 17 May 2025 13:23:31 +0300 Subject: [PATCH] switch around ownership of pool and editort --- crates/app/src/api.rs | 46 ++++---- crates/app/src/audio.rs | 2 +- crates/app/src/model.rs | 65 ++++++------ crates/app/src/view.rs | 18 ++-- crates/cli/tek.rs | 12 +-- crates/device/src/arranger/arranger_model.rs | 35 +++---- crates/device/src/arranger/arranger_view.rs | 105 ++++++++++--------- crates/device/src/editor/editor_model.rs | 24 +++-- 8 files changed, 157 insertions(+), 150 deletions(-) diff --git a/crates/app/src/api.rs b/crates/app/src/api.rs index 3a4516dd..acdadca6 100644 --- a/crates/app/src/api.rs +++ b/crates/app/src/api.rs @@ -24,9 +24,10 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm Selection::TrackClip { track, scene } => { let clip = &mut app.scenes_mut()[scene].clips[track]; if clip.is_none() { + //app.clip_auto_create(); *clip = Some(Default::default()); } - app.editor = clip.as_ref().map(|c|c.into()); + app.project.editor = clip.as_ref().map(|c|c.into()); None } _ => None @@ -62,18 +63,19 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm //} fn select (app: &mut App, selection: Selection) -> Perhaps { *app.project.selection_mut() = selection; - if let Some(ref mut editor) = app.editor { - editor.set_clip(match app.project.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 - }); - } + //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), @@ -102,7 +104,7 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm Ok(command.delegate(app, |command|Self::Message{command})?) } fn editor (app: &mut App, command: MidiEditCommand) -> Perhaps { - Ok(if let Some(editor) = app.editor.as_mut() { + 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 { @@ -117,18 +119,20 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm } fn pool (app: &mut App, command: PoolCommand) -> Perhaps { let undo = command.clone().delegate( - &mut app.project.pool, + &mut app.pool, |command|AppCommand::Pool{command} )?; // update linked editor after pool action - app.editor.as_mut().map(|editor|match command { + match command { // autoselect: automatically load selected clip in editor PoolCommand::Select { .. } | // autocolor: update color in all places simultaneously - PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => - editor.set_clip(app.project.pool.clip().as_ref()), - _ => {} - }); + 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) } } @@ -147,7 +151,7 @@ impl<'state> Context<'state, MidiEditCommand> for App { impl<'state> Context<'state, PoolCommand> for App { fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option { - Context::get(&self.project.pool, iter) + Context::get(&self.pool, iter) } } diff --git a/crates/app/src/audio.rs b/crates/app/src/audio.rs index dd65d0af..b8d7be61 100644 --- a/crates/app/src/audio.rs +++ b/crates/app/src/audio.rs @@ -5,7 +5,7 @@ audio!( 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 { + if let Some(editor) = &self.editor() { let mut pitch: Option = None; for port in midi_in.iter() { for event in port.iter() { diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs index df8b5ce8..b5e6ce76 100644 --- a/crates/app/src/model.rs +++ b/crates/app/src/model.rs @@ -20,23 +20,22 @@ pub struct App { pub history: Vec, // Dialog overlay pub dialog: Option, - /// Contains the currently edited MIDI clip - pub editor: Option, // Cache of formatted strings pub view_cache: Arc>, /// Base color. pub color: ItemTheme, } -has!(Jack: |self: App|self.jack); -has!(Pool: |self: App|self.pool); -has!(Clock: |self: App|self.project.clock); -has!(Selection: |self: App|self.project.selection); -has!(Vec: |self: App|self.project.midi_ins); -has!(Vec: |self: App|self.project.midi_outs); -has!(Vec: |self: App|self.project.scenes); -has!(Vec: |self: App|self.project.tracks); -has!(Measure: |self: App|self.size); +has!(Jack: |self: App|self.jack); +has!(Pool: |self: App|self.pool); +has!(Clock: |self: App|self.project.clock); +has!(Option: |self: App|self.project.editor); +has!(Selection: |self: App|self.project.selection); +has!(Vec: |self: App|self.project.midi_ins); +has!(Vec: |self: App|self.project.midi_outs); +has!(Vec: |self: App|self.project.scenes); +has!(Vec: |self: App|self.project.tracks); +has!(Measure: |self: App|self.size); maybe_has!(Track: |self: App| { MaybeHas::::get(&self.project) }; { MaybeHas::::get_mut(&mut self.project) }); @@ -49,19 +48,19 @@ maybe_has!(Scene: |self: App| impl HasSceneScroll for App { fn scene_scroll (&self) -> usize { self.project.scene_scroll() } } -has_clips!(|self: App|self.project.pool.clips); -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(); -}); +has_clips!(|self: App|self.pool.clips); +//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 App { pub fn toggle_dialog (&mut self, mut dialog: Option) -> Option { @@ -70,7 +69,7 @@ impl App { } pub fn toggle_editor (&mut self, value: Option) { //FIXME: self.editing.store(value.unwrap_or_else(||!self.is_editing()), Relaxed); - let value = value.unwrap_or_else(||!self.editor.is_some()); + let value = value.unwrap_or_else(||!self.editor().is_some()); if value { self.clip_auto_create(); } else { @@ -130,11 +129,11 @@ impl App { && slot.is_none() && let Some(track) = self.project.tracks.get_mut(track) { - let (index, mut clip) = self.project.pool.add_new_clip(); + 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) = self.editor { + if let Some(ref mut editor) = &mut self.project.editor { editor.set_clip(Some(&clip)); } *slot = Some(clip.clone()); @@ -155,7 +154,7 @@ impl App { std::mem::swap(&mut swapped, slot); } if let Some(clip) = swapped { - self.project.pool.delete_clip(&clip.read().unwrap()); + self.pool.delete_clip(&clip.read().unwrap()); } } } @@ -199,7 +198,7 @@ impl App { todo!() } fn w_sidebar (&self) -> u16 { - self.project.w_sidebar(self.editor.is_some()) + self.project.w_sidebar(self.editor().is_some()) } fn h_sample_detail (&self) -> u16 { 6.max(self.height() as u16 * 3 / 9) @@ -232,16 +231,16 @@ impl App { !self.is_editing() && self.selection().is_mix() } fn focus_pool_import (&self) -> bool { - matches!(self.project.pool.mode, Some(PoolMode::Import(..))) + matches!(self.pool.mode, Some(PoolMode::Import(..))) } fn focus_pool_export (&self) -> bool { - matches!(self.project.pool.mode, Some(PoolMode::Export(..))) + matches!(self.pool.mode, Some(PoolMode::Export(..))) } fn focus_pool_rename (&self) -> bool { - matches!(self.project.pool.mode, Some(PoolMode::Rename(..))) + matches!(self.pool.mode, Some(PoolMode::Rename(..))) } fn focus_pool_length (&self) -> bool { - matches!(self.project.pool.mode, Some(PoolMode::Length(..))) + matches!(self.pool.mode, Some(PoolMode::Length(..))) } fn dialog_none (&self) -> Option { None diff --git a/crates/app/src/view.rs b/crates/app/src/view.rs index 4ea5322c..2878985e 100644 --- a/crates/app/src/view.rs +++ b/crates/app/src/view.rs @@ -83,7 +83,7 @@ impl App { self.project.view_scenes_names() } pub fn view_arranger_scenes_clips (&self) -> impl Content + use<'_> { - self.project.view_scenes_clips(&self.editor) + self.project.view_scenes_clips() } pub fn view_arranger_track_names (&self) -> impl Content + use<'_> { self.project.view_track_names(self.color) @@ -117,7 +117,7 @@ impl App { 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.project.pool))))))) + .enclose(PoolView(&self.pool))))))) } pub fn view_samples_keys (&self) -> impl Content + use<'_> { self.project.sampler().map(|s|s.view_list(true, self.editor().unwrap())) @@ -243,20 +243,14 @@ impl ScenesView for App { fn arrangement (&self) -> &Arrangement { &self.project } - fn scenes_height (&self) -> u16 { + fn h_scenes (&self) -> u16 { (self.height() as u16).saturating_sub(20) } - fn width_side (&self) -> u16 { + fn w_side (&self) -> u16 { 20 } - fn width_mid (&self) -> u16 { - (self.width() as u16).saturating_sub(self.width_side()) - } - fn scene_selected (&self) -> Option { - self.project.selection.scene() - } - fn track_selected (&self) -> Option { - self.project.selection.track() + fn w_mid (&self) -> u16 { + (self.width() as u16).saturating_sub(self.w_side()) } } diff --git a/crates/cli/tek.rs b/crates/cli/tek.rs index a99f86db..1cb5dc7e 100644 --- a/crates/cli/tek.rs +++ b/crates/cli/tek.rs @@ -122,9 +122,9 @@ impl Cli { jack: jack.clone(), config, color: ItemTheme::random(), - editor: match self.mode { - LaunchMode::Sequencer | LaunchMode::Groovebox => Some((&clip).into()), - _ => None + pool: match self.mode { + LaunchMode::Sequencer | LaunchMode::Groovebox => (&clip).into(), + _ => Default::default() }, project: Arrangement { name: Default::default(), @@ -136,9 +136,9 @@ impl Cli { selection: Selection::TrackClip { track: 0, scene: 0 }, midi_ins, midi_outs, - pool: match self.mode { - LaunchMode::Sequencer | LaunchMode::Groovebox => (&clip).into(), - _ => Default::default() + editor: match self.mode { + LaunchMode::Sequencer | LaunchMode::Groovebox => Some((&clip).into()), + _ => None }, ..Default::default() }, diff --git a/crates/device/src/arranger/arranger_model.rs b/crates/device/src/arranger/arranger_model.rs index a1c8a407..4bc39ecd 100644 --- a/crates/device/src/arranger/arranger_model.rs +++ b/crates/device/src/arranger/arranger_model.rs @@ -10,6 +10,8 @@ pub struct Arrangement { pub jack: Jack, /// Source of time pub clock: Clock, + /// Allows one MIDI clip to be edited + pub editor: Option, /// List of global midi inputs pub midi_ins: Vec, /// List of global midi outputs @@ -35,18 +37,17 @@ pub struct Arrangement { pub arranger: Arc>, /// Display size pub size: Measure, - /// Contains all clips in arrangement - pub pool: Pool, } -has!(Jack: |self: Arrangement|self.jack); -has!(Clock: |self: Arrangement|self.clock); -has!(Selection: |self: Arrangement|self.selection); -has!(Vec: |self: Arrangement|self.midi_ins); -has!(Vec: |self: Arrangement|self.midi_outs); -has!(Vec: |self: Arrangement|self.scenes); -has!(Vec: |self: Arrangement|self.tracks); -has!(Measure: |self: Arrangement|self.size); +has!(Jack: |self: Arrangement|self.jack); +has!(Clock: |self: Arrangement|self.clock); +has!(Selection: |self: Arrangement|self.selection); +has!(Vec: |self: Arrangement|self.midi_ins); +has!(Vec: |self: Arrangement|self.midi_outs); +has!(Vec: |self: Arrangement|self.scenes); +has!(Vec: |self: Arrangement|self.tracks); +has!(Measure: |self: Arrangement|self.size); +has!(Option: |self: Arrangement|self.editor); maybe_has!(Track: |self: Arrangement| { Has::::get(self).track().map(|index|Has::>::get(self).get(index)).flatten() }; { Has::::get(self).track().map(|index|Has::>::get_mut(self).get_mut(index)).flatten() }); @@ -215,19 +216,13 @@ impl ScenesView for Arrangement { fn arrangement (&self) -> &Arrangement { self } - fn scenes_height (&self) -> u16 { + fn h_scenes (&self) -> u16 { (self.height() as u16).saturating_sub(20) } - fn width_side (&self) -> u16 { + fn w_side (&self) -> u16 { (self.width() as u16 * 2 / 10).max(20) } - fn width_mid (&self) -> u16 { - (self.width() as u16).saturating_sub(2 * self.width_side()).max(40) - } - fn scene_selected (&self) -> Option { - self.selection().scene() - } - fn track_selected (&self) -> Option { - self.selection().track() + fn w_mid (&self) -> u16 { + (self.width() as u16).saturating_sub(2 * self.w_side()).max(40) } } diff --git a/crates/device/src/arranger/arranger_view.rs b/crates/device/src/arranger/arranger_view.rs index ac132a9f..8a1713ce 100644 --- a/crates/device/src/arranger/arranger_view.rs +++ b/crates/device/src/arranger/arranger_view.rs @@ -9,7 +9,7 @@ impl Content for Arrangement { let bg = |x|Tui::bg(Reset, x); //let track_scroll = |x|Bsp::s(&self.track_scroll, x); //let scene_scroll = |x|Bsp::e(&self.scene_scroll, x); - self.size.of(outs(tracks(devices(ins(bg(self.view_scenes_clips(&None))))))) + self.size.of(outs(tracks(devices(ins(bg(self.view_scenes_clips())))))) } } @@ -34,7 +34,7 @@ impl Arrangement { let mon = track.sequencer.monitoring; let rec = if rec { White } else { track.color.darkest.rgb }; let mon = if mon { White } else { track.color.darkest.rgb }; - let bg = if self.track_selected() == Some(t) { + let bg = if self.arrangement().selection().track() == Some(t) { track.color.light.rgb } else { track.color.base.rgb @@ -48,18 +48,18 @@ impl Arrangement { } fn view_input_routes (&self) -> impl Content + '_ { Tryptich::top(self.h_inputs()) - .left(self.width_side(), + .left(self.w_side(), io_ports(Tui::g(224), Tui::g(32), ||self.midi_ins_with_sizes())) - .middle(self.width_mid(), + .middle(self.w_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), move|_, &Track { color, .. }|io_conns( color.dark.rgb, color.darker.rgb, ||self.midi_ins_with_sizes()))) } fn view_input_intos (&self) -> impl Content + '_ { Tryptich::top(2) - .left(self.width_side(), + .left(self.w_side(), Bsp::s(Align::e("Input:"), Align::e("Into clip:"))) - .middle(self.width_mid(), + .middle(self.w_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), |_, _|Tui::bg(Reset, Align::c(Bsp::s(OctaveVertical::default(), " ------ "))))) } @@ -72,9 +72,9 @@ impl Arrangement { } fn view_output_ports (&self) -> impl Content + '_ { Tryptich::top(1) - .left(self.width_side(), self.view_output_count()) - .right(self.width_side(), self.view_output_add()) - .middle(self.width_mid(), self.view_output_map()) + .left(self.w_side(), self.view_output_count()) + .right(self.w_side(), self.view_output_add()) + .middle(self.w_mid(), self.view_output_map()) } fn view_output_count (&self) -> impl Content { button_3( @@ -93,7 +93,7 @@ impl Arrangement { let solo = false; let mute = if mute { White } else { t.color.darkest.rgb }; let solo = if solo { White } else { t.color.darkest.rgb }; - let bg_1 = if self.track_selected() == Some(i) { + let bg_1 = if self.arrangement().selection().track() == Some(i) { t.color.light.rgb } else { t.color.base.rgb @@ -106,9 +106,9 @@ impl Arrangement { } fn view_output_conns (&self) -> impl Content + '_ { Tryptich::top(self.h_outputs()) - .left(self.width_side(), io_ports( + .left(self.w_side(), io_ports( Tui::g(224), Tui::g(32), ||self.midi_outs_with_sizes())) - .middle(self.width_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), + .middle(self.w_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), |_, t|io_conns( t.color.dark.rgb, t.color.darker.rgb, @@ -116,14 +116,14 @@ impl Arrangement { ))) } fn view_output_nexts (&self) -> impl Content + '_ { - Tryptich::top(2).left(self.width_side(), Align::ne("From clip:")) - .middle(self.width_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), + Tryptich::top(2).left(self.w_side(), Align::ne("From clip:")) + .middle(self.w_mid(), per_track_top(||self.tracks_with_sizes_scrolled(), |_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default()))))) } fn view_output_froms (&self) -> impl Content + '_ { let label = Align::ne("Next clip:"); - Tryptich::top(2).left(self.width_side(), label) - .middle(self.width_mid(), per_track_top( + Tryptich::top(2).left(self.w_side(), label) + .middle(self.w_mid(), per_track_top( ||self.tracks_with_sizes_scrolled(), |t, track|{ let queued = track.sequencer.next_clip.is_some(); let queued_blank = Thunk::new(||Tui::bg(Reset, " ------ ")); @@ -143,15 +143,15 @@ impl Arrangement { } /// Render track headers fn view_tracks_0 (&self) -> impl Content + '_ { - let width_side = self.width_side(); - let width_mid = self.width_mid(); + let w_side = self.w_side(); + let w_mid = self.w_mid(); let is_editing = false; // FIXME - let track_selected = self.track_selected(); + let track_selected = self.arrangement().selection().track(); Tryptich::center(3) - .left(width_side, + .left(w_side, button_3("t", "track", format!("{}", self.tracks().len()), is_editing)) - .right(width_side, button_2("T", "add track", is_editing)) - .middle(width_mid, per_track(||self.tracks_with_sizes_scrolled(), + .right(w_side, button_2("T", "add track", is_editing)) + .middle(w_mid, per_track(||self.tracks_with_sizes_scrolled(), move|index, track|wrap( if track_selected == Some(index) { track.color.light @@ -164,14 +164,14 @@ impl Arrangement { } /// Render device switches. fn view_devices_0 (&self) -> impl Content + '_ { - let width_side = self.width_side(); - let width_mid = self.width_mid(); + let w_side = self.w_side(); + let w_mid = self.w_mid(); let is_editing = false; // FIXME - let track_selected = self.track_selected(); + let track_selected = self.arrangement().selection().track(); Tryptich::top(1) - .left(width_side, button_3("d", "devices", format!("{}", 0), is_editing)) - .right(width_side, button_2("D", "add device", is_editing)) - .middle(width_mid, per_track_top(||self.tracks_with_sizes_scrolled(), + .left(w_side, button_3("d", "devices", format!("{}", 0), is_editing)) + .right(w_side, button_2("D", "add device", is_editing)) + .middle(w_mid, per_track_top(||self.tracks_with_sizes_scrolled(), move|index, track|{ let bg = if track_selected == Some(index) { track.color.light @@ -185,12 +185,13 @@ impl Arrangement { } impl TracksView for T -where T: HasSize + HasTrackScroll + HasSelection + HasMidiIns {} +where T: HasSize + HasTrackScroll + HasSelection + HasMidiIns + HasEditor {} impl ClipsView for Arrangement {} -pub trait TracksView: HasSize + HasTrackScroll + HasSelection + HasMidiIns { - fn is_editing (&self) -> bool { false } +pub trait TracksView: + HasSize + HasTrackScroll + HasSelection + HasMidiIns + HasEditor +{ fn tracks_width_available (&self) -> u16 { (self.width() as u16).saturating_sub(40) } @@ -230,19 +231,23 @@ pub trait TracksView: HasSize + HasTrackScroll + HasSelection + HasMidiI for track in self.tracks().iter() { max_outputs = max_outputs.max(track.sequencer.midi_outs.len() as u16); } - let content = Align::w(Fixed::y(max_outputs + 1, + let content = Align::w(Fixed::y(1 + max_outputs*2, Tui::bg(theme.darker.rgb, Align::w(Fill::x( Stack::east(move|add: &mut dyn FnMut(&dyn Render)|{ for (index, track, x1, x2) in self .tracks_with_sizes(&self.selection(), None) .skip(self.track_scroll()) { - (add)(&Fixed::x(track.width as u16, Align::nw(Bsp::s( - Tui::bg(track.color.base.rgb, Fill::x(Align::w(format!("[mut] [sol]")))), - Map::south(1, ||track.sequencer.midi_outs.iter(), + add(&Fixed::x(track.width as u16, Align::nw(Bsp::s( + Tui::bg(if self.selection().track() == Some(index) { + track.color.light.rgb + } else { + track.color.base.rgb + }, Fill::x(Align::w(format!("[mut] [sol]")))), + Map::south(2, ||track.sequencer.midi_outs.iter(), |port, index|Tui::fg(Rgb(255, 255, 255), - Tui::bg(track.color.dark.rgb, Fill::x(Align::w( - format!("{index}: {}", port.name())))))))))); + Fixed::y(2, Tui::bg(track.color.dark.rgb, Fill::x(Align::w( + format!("o{index}: {}", port.name()))))))))))); } })))))); Bsp::w( @@ -270,7 +275,7 @@ pub trait TracksView: HasSize + HasTrackScroll + HasSelection + HasMidiI Fill::x(Align::w(format!("[rec] [mon]")))), Map::south(1, ||track.sequencer.midi_ins.iter(), |port, index|Tui::fg_bg(Rgb(255, 255, 255), track.color.dark.rgb, - Fill::x(Align::w(format!("{index}: {}", port.name()))))))))); + Fill::x(Align::w(format!("i{index}: {}", port.name()))))))))); } })))); @@ -300,28 +305,26 @@ pub trait TracksView: HasSize + HasTrackScroll + HasSelection + HasMidiI { add(&Fixed::xy(track.width as u16, h + 1, Tui::bg(track.color.dark.rgb, Align::nw(Map::south(1, move||0..h, - |_, index|format!("{index}: {}", "--------")))))); + |_, index|format!("d{index}: {}", "--------")))))); } })))))) } fn view_track_header <'a, T: Content> ( &'a self, theme: ItemTheme, content: T ) -> impl Content { - Fixed::x(20, Tui::bg(theme.darker.rgb, Fill::x(Align::e(content)))) + Fixed::x(12, Tui::bg(theme.darker.rgb, Fill::x(Align::e(content)))) } } pub trait ScenesView: HasSelection + HasSceneScroll + Send + Sync { /// Default scene height. - const H_SCENE: usize = 2; + const H_SCENE: usize = 2; /// Default editor height. const H_EDITOR: usize = 15; - fn arrangement (&self) -> &Arrangement; - fn scene_selected (&self) -> Option; - fn track_selected (&self) -> Option; - fn scenes_height (&self) -> u16; - fn width_side (&self) -> u16; - fn width_mid (&self) -> u16; + fn arrangement (&self) -> &Arrangement; + fn h_scenes (&self) -> u16; + fn w_side (&self) -> u16; + fn w_mid (&self) -> u16; fn view_scenes_names (&self) -> impl Content { Stack::south(move|add: &mut dyn FnMut(&dyn Render)|{ for (index, scene) in self.scenes().iter().enumerate().skip(self.scene_scroll()) { @@ -338,7 +341,7 @@ pub trait ScenesView: HasSelection + HasSceneScroll + Send + Sync { format!(" {index:2} "), Tui::fg(Rgb(255, 255, 255), Tui::bold(true, format!("{}", scene.name))))))) - //let height = (1 + y2 - y1) as u16; + //let height = (1 + y2 - y1 as u16; //let name = Some(scene.name.clone()); //let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(" ⯈ ", name)))); //let selected = self.scene_selected() == Some(s); @@ -387,11 +390,11 @@ pub trait ScenesView: HasSelection + HasSceneScroll + Send + Sync { false, // FIXME self.is_editing(), Self::H_SCENE, Self::H_EDITOR, selection.track(), selection.scene(), - ).map_while(|(s, scene, y1, y2)|(y2<=self.scenes_height() as usize) + ).map_while(|(s, scene, y1, y2)|(y2<=self.h_scenes() as usize) .then_some((s, scene, y1, y2))) } /// Height required to display all scenes. - fn scenes_height_total (&self, is_editing: bool) -> u16 { + fn h_scenes_total (&self, is_editing: bool) -> u16 { self.scenes_with_sizes( is_editing, Self::H_SCENE, @@ -405,7 +408,7 @@ pub trait ScenesView: HasSelection + HasSceneScroll + Send + Sync { } pub trait ClipsView: TracksView + ScenesView + Send + Sync { - fn view_scenes_clips <'a> (&'a self, editor: &'a Option) + fn view_scenes_clips <'a> (&'a self) -> impl Content + 'a { Fill::xy(Stack::::east(move|column: &mut dyn FnMut(&dyn Render)|{ diff --git a/crates/device/src/editor/editor_model.rs b/crates/device/src/editor/editor_model.rs index f7495032..0082725c 100644 --- a/crates/device/src/editor/editor_model.rs +++ b/crates/device/src/editor/editor_model.rs @@ -103,12 +103,24 @@ impl MidiViewer for MidiEditor { fn set_clip (&mut self, p: Option<&Arc>>) { self.mode.set_clip(p) } } -pub trait HasEditor { - fn editor (&self) -> Option<&MidiEditor>; - fn editor_mut (&mut self) -> Option<&mut MidiEditor>; - fn is_editing (&self) -> bool { self.editor().is_some() } - fn editor_w (&self) -> usize { 0 } - fn editor_h (&self) -> usize { 0 } +impl>> HasEditor for T {} + +pub trait HasEditor: Has> { + fn editor (&self) -> Option<&MidiEditor> { + self.get().as_ref() + } + fn editor_mut (&mut self) -> Option<&mut MidiEditor> { + self.get_mut().as_mut() + } + fn is_editing (&self) -> bool { + self.editor().is_some() + } + fn editor_w (&self) -> usize { + self.editor().map(|e|e.size.w()).unwrap_or(0) + } + fn editor_h (&self) -> usize { + self.editor().map(|e|e.size.h()).unwrap_or(0) + } } #[macro_export] macro_rules! has_editor {