]> git.huck.website - cellseq.git/commitdiff
fixed: send note offs on stop
authorHuck Boles <huck@huck.website>
Mon, 10 Jul 2023 23:41:00 +0000 (18:41 -0500)
committerHuck Boles <huck@huck.website>
Mon, 10 Jul 2023 23:41:00 +0000 (18:41 -0500)
src/lib.rs
src/midi.rs

index 91b40ac0243763ae311d9ac448f174011a7e81b3..8e5137b217e174dc2dd1fdae16eabe0e10f7876d 100644 (file)
@@ -164,7 +164,7 @@ impl Application for CellSeq {
             }
             Message::Tick(_) => {
                 let map = if self.song.is_looping && self.song.step_num >= self.song.loop_len {
-                    self.song.step_num = 0;
+                    self.song.step_num = 1;
                     self.map.reset_loop()
                 } else {
                     self.song.step_num += 1;
@@ -174,6 +174,9 @@ impl Application for CellSeq {
                 let channel = self.midi.channel_handle();
                 let bytes = self.midi.tick();
 
+                let new_map = map.clone();
+                let hits = self.mask.tick(map);
+
                 let midi = tokio::spawn(async move {
                     for byte in bytes {
                         channel.send(byte).await.unwrap()
@@ -181,8 +184,9 @@ impl Application for CellSeq {
                 });
 
                 let mut commands = Vec::new();
-                commands.push(Command::perform(async move { map }, Message::NewMap));
                 commands.push(Command::perform(midi, |_| Message::None));
+                commands.push(Command::perform(async move { new_map }, Message::NewMap));
+                commands.push(Command::perform(async move { hits }, Message::HitCount));
                 commands.push(Command::perform(async move {}, |_| {
                     Message::MaskMessage(mask::Message::Ticked)
                 }));
@@ -190,15 +194,20 @@ impl Application for CellSeq {
                 return Command::batch(commands);
             }
             Message::TogglePlayback => {
-                self.song.is_playing = !self.song.is_playing;
                 if self.song.is_playing {
-                    self.map.save()
+                    let bytes = self.midi.all_off(self.info.channel);
+                    let channel = self.midi.channel_handle();
+                    for byte in bytes {
+                        channel.try_send(byte).unwrap();
+                    }
                 }
+                self.song.is_playing = !self.song.is_playing;
             }
             Message::ToggleLoop => {
                 self.song.is_looping = !self.song.is_looping;
                 if self.song.is_looping {
-                    self.song.step_num = 0;
+                    self.map.set_loop();
+                    self.song.step_num = 1;
                 }
             }
             Message::RandChanged(r) => {
index 7c722e4004fef94b30e948e7b0b675a2d4cef421..0f4330f1e191f55a4c14094dec8db328334125bb 100644 (file)
@@ -120,6 +120,26 @@ impl MidiLink {
         self.buffer.clear();
         vec
     }
+
+    pub fn all_off(&mut self, channel: u8) -> Vec<u8> {
+        let notes = self
+            .notes_on
+            .iter()
+            .flat_map(|note| {
+                MidiMessage::Off {
+                    note: *note,
+                    velocity: 0,
+                    channel,
+                }
+                .as_bytes()
+            })
+            .flatten()
+            .flatten()
+            .collect();
+
+        self.notes_on.clear();
+        notes
+    }
 }
 
 #[derive(Clone, Copy, Debug, Error)]