From 2c6a2f5a36250a5c62130fa4d013973a7438b0cd Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 13 Dec 2025 08:50:52 -0600 Subject: [PATCH] add midi message type filter --- internal/processor/midi-message-filter.go | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 internal/processor/midi-message-filter.go diff --git a/internal/processor/midi-message-filter.go b/internal/processor/midi-message-filter.go new file mode 100644 index 0000000..9c76764 --- /dev/null +++ b/internal/processor/midi-message-filter.go @@ -0,0 +1,55 @@ +//go:build cgo + +package processor + +import ( + "context" + "fmt" + + "github.com/jwetzell/showbridge-go/internal/config" + "gitlab.com/gomidi/midi/v2" +) + +type MIDIMessageFilter struct { + config config.ProcessorConfig + MIDIType string +} + +func (mmf *MIDIMessageFilter) Process(ctx context.Context, payload any) (any, error) { + payloadMessage, ok := payload.(midi.Message) + + if !ok { + return nil, fmt.Errorf("midi.message.filter processor only accepts an midi.Message") + } + + if payloadMessage.Type().String() != mmf.MIDIType { + return nil, nil + } + + return payloadMessage, nil +} + +func (mmf *MIDIMessageFilter) Type() string { + return mmf.config.Type +} + +func init() { + RegisterProcessor(ProcessorRegistration{ + Type: "midi.message.filter", + New: func(config config.ProcessorConfig) (Processor, error) { + params := config.Params + midiType, ok := params["type"] + + if !ok { + return nil, fmt.Errorf("midi.message.filter requires a type parameter") + } + midiTypeString, ok := midiType.(string) + + if !ok { + return nil, fmt.Errorf("midi.message.filter type must be a string") + } + + return &MIDIMessageFilter{config: config, MIDIType: midiTypeString}, nil + }, + }) +}