X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fmidi_mapper.h;h=72272a1846fdf803b02d842551c29de8236ec33b;hb=6cf87ad853439f8565c575fb29dc539a15fdba87;hp=42bf19a64aeb68388fe41722bf1727d4dcde1431;hpb=392f9d1ccb835c05a3874c4bea163788b2c37024;p=nageru diff --git a/nageru/midi_mapper.h b/nageru/midi_mapper.h index 42bf19a..72272a1 100644 --- a/nageru/midi_mapper.h +++ b/nageru/midi_mapper.h @@ -1,9 +1,9 @@ #ifndef _MIDI_MAPPER_H #define _MIDI_MAPPER_H 1 -// MIDIMapper is a class that listens for incoming MIDI messages from -// mixer controllers (ie., it is not meant to be used with regular -// instruments), interprets them according to a device-specific, user-defined +// MIDIMapper is a class that gets incoming MIDI messages from mixer +// controllers (ie., it is not meant to be used with regular instruments) +// via MIDIDevice, interprets them according to a device-specific, user-defined // mapping, and calls back into a receiver (typically the MainWindow). // This way, it is possible to control audio functionality using physical // pots and faders instead of the mouse. @@ -13,16 +13,13 @@ #include #include #include -#include #include #include #include "defs.h" +#include "shared/midi_device.h" class MIDIMappingProto; -typedef struct snd_seq_addr snd_seq_addr_t; -typedef struct snd_seq_event snd_seq_event_t; -typedef struct _snd_seq snd_seq_t; // Interface for receiving interpreted controller messages. class ControllerReceiver { @@ -50,6 +47,14 @@ public: virtual void toggle_limiter() = 0; virtual void toggle_auto_makeup_gain() = 0; + // Non-audio events. + virtual void switch_video_channel(int channel_number) = 0; + virtual void apply_transition(int transition_number) = 0; + virtual void prev_audio_view() = 0; + virtual void next_audio_view() = 0; + virtual void begin_new_segment() = 0; + virtual void exit() = 0; + // Signals to highlight controls to mark them to the user // as MIDI-controllable (or not). virtual void clear_all_highlights() = 0; @@ -79,7 +84,7 @@ public: virtual void note_on(unsigned note) = 0; }; -class MIDIMapper { +class MIDIMapper : public MIDIReceiver { public: MIDIMapper(ControllerReceiver *receiver); virtual ~MIDIMapper(); @@ -98,10 +103,12 @@ public: this->has_peaked[bus_idx] = has_peaked; } + // MIDIReceiver. + void controller_received(int controller, int value) override; + void note_on_received(int note) override; + void update_num_subscribers(unsigned num_subscribers) override; + 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 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. @@ -110,11 +117,9 @@ 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); + void activate_lights_all_buses(int field_number, std::map *active_lights); std::atomic should_quit{false}; - int should_quit_fd; std::atomic has_peaked[MAX_BUSES] {{ false }}; @@ -125,10 +130,7 @@ private: std::atomic current_controller_bank{0}; std::atomic num_subscribed_ports{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 . + MIDIDevice midi_device; }; bool load_midi_mapping_from_file(const std::string &filename, MIDIMappingProto *new_mapping);