replace Phrase::looped with separate fields; draw them with backgrounds

This commit is contained in:
🪞👃🪞 2024-10-05 10:02:55 +03:00
parent 4c3ad62279
commit ea3edec96b
2 changed files with 31 additions and 21 deletions

View file

@ -691,12 +691,14 @@ pub type PhraseData = Vec<Vec<MidiMessage>>;
/// A MIDI sequence.
#[derive(Debug)]
pub struct Phrase {
pub name: Arc<RwLock<String>>,
pub length: usize,
pub notes: PhraseData,
pub looped: Option<(usize, usize)>,
pub name: Arc<RwLock<String>>,
pub length: usize,
pub notes: PhraseData,
pub loop_on: bool,
pub loop_start: usize,
pub loop_length: usize,
/// All notes are displayed with minimum length
pub percussive: bool
pub percussive: bool,
}
impl Default for Phrase {
fn default () -> Self { Self::new("", 0, None) }
@ -704,13 +706,18 @@ impl Default for Phrase {
impl Phrase {
pub fn new (name: &str, length: usize, notes: Option<PhraseData>) -> Self {
Self {
name: Arc::new(RwLock::new(name.into())),
name: Arc::new(RwLock::new(name.into())),
length,
notes: notes.unwrap_or(vec![Vec::with_capacity(16);length]),
looped: Some((0, length)),
percussive: true,
notes: notes.unwrap_or(vec![Vec::with_capacity(16);length]),
loop_on: true,
loop_start: 0,
loop_length: length,
percussive: true,
}
}
pub fn toggle_loop (&mut self) {
self.loop_on = !self.loop_on;
}
pub fn record_event (&mut self, pulse: usize, message: MidiMessage) {
if pulse >= self.length {
panic!("extend phrase first")