X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmidi_mapper_util.h;h=c9c96bb9516dbd31cf81699b144d19449a0b84eb;hb=55bc1e47c47dfdeeec06c55de9a53b95bdbbd326;hp=072494e07606dee1f576e2f1e6ef8574189535ff;hpb=9921f1fe12f5a7dadab7e84069fa8591d5c5663d;p=nageru diff --git a/shared/midi_mapper_util.h b/shared/midi_mapper_util.h index 072494e..c9c96bb 100644 --- a/shared/midi_mapper_util.h +++ b/shared/midi_mapper_util.h @@ -59,18 +59,26 @@ inline bool match_bank_helper(const Proto &msg, int bank_field_number, int bank) return reflection->GetInt32(msg, bank_descriptor) == 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) +inline MIDILightProto get_light_mapping_helper(const Proto &msg, int field_number) { using namespace google::protobuf; const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number); const Reflection *reflection = msg.GetReflection(); if (!reflection->HasField(msg, descriptor)) { + return MIDILightProto(); + } + return static_cast(reflection->GetMessage(msg, descriptor)); +} + +// 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) +{ + MIDILightProto light_proto = get_light_mapping_helper(msg, field_number); + if (!light_proto.has_note_number()) { return; } - const MIDILightProto &light_proto = - static_cast(reflection->GetMessage(msg, descriptor)); active_lights->emplace(MIDIDevice::LightKey{MIDIDevice::LightKey::NOTE, unsigned(light_proto.note_number())}, light_proto.velocity()); }