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

@ -4,6 +4,9 @@ export RUST_BACKTRACE := "1"
default +ARGS="new": default +ARGS="new":
target/debug/tek {{ARGS}} target/debug/tek {{ARGS}}
doc +ARGS="":
cargo doc --open -j4 --document-private-items {{ARGS}}
cloc: cloc:
for src in {cli,edn/src,input/src,jack/src,midi/src,output/src,plugin/src,sampler/src,tek/src,time/src,tui/src}; do echo; echo $src; cloc --quiet $src; done for src in {cli,edn/src,input/src,jack/src,midi/src,output/src,plugin/src,sampler/src,tek/src,time/src,tui/src}; do echo; echo $src; cloc --quiet $src; done
@ -43,9 +46,6 @@ run-init:
prof: prof:
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph -- CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --
doc:
cargo doc -j4 --workspace --document-private-items
release := "reset && cargo run --release --" release := "reset && cargo run --release --"
release: release:
{{release}} {{release}}

View file

@ -384,12 +384,12 @@ pub fn device_kinds () -> &'static [&'static str] {
] ]
} }
impl<T: Has<Vec<Device>>> HasDevices for T { impl<T: AsRef<Vec<Device>> + AsMut<Vec<Device>>> HasDevices for T {
fn devices (&self) -> &Vec<Device> { fn devices (&self) -> &Vec<Device> {
self.get() self.as_ref()
} }
fn devices_mut (&mut self) -> &mut Vec<Device> { fn devices_mut (&mut self) -> &mut Vec<Device> {
self.get_mut() self.as_mut()
} }
} }
@ -1127,26 +1127,6 @@ mod view {
Fixed::XY(20, 1 + ins, frame.enclose(Fixed::XY(20, 1 + ins, field))) Fixed::XY(20, 1 + ins, frame.enclose(Fixed::XY(20, 1 + ins, field)))
} }
pub fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
Align::x(Tui::bg(Reset, Map::new(tracks,
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{
let width = (x2 - x1) as u16;
map_east(x1 as u16, width, Fixed::X(width, Tui::fg_bg(
track.color.lightest.rgb,
track.color.base.rgb,
callback(index, track))))})))
}
pub fn per_track <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
per_track_top(tracks, move|index, track|Fill::Y(Align::y(callback(index, track))))
}
pub fn io_ports <'a, T: PortsSizes<'a>> ( pub fn io_ports <'a, T: PortsSizes<'a>> (
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a { ) -> impl Content<TuiOut> + 'a {
@ -1159,67 +1139,6 @@ mod view {
Fill::Y(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg, Fill::Y(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg,
&connect.info))))))))) &connect.info)))))))))
} }
#[cfg(feature = "lv2")] pub fn draw_header (state: &Lv2, to: &mut TuiOut, x: u16, y: u16, w: u16) {
let style = Style::default().gray();
let label1 = format!(" {}", state.name);
to.blit(&label1, x + 1, y, Some(style.white().bold()));
if let Some(ref path) = state.path {
let label2 = format!("{}", &path[..((w as usize - 10).min(path.len()))]);
to.blit(&label2, x + 2 + label1.len() as u16, y, Some(style.not_dim()));
}
//Ok(Rect { x, y, width: w, height: 1 })
}
pub fn draw_sample (
to: &mut TuiOut, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool
) -> Usually<usize> {
let style = if focus { Style::default().green() } else { Style::default() };
if focus {
to.blit(&"🬴", x+1, y, Some(style.bold()));
}
let label1 = format!("{:3} {:12}",
note.map(|n|n.to_string()).unwrap_or(String::default()),
sample.name);
let label2 = format!("{:>6} {:>6} +0.0",
sample.start,
sample.end);
to.blit(&label1, x+2, y, Some(style.bold()));
to.blit(&label2, x+3+label1.len()as u16, y, Some(style));
Ok(label1.len() + label2.len() + 4)
}
}
pub(crate) fn sampler_jack_process (
state: &mut Sampler, _: &Client, scope: &ProcessScope
) -> Control {
if let Some(midi_in) = &state.midi_in {
for midi in midi_in.port().iter(scope) {
sampler_midi_in(&state.samples, &state.voices, midi)
}
}
state.process_audio_out(scope);
state.process_audio_in(scope);
Control::Continue
}
/// Create [Voice]s from [Sample]s in response to MIDI input.
pub(crate) fn sampler_midi_in (
samples: &SampleKit<128>, voices: &Arc<RwLock<Vec<Voice>>>, RawMidi { time, bytes }: RawMidi
) {
if let Ok(LiveEvent::Midi { message, .. }) = LiveEvent::parse(bytes) {
match message {
MidiMessage::NoteOn { ref key, ref vel } => {
if let Some(sample) = samples.get(key.as_int() as usize) {
voices.write().unwrap().push(Sample::play(sample, time as usize, vel));
}
},
MidiMessage::Controller { controller: _, value: _ } => {
// TODO
}
_ => {}
}
}
} }
#[cfg(test)] mod test_view_meter { #[cfg(test)] mod test_view_meter {

