diff --git a/src/main.rs b/src/main.rs index a7733eb9..6c80a365 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,6 +67,8 @@ pub fn main () -> Usually<()> { ]))?, ]; + state.tracks[0].sequence = Some(0); + state.tracks[1].sequence = Some(0); state.track_cursor = 1; state.scene_cursor = 1; state.note_start = 12; @@ -121,43 +123,47 @@ pub struct App { process!(App |self, _client, scope| { let transport = self.transport.as_ref().unwrap().query().unwrap(); + let mut send_all_notes_off = false; + if Some(transport.state) != self.playing { + send_all_notes_off = true; + } self.playing = Some(transport.state); self.playhead = transport.pos.frame() as usize; - for Track { - sequence, phrases, midi_out, monitoring, recording, ref mut notes_on, .. - } in self.tracks.iter_mut() { - if sequence.is_none() { continue } - let phrase = phrases.get_mut(sequence.unwrap()); - if phrase.is_none() { continue } - let phrase = phrase.unwrap(); - let frame = scope.last_frame_time() as usize; - let frames = scope.n_frames() as usize; + let frame = scope.last_frame_time() as usize; + let frames = scope.n_frames() as usize; + for track in self.tracks.iter_mut() { + // Output buffer let mut output: Vec>>> = vec![None;frames]; - let transport = self.transport.as_ref().unwrap().query().unwrap(); - if Some(transport.state) != self.playing { - all_notes_off(&mut output); - } - self.playing = Some(transport.state); - // Play from phrase into output buffer - if self.playing == Some(TransportState::Rolling) { - phrase.process_out( - &mut output, - notes_on, + if send_all_notes_off { all_notes_off(&mut output); } + // For highlighting keys + let mut notes_on = vec![false;128]; + // Need to be borrowed outside the if + let recording = track.recording; + let monitoring = track.monitoring; + // If there's an active phrase, play/record + if let Some(phrase) = track.phrase_mut() { + // Play from phrase into output buffer + if self.playing == Some(TransportState::Rolling) { + phrase.process_out( + &mut output, + &mut notes_on, + &self.timebase, + frame, + frames + ); + } + // Play from input to monitor, and record into phrase. + phrase.process_in( + self.midi_in.as_ref().unwrap().iter(scope), + &mut notes_on, + if monitoring { Some(&mut output) } else { None }, + recording && self.playing == Some(TransportState::Rolling), &self.timebase, frame, - frames ); } - // Play from input to monitor, and record into phrase. - phrase.process_in( - self.midi_in.as_ref().unwrap().iter(scope), - notes_on, - if *monitoring { Some(&mut output) } else { None }, - *recording && self.playing == Some(TransportState::Rolling), - &self.timebase, - frame, - ); - write_output(&mut midi_out.writer(scope), &mut output, frames); + track.notes_on = notes_on; + write_output(&mut track.midi_out.writer(scope), &mut output, frames); } Control::Continue }); diff --git a/src/model/track.rs b/src/model/track.rs index b56b2ae5..bfb640b6 100644 --- a/src/model/track.rs +++ b/src/model/track.rs @@ -59,6 +59,13 @@ impl Track { None } } + pub fn phrase_mut (&mut self) -> Option<&mut Phrase> { + if let Some(phrase) = self.sequence { + return self.phrases.get_mut(phrase) + } else { + None + } + } } ports!(Track { diff --git a/src/view/sequencer.rs b/src/view/sequencer.rs index 71f5024f..4cdb2878 100644 --- a/src/view/sequencer.rs +++ b/src/view/sequencer.rs @@ -185,42 +185,42 @@ mod horizontal { let c = if note % 2 == 0 { "▀" } else { "▄" }; c.blit(buf, x, y, Some(style)); } - - pub fn footer ( - buf: &mut Buffer, - area: Rect, - note0: usize, - note: usize, - time0: usize, - time: usize, - time_z: usize, - ) { - let Rect { mut x, y, width, height } = area; - buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())), - Style::default().dim()); - buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())), - Style::default().dim()); - x = x + 2; - { - for (_, [letter, title, value]) in [ - ["S", &format!("ync"), &format!("<4/4>")], - ["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)], - ["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")], - ["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")], - ].iter().enumerate() { - buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim()); - x = x + 1; - buf.set_string(x, y + height + 1, &title, Style::default().bold().dim()); - x = x + title.len() as u16 + 1; - buf.set_string(x, y + height + 1, &value, Style::default().not_dim()); - x = x + value.len() as u16; - buf.set_string(x, y + height + 1, " ", Style::default().dim()); - x = x + 2; - } - } - } } + //pub fn footer ( + //buf: &mut Buffer, + //area: Rect, + //note0: usize, + //note: usize, + //time0: usize, + //time: usize, + //time_z: usize, + //) { + //let Rect { mut x, y, width, height } = area; + //buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())), + //Style::default().dim()); + //buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())), + //Style::default().dim()); + //x = x + 2; + //{ + //for (_, [letter, title, value]) in [ + //["S", &format!("ync"), &format!("<4/4>")], + //["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)], + //["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")], + //["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")], + //].iter().enumerate() { + //buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim()); + //x = x + 1; + //buf.set_string(x, y + height + 1, &title, Style::default().bold().dim()); + //x = x + title.len() as u16 + 1; + //buf.set_string(x, y + height + 1, &value, Style::default().not_dim()); + //x = x + value.len() as u16; + //buf.set_string(x, y + height + 1, " ", Style::default().dim()); + //x = x + 2; + //} + //} + //} + //mod vertical { //use super::*;