mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-13 07:06:41 +01:00
wip: refactor pt.35 (16e) even more traits, even fewer structs
This commit is contained in:
parent
beca1a6ade
commit
7af5bbd02b
12 changed files with 121 additions and 191 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait HasPlayer: HasJack + HasClock {
|
||||
pub trait HasPlayer: HasJack {
|
||||
fn player (&self) -> &MIDIPlayer;
|
||||
fn player_mut (&mut self) -> &mut MIDIPlayer;
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ pub trait HasMidiBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasPhrase: PlayheadApi + HasClock + HasMidiBuffer {
|
||||
pub trait HasPhrase: ClockApi + PlayheadApi + HasMidiBuffer {
|
||||
fn phrase (&self) -> &Option<(Instant, Arc<RwLock<Phrase>>)>;
|
||||
fn next_phrase (&self) -> &Option<(Instant, Arc<RwLock<Phrase>>)>;
|
||||
fn next_phrase_mut (&mut self) -> &mut Option<(Instant, Arc<RwLock<Phrase>>)>;
|
||||
|
|
@ -34,13 +34,13 @@ pub trait HasPhrase: PlayheadApi + HasClock + HasMidiBuffer {
|
|||
//let samples = scope.n_frames() as usize;
|
||||
if let Some((start_at, phrase)) = &self.next_phrase() {
|
||||
let start = start_at.sample.get() as usize;
|
||||
let sample = self.clock().started.read().unwrap().unwrap().0;
|
||||
let sample = self.started().read().unwrap().unwrap().0;
|
||||
// If it's time to switch to the next phrase:
|
||||
if start <= sample0.saturating_sub(sample) {
|
||||
// Samples elapsed since phrase was supposed to start
|
||||
let skipped = sample0 - start;
|
||||
// Switch over to enqueued phrase
|
||||
let started = Instant::from_sample(&self.clock().timebase(), start as f64);
|
||||
let started = Instant::from_sample(&self.timebase(), start as f64);
|
||||
self.phrase = Some((started, phrase.clone()));
|
||||
// Unset enqueuement (TODO: where to implement looping?)
|
||||
*self.next_phrase_mut() = None
|
||||
|
|
@ -54,9 +54,9 @@ pub trait HasPhrase: PlayheadApi + HasClock + HasMidiBuffer {
|
|||
}
|
||||
}
|
||||
fn enqueue_next (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
let start = self.clock().next_launch_pulse();
|
||||
let start = self.next_launch_pulse();
|
||||
self.next_phrase = Some((
|
||||
Instant::from_pulse(&self.clock().timebase(), start as f64),
|
||||
Instant::from_pulse(&self.timebase(), start as f64),
|
||||
phrase.map(|p|p.clone())
|
||||
));
|
||||
self.reset = true;
|
||||
|
|
@ -70,7 +70,7 @@ pub trait HasPhrase: PlayheadApi + HasClock + HasMidiBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait MidiInputApi: PlayheadApi + HasMidiBuffer + HasPhrase {
|
||||
pub trait MidiInputApi: ClockApi + PlayheadApi + HasMidiBuffer + HasPhrase {
|
||||
fn midi_ins (&self) -> &Vec<Port<MidiIn>>;
|
||||
fn midi_ins_mut (&self) -> &mut Vec<Port<MidiIn>>;
|
||||
fn has_midi_ins (&self) -> bool {
|
||||
|
|
@ -147,7 +147,7 @@ pub trait MidiInputApi: PlayheadApi + HasMidiBuffer + HasPhrase {
|
|||
|
||||
}
|
||||
|
||||
pub trait MidiOutputApi: PlayheadApi + HasMidiBuffer + HasPhrase + HasClock {
|
||||
pub trait MidiOutputApi: ClockApi + PlayheadApi + HasMidiBuffer + HasPhrase {
|
||||
fn midi_outs (&self) -> &Vec<Port<MidiOut>>;
|
||||
|
||||
fn midi_outs_mut (&self) -> &mut Vec<Port<MidiOut>>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue