From c1d175acb4965f93e1c2b214ed8a3836a9da1b20 Mon Sep 17 00:00:00 2001 From: Xavier Godart Date: Mon, 10 Apr 2023 20:06:22 +0200 Subject: [PATCH] add silence method to midi package --- midi/midi.go | 8 ++++++++ sequencer/track.go | 1 + 2 files changed, 9 insertions(+) diff --git a/midi/midi.go b/midi/midi.go index d3f85cb..5c07693 100644 --- a/midi/midi.go +++ b/midi/midi.go @@ -24,6 +24,7 @@ type Midi interface { Devices() gomidi.OutPorts NoteOn(device int, channel uint8, note uint8, velocity uint8) NoteOff(device int, channel uint8, note uint8) + Silence(device int, channel uint8) ControlChange(device int, channel, controller, value uint8) ProgramChange(device int, channel uint8, value uint8) Pitchbend(device int, channel uint8, value int16) @@ -120,6 +121,13 @@ func (m *midi) NoteOff(device int, channel uint8, note uint8) { m.outputs[device] <- gomidi.NoteOff(channel, note) } +// Silence sends a note off message for every running note on every channel. +func (m *midi) Silence(device int, channel uint8) { + for _, msg := range gomidi.SilenceChannel(int8(channel)) { + m.outputs[device] <- msg + } +} + // ControlChange sends a Control Change messages to the given device. func (m *midi) ControlChange(device int, channel, controller, value uint8) { m.outputs[device] <- gomidi.ControlChange(channel, controller, value) diff --git a/sequencer/track.go b/sequencer/track.go index d0cf6dc..98cfab6 100644 --- a/sequencer/track.go +++ b/sequencer/track.go @@ -337,4 +337,5 @@ func (t *track) clear() { for _, step := range t.steps { step.reset() } + t.midi.Silence(t.device, t.channel) }