mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
refactor midi player api
This commit is contained in:
parent
a26a1f2967
commit
71e19c9800
11 changed files with 159 additions and 183 deletions
|
|
@ -129,22 +129,6 @@ impl ClockModel {
|
||||||
pub fn is_rolling (&self) -> bool {
|
pub fn is_rolling (&self) -> bool {
|
||||||
*self.playing.read().unwrap() == Some(TransportState::Rolling)
|
*self.playing.read().unwrap() == Some(TransportState::Rolling)
|
||||||
}
|
}
|
||||||
//fn toggle_play (&self) -> Usually<()> {
|
|
||||||
//let playing = self.playing.read().unwrap().expect("1st sample has not been processed yet");
|
|
||||||
//let playing = match playing {
|
|
||||||
//TransportState::Stopped => {
|
|
||||||
//self.transport.start()?;
|
|
||||||
//Some(TransportState::Starting)
|
|
||||||
//},
|
|
||||||
//_ => {
|
|
||||||
//self.transport.stop()?;
|
|
||||||
//self.transport.locate(0)?;
|
|
||||||
//Some(TransportState::Stopped)
|
|
||||||
//},
|
|
||||||
//};
|
|
||||||
//*self.playing.write().unwrap() = playing;
|
|
||||||
//Ok(())
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hosts the JACK callback for updating the temporal pointer and playback status.
|
/// Hosts the JACK callback for updating the temporal pointer and playback status.
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,20 @@ use crate::*;
|
||||||
pub trait JackApi {
|
pub trait JackApi {
|
||||||
fn jack (&self) -> &Arc<RwLock<JackClient>>;
|
fn jack (&self) -> &Arc<RwLock<JackClient>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait HasMidiIns {
|
||||||
|
fn midi_ins (&self) -> &Vec<Port<MidiIn>>;
|
||||||
|
fn midi_ins_mut (&mut self) -> &mut Vec<Port<MidiIn>>;
|
||||||
|
fn has_midi_ins (&self) -> bool {
|
||||||
|
self.midi_ins().len() > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait HasMidiOuts {
|
||||||
|
fn midi_outs (&self) -> &Vec<Port<MidiOut>>;
|
||||||
|
fn midi_outs_mut (&mut self) -> &mut Vec<Port<MidiOut>>;
|
||||||
|
fn midi_note (&mut self) -> &mut Vec<u8>;
|
||||||
|
fn has_midi_outs (&self) -> bool {
|
||||||
|
self.midi_outs().len() > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,19 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub trait HasPlayer: JackApi {
|
pub trait HasPlayer {
|
||||||
fn player (&self) -> &impl MidiPlayerApi;
|
fn player (&self) -> &impl MidiPlayerApi;
|
||||||
fn player_mut (&mut self) -> &mut impl MidiPlayerApi;
|
fn player_mut (&mut self) -> &mut impl MidiPlayerApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MidiPlayerApi: MidiInputApi + MidiOutputApi + Send + Sync {}
|
pub trait MidiPlayerApi: MidiRecordApi + MidiPlaybackApi + Send + Sync {}
|
||||||
|
|
||||||
pub trait HasPhrase: HasClock {
|
pub trait HasPlayPhrase: HasClock {
|
||||||
fn reset (&self) -> bool;
|
fn reset (&self) -> bool;
|
||||||
fn reset_mut (&mut self) -> &mut bool;
|
fn reset_mut (&mut self) -> &mut bool;
|
||||||
|
fn play_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
||||||
fn play_phrase (&self)
|
fn play_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
||||||
-> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
fn next_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
||||||
fn play_phrase_mut (&mut self)
|
fn next_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
||||||
-> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
|
||||||
|
|
||||||
fn next_phrase (&self)
|
|
||||||
-> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
|
||||||
fn next_phrase_mut (&mut self)
|
|
||||||
-> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)>;
|
|
||||||
fn enqueue_next (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
|
||||||
let start = self.clock().next_launch_pulse() as f64;
|
|
||||||
let instant = Instant::from_pulse(&self.clock().timebase(), start);
|
|
||||||
let phrase = phrase.map(|p|p.clone());
|
|
||||||
*self.next_phrase_mut() = Some((instant, phrase));
|
|
||||||
*self.reset_mut() = true;
|
|
||||||
}
|
|
||||||
fn pulses_since_start (&self) -> Option<f64> {
|
fn pulses_since_start (&self) -> Option<f64> {
|
||||||
if let Some((started, Some(_))) = self.play_phrase().as_ref() {
|
if let Some((started, Some(_))) = self.play_phrase().as_ref() {
|
||||||
Some(self.clock().current.pulse.get() - started.pulse.get())
|
Some(self.clock().current.pulse.get() - started.pulse.get())
|
||||||
|
|
@ -34,39 +21,24 @@ pub trait HasPhrase: HasClock {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn enqueue_next (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||||
|
let start = self.clock().next_launch_pulse() as f64;
|
||||||
|
let instant = Instant::from_pulse(&self.clock().timebase(), start);
|
||||||
|
let phrase = phrase.map(|p|p.clone());
|
||||||
|
*self.next_phrase_mut() = Some((instant, phrase));
|
||||||
|
*self.reset_mut() = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MidiInputApi: HasPhrase {
|
pub trait MidiRecordApi: HasClock + HasPlayPhrase + HasMidiIns {
|
||||||
fn midi_ins (&self) -> &Vec<Port<MidiIn>>;
|
fn notes_in (&self) -> &Arc<RwLock<[bool;128]>>;
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<Port<MidiIn>>;
|
|
||||||
fn has_midi_ins (&self) -> bool {
|
|
||||||
self.midi_ins().len() > 0
|
|
||||||
}
|
|
||||||
fn recording (&self) -> bool;
|
fn recording (&self) -> bool;
|
||||||
fn recording_mut (&mut self) -> &mut bool;
|
fn recording_mut (&mut self) -> &mut bool;
|
||||||
fn toggle_record (&mut self) {
|
fn toggle_record (&mut self) {
|
||||||
*self.recording_mut() = !self.recording();
|
*self.recording_mut() = !self.recording();
|
||||||
}
|
}
|
||||||
|
fn record (&mut self, scope: &ProcessScope, midi_buf: &mut Vec<Vec<Vec<u8>>>) {
|
||||||
fn monitoring (&self) -> bool;
|
|
||||||
fn monitoring_mut (&mut self) -> &mut bool;
|
|
||||||
fn toggle_monitor (&mut self) {
|
|
||||||
*self.monitoring_mut() = !self.monitoring();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn overdub (&self) -> bool;
|
|
||||||
fn overdub_mut (&mut self) -> &mut bool;
|
|
||||||
fn toggle_overdub (&mut self) {
|
|
||||||
*self.overdub_mut() = !self.overdub();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn notes_in (&self) -> &Arc<RwLock<[bool;128]>>;
|
|
||||||
|
|
||||||
fn record (
|
|
||||||
&mut self,
|
|
||||||
scope: &ProcessScope,
|
|
||||||
midi_buf: &mut Vec<Vec<Vec<u8>>>,
|
|
||||||
) {
|
|
||||||
let sample0 = scope.last_frame_time() as usize;
|
let sample0 = scope.last_frame_time() as usize;
|
||||||
// For highlighting keys and note repeat
|
// For highlighting keys and note repeat
|
||||||
let notes_in = self.notes_in().clone();
|
let notes_in = self.notes_in().clone();
|
||||||
|
|
@ -107,11 +79,12 @@ pub trait MidiInputApi: HasPhrase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn monitor (
|
fn monitoring (&self) -> bool;
|
||||||
&mut self,
|
fn monitoring_mut (&mut self) -> &mut bool;
|
||||||
scope: &ProcessScope,
|
fn toggle_monitor (&mut self) {
|
||||||
midi_buf: &mut Vec<Vec<Vec<u8>>>,
|
*self.monitoring_mut() = !self.monitoring();
|
||||||
) {
|
}
|
||||||
|
fn monitor (&mut self, scope: &ProcessScope, midi_buf: &mut Vec<Vec<Vec<u8>>>) {
|
||||||
// For highlighting keys and note repeat
|
// For highlighting keys and note repeat
|
||||||
let notes_in = self.notes_in().clone();
|
let notes_in = self.notes_in().clone();
|
||||||
for input in self.midi_ins_mut().iter() {
|
for input in self.midi_ins_mut().iter() {
|
||||||
|
|
@ -124,42 +97,33 @@ pub trait MidiInputApi: HasPhrase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn overdub (&self) -> bool;
|
||||||
|
fn overdub_mut (&mut self) -> &mut bool;
|
||||||
|
fn toggle_overdub (&mut self) {
|
||||||
|
*self.overdub_mut() = !self.overdub();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MidiOutputApi: HasPhrase {
|
pub trait MidiPlaybackApi: HasPlayPhrase + HasClock + HasMidiOuts {
|
||||||
fn midi_outs (&self) -> &Vec<Port<MidiOut>>;
|
|
||||||
|
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<Port<MidiOut>>;
|
|
||||||
|
|
||||||
fn midi_note (&mut self) -> &mut Vec<u8>;
|
|
||||||
|
|
||||||
fn notes_out (&self) -> &Arc<RwLock<[bool;128]>>;
|
fn notes_out (&self) -> &Arc<RwLock<[bool;128]>>;
|
||||||
|
|
||||||
fn has_midi_outs (&self) -> bool {
|
|
||||||
self.midi_outs().len() > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear the section of the output buffer that we will be using,
|
/// Clear the section of the output buffer that we will be using,
|
||||||
/// emitting "all notes off" at start of buffer if requested.
|
/// emitting "all notes off" at start of buffer if requested.
|
||||||
fn clear (
|
fn clear (
|
||||||
&mut self,
|
&mut self, scope: &ProcessScope, out_buf: &mut Vec<Vec<Vec<u8>>>, reset: bool
|
||||||
scope: &ProcessScope,
|
|
||||||
midi_buf: &mut Vec<Vec<Vec<u8>>>,
|
|
||||||
reset: bool
|
|
||||||
) {
|
) {
|
||||||
for frame in &mut midi_buf[0..scope.n_frames() as usize] {
|
for frame in &mut out_buf[0..scope.n_frames() as usize] {
|
||||||
frame.clear();
|
frame.clear();
|
||||||
}
|
}
|
||||||
if reset {
|
if reset {
|
||||||
all_notes_off(midi_buf);
|
all_notes_off(out_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Output notes from phrase to MIDI output ports.
|
||||||
fn play (
|
fn play (
|
||||||
&mut self,
|
&mut self, scope: &ProcessScope, note_buf: &mut Vec<u8>, out_buf: &mut Vec<Vec<Vec<u8>>>
|
||||||
scope: &ProcessScope,
|
|
||||||
note_buffer: &mut Vec<u8>,
|
|
||||||
output_buffer: &mut Vec<Vec<Vec<u8>>>
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut next = false;
|
let mut next = false;
|
||||||
// Write MIDI events from currently playing phrase (if any) to MIDI output buffer
|
// Write MIDI events from currently playing phrase (if any) to MIDI output buffer
|
||||||
|
|
@ -207,15 +171,15 @@ pub trait MidiOutputApi: HasPhrase {
|
||||||
// Output each MIDI event from phrase at appropriate frames of output buffer:
|
// Output each MIDI event from phrase at appropriate frames of output buffer:
|
||||||
for message in phrase.notes[pulse].iter() {
|
for message in phrase.notes[pulse].iter() {
|
||||||
// Clear output buffer for this MIDI event.
|
// Clear output buffer for this MIDI event.
|
||||||
note_buffer.clear();
|
note_buf.clear();
|
||||||
// TODO: support MIDI channels other than CH1.
|
// TODO: support MIDI channels other than CH1.
|
||||||
let channel = 0.into();
|
let channel = 0.into();
|
||||||
// Serialize MIDI event into message buffer.
|
// Serialize MIDI event into message buffer.
|
||||||
LiveEvent::Midi { channel, message: *message }
|
LiveEvent::Midi { channel, message: *message }
|
||||||
.write(note_buffer)
|
.write(note_buf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Append serialized message to output buffer.
|
// Append serialized message to output buffer.
|
||||||
output_buffer[sample].push(note_buffer.clone());
|
out_buf[sample].push(note_buf.clone());
|
||||||
// Update the list of currently held notes.
|
// Update the list of currently held notes.
|
||||||
update_keys(&mut*notes, &message);
|
update_keys(&mut*notes, &message);
|
||||||
}
|
}
|
||||||
|
|
@ -227,11 +191,9 @@ pub trait MidiOutputApi: HasPhrase {
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle switchover from current to next playing phrase.
|
||||||
fn switchover (
|
fn switchover (
|
||||||
&mut self,
|
&mut self, scope: &ProcessScope, note_buf: &mut Vec<u8>, out_buf: &mut Vec<Vec<Vec<u8>>>
|
||||||
scope: &ProcessScope,
|
|
||||||
note_buffer: &mut Vec<u8>,
|
|
||||||
output_buffer: &mut Vec<Vec<Vec<u8>>>
|
|
||||||
) {
|
) {
|
||||||
if self.clock().is_rolling() {
|
if self.clock().is_rolling() {
|
||||||
let sample0 = scope.last_frame_time() as usize;
|
let sample0 = scope.last_frame_time() as usize;
|
||||||
|
|
@ -251,19 +213,22 @@ pub trait MidiOutputApi: HasPhrase {
|
||||||
}
|
}
|
||||||
// TODO fill in remaining ticks of chunk from next phrase.
|
// TODO fill in remaining ticks of chunk from next phrase.
|
||||||
// ?? just call self.play(scope) again, since enqueuement is off ???
|
// ?? just call self.play(scope) again, since enqueuement is off ???
|
||||||
self.play(scope, note_buffer, output_buffer);
|
self.play(scope, note_buf, out_buf);
|
||||||
// ?? or must it be with modified scope ??
|
// ?? or must it be with modified scope ??
|
||||||
// likely not because start time etc
|
// likely not because start time etc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write (&mut self, scope: &ProcessScope, output_buffer: &Vec<Vec<Vec<u8>>>) {
|
/// Write a chunk of MIDI notes to the output buffer.
|
||||||
|
fn write (
|
||||||
|
&mut self, scope: &ProcessScope, out_buf: &Vec<Vec<Vec<u8>>>
|
||||||
|
) {
|
||||||
let samples = scope.n_frames() as usize;
|
let samples = scope.n_frames() as usize;
|
||||||
for port in self.midi_outs_mut().iter_mut() {
|
for port in self.midi_outs_mut().iter_mut() {
|
||||||
let writer = &mut port.writer(scope);
|
let writer = &mut port.writer(scope);
|
||||||
for time in 0..samples {
|
for time in 0..samples {
|
||||||
for event in output_buffer[time].iter() {
|
for event in out_buf[time].iter() {
|
||||||
writer.write(&RawMidi { time: time as u32, bytes: &event })
|
writer.write(&RawMidi { time: time as u32, bytes: &event })
|
||||||
.expect(&format!("{event:?}"));
|
.expect(&format!("{event:?}"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ pub trait ArrangerSceneApi: Sized {
|
||||||
Some(clip) => tracks
|
Some(clip) => tracks
|
||||||
.get(track_index)
|
.get(track_index)
|
||||||
.map(|track|{
|
.map(|track|{
|
||||||
if let Some((_, Some(phrase))) = track.play_phrase() {
|
if let Some((_, Some(phrase))) = track.player().play_phrase() {
|
||||||
*phrase.read().unwrap() == *clip.read().unwrap()
|
*phrase.read().unwrap() == *clip.read().unwrap()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub enum ArrangerTrackCommand {
|
||||||
SetZoom(usize),
|
SetZoom(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ArrangerTrackApi: MidiPlayerApi + Send + Sync + Sized {
|
pub trait ArrangerTrackApi: HasPlayer + Send + Sync + Sized {
|
||||||
/// Name of track
|
/// Name of track
|
||||||
fn name (&self) -> &Arc<RwLock<String>>;
|
fn name (&self) -> &Arc<RwLock<String>>;
|
||||||
/// Preferred width of track column
|
/// Preferred width of track column
|
||||||
|
|
@ -78,7 +78,7 @@ impl<'a, T: ArrangerTrackApi, H: HasTracks<T>> Audio for TracksAudio<'a, T, H> {
|
||||||
let note_buffer = &mut self.1;
|
let note_buffer = &mut self.1;
|
||||||
let output_buffer = &mut self.2;
|
let output_buffer = &mut self.2;
|
||||||
for track in model.tracks_mut().iter_mut() {
|
for track in model.tracks_mut().iter_mut() {
|
||||||
if PlayerAudio(track, note_buffer, output_buffer).process(client, scope) == Control::Quit {
|
if PlayerAudio(track.player_mut(), note_buffer, output_buffer).process(client, scope) == Control::Quit {
|
||||||
return Control::Quit
|
return Control::Quit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,79 +91,6 @@ impl TuiTheme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_midi_player {
|
|
||||||
($Struct:ident $(:: $field:ident)*) => {
|
|
||||||
impl HasPhrase for $Struct {
|
|
||||||
fn reset (&self) -> bool {
|
|
||||||
self$(.$field)*.reset
|
|
||||||
}
|
|
||||||
fn reset_mut (&mut self) -> &mut bool {
|
|
||||||
&mut self$(.$field)*.reset
|
|
||||||
}
|
|
||||||
fn play_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
|
||||||
&self$(.$field)*.play_phrase
|
|
||||||
}
|
|
||||||
fn play_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
|
||||||
&mut self$(.$field)*.play_phrase
|
|
||||||
}
|
|
||||||
fn next_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
|
||||||
&self$(.$field)*.next_phrase
|
|
||||||
}
|
|
||||||
fn next_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
|
||||||
&mut self$(.$field)*.next_phrase
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl MidiInputApi for $Struct {
|
|
||||||
fn midi_ins (&self) -> &Vec<Port<jack::MidiIn>> {
|
|
||||||
&self$(.$field)*.midi_ins
|
|
||||||
}
|
|
||||||
fn midi_ins_mut (&mut self) -> &mut Vec<Port<jack::MidiIn>> {
|
|
||||||
&mut self$(.$field)*.midi_ins
|
|
||||||
}
|
|
||||||
fn recording (&self) -> bool {
|
|
||||||
self$(.$field)*.recording
|
|
||||||
}
|
|
||||||
fn recording_mut (&mut self) -> &mut bool {
|
|
||||||
&mut self$(.$field)*.recording
|
|
||||||
}
|
|
||||||
fn monitoring (&self) -> bool {
|
|
||||||
self$(.$field)*.monitoring
|
|
||||||
}
|
|
||||||
fn monitoring_mut (&mut self) -> &mut bool {
|
|
||||||
&mut self$(.$field)*.monitoring
|
|
||||||
}
|
|
||||||
fn overdub (&self) -> bool {
|
|
||||||
self$(.$field)*.overdub
|
|
||||||
}
|
|
||||||
fn overdub_mut (&mut self) -> &mut bool {
|
|
||||||
&mut self$(.$field)*.overdub
|
|
||||||
}
|
|
||||||
fn notes_in (&self) -> &Arc<RwLock<[bool; 128]>> {
|
|
||||||
&self$(.$field)*.notes_in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl MidiOutputApi for $Struct {
|
|
||||||
fn midi_outs (&self) -> &Vec<Port<jack::MidiOut>> {
|
|
||||||
&self$(.$field)*.midi_outs
|
|
||||||
}
|
|
||||||
fn midi_outs_mut (&mut self) -> &mut Vec<Port<jack::MidiOut>> {
|
|
||||||
&mut self$(.$field)*.midi_outs
|
|
||||||
}
|
|
||||||
fn midi_note (&mut self) -> &mut Vec<u8> {
|
|
||||||
&mut self$(.$field)*.note_buf
|
|
||||||
}
|
|
||||||
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
|
|
||||||
&self$(.$field)*.notes_in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl MidiPlayerApi for $Struct {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_midi_player!(SequencerTui::player);
|
|
||||||
impl_midi_player!(ArrangerTrack::player);
|
|
||||||
impl_midi_player!(PhrasePlayerModel);
|
|
||||||
|
|
||||||
use std::fmt::{Debug, Formatter, Error};
|
use std::fmt::{Debug, Formatter, Error};
|
||||||
type DebugResult = std::result::Result<(), Error>;
|
type DebugResult = std::result::Result<(), Error>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ impl ArrangerControl for ArrangerTui {
|
||||||
for (t, track) in self.tracks.iter_mut().enumerate() {
|
for (t, track) in self.tracks.iter_mut().enumerate() {
|
||||||
let phrase = self.scenes[s].clips[t].clone();
|
let phrase = self.scenes[s].clips[t].clone();
|
||||||
if track.player.play_phrase.is_some() || phrase.is_some() {
|
if track.player.play_phrase.is_some() || phrase.is_some() {
|
||||||
track.enqueue_next(phrase.as_ref());
|
track.player.enqueue_next(phrase.as_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.clock().is_stopped() {
|
if self.clock().is_stopped() {
|
||||||
|
|
@ -94,7 +94,7 @@ impl ArrangerControl for ArrangerTui {
|
||||||
}
|
}
|
||||||
} else if let ArrangerSelection::Clip(t, s) = self.selected {
|
} else if let ArrangerSelection::Clip(t, s) = self.selected {
|
||||||
let phrase = self.scenes()[s].clips[t].clone();
|
let phrase = self.scenes()[s].clips[t].clone();
|
||||||
self.tracks_mut()[t].enqueue_next(phrase.as_ref());
|
self.tracks_mut()[t].player.enqueue_next(phrase.as_ref());
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,15 @@ pub struct ArrangerTrack {
|
||||||
pub(crate) player: PhrasePlayerModel,
|
pub(crate) player: PhrasePlayerModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasPlayer for ArrangerTrack {
|
||||||
|
fn player (&self) -> &impl MidiPlayerApi {
|
||||||
|
&self.player
|
||||||
|
}
|
||||||
|
fn player_mut (&mut self) -> &mut impl MidiPlayerApi {
|
||||||
|
&mut self.player
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ArrangerTrackApi for ArrangerTrack {
|
impl ArrangerTrackApi for ArrangerTrack {
|
||||||
/// Name of track
|
/// Name of track
|
||||||
fn name (&self) -> &Arc<RwLock<String>> {
|
fn name (&self) -> &Arc<RwLock<String>> {
|
||||||
|
|
|
||||||
|
|
@ -52,3 +52,77 @@ impl HasClock for PhrasePlayerModel {
|
||||||
&self.clock
|
&self.clock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasPlayPhrase for PhrasePlayerModel {
|
||||||
|
fn reset (&self) -> bool {
|
||||||
|
self.reset
|
||||||
|
}
|
||||||
|
fn reset_mut (&mut self) -> &mut bool {
|
||||||
|
&mut self.reset
|
||||||
|
}
|
||||||
|
fn play_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||||
|
&self.play_phrase
|
||||||
|
}
|
||||||
|
fn play_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||||
|
&mut self.play_phrase
|
||||||
|
}
|
||||||
|
fn next_phrase (&self) -> &Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||||
|
&self.next_phrase
|
||||||
|
}
|
||||||
|
fn next_phrase_mut (&mut self) -> &mut Option<(Instant, Option<Arc<RwLock<Phrase>>>)> {
|
||||||
|
&mut self.next_phrase
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasMidiIns for PhrasePlayerModel {
|
||||||
|
fn midi_ins (&self) -> &Vec<Port<jack::MidiIn>> {
|
||||||
|
&self.midi_ins
|
||||||
|
}
|
||||||
|
fn midi_ins_mut (&mut self) -> &mut Vec<Port<jack::MidiIn>> {
|
||||||
|
&mut self.midi_ins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MidiRecordApi for PhrasePlayerModel {
|
||||||
|
fn recording (&self) -> bool {
|
||||||
|
self.recording
|
||||||
|
}
|
||||||
|
fn recording_mut (&mut self) -> &mut bool {
|
||||||
|
&mut self.recording
|
||||||
|
}
|
||||||
|
fn monitoring (&self) -> bool {
|
||||||
|
self.monitoring
|
||||||
|
}
|
||||||
|
fn monitoring_mut (&mut self) -> &mut bool {
|
||||||
|
&mut self.monitoring
|
||||||
|
}
|
||||||
|
fn overdub (&self) -> bool {
|
||||||
|
self.overdub
|
||||||
|
}
|
||||||
|
fn overdub_mut (&mut self) -> &mut bool {
|
||||||
|
&mut self.overdub
|
||||||
|
}
|
||||||
|
fn notes_in (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||||
|
&self.notes_in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasMidiOuts for PhrasePlayerModel {
|
||||||
|
fn midi_outs (&self) -> &Vec<Port<jack::MidiOut>> {
|
||||||
|
&self.midi_outs
|
||||||
|
}
|
||||||
|
fn midi_outs_mut (&mut self) -> &mut Vec<Port<jack::MidiOut>> {
|
||||||
|
&mut self.midi_outs
|
||||||
|
}
|
||||||
|
fn midi_note (&mut self) -> &mut Vec<u8> {
|
||||||
|
&mut self.note_buf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MidiPlaybackApi for PhrasePlayerModel {
|
||||||
|
fn notes_out (&self) -> &Arc<RwLock<[bool; 128]>> {
|
||||||
|
&self.notes_in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MidiPlayerApi for PhrasePlayerModel {}
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,9 @@ pub fn arranger_content_vertical (
|
||||||
let name = format!("▎{}", &name[0..max_w]);
|
let name = format!("▎{}", &name[0..max_w]);
|
||||||
let name = TuiStyle::bold(name, true);
|
let name = TuiStyle::bold(name, true);
|
||||||
// beats elapsed
|
// beats elapsed
|
||||||
let elapsed = if let Some((_, Some(phrase))) = track.play_phrase().as_ref() {
|
let elapsed = if let Some((_, Some(phrase))) = track.player.play_phrase().as_ref() {
|
||||||
let length = phrase.read().unwrap().length;
|
let length = phrase.read().unwrap().length;
|
||||||
let elapsed = track.pulses_since_start().unwrap();
|
let elapsed = track.player.pulses_since_start().unwrap();
|
||||||
let elapsed = timebase.format_beats_1_short(
|
let elapsed = timebase.format_beats_1_short(
|
||||||
(elapsed as usize % length) as f64
|
(elapsed as usize % length) as f64
|
||||||
);
|
);
|
||||||
|
|
@ -147,7 +147,7 @@ pub fn arranger_content_vertical (
|
||||||
String::from("▎")
|
String::from("▎")
|
||||||
};
|
};
|
||||||
// beats until switchover
|
// beats until switchover
|
||||||
let until_next = track.next_phrase().as_ref().map(|(t, _)|{
|
let until_next = track.player.next_phrase().as_ref().map(|(t, _)|{
|
||||||
let target = t.pulse.get();
|
let target = t.pulse.get();
|
||||||
let current = current.pulse.get();
|
let current = current.pulse.get();
|
||||||
if target > current {
|
if target > current {
|
||||||
|
|
@ -158,12 +158,12 @@ pub fn arranger_content_vertical (
|
||||||
}
|
}
|
||||||
}).unwrap_or(String::from("▎"));
|
}).unwrap_or(String::from("▎"));
|
||||||
// name of active MIDI input
|
// name of active MIDI input
|
||||||
let input = format!("▎>{}", track.midi_ins().get(0)
|
let input = format!("▎>{}", track.player.midi_ins().get(0)
|
||||||
.map(|port|port.short_name())
|
.map(|port|port.short_name())
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or("(none)".into()));
|
.unwrap_or("(none)".into()));
|
||||||
// name of active MIDI output
|
// name of active MIDI output
|
||||||
let output = format!("▎<{}", track.midi_outs().get(0)
|
let output = format!("▎<{}", track.player.midi_outs().get(0)
|
||||||
.map(|port|port.short_name())
|
.map(|port|port.short_name())
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or("(none)".into()));
|
.unwrap_or("(none)".into()));
|
||||||
|
|
@ -196,7 +196,7 @@ pub fn arranger_content_vertical (
|
||||||
let color = phrase.read().unwrap().color;
|
let color = phrase.read().unwrap().color;
|
||||||
add(&name.as_str()[0..max_w].push_x(1).fixed_x(w as u16))?;
|
add(&name.as_str()[0..max_w].push_x(1).fixed_x(w as u16))?;
|
||||||
bg = color.dark.rgb;
|
bg = color.dark.rgb;
|
||||||
if let Some((_, Some(ref playing))) = track.play_phrase() {
|
if let Some((_, Some(ref playing))) = track.player.play_phrase() {
|
||||||
if *playing.read().unwrap() == *phrase.read().unwrap() {
|
if *playing.read().unwrap() == *phrase.read().unwrap() {
|
||||||
bg = color.light.rgb
|
bg = color.light.rgb
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub struct PhraseSelector<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PhraseSelector<'a> {
|
impl<'a> PhraseSelector<'a> {
|
||||||
pub fn play_phrase <T: HasPhrase> (
|
pub fn play_phrase <T: HasPlayPhrase> (
|
||||||
state: &'a T,
|
state: &'a T,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
entered: bool,
|
entered: bool,
|
||||||
|
|
@ -20,7 +20,7 @@ impl<'a> PhraseSelector<'a> {
|
||||||
title: "Now:",
|
title: "Now:",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn next_phrase <T: HasPhrase> (
|
pub fn next_phrase <T: HasPlayPhrase> (
|
||||||
state: &'a T,
|
state: &'a T,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
entered: bool,
|
entered: bool,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue