mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
39 lines
784 B
Go
39 lines
784 B
Go
//go:build cgo
|
|
|
|
package processor
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/jwetzell/showbridge-go/internal/config"
|
|
"gitlab.com/gomidi/midi/v2"
|
|
)
|
|
|
|
type MIDIMessageEncode struct {
|
|
config config.ProcessorConfig
|
|
}
|
|
|
|
func (mme *MIDIMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
payloadMessage, ok := GetAnyAs[midi.Message](payload)
|
|
|
|
if !ok {
|
|
return nil, errors.New("midi.message.encode processor only accepts a midi.Message")
|
|
}
|
|
|
|
return payloadMessage.Bytes(), nil
|
|
}
|
|
|
|
func (mme *MIDIMessageEncode) Type() string {
|
|
return mme.config.Type
|
|
}
|
|
|
|
func init() {
|
|
RegisterProcessor(ProcessorRegistration{
|
|
Type: "midi.message.encode",
|
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
return &MIDIMessageEncode{config: config}, nil
|
|
},
|
|
})
|
|
}
|