]> git.sesse.net Git - nageru/blobdiff - futatabi/midi_mapper.cpp
Add support for a master speed MIDI light.
[nageru] / futatabi / midi_mapper.cpp
index 93e367a77aa1ad0987c1a0f40e38372f90c0f14f..c675820fb3a40ef3a3244818a0fdb249a5460858 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>
@@ -245,6 +246,15 @@ void MIDIMapper::update_lights_lock_held()
                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 - 1) * 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::kCueInEnabledFieldNumber, &active_lights);
        activate_mapped_light(*mapping_proto, MIDIMappingProto::kCueOutEnabledFieldNumber, &active_lights);