]> git.sesse.net Git - nageru/blobdiff - futatabi/midi_mapper.cpp
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / midi_mapper.cpp
index d1cfea245178246031397a423625273a602c0cca..9cfb3be6749e2f9234fe81c2fde5fb6bbd926da1 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 <math.h>
 #include <pthread.h>
 #include <poll.h>
 #include <stdint.h>
@@ -16,6 +17,7 @@
 #include <unistd.h>
 #include <algorithm>
 #include <functional>
+#include <map>
 #include <thread>
 
 #include "defs.h"
@@ -141,6 +143,8 @@ void MIDIMapper::note_on_received(int note)
                bind(&ControllerReceiver::queue, receiver));
        match_button(note, MIDIMappingProto::kPlayFieldNumber, MIDIMappingProto::kPlayBankFieldNumber,
                bind(&ControllerReceiver::play, receiver));
+       match_button(note, MIDIMappingProto::kNextFieldNumber, MIDIMappingProto::kNextButtonBankFieldNumber,
+               bind(&ControllerReceiver::next, receiver));
        match_button(note, MIDIMappingProto::kToggleLockFieldNumber, MIDIMappingProto::kToggleLockBankFieldNumber,
                bind(&ControllerReceiver::toggle_lock, receiver));
 
@@ -205,7 +209,7 @@ void MIDIMapper::refresh_lights()
 
 void MIDIMapper::update_lights_lock_held()
 {
-       set<unsigned> active_lights;  // Desired state.
+       map<MIDIDevice::LightKey, uint8_t> active_lights;  // Desired state.
        if (current_controller_bank == 0) {
                activate_mapped_light(*mapping_proto, MIDIMappingProto::kBank1IsSelectedFieldNumber, &active_lights);
        }
@@ -221,26 +225,44 @@ void MIDIMapper::update_lights_lock_held()
        if (current_controller_bank == 4) {
                activate_mapped_light(*mapping_proto, MIDIMappingProto::kBank5IsSelectedFieldNumber, &active_lights);
        }
-       if (preview_enabled_light) {
-               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPreviewEnabledFieldNumber, &active_lights);
+       if (preview_enabled_light == On) {  // Playing.
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPreviewPlayingFieldNumber, &active_lights);
+       } else if (preview_enabled_light == Blinking) {  // Preview ready.
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPreviewReadyFieldNumber, &active_lights);
        }
        if (queue_enabled_light) {
                activate_mapped_light(*mapping_proto, MIDIMappingProto::kQueueEnabledFieldNumber, &active_lights);
        }
-       if (play_enabled_light) {
-               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPlayEnabledFieldNumber, &active_lights);
+       if (play_enabled_light == On) {  // Playing.
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPlayingFieldNumber, &active_lights);
+       } else if (play_enabled_light == Blinking) {  // Play ready.
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kPlayReadyFieldNumber, &active_lights);
        }
-       if (locked_light) {
+       if (next_ready_light == On) {
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kNextReadyFieldNumber, &active_lights);
+       }
+       if (locked_light == On) {
                activate_mapped_light(*mapping_proto, MIDIMappingProto::kLockedFieldNumber, &active_lights);
+       } else if (locked_light == Blinking) {
+               activate_mapped_light(*mapping_proto, MIDIMappingProto::kLockedBlinkingFieldNumber, &active_lights);
        }
        if (current_highlighted_camera >= 0 && current_highlighted_camera < mapping_proto->camera_size()) {
                const CameraMIDIMappingProto &camera = mapping_proto->camera(current_highlighted_camera);
                activate_mapped_light(camera, CameraMIDIMappingProto::kIsCurrentFieldNumber, &active_lights);
        }
 
+       // Master speed light.
+       if (mapping_proto->has_master_speed_light()) {
+               unsigned controller = mapping_proto->master_speed_light().controller_number();
+               unsigned min = mapping_proto->master_speed_light_min();
+               unsigned max = mapping_proto->master_speed_light_max();
+               int speed_light_value = lrintf((max - min) * current_speed / 2.0f) + min;
+               active_lights[MIDIDevice::LightKey{MIDIDevice::LightKey::CONTROLLER, controller}] = speed_light_value;
+       }
+
        // These are always enabled right now.
-       activate_mapped_light(*mapping_proto, MIDIMappingProto::kCueInFieldNumber, &active_lights);
-       activate_mapped_light(*mapping_proto, MIDIMappingProto::kCueOutFieldNumber, &active_lights);
+       activate_mapped_light(*mapping_proto, MIDIMappingProto::kCueInEnabledFieldNumber, &active_lights);
+       activate_mapped_light(*mapping_proto, MIDIMappingProto::kCueOutEnabledFieldNumber, &active_lights);
 
        midi_device.update_lights(active_lights);
 }