]> git.sesse.net Git - nageru/commitdiff
Don't highlight any controllers if no MIDI controller is attached.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Oct 2016 20:31:05 +0000 (22:31 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 25 Oct 2016 16:48:35 +0000 (18:48 +0200)
Previously, we'd highlight unconditionally as long as we had a
MIDI mapping loaded.

midi_mapper.cpp
midi_mapper.h

index 6395ff7381a25a008214188449e2f4c22ed53a6c..ba996e8f4fab580f5eaf6b388b670b7ed8c7d3b5 100644 (file)
@@ -346,13 +346,27 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event)
        case SND_SEQ_EVENT_PORT_EXIT:
                printf("MIDI port %d:%d went away.\n", event->data.addr.client, event->data.addr.port);
                break;
+       case SND_SEQ_EVENT_PORT_SUBSCRIBED:
+               if (event->data.connect.sender.client != 0 &&  // Ignore system senders.
+                   event->data.connect.sender.client != snd_seq_client_id(seq) &&
+                   event->data.connect.dest.client == snd_seq_client_id(seq)) {
+                       ++num_subscribed_ports;
+                       update_highlights();
+               }
+               break;
+       case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
+               if (event->data.connect.sender.client != 0 &&  // Ignore system senders.
+                   event->data.connect.sender.client != snd_seq_client_id(seq) &&
+                   event->data.connect.dest.client == snd_seq_client_id(seq)) {
+                       --num_subscribed_ports;
+                       update_highlights();
+               }
+               break;
        case SND_SEQ_EVENT_NOTEOFF:
        case SND_SEQ_EVENT_CLIENT_START:
        case SND_SEQ_EVENT_CLIENT_EXIT:
        case SND_SEQ_EVENT_CLIENT_CHANGE:
        case SND_SEQ_EVENT_PORT_CHANGE:
-       case SND_SEQ_EVENT_PORT_SUBSCRIBED:
-       case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
                break;
        default:
                printf("Ignoring MIDI event of unknown type %d.\n", event->type);
@@ -467,6 +481,11 @@ void MIDIMapper::refresh_lights()
 
 void MIDIMapper::update_highlights()
 {
+       if (num_subscribed_ports.load() == 0) {
+               receiver->clear_all_highlights();
+               return;
+       }
+
        // Global controllers.
        bool highlight_locut = false;
        bool highlight_limiter_threshold = false;
index be785ecdc709095340dbbe3cd98ccfd9a67174a8..62746165370c2eb9ac24f21ea1217aa8e5e3a782 100644 (file)
@@ -117,6 +117,7 @@ private:
        std::unique_ptr<MIDIMappingProto> mapping_proto;  // Under <mu>.
        int num_controller_banks;  // Under <mu>.
        std::atomic<int> current_controller_bank{0};
+       std::atomic<int> num_subscribed_ports{0};
 
        std::thread midi_thread;
        std::map<unsigned, bool> current_light_status;  // Keyed by note number. Under <mu>.