wip: enqueue synced (!!!)

This commit is contained in:
🪞👃🪞 2024-10-26 19:12:26 +03:00
parent 2d1c901b8c
commit 89dcc2afe2
5 changed files with 26 additions and 15 deletions

View file

@ -115,12 +115,10 @@ pub struct PhrasePlayer<E: Engine> {
_engine: PhantomData<E>,
/// Global timebase
pub clock: Arc<TransportTime>,
/// Phrase being played
pub phrase: Option<Arc<RwLock<Phrase>>>,
/// Next phrase
pub next_phrase: Option<Arc<RwLock<Phrase>>>,
/// Current point in playing phrase
pub now: Arc<AtomicUsize>,
/// Start time and phrase being played
pub phrase: Option<(AtomicUsize, Option<Arc<RwLock<Phrase>>>)>,
/// Start time and next phrase
pub next_phrase: Option<(AtomicUsize, Option<Arc<RwLock<Phrase>>>)>,
/// Frames remaining until switch to next phrase
pub switch_at: Option<AtomicUsize>,
/// Play input through output.
@ -336,7 +334,6 @@ impl<E: Engine> PhrasePlayer<E> {
clock: clock.clone(),
phrase: None,
next_phrase: None,
now: Arc::new(0.into()),
switch_at: None,
notes_in: Arc::new(RwLock::new([false;128])),
notes_out: Arc::new(RwLock::new([false;128])),
@ -351,6 +348,15 @@ impl<E: Engine> PhrasePlayer<E> {
pub fn toggle_monitor (&mut self) { self.monitoring = !self.monitoring; }
pub fn toggle_record (&mut self) { self.recording = !self.recording; }
pub fn toggle_overdub (&mut self) { self.overdub = !self.overdub; }
pub fn enqueue_next (&mut self, start_at: usize, phrase: Option<&Arc<RwLock<Phrase>>>) {
self.next_phrase = Some((start_at.into(), phrase.map(|p|p.clone())));
self.reset = true;
}
pub fn frames_since_start (&self) -> Option<usize> {
self.phrase.as_ref()
.map(|(started,_)|started.load(Ordering::Relaxed))
.map(|started|started - self.clock.frame())
}
}
/// Displays and edits phrase length
pub struct PhraseLength<E: Engine> {