#include "midi_mapper.h"
-#include "audio_mixer.h"
-#include "midi_mapping.pb.h"
-
#include <alsa/asoundlib.h>
-#include <google/protobuf/text_format.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <assert.h>
+#include <errno.h>
#include <fcntl.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/text_format.h>
+#include <poll.h>
+#include <stdint.h>
+#include <stdio.h>
#include <sys/eventfd.h>
-
+#include <unistd.h>
+#include <algorithm>
#include <functional>
#include <thread>
+#include "audio_mixer.h"
+#include "midi_mapping.pb.h"
+
using namespace google::protobuf;
using namespace std;
using namespace std::placeholders;
{
should_quit_fd = eventfd(/*initval=*/0, /*flags=*/0);
assert(should_quit_fd != -1);
- refresh_highlights();
}
MIDIMapper::~MIDIMapper()
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,
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);
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;
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(
}
unsigned num_buses = min<unsigned>(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);
}