From 753b239df6c457ba0ba943592a4267fc7b25a1dd Mon Sep 17 00:00:00 2001 From: Will Hedgecock Date: Tue, 10 Dec 2024 21:52:14 -0600 Subject: [PATCH] Add "drain" option to all structures --- amm_sdk/src/storage/midi.rs | 1 + amm_sdk/src/structure/chord.rs | 5 +++++ amm_sdk/src/structure/multivoice.rs | 5 +++++ amm_sdk/src/structure/part.rs | 5 +++++ amm_sdk/src/structure/phrase.rs | 5 +++++ amm_sdk/src/structure/section.rs | 5 +++++ amm_sdk/src/structure/staff.rs | 5 +++++ 7 files changed, 31 insertions(+) diff --git a/amm_sdk/src/storage/midi.rs b/amm_sdk/src/storage/midi.rs index 814cf24..a34d7d4 100644 --- a/amm_sdk/src/storage/midi.rs +++ b/amm_sdk/src/storage/midi.rs @@ -686,3 +686,4 @@ mod test { // TODO: Implement tuplets // TODO: Attempt to implement dynamics // TODO: Attempt to implement mordents, trills, and other ornaments based on timing data +// IDEA: Pre-create timeslices for min note lengths (associate each slice with MIDI tick start time), round note start time to nearest timeslice start time and add note to slice (but how handle tuplets?, maybe add a flag if suspected tuplet because note falls in 1/3 or 2/3 or expected timeslice time and then check for consecutive flags?) diff --git a/amm_sdk/src/structure/chord.rs b/amm_sdk/src/structure/chord.rs index ba73ded..5607fb2 100644 --- a/amm_sdk/src/structure/chord.rs +++ b/amm_sdk/src/structure/chord.rs @@ -143,6 +143,11 @@ impl Chord { self.modifications.iter() } + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, ChordContent> { + self.content.drain(..) + } + #[must_use] pub fn to_timeslice(&self) -> Timeslice { let mut timeslice = Timeslice::new(); diff --git a/amm_sdk/src/structure/multivoice.rs b/amm_sdk/src/structure/multivoice.rs index dfb9820..21179f8 100644 --- a/amm_sdk/src/structure/multivoice.rs +++ b/amm_sdk/src/structure/multivoice.rs @@ -468,6 +468,11 @@ impl MultiVoice { .collect(), } } + + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, MultiVoiceContent> { + self.content.drain(..) + } } impl IntoIterator for MultiVoice { diff --git a/amm_sdk/src/structure/part.rs b/amm_sdk/src/structure/part.rs index ec82079..be10d27 100644 --- a/amm_sdk/src/structure/part.rs +++ b/amm_sdk/src/structure/part.rs @@ -277,6 +277,11 @@ impl Part { .iter() .flat_map(|PartContent::Section(section)| section.iter_timeslices()) } + + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, PartContent> { + self.content.drain(..) + } } impl IntoIterator for Part { diff --git a/amm_sdk/src/structure/phrase.rs b/amm_sdk/src/structure/phrase.rs index f444745..7fdfd24 100644 --- a/amm_sdk/src/structure/phrase.rs +++ b/amm_sdk/src/structure/phrase.rs @@ -462,6 +462,11 @@ impl Phrase { modifications: &self.modifications, } } + + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, PhraseContent> { + self.content.drain(..) + } } impl IntoIterator for Phrase { diff --git a/amm_sdk/src/structure/section.rs b/amm_sdk/src/structure/section.rs index d7e9a0d..8f2a390 100644 --- a/amm_sdk/src/structure/section.rs +++ b/amm_sdk/src/structure/section.rs @@ -541,6 +541,11 @@ impl Section { processing_staves: false, } } + + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, SectionContent> { + self.content.drain(..) + } } impl IntoIterator for Section { diff --git a/amm_sdk/src/structure/staff.rs b/amm_sdk/src/structure/staff.rs index 5bd3112..2c3ebda 100644 --- a/amm_sdk/src/structure/staff.rs +++ b/amm_sdk/src/structure/staff.rs @@ -446,6 +446,11 @@ impl Staff { child_multivoice: None, } } + + #[must_use] + pub fn drain(&mut self) -> alloc::vec::Drain<'_, StaffContent> { + self.content.drain(..) + } } impl IntoIterator for Staff {