From 694aed6d9be9f1eace5d62eefe7e67444969bdfe Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 23 Oct 2024 00:33:01 +0300 Subject: [PATCH] make 'now' fields Arc --- crates/tek_core/src/lib.rs | 2 +- crates/tek_sequencer/src/sequencer.rs | 7 +++++-- crates/tek_sequencer/src/sequencer_tui.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/tek_core/src/lib.rs b/crates/tek_core/src/lib.rs index 370c6a0c..41744473 100644 --- a/crates/tek_core/src/lib.rs +++ b/crates/tek_core/src/lib.rs @@ -6,7 +6,7 @@ pub use clap; pub use std::sync::{Arc, Mutex, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard}; pub use std::collections::BTreeMap; pub use once_cell::sync::Lazy; -pub use std::sync::atomic::{Ordering, AtomicBool}; +pub use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize}; pub use std::rc::Rc; pub use std::cell::RefCell; pub use std::marker::PhantomData; diff --git a/crates/tek_sequencer/src/sequencer.rs b/crates/tek_sequencer/src/sequencer.rs index 3a235392..8fbf86fe 100644 --- a/crates/tek_sequencer/src/sequencer.rs +++ b/crates/tek_sequencer/src/sequencer.rs @@ -101,6 +101,8 @@ pub struct PhraseEditor { pub notes_in: Arc>, /// Notes currently held at output pub notes_out: Arc>, + /// Current position of global playhead + pub now: Arc, } /// Phrase player. pub struct PhrasePlayer { @@ -112,7 +114,7 @@ pub struct PhrasePlayer { /// Notes currently held at output pub notes_out: Arc>, /// Current point in playing phrase - pub now: usize, + pub now: Arc, /// Play input through output. pub monitoring: bool, /// Write input to sequence. @@ -234,6 +236,7 @@ impl PhraseEditor { focused: false, entered: false, mode: false, + now: Arc::new(0.into()), } } } @@ -310,7 +313,7 @@ impl PhrasePlayer { midi_out: None, midi_out_buf: vec![Vec::with_capacity(16);16384], reset: true, - now: 0, + now: Arc::new(0.into()), } } pub fn toggle_monitor (&mut self) { self.monitoring = !self.monitoring; } diff --git a/crates/tek_sequencer/src/sequencer_tui.rs b/crates/tek_sequencer/src/sequencer_tui.rs index e7198092..4dad360c 100644 --- a/crates/tek_sequencer/src/sequencer_tui.rs +++ b/crates/tek_sequencer/src/sequencer_tui.rs @@ -102,7 +102,7 @@ impl Content for PhraseEditor { |to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{ if let Some(_) = phrase { - let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length; + let now = self.now.load(Ordering::Relaxed); // TODO FIXME: self.now % phrase.read().unwrap().length; let ScaledAxis { start: first_beat, scale: time_zoom, clamp, .. } = time_axis; let clamp = clamp.expect("time_axis of sequencer expected to be clamped"); for x in 0..clamp/time_zoom {