PhrasePlayerModel -> MidiPlayer

This commit is contained in:
🪞👃🪞 2024-12-27 08:35:29 +01:00
parent d7c47c2561
commit 58bb25eb40
7 changed files with 16 additions and 34 deletions

View file

@ -59,7 +59,7 @@ pub const MIDI_NOTE_NAMES: [&str; 128] = [
pub trait MidiPlayerApi: MidiRecordApi + MidiPlaybackApi + Send + Sync {}
impl MidiPlayerApi for PhrasePlayerModel {}
impl MidiPlayerApi for MidiPlayer {}
pub trait HasPlayer {
fn player (&self) -> &impl MidiPlayerApi;
@ -76,7 +76,7 @@ pub trait HasPlayer {
}
/// Contains state for playing a phrase
pub struct PhrasePlayerModel {
pub struct MidiPlayer {
/// State of clock and playhead
pub(crate) clock: ClockModel,
/// Start time and phrase being played
@ -102,16 +102,16 @@ pub struct PhrasePlayerModel {
/// MIDI output buffer
pub note_buf: Vec<u8>,
}
impl std::fmt::Debug for PhrasePlayerModel {
impl std::fmt::Debug for MidiPlayer {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
f.debug_struct("PhrasePlayerModel")
f.debug_struct("MidiPlayer")
.field("clock", &self.clock)
.field("play_phrase", &self.play_phrase)
.field("next_phrase", &self.next_phrase)
.finish()
}
}
from!(|clock: &ClockModel| PhrasePlayerModel = Self {
from!(|clock: &ClockModel| MidiPlayer = Self {
clock: clock.clone(),
midi_ins: vec![],
midi_outs: vec![],
@ -125,15 +125,15 @@ from!(|clock: &ClockModel| PhrasePlayerModel = Self {
notes_in: RwLock::new([false;128]).into(),
notes_out: RwLock::new([false;128]).into(),
});
from!(|state: (&ClockModel, &Arc<RwLock<Phrase>>)|PhrasePlayerModel = {
from!(|state: (&ClockModel, &Arc<RwLock<Phrase>>)|MidiPlayer = {
let (clock, phrase) = state;
let mut model = Self::from(clock);
model.play_phrase = Some((Moment::zero(&clock.timebase), Some(phrase.clone())));
model
});
has_clock!(|self:PhrasePlayerModel|&self.clock);
has_clock!(|self: MidiPlayer|&self.clock);
impl HasMidiIns for PhrasePlayerModel {
impl HasMidiIns for MidiPlayer {
fn midi_ins (&self) -> &Vec<Port<MidiIn>> {
&self.midi_ins
}
@ -142,7 +142,7 @@ impl HasMidiIns for PhrasePlayerModel {
}
}
impl HasMidiOuts for PhrasePlayerModel {
impl HasMidiOuts for MidiPlayer {
fn midi_outs (&self) -> &Vec<Port<MidiOut>> {
&self.midi_outs
}
@ -191,7 +191,7 @@ impl<'a, T: MidiPlayerApi> Audio for PlayerAudio<'a, T> {
}
}
impl MidiRecordApi for PhrasePlayerModel {
impl MidiRecordApi for MidiPlayer {
fn recording (&self) -> bool {
self.recording
}
@ -215,13 +215,13 @@ impl MidiRecordApi for PhrasePlayerModel {
}
}
impl MidiPlaybackApi for PhrasePlayerModel {
impl MidiPlaybackApi for MidiPlayer {
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
&self.notes_in
}
}
impl HasPlayPhrase for PhrasePlayerModel {
impl HasPlayPhrase for MidiPlayer {
fn reset (&self) -> bool {
self.reset
}

View file

@ -9,7 +9,7 @@ pub struct SequencerTui {
_jack: Arc<RwLock<JackClient>>,
pub(crate) clock: ClockModel,
pub(crate) phrases: PoolModel,
pub(crate) player: PhrasePlayerModel,
pub(crate) player: MidiPlayer,
pub(crate) editor: PhraseEditorModel,
pub(crate) size: Measure<Tui>,
pub(crate) status: bool,
@ -27,7 +27,7 @@ from_jack!(|jack|SequencerTui {
_jack: jack.clone(),
phrases: PoolModel::from(&phrase),
editor: PhraseEditorModel::from(&phrase),
player: PhrasePlayerModel::from((&clock, &phrase)),
player: MidiPlayer::from((&clock, &phrase)),
size: Measure::new(),
midi_buf: vec![vec![];65536],
note_buf: vec![],

View file

@ -1,5 +1,4 @@
use crate::*;
/// Display mode of arranger
#[derive(Clone, PartialEq)]
pub enum ArrangerMode {
@ -9,7 +8,6 @@ pub enum ArrangerMode {
H,
}
render!(<Tui>|self: ArrangerMode|{});
/// Arranger display mode can be cycled
impl ArrangerMode {
/// Cycle arranger display mode
@ -23,7 +21,6 @@ impl ArrangerMode {
}
}
}
fn any_size <E: Engine> (_: E::Size) -> Perhaps<E::Size>{
Ok(Some([0.into(),0.into()].into()))
}

View file

@ -1,5 +1,4 @@
use crate::*;
impl ArrangerTui {
pub fn scene_add (&mut self, name: Option<&str>, color: Option<ItemPalette>)
-> Usually<&mut ArrangerScene>
@ -27,7 +26,6 @@ impl ArrangerTui {
self.selected.scene().map(|s|self.scenes.get_mut(s)).flatten()
}
}
#[derive(Default, Debug, Clone)] pub struct ArrangerScene {
/// Name of scene
pub(crate) name: Arc<RwLock<String>>,
@ -36,7 +34,6 @@ impl ArrangerTui {
/// Identifying color of scene
pub(crate) color: ItemPalette,
}
impl ArrangerScene {
pub fn name (&self) -> &Arc<RwLock<String>> {
&self.name

View file

@ -1,5 +1,4 @@
use crate::*;
#[derive(PartialEq, Clone, Copy, Debug)]
/// Represents the current user selection in the arranger
pub enum ArrangerSelection {
@ -12,7 +11,6 @@ pub enum ArrangerSelection {
/// A clip (track × scene) is selected.
Clip(usize, usize),
}
/// Focus identification methods
impl ArrangerSelection {
pub fn description <E: Engine> (

View file

@ -1,5 +1,4 @@
use crate::*;
impl ArrangerTui {
pub fn track_next_name (&self) -> String {
format!("T{}", self.tracks.len() + 1)
@ -12,7 +11,7 @@ impl ArrangerTui {
width: name.len() + 2,
name: Arc::new(name.into()),
color: color.unwrap_or_else(||ItemPalette::random()),
player: PhrasePlayerModel::from(&self.clock),
player: MidiPlayer::from(&self.clock),
};
self.tracks.push(track);
let index = self.tracks.len() - 1;
@ -25,7 +24,6 @@ impl ArrangerTui {
}
}
}
#[derive(Debug)] pub struct ArrangerTrack {
/// Name of track
pub(crate) name: Arc<RwLock<String>>,
@ -34,12 +32,10 @@ impl ArrangerTui {
/// Identifying color of track
pub(crate) color: ItemPalette,
/// MIDI player state
pub(crate) player: PhrasePlayerModel,
pub(crate) player: MidiPlayer,
}
has_clock!(|self:ArrangerTrack|self.player.clock());
has_player!(|self:ArrangerTrack|self.player);
impl ArrangerTrack {
pub fn widths (tracks: &[Self]) -> Vec<(usize, usize)> {
let mut widths = vec![];
@ -91,7 +87,6 @@ impl ArrangerTrack {
}
}
}
/// Hosts the JACK callback for a collection of tracks
pub struct TracksAudio<'a>(
// Track collection
@ -101,7 +96,6 @@ pub struct TracksAudio<'a>(
/// Note chunk buffer
pub &'a mut Vec<Vec<Vec<u8>>>,
);
impl<'a> Audio for TracksAudio<'a> {
#[inline] fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
let model = &mut self.0;

View file

@ -1,14 +1,11 @@
use crate::*;
mod v_clips; pub(crate) use self::v_clips::*;
mod v_cursor; pub(crate) use self::v_cursor::*;
mod v_head; pub(crate) use self::v_head::*;
mod v_io; pub(crate) use self::v_io::*;
mod v_sep; pub(crate) use self::v_sep::*;
const HEADER_H: u16 = 5;
const SCENES_W_OFFSET: u16 = 3;
impl ArrangerTui {
pub fn render_mode_v (state: &ArrangerTui, factor: usize) -> impl Render<Tui> + use<'_> {
lay!([
@ -24,4 +21,3 @@ impl ArrangerTui {
])
}
}