2 #define _MIDI_DEVICE_H 1
4 // MIDIDevice is a class that pools incoming MIDI messages from
5 // all MIDI devices in the system, decodes them and sends them on.
13 typedef struct snd_seq_addr snd_seq_addr_t;
14 typedef struct snd_seq_event snd_seq_event_t;
15 typedef struct _snd_seq snd_seq_t;
19 virtual ~MIDIReceiver() {}
20 virtual void controller_received(int controller, int value) = 0;
21 virtual void note_on_received(int note) = 0;
22 virtual void update_num_subscribers(unsigned num_subscribers) = 0;
27 MIDIDevice(MIDIReceiver *receiver);
31 void update_lights(const std::set<unsigned> &active_lights)
33 std::lock_guard<std::mutex> lock(mu);
34 update_lights_lock_held(active_lights);
39 void handle_event(snd_seq_t *seq, snd_seq_event_t *event);
40 void subscribe_to_port_lock_held(snd_seq_t *seq, const snd_seq_addr_t &addr);
41 void update_lights_lock_held(const std::set<unsigned> &active_lights);
43 std::atomic<bool> should_quit{false};
46 mutable std::mutex mu;
47 MIDIReceiver *receiver; // Under <mu>.
49 std::thread midi_thread;
50 std::map<unsigned, bool> current_light_status; // Keyed by note number. Under <mu>.
51 snd_seq_t *alsa_seq{nullptr}; // Under <mu>.
52 int alsa_queue_id{-1}; // Under <mu>.
53 std::atomic<int> num_subscribed_ports{0};
56 #endif // !defined(_MIDI_DEVICE_H)