From 9f98c5a4da8eefacddd65267e1307341c18a5710 Mon Sep 17 00:00:00 2001 From: Denis Redozubov Date: Fri, 9 Jun 2023 20:40:21 +0400 Subject: [PATCH] Add Midi text message to output file --- src/midi/core.rs | 69 +++++------------------------------------------- src/midi/time.rs | 2 -- 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/src/midi/core.rs b/src/midi/core.rs index 06ce6d1..d3093db 100644 --- a/src/midi/core.rs +++ b/src/midi/core.rs @@ -796,66 +796,7 @@ fn flatten_and_merge( #[test] fn test_flatten_and_merge() { - let kick_events = vec![ - Event { - tick: Tick(0), - event_type: NoteOn(KickDrum), - }, - Event { - tick: Tick(12), - event_type: NoteOff(KickDrum), - }, - Event { - tick: Tick(12), - event_type: NoteOn(KickDrum), - }, - Event { - tick: Tick(24), - event_type: NoteOff(KickDrum), - }, - Event { - tick: Tick(36), - event_type: NoteOn(KickDrum), - }, - Event { - tick: Tick(48), - event_type: NoteOff(KickDrum), - }, - Event { - tick: Tick(60), - event_type: NoteOn(KickDrum), - }, - Event { - tick: Tick(72), - event_type: NoteOff(KickDrum), - }, - Event { - tick: Tick(72), - event_type: NoteOn(KickDrum), - }, - Event { - tick: Tick(84), - event_type: NoteOff(KickDrum), - }, - ]; - let snare_events = [ - Event { - tick: Tick(24), - event_type: NoteOn(SnareDrum), - }, - Event { - tick: Tick(48), - event_type: NoteOff(SnareDrum), - }, - Event { - tick: Tick(96), - event_type: NoteOn(SnareDrum), - }, - Event { - tick: Tick(120), - event_type: NoteOff(SnareDrum), - }, - ]; + let kick_events = vec![Event { tick: Tick(0), event_type: NoteOn(KickDrum) }, Event { tick: Tick(12), event_type: NoteOff(KickDrum) }, Event { tick: Tick(12), event_type: NoteOn(KickDrum) }, Event { tick: Tick(24), event_type: NoteOff(KickDrum) }, Event { tick: Tick(36), event_type: NoteOn(KickDrum) }, Event { tick: Tick(48), event_type: NoteOff(KickDrum) }, Event { tick: Tick(60), event_type: NoteOn(KickDrum) }, Event { tick: Tick(72), event_type: NoteOff(KickDrum) }, Event { tick: Tick(72), event_type: NoteOn(KickDrum) }, Event { tick: Tick(84), event_type: NoteOff(KickDrum) }]; let snare_events = [Event { tick: Tick(24), event_type: NoteOn(SnareDrum) }, Event { tick: Tick(48), event_type: NoteOff(SnareDrum) }, Event { tick: Tick(96), event_type: NoteOn(SnareDrum) }, Event { tick: Tick(120), event_type: NoteOff(SnareDrum) }]; let four_fourth = TimeSignature::from_str("4/4").unwrap(); // let kick_event_grid = EventGrid { events, length: Tick(48 * 4) }; let flattened_kick = flatten_and_merge( @@ -882,6 +823,9 @@ fn test_flatten_and_merge() { assert_eq!( flattened_kick + .iter() + .all(|x| flattened_kick_and_snare.contains(x)) && + flattened_snare .iter() .all(|x| flattened_kick_and_snare.contains(x)), true @@ -976,9 +920,8 @@ fn create_tracks<'a>( 8, )), }); - - // println!("{:?}", text_event.as_bytes()); - // drums.push(TrackEvent { delta: 0.into(), kind: TrackEventKind::Meta(MetaMessage::Text("!!!!!!!".as_bytes())) }); + + drums.push(TrackEvent { delta: 0.into(), kind: TrackEventKind::Meta(MetaMessage::Text(text_event.as_bytes())) }); for event in event_grid.events { let midi_message = match event.event_type { diff --git a/src/midi/time.rs b/src/midi/time.rs index d5f0d97..69f14d7 100644 --- a/src/midi/time.rs +++ b/src/midi/time.rs @@ -96,7 +96,6 @@ fn test_cmp_time_signature() { impl KnownLength for TimeSignature { fn to_128th(&self) -> u32 { - println!("{}", self.denominator.to_128th()); self.denominator.to_128th() * self.numerator as u32 } } @@ -109,7 +108,6 @@ fn test_time_signature_known_length() { impl TimeSignature { pub fn converges>(&self, multiple: I) -> Result { let bar_len = self.to_128th(); - println!("bar_len: {}", bar_len); let result = multiple .into_iter() .fold(bar_len, |acc, t| lowest_common_divisor(t.to_128th(), acc));