X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmidi_device.h;h=ec6bf9b5a160b5ededf14600744435a96ef0e951;hb=e15251d2787cb8e6b677af801de6180e55171763;hp=498443931ab368ba931d2ead88192a969a27b116;hpb=beead04c23b42c815f448cd0126d87f9627bbfde;p=nageru diff --git a/shared/midi_device.h b/shared/midi_device.h index 4984439..ec6bf9b 100644 --- a/shared/midi_device.h +++ b/shared/midi_device.h @@ -7,7 +7,6 @@ #include #include #include -#include #include typedef struct snd_seq_addr snd_seq_addr_t; @@ -29,13 +28,26 @@ public: class MIDIDevice { public: + struct LightKey { + enum { NOTE, CONTROLLER } type; + unsigned number; + + bool operator< (const LightKey& other) const + { + if (type != other.type) { + return type < other.type; + } + return number < other.number; + } + }; + MIDIDevice(MIDIReceiver *receiver); ~MIDIDevice(); void start_thread(); - void update_lights(const std::set &active_lights) + void update_lights(const std::map &active_lights) { - std::lock_guard lock(mu); + std::lock_guard lock(mu); update_lights_lock_held(active_lights); } @@ -43,16 +55,16 @@ private: void thread_func(); void handle_event(snd_seq_t *seq, snd_seq_event_t *event); void subscribe_to_port_lock_held(snd_seq_t *seq, const snd_seq_addr_t &addr); - void update_lights_lock_held(const std::set &active_lights); + void update_lights_lock_held(const std::map &active_lights); std::atomic should_quit{false}; int should_quit_fd; - mutable std::mutex mu; + mutable std::recursive_mutex mu; // Recursive because the MIDI receiver may update_lights() back while we are sending it stuff. MIDIReceiver *receiver; // Under . std::thread midi_thread; - std::map current_light_status; // Keyed by note number. Under . + std::map current_light_status; // Keyed by note number. Under . snd_seq_t *alsa_seq{nullptr}; // Under . int alsa_queue_id{-1}; // Under . std::atomic num_subscribed_ports{0};