@@ -38,16 +38,49 @@ func (d *OutputDevice) Reset() {
3838 notify .Warnf ("reset failed for device:%v" , d .id )
3939 }
4040 }()
41+ // Stop the timeline goroutine first, then clear the queue
42+ d .timeline .Stop ()
4143 d .timeline .Reset ()
44+ // Give timeline time to stop processing any pending events
45+ time .Sleep (10 * time .Millisecond )
46+
4247 if notify .IsDebug () {
4348 notify .Debugf ("device.%d: sending Note OFF to all 16 channels" , d .id )
4449 }
4550 if d .stream != nil {
46- // send note off all to all channels for current device
51+ // Send a robust panic sequence for each channel.
52+ // Some devices respond better to CC123, others to CC120, and sustained notes
53+ // require a sustain-off first.
4754 for c := 1 ; c <= 16 ; c ++ {
48- if err := d .stream .WriteShort (controlChange | int64 (c - 1 ), noteAllOff , 0 ); err != nil {
55+ status := controlChange | int64 (c - 1 )
56+ notify .Debugf ("reset: sending off events to [channel %d]" , c )
57+ if err := d .stream .WriteShort (status , sustainPedal , sustainOff ); err != nil {
58+ notify .Console .Errorf ("device.%d: midi write error:%v" , d .id , err )
59+ }
60+ if err := d .stream .WriteShort (status , allNotesOff , 0 ); err != nil {
61+ notify .Console .Errorf ("device.%d: midi write error:%v" , d .id , err )
62+ }
63+ if err := d .stream .WriteShort (status , allSoundOff , 0 ); err != nil {
4964 notify .Console .Errorf ("device.%d: midi write error:%v" , d .id , err )
5065 }
66+ // Small delay between channels to allow receiver to process messages.
67+ time .Sleep (5 * time .Millisecond )
68+ }
69+
70+ // Send explicit note-off messages for all notes on all channels.
71+ // This is more direct than relying on CC123/CC120 alone and handles
72+ // devices/DAWs that may not respond to control changes during shutdown.
73+ noteOff := int64 (0x80 ) // MIDI Note Off status
74+ for c := 1 ; c <= 16 ; c ++ {
75+ status := noteOff | int64 (c - 1 )
76+ notify .Debugf ("reset: sending explicit note-off for all notes on channel %d" , c )
77+ for n := 0 ; n <= 127 ; n ++ {
78+ if err := d .stream .WriteShort (status , int64 (n ), 0 ); err != nil {
79+ notify .Console .Errorf ("device.%d: note-off write error:%v" , d .id , err )
80+ }
81+ }
82+ // Small delay between channels
83+ time .Sleep (5 * time .Millisecond )
5184 }
5285 }
5386}
0 commit comments