]> git.sesse.net Git - nageru/commitdiff
Move another helper into midi_mapper_util.h.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 8 Jan 2019 21:40:33 +0000 (22:40 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 8 Jan 2019 21:40:33 +0000 (22:40 +0100)
nageru/midi_mapper.cpp
shared/midi_mapper_util.h

index 59637b1d24107473893f8487227c270942a19058..7457fbb53f99082a292c5c8699e6fd01e28fd103 100644 (file)
@@ -327,19 +327,6 @@ void MIDIMapper::update_highlights()
        }
 }
 
-// Find what MIDI note the given light (as given by field_number) is mapped to, and enable it.
-void activate_mapped_light(const MIDIMappingBusProto &bus_mapping, int field_number, set<unsigned> *active_lights)
-{
-       const FieldDescriptor *descriptor = bus_mapping.GetDescriptor()->FindFieldByNumber(field_number);
-       const Reflection *bus_reflection = bus_mapping.GetReflection();
-       if (!bus_reflection->HasField(bus_mapping, descriptor)) {
-               return;
-       }
-       const MIDILightProto &light_proto =
-               static_cast<const MIDILightProto &>(bus_reflection->GetMessage(bus_mapping, descriptor));
-       active_lights->insert(light_proto.note_number());
-}
-
 void MIDIMapper::update_lights_lock_held()
 {
        if (global_audio_mixer == nullptr) {
index bc9b1bf164c83921a44c74b897eb52d7f2005e45..39ccd84e43f7d1ec1e707e2de730ea1d08ad59d9 100644 (file)
@@ -46,4 +46,19 @@ 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 <class Proto>
+void activate_mapped_light(const Proto &msg, int field_number, std::set<unsigned> *active_lights)
+{
+       using namespace google::protobuf;
+       const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number);
+       const Reflection *reflection = msg.GetReflection();
+       if (!reflection->HasField(msg, descriptor)) {
+               return;
+       }
+       const MIDILightProto &light_proto =
+               static_cast<const MIDILightProto &>(reflection->GetMessage(msg, descriptor));
+       active_lights->insert(light_proto.note_number());
+}
+
 #endif  // !defined(_MIDI_MAPPER_UTIL_H)