X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmidi_mapper_util.h;h=072494e07606dee1f576e2f1e6ef8574189535ff;hb=f9a11c73b0c2ff2d44d79f856998f8cbfc88a478;hp=07f2a53b4241dd7f69b71b62e12de93e83775659;hpb=873c8b204ab70622f6e231556cc94d3aab1889ce;p=nageru diff --git a/shared/midi_mapper_util.h b/shared/midi_mapper_util.h index 07f2a53..072494e 100644 --- a/shared/midi_mapper_util.h +++ b/shared/midi_mapper_util.h @@ -7,31 +7,43 @@ #include template -inline bool match_controller_helper(const Proto &msg, int field_number, int controller) +inline int get_controller_mapping_helper(const Proto &msg, int field_number, int default_value) { using namespace google::protobuf; const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number); const Reflection *reflection = msg.GetReflection(); if (!reflection->HasField(msg, descriptor)) { - return false; + return default_value; } const MIDIControllerProto &controller_proto = static_cast(reflection->GetMessage(msg, descriptor)); - return (controller_proto.controller_number() == controller); + return controller_proto.controller_number(); } template -inline bool match_button_helper(const Proto &msg, int field_number, int note) +inline bool match_controller_helper(const Proto &msg, int field_number, int controller) +{ + return (get_controller_mapping_helper(msg, field_number, -1) == controller); +} + +template +inline int get_button_mapping_helper(const Proto &msg, int field_number, int default_value) { using namespace google::protobuf; const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number); const Reflection *reflection = msg.GetReflection(); if (!reflection->HasField(msg, descriptor)) { - return false; + return default_value; } const MIDIButtonProto &button_proto = static_cast(reflection->GetMessage(msg, descriptor)); - return (button_proto.note_number() == note); + return button_proto.note_number(); +} + +template +inline bool match_button_helper(const Proto &msg, int field_number, int note) +{ + return (get_button_mapping_helper(msg, field_number, -1) == note); } template @@ -49,7 +61,7 @@ inline bool match_bank_helper(const Proto &msg, int bank_field_number, int bank) // Find what MIDI note the given light (as given by field_number) is mapped to, and enable it. template -void activate_mapped_light(const Proto &msg, int field_number, std::map *active_lights) +void activate_mapped_light(const Proto &msg, int field_number, std::map *active_lights) { using namespace google::protobuf; const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number); @@ -59,7 +71,8 @@ void activate_mapped_light(const Proto &msg, int field_number, std::map(reflection->GetMessage(msg, descriptor)); - active_lights->emplace(light_proto.note_number(), light_proto.velocity()); + active_lights->emplace(MIDIDevice::LightKey{MIDIDevice::LightKey::NOTE, unsigned(light_proto.note_number())}, + light_proto.velocity()); } inline double map_controller_to_float(int controller, int val)