mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
switch around ownership of pool and editort
This commit is contained in:
parent
3f1a2fee80
commit
c7e7c9f68c
8 changed files with 157 additions and 150 deletions
|
|
@ -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<Self> {
|
||||
*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<Self> {
|
||||
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<Self> {
|
||||
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<PoolCommand> {
|
||||
Context::get(&self.project.pool, iter)
|
||||
Context::get(&self.pool, iter)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<u7> = None;
|
||||
for port in midi_in.iter() {
|
||||
for event in port.iter() {
|
||||
|
|
|
|||
|
|
@ -20,23 +20,22 @@ pub struct App {
|
|||
pub history: Vec<AppCommand>,
|
||||
// Dialog overlay
|
||||
pub dialog: Option<Dialog>,
|
||||
/// Contains the currently edited MIDI clip
|
||||
pub editor: Option<MidiEditor>,
|
||||
// Cache of formatted strings
|
||||
pub view_cache: Arc<RwLock<ViewCache>>,
|
||||
/// 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<JackMidiIn>: |self: App|self.project.midi_ins);
|
||||
has!(Vec<JackMidiOut>: |self: App|self.project.midi_outs);
|
||||
has!(Vec<Scene>: |self: App|self.project.scenes);
|
||||
has!(Vec<Track>: |self: App|self.project.tracks);
|
||||
has!(Measure<TuiOut>: |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<MidiEditor>: |self: App|self.project.editor);
|
||||
has!(Selection: |self: App|self.project.selection);
|
||||
has!(Vec<JackMidiIn>: |self: App|self.project.midi_ins);
|
||||
has!(Vec<JackMidiOut>: |self: App|self.project.midi_outs);
|
||||
has!(Vec<Scene>: |self: App|self.project.scenes);
|
||||
has!(Vec<Track>: |self: App|self.project.tracks);
|
||||
has!(Measure<TuiOut>: |self: App|self.size);
|
||||
maybe_has!(Track: |self: App|
|
||||
{ MaybeHas::<Track>::get(&self.project) };
|
||||
{ MaybeHas::<Track>::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<Dialog>) -> Option<Dialog> {
|
||||
|
|
@ -70,7 +69,7 @@ impl App {
|
|||
}
|
||||
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());
|
||||
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<Dialog> {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ impl App {
|
|||
self.project.view_scenes_names()
|
||||
}
|
||||
pub fn view_arranger_scenes_clips (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
self.project.view_scenes_clips(&self.editor)
|
||||
self.project.view_scenes_clips()
|
||||
}
|
||||
pub fn view_arranger_track_names (&self) -> impl Content<TuiOut> + 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<TuiOut> + 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<usize> {
|
||||
self.project.selection.scene()
|
||||
}
|
||||
fn track_selected (&self) -> Option<usize> {
|
||||
self.project.selection.track()
|
||||
fn w_mid (&self) -> u16 {
|
||||
(self.width() as u16).saturating_sub(self.w_side())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue