Re: [AD] MIDI player missing sustain

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> There's one other change I just realised we have to make, that means the
> sound gets properly muted when stop_midi is called. Without this patch,
> any sustained notes will continue playing after the user stops the track:
>
> Around line 558 of midi.c (top of all_notes_off function):
>     if (midi_driver->raw_midi) {
> +      midi_driver->raw_midi(0xB0+channel);
> +      midi_driver->raw_midi(120);
> +      midi_driver->raw_midi(0);
>        midi_driver->raw_midi(0xB0+channel);
>        midi_driver->raw_midi(123);
>        midi_driver->raw_midi(0);
>        return;
>     }

What about the attached patch instead?

-- 
Eric Botcazou
--- /home/eric/cvs/allegro/src/midi.c	Sun Jun 15 13:19:54 2003
+++ allegro/src/midi.c	Tue Jun 17 16:34:32 2003
@@ -575,6 +575,23 @@
 
 
 
+/* all_sound_off:
+ *  Turns off sound.
+ */
+static void all_sound_off(int channel)
+{
+   if (midi_driver->raw_midi) {
+      midi_driver->raw_midi(0xB0+channel);
+      midi_driver->raw_midi(120);
+      midi_driver->raw_midi(0);
+      return;
+   }
+}
+
+END_OF_STATIC_FUNCTION(all_sound_off);
+
+
+
 /* reset_controllers:
  *  Resets volume, pan, pitch bend, etc, to default positions.
  */
@@ -674,6 +691,10 @@
 	 }
 	 break;
 
+      case 120:                                 /* all sound off */
+	 all_sound_off(channel);
+	 break;
+
       case 121:                                 /* reset all controllers */
 	 reset_controllers(channel);
 	 break;
@@ -938,8 +959,10 @@
 	    goto do_it_all_again;
 	 }
 	 else {
-	    for (c=0; c<16; c++)
+	    for (c=0; c<16; c++) {
 	       all_notes_off(c);
+	       all_sound_off(c);
+	    }
 	    prepare_to_play(midifile);
 	    goto do_it_all_again;
 	 }
@@ -1205,8 +1228,10 @@
 
    remove_int(midi_player);
 
-   for (c=0; c<16; c++)
+   for (c=0; c<16; c++) {
       all_notes_off(c);
+      all_sound_off(c);
+   }
 
    if (midi) {
       if (!midi_loaded_patches)
@@ -1280,8 +1305,10 @@
 
    remove_int(midi_player);
 
-   for (c=0; c<16; c++)
+   for (c=0; c<16; c++) {
       all_notes_off(c);
+      all_sound_off(c);
+   }
 }
 
 END_OF_FUNCTION(midi_pause);
@@ -1498,6 +1525,7 @@
    LOCK_FUNCTION(_midi_allocate_voice);
    LOCK_FUNCTION(midi_note_on);
    LOCK_FUNCTION(all_notes_off);
+   LOCK_FUNCTION(all_sound_off);
    LOCK_FUNCTION(reset_controllers);
    LOCK_FUNCTION(update_controllers);
    LOCK_FUNCTION(process_controller);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/