mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-28 21:06:56 +02:00
This commit is contained in:
parent
a4931d8e4f
commit
def7a1b210
17 changed files with 2209 additions and 1790 deletions
|
|
@ -20,63 +20,6 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
#[tek_proc::commands(ClockCommand = "clock")]
|
||||
impl Clock {
|
||||
#[command(SeekUsec = "usec")]
|
||||
fn seek_usec (&mut self, usec: f64) -> Perhaps<ClockCommand> {
|
||||
self.playhead.update_from_usec(usec);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SeekSample = "sample")]
|
||||
fn seek_sample (&mut self, sample: f64) -> Perhaps<ClockCommand> {
|
||||
self.playhead.update_from_sample(sample);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SeekPulse = "pulse")]
|
||||
fn seek_pulse (&mut self, pulse: f64) -> Perhaps<ClockCommand> {
|
||||
self.playhead.update_from_pulse(pulse);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SetBpm = "bpm")]
|
||||
fn set_bpm (&mut self, bpm: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetBpm { bpm: self.timebase().bpm.set(bpm) }))
|
||||
}
|
||||
|
||||
#[command(SetQuant = "quant")]
|
||||
fn set_quant (&mut self, quant: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetQuant { quant: self.quant.set(quant) }))
|
||||
}
|
||||
|
||||
#[command(SetSync = "sync")]
|
||||
fn set_sync (&mut self, sync: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetSync { sync: self.sync.set(sync) }))
|
||||
}
|
||||
|
||||
#[command(Play = "play")]
|
||||
fn play (&mut self, position: Option<u32>) -> Perhaps<ClockCommand> {
|
||||
self.play_from(position)?;
|
||||
Ok(None) /* TODO Some(Pause(previousPosition)) */
|
||||
}
|
||||
|
||||
#[command(Pause = "pause")]
|
||||
fn pause (&mut self, position: Option<u32>) -> Perhaps<ClockCommand> {
|
||||
self.pause_at(position)?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(TogglePlayback = "toggle")]
|
||||
fn toggle (&mut self, position: u32) -> Perhaps<ClockCommand> {
|
||||
Ok(if self.is_rolling() {
|
||||
self.pause_at(Some(position))?; None
|
||||
} else {
|
||||
self.play_from(Some(position))?; None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The source of time.
|
||||
///
|
||||
/// ```
|
||||
|
|
@ -84,23 +27,23 @@ impl Clock {
|
|||
/// ```
|
||||
#[derive(Clone, Default)] pub struct Clock {
|
||||
/// JACK transport handle.
|
||||
pub transport: Arc<Option<Transport>>,
|
||||
pub transport: Arc<Option<Transport>>,
|
||||
/// Global temporal resolution (shared by [Moment] fields)
|
||||
pub timebase: Arc<Timebase>,
|
||||
pub timebase: Arc<Timebase>,
|
||||
/// Current global sample and usec (monotonic from JACK clock)
|
||||
pub global: Arc<Moment>,
|
||||
pub global: Arc<Moment>,
|
||||
/// Global sample and usec at which playback started
|
||||
pub started: Arc<RwLock<Option<Moment>>>,
|
||||
pub started: Arc<RwLock<Option<Moment>>>,
|
||||
/// Playback offset (when playing not from start)
|
||||
pub offset: Arc<Moment>,
|
||||
pub offset: Arc<Moment>,
|
||||
/// Current playhead position
|
||||
pub playhead: Arc<Moment>,
|
||||
pub playhead: Arc<Moment>,
|
||||
/// Note quantization factor
|
||||
pub quant: Arc<Quantize>,
|
||||
pub quant: Arc<Quantize>,
|
||||
/// Launch quantization factor
|
||||
pub sync: Arc<LaunchSync>,
|
||||
pub sync: Arc<LaunchSync>,
|
||||
/// Size of buffer in samples
|
||||
pub chunk: Arc<AtomicUsize>,
|
||||
pub chunk: Arc<AtomicUsize>,
|
||||
// Cache of formatted strings
|
||||
pub view_cache: Arc<RwLock<ClockView>>,
|
||||
/// For syncing the clock to an external source
|
||||
|
|
@ -111,10 +54,10 @@ impl Clock {
|
|||
#[cfg(feature = "port")] pub click_out: Arc<RwLock<Option<AudioOutput>>>,
|
||||
}
|
||||
|
||||
impl <T: AsRef<Clock>+AsMut<Clock>> HasClock for T {}
|
||||
impl<T: AsRef<Clock> + AsMut<Clock>> HasClock for T {}
|
||||
|
||||
pub trait HasClock: AsRef<Clock> + AsMut<Clock> {
|
||||
fn clock (&self) -> &Clock {
|
||||
fn clock (&self) -> &Clock {
|
||||
self.as_ref()
|
||||
}
|
||||
fn clock_mut (&mut self) -> &mut Clock {
|
||||
|
|
@ -122,12 +65,87 @@ pub trait HasClock: AsRef<Clock> + AsMut<Clock> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: HasClock> Act<T> for ClockCommand {
|
||||
fn act (&self, state: &mut T) -> Perhaps<Self> {
|
||||
self.act(state.clock_mut()) // awesome
|
||||
impl<T: HasClock
|
||||
+ for<'a> Namespace<'a, u32>
|
||||
+ for<'a> Namespace<'a, f64>
|
||||
+ for<'a> Namespace<'a, Option<u32>>
|
||||
> ClockController for T {}
|
||||
|
||||
#[tek_proc::commands(ClockCommand = "clock")]
|
||||
pub trait ClockController: HasClock
|
||||
+ for<'a> Namespace<'a, u32>
|
||||
+ for<'a> Namespace<'a, f64>
|
||||
+ for<'a> Namespace<'a, Option<u32>>
|
||||
{
|
||||
#[command(SeekUsec = "usec")]
|
||||
fn seek_usec (&mut self, usec: f64) -> Perhaps<ClockCommand> {
|
||||
self.clock().playhead.update_from_usec(usec);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SeekSample = "sample")]
|
||||
fn seek_sample (&mut self, sample: f64) -> Perhaps<ClockCommand> {
|
||||
self.clock().playhead.update_from_sample(sample);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SeekPulse = "pulse")]
|
||||
fn seek_pulse (&mut self, pulse: f64) -> Perhaps<ClockCommand> {
|
||||
self.clock().playhead.update_from_pulse(pulse);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(SetBpm = "bpm")]
|
||||
fn set_bpm (&mut self, bpm: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetBpm {
|
||||
bpm: self.clock().timebase().bpm.set(bpm)
|
||||
}))
|
||||
}
|
||||
|
||||
#[command(SetQuant = "quant")]
|
||||
fn set_quant (&mut self, quant: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetQuant {
|
||||
quant: self.clock().quant.set(quant)
|
||||
}))
|
||||
}
|
||||
|
||||
#[command(SetSync = "sync")]
|
||||
fn set_sync (&mut self, sync: f64) -> Perhaps<ClockCommand> {
|
||||
Ok(Some(ClockCommand::SetSync {
|
||||
sync: self.clock().sync.set(sync)
|
||||
}))
|
||||
}
|
||||
|
||||
#[command(Play = "play")]
|
||||
fn play (&mut self, position: Option<u32>) -> Perhaps<ClockCommand> {
|
||||
self.clock().play_from(position)?;
|
||||
Ok(None) /* TODO Some(Pause(previousPosition)) */
|
||||
}
|
||||
|
||||
#[command(Pause = "pause")]
|
||||
fn pause (&mut self, position: Option<u32>) -> Perhaps<ClockCommand> {
|
||||
self.clock().pause_at(position)?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[command(TogglePlayback = "toggle")]
|
||||
fn toggle (&mut self, position: u32) -> Perhaps<ClockCommand> {
|
||||
Ok(if self.clock().is_rolling() {
|
||||
self.clock().pause_at(Some(position))?;
|
||||
None
|
||||
} else {
|
||||
self.clock().play_from(Some(position))?;
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//impl<T: HasClock> Act<T> for ClockCommand {
|
||||
//fn act (&self, state: &mut T) -> Perhaps<Self> {
|
||||
//self.act(state.clock_mut()) // awesome
|
||||
//}
|
||||
//}
|
||||
|
||||
/// Quantization setting for launching clips
|
||||
///
|
||||
/// ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue