]> git.sesse.net Git - nageru/blobdiff - midi_mapper.cpp
Small optimization.
[nageru] / midi_mapper.cpp
index 4f0fb48c2da350ad75a5096bea49d003043ba23a..d03f38211e524a2fcb85b70c96cddc4c958b46d9 100644 (file)
@@ -8,6 +8,7 @@
 #include <google/protobuf/io/zero_copy_stream_impl.h>
 #include <google/protobuf/message.h>
 #include <google/protobuf/text_format.h>
+#include <pthread.h>
 #include <poll.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -45,14 +46,16 @@ MIDIMapper::MIDIMapper(ControllerReceiver *receiver)
 {
        should_quit_fd = eventfd(/*initval=*/0, /*flags=*/0);
        assert(should_quit_fd != -1);
-       refresh_highlights();
 }
 
 MIDIMapper::~MIDIMapper()
 {
        should_quit = true;
        const uint64_t one = 1;
-       write(should_quit_fd, &one, sizeof(one));
+       if (write(should_quit_fd, &one, sizeof(one)) != sizeof(one)) {
+               perror("write(should_quit_fd)");
+               exit(1);
+       }
        midi_thread.join();
        close(should_quit_fd);
 }
@@ -146,6 +149,8 @@ ControllerReceiver *MIDIMapper::set_receiver(ControllerReceiver *new_receiver)
 
 void MIDIMapper::thread_func()
 {
+       pthread_setname_np(pthread_self(), "MIDIMapper");
+
        snd_seq_t *seq;
        int err;
 
@@ -247,8 +252,6 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event)
        lock_guard<mutex> 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);
 
@@ -282,8 +285,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() &&
@@ -348,6 +349,7 @@ void MIDIMapper::handle_event(snd_seq_t *seq, snd_seq_event_t *event)
                        bind(&ControllerReceiver::toggle_limiter, receiver));
                match_button(note, MIDIMappingBusProto::kToggleAutoMakeupGainFieldNumber, MIDIMappingProto::kToggleAutoMakeupGainBankFieldNumber,
                        bind(&ControllerReceiver::toggle_auto_makeup_gain, receiver));
+               break;
        }
        case SND_SEQ_EVENT_PORT_START:
                subscribe_to_port_lock_held(seq, event->data.addr);