X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=midi_mapper.cpp;h=4f8c33bf4ca25071f21e5e93f5a180159520fb41;hb=5cd2e667b7531777991c98dc6d3249e95b98314c;hp=6395ff7381a25a008214188449e2f4c22ed53a6c;hpb=7a81f05c63a992acf4a859fd1136700e1d8b98ac;p=nageru diff --git a/midi_mapper.cpp b/midi_mapper.cpp index 6395ff7..4f8c33b 100644 --- a/midi_mapper.cpp +++ b/midi_mapper.cpp @@ -1,18 +1,25 @@ #include "midi_mapper.h" -#include "audio_mixer.h" -#include "midi_mapping.pb.h" - #include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include - +#include +#include #include #include +#include "audio_mixer.h" +#include "midi_mapping.pb.h" + using namespace google::protobuf; using namespace std; using namespace std::placeholders; @@ -38,7 +45,6 @@ MIDIMapper::MIDIMapper(ControllerReceiver *receiver) { should_quit_fd = eventfd(/*initval=*/0, /*flags=*/0); assert(should_quit_fd != -1); - refresh_highlights(); } MIDIMapper::~MIDIMapper() @@ -240,8 +246,6 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event) lock_guard lock(mu); switch (event->type) { case SND_SEQ_EVENT_CONTROLLER: { - printf("Controller %d changed to %d\n", event->data.control.param, event->data.control.value); - const int controller = event->data.control.param; const float value = map_controller_to_float(event->data.control.value); @@ -275,8 +279,6 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event) receiver->note_on(note); - printf("Note: %d\n", note); - for (size_t bus_idx = 0; bus_idx < size_t(mapping_proto->bus_mapping_size()); ++bus_idx) { const MIDIMappingBusProto &bus_mapping = mapping_proto->bus_mapping(bus_idx); if (bus_mapping.has_prev_bank() && @@ -335,6 +337,8 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event) bind(&ControllerReceiver::toggle_compressor, receiver, _1)); match_button(note, MIDIMappingBusProto::kClearPeakFieldNumber, MIDIMappingProto::kClearPeakBankFieldNumber, bind(&ControllerReceiver::clear_peak, receiver, _1)); + match_button(note, MIDIMappingBusProto::kToggleMuteFieldNumber, MIDIMappingProto::kClearPeakBankFieldNumber, + bind(&ControllerReceiver::toggle_mute, receiver, _1)); match_button(note, MIDIMappingBusProto::kToggleLimiterFieldNumber, MIDIMappingProto::kToggleLimiterBankFieldNumber, bind(&ControllerReceiver::toggle_limiter, receiver)); match_button(note, MIDIMappingBusProto::kToggleAutoMakeupGainFieldNumber, MIDIMappingProto::kToggleAutoMakeupGainBankFieldNumber, @@ -346,13 +350,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 +485,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; @@ -515,6 +538,8 @@ void MIDIMapper::update_highlights() bus_idx, MIDIMappingBusProto::kCompressorThresholdFieldNumber, MIDIMappingProto::kCompressorThresholdBankFieldNumber)); receiver->highlight_fader(bus_idx, has_active_controller( bus_idx, MIDIMappingBusProto::kFaderFieldNumber, MIDIMappingProto::kFaderBankFieldNumber)); + receiver->highlight_mute(bus_idx, has_active_controller( + bus_idx, MIDIMappingBusProto::kToggleMuteFieldNumber, MIDIMappingProto::kToggleMuteBankFieldNumber)); receiver->highlight_toggle_locut(bus_idx, has_active_controller( bus_idx, MIDIMappingBusProto::kToggleLocutFieldNumber, MIDIMappingProto::kToggleLocutBankFieldNumber)); receiver->highlight_toggle_auto_gain_staging(bus_idx, has_active_controller( @@ -554,6 +579,9 @@ void MIDIMapper::update_lights_lock_held() } unsigned num_buses = min(global_audio_mixer->num_buses(), mapping_proto->bus_mapping_size()); for (unsigned bus_idx = 0; bus_idx < num_buses; ++bus_idx) { + if (global_audio_mixer->get_mute(bus_idx)) { + activate_lights(bus_idx, MIDIMappingBusProto::kIsMutedFieldNumber, &active_lights); + } if (global_audio_mixer->get_locut_enabled(bus_idx)) { activate_lights(bus_idx, MIDIMappingBusProto::kLocutIsOnFieldNumber, &active_lights); }