Compare commits
1 Commits
80986de54b
...
0442655a93
Author | SHA1 | Date | |
---|---|---|---|
0442655a93 |
BIN
.config.yaml.kate-swp
Normal file
BIN
.config.yaml.kate-swp
Normal file
Binary file not shown.
@ -110,7 +110,7 @@ On MacOS, there is an IAC Driver that can be enabled in Audio MIDI Setup.
|
||||
midi_routers:
|
||||
- name: service_notifications
|
||||
device: IAC Driver Bus 1
|
||||
log_level: 1
|
||||
debug_listener: true
|
||||
```
|
||||
|
||||
### Example note trigger configuration
|
||||
@ -120,7 +120,7 @@ midi_routers:
|
||||
midi_routers:
|
||||
- name: service_notifications
|
||||
device: IAC Driver Bus 1
|
||||
log_level: 1
|
||||
debug_listener: true
|
||||
note_triggers:
|
||||
- channel: 0
|
||||
note: 0
|
||||
@ -136,7 +136,7 @@ midi_routers:
|
||||
midi_routers:
|
||||
- name: service_notifications
|
||||
device: IAC Driver Bus 1
|
||||
log_level: 1
|
||||
debug_listener: true
|
||||
request_triggers:
|
||||
- channel: 0
|
||||
note: 0
|
||||
@ -152,7 +152,7 @@ midi_routers:
|
||||
midi_routers:
|
||||
- name: service_notifications
|
||||
device: IAC Driver Bus 1
|
||||
log_level: 2
|
||||
debug_listener: true
|
||||
note_triggers:
|
||||
- channel: 0
|
||||
note: 0
|
||||
@ -174,4 +174,5 @@ midi_routers:
|
||||
headers:
|
||||
Content-Type:
|
||||
- multipart/form-data; boundary=---------------------------888832887744
|
||||
debug_request: true
|
||||
```
|
||||
|
@ -70,14 +70,12 @@ type MQTTPayload struct {
|
||||
|
||||
// Triggers that occur from MIDI messages received.
|
||||
type NoteTrigger struct {
|
||||
// If set, every note played will be matched.
|
||||
MatchAllNotes bool `fig:"match_all_notes"`
|
||||
// Channel to match.
|
||||
Channel uint8 `fig:"channel"`
|
||||
// If we should match all channel values.
|
||||
MatchAllChannels bool `fig:"match_all_channels"`
|
||||
// Note to match.
|
||||
Note uint8 `fig:"note"`
|
||||
// If we should match all note values.
|
||||
MatchAllNotes bool `fig:"match_all_notes"`
|
||||
// Velocity to match.
|
||||
Velocity uint8 `fig:"velocity"`
|
||||
// If we should match all velocity values.
|
||||
@ -85,7 +83,7 @@ type NoteTrigger struct {
|
||||
// Custom MQTT message. Do not set to ignore MQTT.
|
||||
MqttTopic string `fig:"mqtt_topic"`
|
||||
// Nil payload will generate a payload with midi info.
|
||||
MqttPayload interface{} `fig:"mqtt_payload"`
|
||||
MqttPayload []interface{} `fig:"mqtt_payload"`
|
||||
// If the HTTP request should includ midi info.
|
||||
MidiInfoInRequest bool `fig:"midi_info_in_request"`
|
||||
// Should SSL requests require a valid certificate.
|
||||
@ -135,17 +133,17 @@ type MidiRouter struct {
|
||||
|
||||
// How much logging.
|
||||
// 0 - Errors
|
||||
// 1 - MQTT, HTTP, and MIDI receive logging.
|
||||
// 2 - MQTT, HTTP, and MIDI send logging.
|
||||
// 1 - MQTT and OSC receive logging.
|
||||
// 2 - MQTT and OSC send logging.
|
||||
// 3 - Debug
|
||||
LogLevel LogLevel `fig:"log_level"`
|
||||
LogLevel LogLevel `yaml:"log_level" json:"log_level"`
|
||||
|
||||
// Connection to MIDI device.
|
||||
MidiOut drivers.Out `fig:"-"`
|
||||
// Function to stop listening to MIDI device.
|
||||
ListenerStop func() `fig:"-"`
|
||||
// The client connection to MQTT.
|
||||
MqttClient mqtt.Client `fig:"-"`
|
||||
MqttClient mqtt.Client `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
// Logging function to allow log levels.
|
||||
@ -158,7 +156,7 @@ func (r *MidiRouter) Log(level LogLevel, format string, args ...interface{}) {
|
||||
// When a MIDI message occurs, send the HTTP request.
|
||||
func (r *MidiRouter) sendRequest(channel, note, velocity uint8) {
|
||||
// If MQTT firehose not disabled, send to general cmd topic.
|
||||
if r.MqttClient != nil && !r.MQTT.DisableMidiFirehose {
|
||||
if r.MQTT.Host != "" && r.MQTT.Port != 0 && !r.MQTT.DisableMidiFirehose {
|
||||
payload := MQTTPayload{
|
||||
Channel: channel,
|
||||
Note: note,
|
||||
@ -170,7 +168,7 @@ func (r *MidiRouter) sendRequest(channel, note, velocity uint8) {
|
||||
} else {
|
||||
topic := r.MQTT.Topic + "/cmd"
|
||||
r.MqttClient.Publish(topic, 0, true, data)
|
||||
r.Log(SendLog, "-> [MQTT] %s: %s", topic, string(data))
|
||||
r.Log(SendLog, "-> [MQTT] %s", topic)
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,19 +177,14 @@ func (r *MidiRouter) sendRequest(channel, note, velocity uint8) {
|
||||
// If match all notes, process this request.
|
||||
// If not, check if channel, note, and velocity matches.
|
||||
// The velocity may be defined to accept all.
|
||||
if (trig.Channel == channel || trig.MatchAllChannels) && (trig.Note == note || trig.MatchAllNotes) && (trig.Velocity == velocity || trig.MatchAllVelocities) {
|
||||
if trig.MatchAllNotes || (trig.Channel == channel && trig.Note == note && (trig.Velocity == velocity || trig.MatchAllVelocities)) {
|
||||
// For all logging, we want to print the message so setup a common string to print.
|
||||
logInfo := fmt.Sprintf("note %s(%d) on channel %v with velocity %v", midi.Note(note), note, channel, velocity)
|
||||
|
||||
if trig.MqttTopic != "" && r.MqttClient != nil {
|
||||
if trig.MqttTopic != "" {
|
||||
if trig.MqttPayload != nil {
|
||||
data, err := json.Marshal(trig.MqttPayload)
|
||||
if err != nil {
|
||||
r.Log(ErrorLog, "Json Encode: %s", err)
|
||||
} else {
|
||||
r.MqttClient.Publish(trig.MqttTopic, 0, true, data)
|
||||
r.Log(SendLog, "-> [MQTT] %s: %s", trig.MqttTopic, string(data))
|
||||
}
|
||||
r.MqttClient.Publish(trig.MqttTopic, 0, true, trig.MqttPayload)
|
||||
r.Log(SendLog, "-> [MQTT] %s", trig.MqttTopic)
|
||||
} else {
|
||||
payload := MQTTPayload{
|
||||
Channel: channel,
|
||||
@ -203,7 +196,7 @@ func (r *MidiRouter) sendRequest(channel, note, velocity uint8) {
|
||||
r.Log(ErrorLog, "Json Encode: %s", err)
|
||||
} else {
|
||||
r.MqttClient.Publish(trig.MqttTopic, 0, true, data)
|
||||
r.Log(SendLog, "-> [MQTT] %s: %s", trig.MqttTopic, string(data))
|
||||
r.Log(SendLog, "-> [MQTT] %s", trig.MqttTopic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user