X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fmidi_mapper.cpp;h=2fd6dbb9ab04c11e72fb9c8efb1f97125c128f74;hb=HEAD;hp=fe62546569c4defca910c6a06f917244bcaf7b37;hpb=beead04c23b42c815f448cd0126d87f9627bbfde;p=nageru diff --git a/nageru/midi_mapper.cpp b/nageru/midi_mapper.cpp index fe62546..e7b9068 100644 --- a/nageru/midi_mapper.cpp +++ b/nageru/midi_mapper.cpp @@ -1,22 +1,16 @@ #include "midi_mapper.h" -#include #include -#include -#include #include -#include #include -#include -#include +#include +#include #include #include #include -#include -#include +#include #include #include -#include #include "audio_mixer.h" #include "nageru_midi_mapping.pb.h" @@ -28,37 +22,6 @@ using namespace google::protobuf; using namespace std; using namespace std::placeholders; -namespace { - -double map_controller_to_float(int controller, int val) -{ - if (controller == MIDIReceiver::PITCH_BEND_CONTROLLER) { - // We supposedly go from -8192 to 8191 (inclusive), but there are - // controllers that only have 10-bit precision and do the upconversion - // to 14-bit wrong (just padding with zeros), making 8176 the highest - // attainable value. We solve this by making the effective range - // -8176..8176 (inclusive). - if (val <= -8176) { - return 0.0; - } else if (val >= 8176) { - return 1.0; - } else { - return 0.5 * (double(val) / 8176.0) + 0.5; - } - } - - // Slightly hackish mapping so that we can represent exactly 0.0, 0.5 and 1.0. - if (val <= 0) { - return 0.0; - } else if (val >= 127) { - return 1.0; - } else { - return (val + 0.5) / 127.0; - } -} - -} // namespace - MIDIMapper::MIDIMapper(ControllerReceiver *receiver) : receiver(receiver), mapping_proto(new MIDIMappingProto), midi_device(this) { @@ -86,7 +49,7 @@ void MIDIMapper::set_midi_mapping(const MIDIMappingProto &new_mapping) } num_controller_banks = min(max(mapping_proto->num_controller_banks(), 1), 5); - current_controller_bank = 0; + current_controller_bank = 0; receiver->clear_all_highlights(); update_highlights(); @@ -210,6 +173,18 @@ void MIDIMapper::note_on_received(int note) bind(&ControllerReceiver::toggle_limiter, receiver)); match_button(note, MIDIMappingBusProto::kToggleAutoMakeupGainFieldNumber, MIDIMappingProto::kToggleAutoMakeupGainBankFieldNumber, bind(&ControllerReceiver::toggle_auto_makeup_gain, receiver)); + match_button(note, MIDIMappingBusProto::kSwitchVideoChannelFieldNumber, MIDIMappingProto::kSwitchVideoChannelBankFieldNumber, + bind(&ControllerReceiver::switch_video_channel, receiver, _1)); + match_button(note, MIDIMappingBusProto::kApplyTransitionFieldNumber, MIDIMappingProto::kApplyTransitionBankFieldNumber, + bind(&ControllerReceiver::apply_transition, receiver, _1)); + match_button(note, MIDIMappingBusProto::kPrevAudioViewFieldNumber, MIDIMappingProto::kPrevAudioViewBankFieldNumber, + bind(&ControllerReceiver::prev_audio_view, receiver)); + match_button(note, MIDIMappingBusProto::kNextAudioViewFieldNumber, MIDIMappingProto::kNextAudioViewBankFieldNumber, + bind(&ControllerReceiver::prev_audio_view, receiver)); + match_button(note, MIDIMappingBusProto::kBeginNewVideoSegmentFieldNumber, MIDIMappingProto::kBeginNewVideoSegmentBankFieldNumber, + bind(&ControllerReceiver::begin_new_segment, receiver)); + match_button(note, MIDIMappingBusProto::kExitFieldNumber, MIDIMappingProto::kExitBankFieldNumber, + bind(&ControllerReceiver::exit, receiver)); } void MIDIMapper::update_num_subscribers(unsigned num_subscribers) @@ -349,7 +324,7 @@ void MIDIMapper::update_lights_lock_held() return; } - set active_lights; // Desired state. + map active_lights; // Desired state. if (current_controller_bank == 0) { activate_lights_all_buses(MIDIMappingBusProto::kBank1IsSelectedFieldNumber, &active_lights); } @@ -394,7 +369,7 @@ void MIDIMapper::update_lights_lock_held() midi_device.update_lights(active_lights); } -void MIDIMapper::activate_lights_all_buses(int field_number, set *active_lights) +void MIDIMapper::activate_lights_all_buses(int field_number, map *active_lights) { 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);