mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
transport -> clock
This commit is contained in:
parent
7f57465b3a
commit
7a4fa1692b
15 changed files with 37 additions and 36 deletions
|
|
@ -11,7 +11,7 @@ mod arranger_h;
|
|||
/// Root view for standalone `tek_arranger`
|
||||
pub struct ArrangerTui {
|
||||
jack: Arc<RwLock<JackConnection>>,
|
||||
pub clock: ClockModel,
|
||||
pub clock: Clock,
|
||||
pub phrases: PoolModel,
|
||||
pub tracks: Vec<ArrangerTrack>,
|
||||
pub scenes: Vec<ArrangerScene>,
|
||||
|
|
@ -69,7 +69,7 @@ impl ArrangerTui {
|
|||
}
|
||||
}
|
||||
from_jack!(|jack| ArrangerTui {
|
||||
let clock = ClockModel::from(jack);
|
||||
let clock = Clock::from(jack);
|
||||
let phrase = Arc::new(RwLock::new(MidiClip::new(
|
||||
"New", true, 4 * clock.timebase.ppq.get() as usize,
|
||||
None, Some(ItemColor::random().into())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
pub mod clock_tui; pub use self::clock_tui::*;
|
||||
pub mod microsecond; pub(crate) use self::microsecond::*;
|
||||
pub mod moment; pub(crate) use self::moment::*;
|
||||
pub mod perf; pub(crate) use self::perf::*;
|
||||
|
|
@ -10,13 +11,13 @@ pub mod timebase; pub(crate) use self::timebase::*;
|
|||
pub mod unit; pub(crate) use self::unit::*;
|
||||
|
||||
pub trait HasClock: Send + Sync {
|
||||
fn clock (&self) -> &ClockModel;
|
||||
fn clock (&self) -> &Clock;
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! has_clock {
|
||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||
impl $(<$($L),*$($T $(: $U)?),*>)? HasClock for $Struct $(<$($L),*$($T),*>)? {
|
||||
fn clock (&$self) -> &ClockModel { $cb }
|
||||
fn clock (&$self) -> &Clock { $cb }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +62,7 @@ impl<T: HasClock> Command<T> for ClockCommand {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ClockModel {
|
||||
pub struct Clock {
|
||||
/// JACK transport handle.
|
||||
pub transport: Arc<Transport>,
|
||||
/// Global temporal resolution (shared by [Moment] fields)
|
||||
|
|
@ -82,7 +83,7 @@ pub struct ClockModel {
|
|||
pub chunk: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
from!(|jack: &Arc<RwLock<JackConnection>>| ClockModel = {
|
||||
from!(|jack: &Arc<RwLock<JackConnection>>| Clock = {
|
||||
let jack = jack.read().unwrap();
|
||||
let chunk = jack.client().buffer_size();
|
||||
let transport = jack.client().transport();
|
||||
|
|
@ -100,9 +101,9 @@ from!(|jack: &Arc<RwLock<JackConnection>>| ClockModel = {
|
|||
}
|
||||
});
|
||||
|
||||
impl std::fmt::Debug for ClockModel {
|
||||
impl std::fmt::Debug for Clock {
|
||||
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
f.debug_struct("ClockModel")
|
||||
f.debug_struct("Clock")
|
||||
.field("timebase", &self.timebase)
|
||||
.field("chunk", &self.chunk)
|
||||
.field("quant", &self.quant)
|
||||
|
|
@ -114,7 +115,7 @@ impl std::fmt::Debug for ClockModel {
|
|||
}
|
||||
}
|
||||
|
||||
impl ClockModel {
|
||||
impl Clock {
|
||||
pub fn timebase (&self) -> &Arc<Timebase> {
|
||||
&self.timebase
|
||||
}
|
||||
|
|
@ -6,14 +6,14 @@ use KeyCode::{Enter, Left, Right, Char};
|
|||
/// Transport clock app.
|
||||
pub struct TransportTui {
|
||||
pub jack: Arc<RwLock<JackConnection>>,
|
||||
pub clock: ClockModel,
|
||||
pub clock: Clock,
|
||||
pub size: Measure<Tui>,
|
||||
pub cursor: (usize, usize),
|
||||
pub color: ItemPalette,
|
||||
}
|
||||
from_jack!(|jack|TransportTui Self {
|
||||
jack: jack.clone(),
|
||||
clock: ClockModel::from(jack),
|
||||
clock: Clock::from(jack),
|
||||
size: Measure::new(),
|
||||
cursor: (0, 0),
|
||||
color: ItemPalette::random(),
|
||||
|
|
@ -23,7 +23,7 @@ audio!(|self: TransportTui, client, scope|ClockAudio(self).process(client, scope
|
|||
handle!(<Tui>|self: TransportTui, from|TransportCommand::execute_with_state(self, from));
|
||||
render!(Tui: (self: TransportTui) => TransportView(&self.clock));
|
||||
|
||||
pub struct TransportView<'a>(pub &'a ClockModel);
|
||||
pub struct TransportView<'a>(pub &'a Clock);
|
||||
render!(Tui: (self: TransportView<'a>) => row!(
|
||||
BeatStats::new(self.0), " ",
|
||||
PlayPause(self.0.is_rolling()), " ",
|
||||
|
|
@ -48,7 +48,7 @@ impl std::fmt::Debug for TransportTui {
|
|||
|
||||
pub struct BeatStats { bpm: String, beat: String, time: String, }
|
||||
impl BeatStats {
|
||||
fn new (clock: &ClockModel) -> Self {
|
||||
fn new (clock: &Clock) -> Self {
|
||||
let (beat, time) = clock.started.read().unwrap().as_ref().map(|started|{
|
||||
let current_usec = clock.global.usec.get() - started.usec.get();
|
||||
(
|
||||
|
|
@ -65,7 +65,7 @@ render!(Tui: (self: BeatStats) => col!(
|
|||
|
||||
pub struct OutputStats { sample_rate: String, buffer_size: String, latency: String, }
|
||||
impl OutputStats {
|
||||
fn new (clock: &ClockModel) -> Self {
|
||||
fn new (clock: &Clock) -> Self {
|
||||
let rate = clock.timebase.sr.get();
|
||||
let chunk = clock.chunk.load(Relaxed);
|
||||
Self {
|
||||
|
|
@ -153,6 +153,7 @@ render!(Tui: (self: Groovebox) => {
|
|||
)
|
||||
)});
|
||||
|
||||
// TODO move this to sampler
|
||||
struct GrooveboxSamples<'a>(&'a Groovebox);
|
||||
render!(Tui: (self: GrooveboxSamples<'a>) => {
|
||||
let note_lo = self.0.editor.note_lo().load(Relaxed);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ pub(crate) use std::time::Duration;
|
|||
|
||||
pub mod arranger; pub use self::arranger::*;
|
||||
pub mod border; pub use self::border::*;
|
||||
pub mod clock; pub use self::clock::*;
|
||||
pub mod color; pub use self::color::*;
|
||||
pub mod command; pub use self::command::*;
|
||||
pub mod event; pub use self::event::*;
|
||||
|
|
@ -64,8 +65,6 @@ pub mod sequencer; pub use self::sequencer::*;
|
|||
pub mod status; pub use self::status::*;
|
||||
pub mod style; pub use self::style::*;
|
||||
pub mod theme; pub use self::theme::*;
|
||||
pub mod time; pub use self::time::*;
|
||||
pub mod transport; pub use self::transport::*;
|
||||
|
||||
pub use ::atomic_float;
|
||||
pub(crate) use atomic_float::*;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ pub trait HasPlayer {
|
|||
/// Contains state for playing a phrase
|
||||
pub struct MidiPlayer {
|
||||
/// State of clock and playhead
|
||||
pub(crate) clock: ClockModel,
|
||||
pub(crate) clock: Clock,
|
||||
/// Start time and phrase being played
|
||||
pub(crate) play_phrase: Option<(Moment, Option<Arc<RwLock<MidiClip>>>)>,
|
||||
/// Start time and next phrase
|
||||
|
|
@ -135,7 +135,7 @@ impl MidiPlayer {
|
|||
) -> Usually<Self> {
|
||||
let name = name.as_ref();
|
||||
Ok(Self {
|
||||
clock: ClockModel::from(jack),
|
||||
clock: Clock::from(jack),
|
||||
play_phrase: None,
|
||||
next_phrase: None,
|
||||
recording: false,
|
||||
|
|
@ -166,7 +166,7 @@ impl std::fmt::Debug for MidiPlayer {
|
|||
.finish()
|
||||
}
|
||||
}
|
||||
from!(|clock: &ClockModel| MidiPlayer = Self {
|
||||
from!(|clock: &Clock| MidiPlayer = Self {
|
||||
clock: clock.clone(),
|
||||
midi_ins: vec![],
|
||||
midi_outs: vec![],
|
||||
|
|
@ -180,7 +180,7 @@ from!(|clock: &ClockModel| MidiPlayer = Self {
|
|||
notes_in: RwLock::new([false;128]).into(),
|
||||
notes_out: RwLock::new([false;128]).into(),
|
||||
});
|
||||
from!(|state: (&ClockModel, &Arc<RwLock<MidiClip>>)|MidiPlayer = {
|
||||
from!(|state: (&Clock, &Arc<RwLock<MidiClip>>)|MidiPlayer = {
|
||||
let (clock, phrase) = state;
|
||||
let mut model = Self::from(clock);
|
||||
model.play_phrase = Some((Moment::zero(&clock.timebase), Some(phrase.clone())));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::*;
|
||||
use ClockCommand::{Play, Pause};
|
||||
use KeyCode::{Tab, Char};
|
||||
use SequencerCommand::*;
|
||||
use SequencerCommand as Cmd;
|
||||
use PhraseCommand::*;
|
||||
use PhrasePoolCommand::*;
|
||||
/// Root view for standalone `tek_sequencer`.
|
||||
|
|
@ -9,7 +9,7 @@ pub struct SequencerTui {
|
|||
_jack: Arc<RwLock<JackConnection>>,
|
||||
pub transport: bool,
|
||||
pub selectors: bool,
|
||||
pub clock: ClockModel,
|
||||
pub clock: Clock,
|
||||
pub phrases: PoolModel,
|
||||
pub player: MidiPlayer,
|
||||
pub editor: MidiEditor,
|
||||
|
|
@ -20,7 +20,7 @@ pub struct SequencerTui {
|
|||
pub perf: PerfModel,
|
||||
}
|
||||
from_jack!(|jack|SequencerTui {
|
||||
let clock = ClockModel::from(jack);
|
||||
let clock = Clock::from(jack);
|
||||
let phrase = Arc::new(RwLock::new(MidiClip::new(
|
||||
"New", true, 4 * clock.timebase.ppq.get() as usize,
|
||||
None, Some(ItemColor::random().into())
|
||||
|
|
@ -102,28 +102,28 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
|
|||
// TODO: k: toggle on-screen keyboard
|
||||
key_pat!(Ctrl-Char('k')) => { todo!("keyboard") },
|
||||
// Transport: Play/pause
|
||||
key_pat!(Char(' ')) => Clock(
|
||||
key_pat!(Char(' ')) => Cmd::Clock(
|
||||
if state.clock().is_stopped() { Play(None) } else { Pause(None) }
|
||||
),
|
||||
// Transport: Play from start or rewind to start
|
||||
key_pat!(Shift-Char(' ')) => Clock(
|
||||
key_pat!(Shift-Char(' ')) => Cmd::Clock(
|
||||
if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }
|
||||
),
|
||||
// u: undo
|
||||
key_pat!(Char('u')) => History(-1),
|
||||
key_pat!(Char('u')) => Cmd::History(-1),
|
||||
// Shift-U: redo
|
||||
key_pat!(Char('U')) => History( 1),
|
||||
key_pat!(Char('U')) => Cmd::History( 1),
|
||||
// Tab: Toggle visibility of phrase pool column
|
||||
key_pat!(Tab) => Pool(PoolCommand::Show(!state.phrases.visible)),
|
||||
key_pat!(Tab) => Cmd::Pool(PoolCommand::Show(!state.phrases.visible)),
|
||||
// q: Enqueue currently edited phrase
|
||||
key_pat!(Char('q')) => Enqueue(Some(state.phrases.phrase().clone())),
|
||||
key_pat!(Char('q')) => Cmd::Enqueue(Some(state.phrases.phrase().clone())),
|
||||
// 0: Enqueue phrase 0 (stop all)
|
||||
key_pat!(Char('0')) => Enqueue(Some(state.phrases.phrases()[0].clone())),
|
||||
key_pat!(Char('0')) => Cmd::Enqueue(Some(state.phrases.phrases()[0].clone())),
|
||||
// e: Toggle between editing currently playing or other phrase
|
||||
key_pat!(Char('e')) => if let Some((_, Some(playing))) = state.player.play_phrase() {
|
||||
let editing = state.editor.phrase().as_ref().map(|p|p.read().unwrap().clone());
|
||||
let selected = state.phrases.phrase().clone();
|
||||
Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
|
||||
Cmd::Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
|
||||
selected
|
||||
} else {
|
||||
playing.clone()
|
||||
|
|
@ -134,9 +134,9 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
|
|||
// For the rest, use the default keybindings of the components.
|
||||
// The ones defined above supersede them.
|
||||
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
|
||||
Editor(command)
|
||||
Cmd::Editor(command)
|
||||
} else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
|
||||
Pool(command)
|
||||
Cmd::Pool(command)
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ command!(|self: SequencerCommand, state: SequencerTui|match self {
|
|||
Self::Pool(cmd) => {
|
||||
let mut default = |cmd: PoolCommand|cmd
|
||||
.execute(&mut state.phrases)
|
||||
.map(|x|x.map(Pool));
|
||||
.map(|x|x.map(Cmd::Pool));
|
||||
match cmd {
|
||||
// autoselect: automatically load selected phrase in editor
|
||||
PoolCommand::Select(_) => {
|
||||
|
|
@ -163,12 +163,12 @@ command!(|self: SequencerCommand, state: SequencerTui|match self {
|
|||
}
|
||||
},
|
||||
Self::Editor(cmd) => {
|
||||
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Editor));
|
||||
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Cmd::Editor));
|
||||
match cmd {
|
||||
_ => default()?
|
||||
}
|
||||
},
|
||||
Self::Clock(cmd) => cmd.execute(state)?.map(Clock),
|
||||
Self::Clock(cmd) => cmd.execute(state)?.map(Cmd::Clock),
|
||||
Self::Enqueue(phrase) => {
|
||||
state.player.enqueue_next(phrase.as_ref());
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue