X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=midi_mapper.h;fp=midi_mapper.h;h=be785ecdc709095340dbbe3cd98ccfd9a67174a8;hb=7a81f05c63a992acf4a859fd1136700e1d8b98ac;hp=49c98cc31676d142d8d01b314556fe3e033965f7;hpb=2068106ac4d44719e78d2931ccbe2fe67947b381;p=nageru diff --git a/midi_mapper.h b/midi_mapper.h index 49c98cc..be785ec 100644 --- a/midi_mapper.h +++ b/midi_mapper.h @@ -10,11 +10,15 @@ #include #include +#include #include #include +#include #include #include +#include "defs.h" + class MIDIMappingProto; typedef struct snd_seq_addr snd_seq_addr_t; typedef struct snd_seq_event snd_seq_event_t; @@ -81,11 +85,17 @@ public: ControllerReceiver *set_receiver(ControllerReceiver *new_receiver); void refresh_highlights(); + void refresh_lights(); + + void set_has_peaked(unsigned bus_idx, bool has_peaked) + { + this->has_peaked[bus_idx] = has_peaked; + } private: void thread_func(); void handle_event(snd_seq_t *seq, snd_seq_event_t *event); - void subscribe_to_port(snd_seq_t *seq, const snd_seq_addr_t &addr); + void subscribe_to_port_lock_held(snd_seq_t *seq, const snd_seq_addr_t &addr); void match_controller(int controller, int field_number, int bank_field_number, float value, std::function func); void match_button(int note, int field_number, int bank_field_number, std::function func); bool has_active_controller(unsigned bus_idx, int field_number, int bank_field_number); // Also works for buttons. @@ -93,16 +103,25 @@ private: void update_highlights(); + void update_lights_lock_held(); + void activate_lights(unsigned bus_idx, int field_number, std::set *active_lights); + void activate_lights_all_buses(int field_number, std::set *active_lights); + std::atomic should_quit{false}; int should_quit_fd; - mutable std::mutex mapping_mu; - ControllerReceiver *receiver; // Under . - std::unique_ptr mapping_proto; // Under . - int num_controller_banks; // Under . + std::atomic has_peaked[MAX_BUSES] {{ false }}; + + mutable std::mutex mu; + ControllerReceiver *receiver; // Under . + std::unique_ptr mapping_proto; // Under . + int num_controller_banks; // Under . std::atomic current_controller_bank{0}; std::thread midi_thread; + std::map current_light_status; // Keyed by note number. Under . + snd_seq_t *alsa_seq{nullptr}; // Under . + int alsa_queue_id{-1}; // Under . }; bool load_midi_mapping_from_file(const std::string &filename, MIDIMappingProto *new_mapping);