File diff suppressed because it is too large Load diff

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 { pub trait HasN<T>: Send + Sync {
fn get_nth (&self, key: usize) -> &T; fn get_nth (&self, key: usize) -> &T;
fn get_nth_mut (&mut self, key: usize) -> &mut 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. /// can be clocked in microseconds with f64 without losing precision.
pub trait TimeUnit: InteriorMutable<f64> {} pub trait TimeUnit: InteriorMutable<f64> {}
pub trait HasSceneScroll: HasScenes { pub trait HasClipsSize { fn clips_size (&self) -> &Measure<TuiOut>; }
fn scene_scroll (&self) -> usize;
}
pub trait HasTrackScroll: HasTracks {
fn track_scroll (&self) -> usize;
}
pub trait HasMidiClip { pub trait HasMidiClip {
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>>; fn clip (&self) -> Option<Arc<RwLock<MidiClip>>>;
} }
pub trait HasClock: AsRef<Clock> + AsMut<Clock> {
pub trait HasClipsSize { fn clock_mut (&mut self) -> &mut Clock { self.as_mut() }
fn clips_size (&self) -> &Measure<TuiOut>; fn clock (&self) -> &Clock { self.as_ref() }
} }
pub trait HasDevices: AsRef<Vec<Device>> + AsMut<Vec<Device>> {
pub trait HasClock: Send + Sync { fn devices_mut (&mut self) -> &mut Vec<Device> { self.as_mut() }
fn clock (&self) -> &Clock; fn devices (&self) -> &Vec<Device> { self.as_reF() }
fn clock_mut (&mut self) -> &mut Clock;
} }
pub trait HasSelection: AsRef<Selection> + AsMut<Selection> {
pub trait HasDevices { fn selection_mut (&mut self) -> &mut Selection { self.as_mut() }
fn devices (&self) -> &Vec<Device>; fn selection (&self) -> &Selection { self.as_ref() }
fn devices_mut (&mut self) -> &mut Vec<Device>;
} }
pub trait HasSequencer: AsRef<Sequencer> + AsMut<Sequencer> {
pub trait HasSelection: Has<Selection> { fn sequencer_mut (&mut self) -> &mut Sequencer { self.as_mut() }
fn selection (&self) -> &Selection { self.get() } fn sequencer (&self) -> &Sequencer { self.as_ref() }
fn selection_mut (&mut self) -> &mut Selection { self.get_mut() } }
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 { pub trait HasWidth {
const MIN_WIDTH: usize; const MIN_WIDTH: usize;
/// Increment track width. /// Increment track width.
@ -280,48 +283,17 @@ pub trait HasWidth {
/// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH]. /// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH].
fn width_dec (&mut self); fn width_dec (&mut self);
} }
pub trait HasMidiBuffers { pub trait HasMidiBuffers {
fn note_buf_mut (&mut self) -> &mut Vec<u8>; fn note_buf_mut (&mut self) -> &mut Vec<u8>;
fn midi_buf_mut (&mut self) -> &mut Vec<Vec<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}; /// use tek::{MidiEditor, HasEditor, tengri::Has};
/// ///
/// let mut host = TestEditorHost(Some(MidiEditor::default())); /// let mut host = TestEditorHost(Some(MidiEditor::default()));
/// struct TestEditorHost(Option<MidiEditor>); /// 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 (&self) -> &Option<MidiEditor> { &self.0 }
/// fn get_mut (&mut self) -> &mut Option<MidiEditor> { &mut 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_w();
/// let _ = host.editor_h(); /// let _ = host.editor_h();
/// ``` /// ```
pub trait HasEditor: Has<Option<MidiEditor>> { pub trait HasEditor: AsRef<Option<MidiEditor>> {
fn editor (&self) -> Option<&MidiEditor> { fn editor (&self) -> Option<&MidiEditor> {
self.get().as_ref() self.get().as_ref()
} }
@ -407,9 +379,10 @@ pub trait HasMidiOuts {
} }
} }
pub trait HasTracks: Has<Vec<Track>> + Send + Sync { impl<T: AsRef<Vec<Track>> + AsMut<Vec<Track>> + Send + Sync> HasTracks for T {}
fn tracks (&self) -> &Vec<Track> { Has::<Vec<Track>>::get(self) } pub trait HasTracks: AsRef<Vec<Track>> + AsMut<Vec<Track>> + Send + Sync {
fn tracks_mut (&mut self) -> &mut Vec<Track> { Has::<Vec<Track>>::get_mut(self) } 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 /// Run audio callbacks for every track and every device
fn process_tracks (&mut self, client: &Client, scope: &ProcessScope) -> Control { fn process_tracks (&mut self, client: &Client, scope: &ProcessScope) -> Control {
for track in self.tracks_mut().iter_mut() { for track in self.tracks_mut().iter_mut() {

2
dizzle

@ -1 +1 @@
Subproject commit 7d1fbe3fbe53699a3e12eb5a3d55db79653d72d8 Subproject commit 909b94cbd4beffb49be314724dc79db9374bcc99