separate viewing/playing phrase + format

This commit is contained in:
🪞👃🪞 2024-10-03 21:41:14 +03:00
parent 6f91eb085d
commit ae60b792d6
4 changed files with 127 additions and 138 deletions

View file

@ -36,12 +36,12 @@ impl<E: Engine> Arranger<E> {
match self.selected {
ArrangerFocus::Scene(s) => {
for (track_index, track) in self.tracks.iter_mut().enumerate() {
track.sequence = self.scenes[s].clips[track_index];
track.playing_phrase = self.scenes[s].clips[track_index];
track.reset = true;
}
},
ArrangerFocus::Clip(t, s) => {
self.tracks[t].sequence = self.scenes[s].clips[t];
self.tracks[t].playing_phrase = self.scenes[s].clips[t];
self.tracks[t].reset = true;
},
_ => {}
@ -433,7 +433,7 @@ impl Scene {
.all(|(track_index, phrase_index)|match phrase_index {
Some(i) => tracks
.get(track_index)
.map(|track|track.sequence == Some(*i))
.map(|track|track.playing_phrase == Some(*i))
.unwrap_or(false),
None => true
})
@ -444,71 +444,80 @@ impl Scene {
/// Phrase editor.
pub struct Sequencer<E: Engine> {
pub name: Arc<RwLock<String>>,
pub mode: bool,
pub focused: bool,
pub entered: bool,
pub phrase: Option<Arc<RwLock<Phrase>>>,
pub transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
pub buffer: BigBuffer,
pub keys: Buffer,
pub name: Arc<RwLock<String>>,
pub mode: bool,
pub focused: bool,
pub entered: bool,
pub phrase: Option<Arc<RwLock<Phrase>>>,
pub transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
/// The full piano roll is rendered to this buffer
pub buffer: BigBuffer,
/// The full piano keys is rendered to this buffer
pub keys: Buffer,
/// Highlight input keys
pub keys_in: [bool; 128],
pub keys_in: [bool; 128],
/// Highlight output keys
pub keys_out: [bool; 128],
pub now: usize,
pub ppq: usize,
pub note_axis: FixedAxis<usize>,
pub time_axis: ScaledAxis<usize>,
pub keys_out: [bool; 128],
/// Current point in playing phrase
pub now: usize,
/// Temporal resolution (default 96)
pub ppq: usize,
/// Scroll/room in pitch axis
pub note_axis: FixedAxis<usize>,
/// Scroll/room in time axis
pub time_axis: ScaledAxis<usize>,
/// Play input through output.
pub monitoring: bool,
pub monitoring: bool,
/// Write input to sequence.
pub recording: bool,
pub recording: bool,
/// Overdub input to sequence.
pub overdub: bool,
pub overdub: bool,
/// Map: tick -> MIDI events at tick
pub phrases: Vec<Arc<RwLock<Phrase>>>,
/// Phrase selector
pub sequence: Option<usize>,
pub phrases: Vec<Arc<RwLock<Phrase>>>,
/// Phrase currently being played
pub playing_phrase: Option<usize>,
/// Phrase currently being viewed
pub viewing_phrase: Option<usize>,
/// Output from current sequence.
pub midi_out: Option<Port<MidiOut>>,
pub midi_out: Option<Port<MidiOut>>,
/// MIDI output buffer
midi_out_buf: Vec<Vec<Vec<u8>>>,
midi_out_buf: Vec<Vec<Vec<u8>>>,
/// Send all notes off
pub reset: bool, // TODO?: after Some(nframes)
pub reset: bool, // TODO?: after Some(nframes)
/// Highlight keys on piano roll.
pub notes_in: [bool;128],
pub notes_in: [bool;128],
/// Highlight keys on piano roll.
pub notes_out: [bool;128],
pub notes_out: [bool;128],
}
impl<E: Engine> Sequencer<E> {
pub fn new (name: &str) -> Self {
Self {
name: Arc::new(RwLock::new(name.into())),
monitoring: false,
recording: false,
overdub: true,
phrases: vec![],
sequence: None,
midi_out: None,
midi_out_buf: vec![Vec::with_capacity(16);16384],
reset: true,
notes_in: [false;128],
notes_out: [false;128],
buffer: Default::default(),
keys: keys_vert(),
entered: false,
focused: false,
mode: false,
keys_in: [false;128],
keys_out: [false;128],
phrase: None,
now: 0,
ppq: 96,
transport: None,
note_axis: FixedAxis { start: 12, point: Some(36) },
time_axis: ScaledAxis { start: 0, scale: 24, point: Some(0) },
name: Arc::new(RwLock::new(name.into())),
monitoring: false,
recording: false,
overdub: true,
phrases: vec![],
viewing_phrase: None,
playing_phrase: None,
midi_out: None,
midi_out_buf: vec![Vec::with_capacity(16);16384],
reset: true,
notes_in: [false;128],
notes_out: [false;128],
buffer: Default::default(),
keys: keys_vert(),
entered: false,
focused: false,
mode: false,
keys_in: [false;128],
keys_out: [false;128],
phrase: None,
now: 0,
ppq: 96,
transport: None,
note_axis: FixedAxis { start: 12, point: Some(36) },
time_axis: ScaledAxis { start: 0, scale: 24, point: Some(0) },
}
}
pub fn toggle_monitor (&mut self) {
@ -549,7 +558,7 @@ impl<E: Engine> Sequencer<E> {
if let (
Some(TransportState::Rolling), Some((start_frame, _)), Some(phrase)
) = (
playing, started, self.sequence.and_then(|id|self.phrases.get_mut(id))
playing, started, self.playing_phrase.and_then(|id|self.phrases.get_mut(id))
) {
phrase.read().map(|phrase|{
if self.midi_out.is_some() {