mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
down to 3 errors
This commit is contained in:
parent
ebdb8881e9
commit
8df49850ae
7 changed files with 84 additions and 81 deletions
|
|
@ -47,13 +47,27 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
|
|||
Ok(None)
|
||||
}
|
||||
fn select (app: &mut App, selection: Selection) -> Perhaps<Self> {
|
||||
app.select(selection);
|
||||
app.arranger.select(selection);
|
||||
if let Some(ref mut editor) = app.editor {
|
||||
editor.set_clip(match app.arranger.selected {
|
||||
Some(Selection::TrackClip { track, scene })
|
||||
if let Some(Some(Some(clip))) = app
|
||||
.arranger
|
||||
.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 stop_all (app: &mut App) -> Perhaps<Self> {
|
||||
app.stop_all();
|
||||
|
|
|
|||
|
|
@ -14,16 +14,6 @@ impl ArrangementCommand {
|
|||
/// Set the selection
|
||||
fn select (arranger: &mut Arrangement, s: Option<Selection>) -> Perhaps<Self> {
|
||||
arranger.selected = s;
|
||||
// autoedit: load focused clip in editor.
|
||||
if let Some(ref mut editor) = arranger.editor {
|
||||
editor.set_clip(match arranger.selected {
|
||||
Some(Selection::TrackClip { track, scene })
|
||||
if let Some(Some(Some(clip))) = arranger
|
||||
.scenes.get(scene)
|
||||
.map(|s|s.clips.get(track)) => Some(clip),
|
||||
_ => None
|
||||
});
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
/// Launch a clip or scene
|
||||
|
|
|
|||
|
|
@ -33,38 +33,4 @@ impl ClipCommand {
|
|||
|
||||
impl Arrangement {
|
||||
|
||||
/// Put a clip in a slot
|
||||
pub(crate) fn clip_put (
|
||||
&mut self, track: usize, scene: usize, clip: Option<Arc<RwLock<MidiClip>>>
|
||||
) -> Option<Arc<RwLock<MidiClip>>> {
|
||||
let old = self.scenes[scene].clips[track].clone();
|
||||
self.scenes[scene].clips[track] = clip;
|
||||
old
|
||||
}
|
||||
|
||||
/// Change the color of a clip, returning the previous one
|
||||
pub(crate) fn clip_set_color (
|
||||
&self, track: usize, scene: usize, color: ItemTheme
|
||||
) -> Option<ItemTheme> {
|
||||
self.scenes[scene].clips[track].as_ref().map(|clip|{
|
||||
let mut clip = clip.write().unwrap();
|
||||
let old = clip.color.clone();
|
||||
clip.color = color.clone();
|
||||
panic!("{color:?} {old:?}");
|
||||
old
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the active clip
|
||||
pub(crate) fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
||||
self.scene()?.clips.get(self.selected.track()?)?.clone()
|
||||
}
|
||||
|
||||
/// Toggle looping for the active clip
|
||||
pub(crate) fn toggle_loop (&mut self) {
|
||||
if let Some(clip) = self.clip() {
|
||||
clip.write().unwrap().toggle_loop()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,16 +119,66 @@ impl Arrangement {
|
|||
2
|
||||
//1 + self.devices_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
||||
}
|
||||
/// Get the active track
|
||||
fn get_track (&self) -> Option<&Track> {
|
||||
let index = self.selection()?.track()?;
|
||||
Has::<Vec<Track>>::get(self).get(index)
|
||||
}
|
||||
/// Get a mutable reference to the active track
|
||||
fn get_track_mut (&mut self) -> Option<&mut Track> {
|
||||
let index = self.selection()?.track()?;
|
||||
Has::<Vec<Track>>::get_mut(self).get_mut(index)
|
||||
}
|
||||
/// Get the active scene
|
||||
fn get_scene (&self) -> Option<&Scene> {
|
||||
let index = self.selection()?.scene()?;
|
||||
Has::<Vec<Scene>>::get(self).get(index)
|
||||
}
|
||||
/// Get a mutable reference to the active scene
|
||||
fn get_scene_mut (&mut self) -> Option<&mut Scene> {
|
||||
let index = self.selection()?.scene()?;
|
||||
Has::<Vec<Scene>>::get_mut(self).get_mut(index)
|
||||
}
|
||||
/// Get the active clip
|
||||
fn get_clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
|
||||
self.get_scene()?.clips.get(self.selection()?.track()?)?.clone()
|
||||
}
|
||||
/// Put a clip in a slot
|
||||
pub(crate) fn clip_put (
|
||||
&mut self, track: usize, scene: usize, clip: Option<Arc<RwLock<MidiClip>>>
|
||||
) -> Option<Arc<RwLock<MidiClip>>> {
|
||||
let old = self.scenes[scene].clips[track].clone();
|
||||
self.scenes[scene].clips[track] = clip;
|
||||
old
|
||||
}
|
||||
/// Change the color of a clip, returning the previous one
|
||||
pub(crate) fn clip_set_color (&self, track: usize, scene: usize, color: ItemTheme)
|
||||
-> Option<ItemTheme>
|
||||
{
|
||||
self.scenes[scene].clips[track].as_ref().map(|clip|{
|
||||
let mut clip = clip.write().unwrap();
|
||||
let old = clip.color.clone();
|
||||
clip.color = color.clone();
|
||||
panic!("{color:?} {old:?}");
|
||||
old
|
||||
})
|
||||
}
|
||||
/// Toggle looping for the active clip
|
||||
pub(crate) fn toggle_loop (&mut self) {
|
||||
if let Some(clip) = self.get_clip() {
|
||||
clip.write().unwrap().toggle_loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sampler")]
|
||||
impl Arrangement {
|
||||
/// Get the first sampler of the active track
|
||||
pub fn sampler (&self) -> Option<&Sampler> {
|
||||
self.track().map(|t|t.sampler(0)).flatten()
|
||||
self.get_track()?.sampler(0)
|
||||
}
|
||||
/// Get the first sampler of the active track
|
||||
pub fn sampler_mut (&mut self) -> Option<&mut Sampler> {
|
||||
self.track_mut().map(|t|t.sampler_mut(0)).flatten()
|
||||
self.get_track_mut()?.sampler_mut(0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,17 @@
|
|||
use crate::*;
|
||||
|
||||
impl<T: Has<Selection>> HasSelection for T {}
|
||||
impl<T: Has<Option<Selection>>> HasSelection for T {}
|
||||
|
||||
pub trait HasSelection: Has<Selection> {
|
||||
fn selection (&self) -> &Selection {
|
||||
self.get()
|
||||
pub trait HasSelection: Has<Option<Selection>> {
|
||||
fn selection (&self) -> Option<&Selection> {
|
||||
self.get().as_ref()
|
||||
}
|
||||
fn selection_mut (&mut self) -> &mut Selection {
|
||||
fn selection_mut (&mut self) -> &mut Option<Selection> {
|
||||
self.get_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl Has<Option<Track>> for Arrangement {
|
||||
fn get (&self) -> &Option<Track> {
|
||||
let selection: Selection = Has::<Option<Track>>::get(self)?;
|
||||
let index: Option<usize> = selection.track()?;
|
||||
let track: Track = Has::<Vec<Track>>::get(self).get(index)?;
|
||||
}
|
||||
fn get_mut (&mut self) -> &mut Option<Track> {
|
||||
Has::<Option<Selection>>::get(self)
|
||||
.and_then(|selection|selection.track())
|
||||
.and_then(|index|Has::<Vec<Track>>::get_mut(self).get_mut(index))
|
||||
}
|
||||
}
|
||||
|
||||
impl Has<Option<Scene>> for Arrangement {
|
||||
fn get (&self) -> &Option<Scene> {
|
||||
Has::<Option<Selection>>::get(self)
|
||||
.and_then(|selection|selection.track())
|
||||
.and_then(|index|Has::<Vec<Scene>>::get(self).get(index))
|
||||
}
|
||||
fn get_mut (&mut self) -> &mut Option<Scene> {
|
||||
Has::<Option<Selection>>::get(self)
|
||||
.and_then(|selection|selection.track())
|
||||
.and_then(|index|Has::<Vec<Scene>>::get_mut(self).get_mut(index).as_deref())
|
||||
}
|
||||
impl Arrangement {
|
||||
}
|
||||
|
||||
/// Represents the current user selection in the arranger
|
||||
|
|
|
|||
|
|
@ -81,11 +81,9 @@ impl<'a> ArrangerView<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: HasTracks + HasScenes + HasClock + HasJack> AddTrack for T {}
|
||||
|
||||
pub trait AddTrack: HasTracks + HasScenes + HasClock + HasJack {
|
||||
impl Arrangement {
|
||||
/// Add multiple tracks
|
||||
fn tracks_add (
|
||||
pub fn tracks_add (
|
||||
&mut self,
|
||||
count: usize,
|
||||
width: Option<usize>,
|
||||
|
|
@ -106,7 +104,7 @@ pub trait AddTrack: HasTracks + HasScenes + HasClock + HasJack {
|
|||
}
|
||||
|
||||
/// Add a track
|
||||
fn track_add (
|
||||
pub fn track_add (
|
||||
&mut self,
|
||||
name: Option<&str>,
|
||||
color: Option<ItemTheme>,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,14 @@ impl<T, U: Has<Option<T>>> MaybeHas<T> for U {
|
|||
};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! as_ref {
|
||||
($T:ty: |$self:ident : $S:ty| $x:expr) => {
|
||||
impl AsRef<$T> for $S {
|
||||
fn as_ref (&$self) -> &$T { &$x }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub trait HasN<T>: Send + Sync {
|
||||
fn get_nth (&self, key: usize) -> &T;
|
||||
fn get_nth_mut (&mut self, key: usize) -> &mut T;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue