mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
wip: refactor pt.21: api traits
This commit is contained in:
parent
b8708d6b2d
commit
029614631e
10 changed files with 626 additions and 490 deletions
|
|
@ -1,16 +1,42 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Transport {
|
||||
pub jack: Arc<RwLock<JackClient>>,
|
||||
/// JACK transport handle.
|
||||
pub transport: jack::Transport,
|
||||
/// Current sample rate, tempo, and PPQ.
|
||||
pub clock: Arc<Clock>,
|
||||
/// Enable metronome?
|
||||
pub metronome: bool,
|
||||
pub trait TransportModelApi: JackModelApi + ClockModelApi {
|
||||
fn transport (&self) -> &jack::Transport;
|
||||
fn metronome (&self) -> bool;
|
||||
}
|
||||
|
||||
impl Debug for Transport {
|
||||
impl JackModelApi for TransportModel {
|
||||
fn jack (&self) -> &Arc<RwLock<JackClient>> {
|
||||
&self.jack
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockModelApi for TransportModel {
|
||||
fn clock (&self) -> &Arc<Clock> {
|
||||
&self.clock
|
||||
}
|
||||
}
|
||||
|
||||
impl TransportModelApi for TransportModel {
|
||||
fn transport (&self) -> &jack::Transport {
|
||||
&self.transport
|
||||
}
|
||||
fn metronome (&self) -> bool {
|
||||
self.metronome
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TransportModel {
|
||||
jack: Arc<RwLock<JackClient>>,
|
||||
/// Current sample rate, tempo, and PPQ.
|
||||
clock: Arc<Clock>,
|
||||
/// JACK transport handle.
|
||||
transport: jack::Transport,
|
||||
/// Enable metronome?
|
||||
metronome: bool,
|
||||
}
|
||||
|
||||
impl Debug for TransportModel {
|
||||
fn fmt (&self, f: &mut Formatter<'_>) -> std::result::Result<(), Error> {
|
||||
f.debug_struct("transport")
|
||||
.field("jack", &self.jack)
|
||||
|
|
@ -21,7 +47,7 @@ impl Debug for Transport {
|
|||
}
|
||||
}
|
||||
|
||||
impl Transport {
|
||||
impl TransportModel {
|
||||
pub fn toggle_play (&mut self) -> Usually<()> {
|
||||
let playing = self.clock.playing.read().unwrap().expect("1st sample has not been processed yet");
|
||||
let playing = match playing {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue