mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
MidiPlayer -> Sequencer; connect sequencer to sampler in groovebox mode
This commit is contained in:
parent
c5586c3a35
commit
5fab1af138
10 changed files with 120 additions and 81 deletions
|
|
@ -2,7 +2,7 @@ use crate::*;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum Device {
|
||||
#[cfg(feature = "sequencer")] Sequencer(MidiPlayer),
|
||||
#[cfg(feature = "sequencer")] Sequencer(Sequencer),
|
||||
#[cfg(feature = "sampler")] Sampler(Sampler),
|
||||
#[cfg(feature = "lv2")] Lv2(Lv2), // TODO
|
||||
#[cfg(feature = "vst2")] Vst2, // TODO
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ mod seq_view; pub use self::seq_view::*;
|
|||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_midi_play () {
|
||||
let player = MidiPlayer::default();
|
||||
println!("{player:?}");
|
||||
let sequencer = Sequencer::default();
|
||||
println!("{sequencer:?}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
//! MIDI player
|
||||
//! MIDI sequencer
|
||||
use crate::*;
|
||||
use tek_engine::jack::*;
|
||||
|
||||
pub trait HasPlayer {
|
||||
fn player (&self) -> &impl MidiPlayerApi;
|
||||
fn player_mut (&mut self) -> &mut impl MidiPlayerApi;
|
||||
pub trait HasSequencer {
|
||||
fn sequencer (&self) -> &impl MidiPlayerApi;
|
||||
fn sequencer_mut (&mut self) -> &mut impl MidiPlayerApi;
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! has_player {
|
||||
#[macro_export] macro_rules! has_sequencer {
|
||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||
impl $(<$($L),*$($T $(: $U)?),*>)? HasPlayer for $Struct $(<$($L),*$($T),*>)? {
|
||||
fn player (&$self) -> &impl MidiPlayerApi { &$cb }
|
||||
fn player_mut (&mut $self) -> &mut impl MidiPlayerApi { &mut$cb }
|
||||
impl $(<$($L),*$($T $(: $U)?),*>)? HasSequencer for $Struct $(<$($L),*$($T),*>)? {
|
||||
fn sequencer (&$self) -> &impl MidiPlayerApi { &$cb }
|
||||
fn sequencer_mut (&mut $self) -> &mut impl MidiPlayerApi { &mut$cb }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MidiPlayerApi: MidiRecordApi + MidiPlaybackApi + Send + Sync {}
|
||||
|
||||
impl MidiPlayerApi for MidiPlayer {}
|
||||
impl MidiPlayerApi for Sequencer {}
|
||||
|
||||
/// Contains state for playing a clip
|
||||
pub struct MidiPlayer {
|
||||
pub struct Sequencer {
|
||||
/// State of clock and playhead
|
||||
pub clock: Clock,
|
||||
/// Start time and clip being played
|
||||
|
|
@ -48,7 +48,7 @@ pub struct MidiPlayer {
|
|||
pub note_buf: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Default for MidiPlayer {
|
||||
impl Default for Sequencer {
|
||||
fn default () -> Self {
|
||||
Self {
|
||||
play_clip: None,
|
||||
|
|
@ -69,7 +69,7 @@ impl Default for MidiPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
impl MidiPlayer {
|
||||
impl Sequencer {
|
||||
pub fn new (
|
||||
name: impl AsRef<str>,
|
||||
jack: &Jack,
|
||||
|
|
@ -97,9 +97,9 @@ impl MidiPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MidiPlayer {
|
||||
impl std::fmt::Debug for Sequencer {
|
||||
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
f.debug_struct("MidiPlayer")
|
||||
f.debug_struct("Sequencer")
|
||||
.field("clock", &self.clock)
|
||||
.field("play_clip", &self.play_clip)
|
||||
.field("next_clip", &self.next_clip)
|
||||
|
|
@ -107,20 +107,20 @@ impl std::fmt::Debug for MidiPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
has_clock!(|self: MidiPlayer|self.clock);
|
||||
has_clock!(|self: Sequencer|self.clock);
|
||||
|
||||
impl HasMidiIns for MidiPlayer {
|
||||
impl HasMidiIns for Sequencer {
|
||||
fn midi_ins (&self) -> &Vec<JackMidiIn> { &self.midi_ins }
|
||||
fn midi_ins_mut (&mut self) -> &mut Vec<JackMidiIn> { &mut self.midi_ins }
|
||||
}
|
||||
|
||||
impl HasMidiOuts for MidiPlayer {
|
||||
impl HasMidiOuts for Sequencer {
|
||||
fn midi_outs (&self) -> &Vec<JackMidiOut> { &self.midi_outs }
|
||||
fn midi_outs_mut (&mut self) -> &mut Vec<JackMidiOut> { &mut self.midi_outs }
|
||||
fn midi_note (&mut self) -> &mut Vec<u8> { &mut self.note_buf }
|
||||
}
|
||||
|
||||
/// Hosts the JACK callback for a single MIDI player
|
||||
/// Hosts the JACK callback for a single MIDI sequencer
|
||||
pub struct PlayerAudio<'a, T: MidiPlayerApi>(
|
||||
/// Player
|
||||
pub &'a mut T,
|
||||
|
|
@ -130,7 +130,7 @@ pub struct PlayerAudio<'a, T: MidiPlayerApi>(
|
|||
pub &'a mut Vec<Vec<Vec<u8>>>,
|
||||
);
|
||||
|
||||
/// JACK process callback for a sequencer's clip player/recorder.
|
||||
/// JACK process callback for a sequencer's clip sequencer/recorder.
|
||||
impl<T: MidiPlayerApi> Audio for PlayerAudio<'_, T> {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
let model = &mut self.0;
|
||||
|
|
@ -157,7 +157,7 @@ impl<T: MidiPlayerApi> Audio for PlayerAudio<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl MidiRecordApi for MidiPlayer {
|
||||
impl MidiRecordApi for Sequencer {
|
||||
fn recording (&self) -> bool {
|
||||
self.recording
|
||||
}
|
||||
|
|
@ -181,13 +181,13 @@ impl MidiRecordApi for MidiPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
impl MidiPlaybackApi for MidiPlayer {
|
||||
impl MidiPlaybackApi for Sequencer {
|
||||
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||
&self.notes_out
|
||||
}
|
||||
}
|
||||
|
||||
impl HasPlayClip for MidiPlayer {
|
||||
impl HasPlayClip for Sequencer {
|
||||
fn reset (&self) -> bool {
|
||||
self.reset
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue