wip: removing Has trait

This commit is contained in:
okay stopped screaming 2026-02-23 18:40:30 +02:00
parent b6559fc904
commit 9ae35830c3
5 changed files with 520 additions and 540 deletions

View file

@ -115,10 +115,6 @@ pub trait JackPerfModel {
}
//pub trait MaybeHas<T>: Send + Sync {
//fn get (&self) -> Option<&T>;
//}
pub trait HasN<T>: Send + Sync {
fn get_nth (&self, key: usize) -> &T;
fn get_nth_mut (&mut self, key: usize) -> &mut T;
@ -242,37 +238,44 @@ pub trait MidiRange: TimeRange + NoteRange {}
/// can be clocked in microseconds with f64 without losing precision.
pub trait TimeUnit: InteriorMutable<f64> {}
pub trait HasSceneScroll: HasScenes {
fn scene_scroll (&self) -> usize;
}
pub trait HasTrackScroll: HasTracks {
fn track_scroll (&self) -> usize;
}
pub trait HasClipsSize { fn clips_size (&self) -> &Measure<TuiOut>; }
pub trait HasMidiClip {
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>>;
}
pub trait HasClipsSize {
fn clips_size (&self) -> &Measure<TuiOut>;
pub trait HasClock: AsRef<Clock> + AsMut<Clock> {
fn clock_mut (&mut self) -> &mut Clock { self.as_mut() }
fn clock (&self) -> &Clock { self.as_ref() }
}
pub trait HasClock: Send + Sync {
fn clock (&self) -> &Clock;
fn clock_mut (&mut self) -> &mut Clock;
pub trait HasDevices: AsRef<Vec<Device>> + AsMut<Vec<Device>> {
fn devices_mut (&mut self) -> &mut Vec<Device> { self.as_mut() }
fn devices (&self) -> &Vec<Device> { self.as_reF() }
}
pub trait HasDevices {
fn devices (&self) -> &Vec<Device>;
fn devices_mut (&mut self) -> &mut Vec<Device>;
pub trait HasSelection: AsRef<Selection> + AsMut<Selection> {
fn selection_mut (&mut self) -> &mut Selection { self.as_mut() }
fn selection (&self) -> &Selection { self.as_ref() }
}
pub trait HasSelection: Has<Selection> {
fn selection (&self) -> &Selection { self.get() }
fn selection_mut (&mut self) -> &mut Selection { self.get_mut() }
pub trait HasSequencer: AsRef<Sequencer> + AsMut<Sequencer> {
fn sequencer_mut (&mut self) -> &mut Sequencer { self.as_mut() }
fn sequencer (&self) -> &Sequencer { self.as_ref() }
}
pub trait HasScene: AsRef<Option<Scene>> + AsMut<Option<Scene>> {
fn scene_mut (&mut self) -> &mut Option<Scene> { self.as_mut() }
fn scene (&self) -> Option<&Scene> { self.as_ref() }
}
pub trait HasScenes: AsRef<Vec<Scene>> + AsMut<Vec<Scene>> {
fn scenes (&self) -> &Vec<Scene> { self.as_reF() }
fn scenes_mut (&mut self) -> &mut Vec<Scene> { self.as_mut() }
/// Generate the default name for a new scene
fn scene_default_name (&self) -> Arc<str> { format!("s{:3>}", self.scenes().len() + 1).into() }
fn scene_longest_name (&self) -> usize { self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max) }
}
pub trait HasSceneScroll: HasScenes {
fn scene_scroll (&self) -> usize;
}
pub trait HasTrackScroll: HasTracks {
fn track_scroll (&self) -> usize;
}
pub trait HasWidth {
const MIN_WIDTH: usize;
/// Increment track width.
@ -280,48 +283,17 @@ pub trait HasWidth {
/// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH].
fn width_dec (&mut self);
}
pub trait HasMidiBuffers {
fn note_buf_mut (&mut self) -> &mut Vec<u8>;
fn midi_buf_mut (&mut self) -> &mut Vec<Vec<Vec<u8>>>;
}
pub trait HasSequencer {
fn sequencer (&self) -> &Sequencer;
fn sequencer_mut (&mut self) -> &mut Sequencer;
}
pub trait HasScene: Has<Option<Scene>> + Send + Sync {
fn scene (&self) -> Option<&Scene> {
Has::<Option<Scene>>::get(self).as_ref()
}
fn scene_mut (&mut self) -> &mut Option<Scene> {
Has::<Option<Scene>>::get_mut(self)
}
}
pub trait HasScenes: Has<Vec<Scene>> + Send + Sync {
fn scenes (&self) -> &Vec<Scene> {
Has::<Vec<Scene>>::get(self)
}
fn scenes_mut (&mut self) -> &mut Vec<Scene> {
Has::<Vec<Scene>>::get_mut(self)
}
/// Generate the default name for a new scene
fn scene_default_name (&self) -> Arc<str> {
format!("s{:3>}", self.scenes().len() + 1).into()
}
fn scene_longest_name (&self) -> usize {
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
}
}
/// ```
/// use tek::{MidiEditor, HasEditor, tengri::Has};
///
/// let mut host = TestEditorHost(Some(MidiEditor::default()));
/// struct TestEditorHost(Option<MidiEditor>);
/// impl Has<Option<MidiEditor>> for TestEditorHost {
/// impl AsRef<Option<MidiEditor>> for TestEditorHost {
/// fn get (&self) -> &Option<MidiEditor> { &self.0 }
/// fn get_mut (&mut self) -> &mut Option<MidiEditor> { &mut self.0 }
/// }
@ -332,7 +304,7 @@ pub trait HasScenes: Has<Vec<Scene>> + Send + Sync {
/// let _ = host.editor_w();
/// let _ = host.editor_h();
/// ```
pub trait HasEditor: Has<Option<MidiEditor>> {
pub trait HasEditor: AsRef<Option<MidiEditor>> {
fn editor (&self) -> Option<&MidiEditor> {
self.get().as_ref()
}
@ -407,9 +379,10 @@ pub trait HasMidiOuts {
}
}
pub trait HasTracks: Has<Vec<Track>> + Send + Sync {
fn tracks (&self) -> &Vec<Track> { Has::<Vec<Track>>::get(self) }
fn tracks_mut (&mut self) -> &mut Vec<Track> { Has::<Vec<Track>>::get_mut(self) }
impl<T: AsRef<Vec<Track>> + AsMut<Vec<Track>> + Send + Sync> HasTracks for T {}
pub trait HasTracks: AsRef<Vec<Track>> + AsMut<Vec<Track>> + Send + Sync {
fn tracks (&self) -> &Vec<Track> { self.as_ref() }
fn tracks_mut (&mut self) -> &mut Vec<Track> { self.as_mut() }
/// Run audio callbacks for every track and every device
fn process_tracks (&mut self, client: &Client, scope: &ProcessScope) -> Control {
for track in self.tracks_mut().iter_mut() {