From c7627f3f46ca3ec755e301dde2fca2f6e244f64d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 8 Jan 2019 22:40:33 +0100 Subject: [PATCH] Move another helper into midi_mapper_util.h. --- nageru/midi_mapper.cpp | 13 ------------- shared/midi_mapper_util.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/nageru/midi_mapper.cpp b/nageru/midi_mapper.cpp index 59637b1..7457fbb 100644 --- a/nageru/midi_mapper.cpp +++ b/nageru/midi_mapper.cpp @@ -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 *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(bus_reflection->GetMessage(bus_mapping, descriptor)); - active_lights->insert(light_proto.note_number()); -} - void MIDIMapper::update_lights_lock_held() { if (global_audio_mixer == nullptr) { diff --git a/shared/midi_mapper_util.h b/shared/midi_mapper_util.h index bc9b1bf..39ccd84 100644 --- a/shared/midi_mapper_util.h +++ b/shared/midi_mapper_util.h @@ -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 +void activate_mapped_light(const Proto &msg, int field_number, std::set *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(reflection->GetMessage(msg, descriptor)); + active_lights->insert(light_proto.note_number()); +} + #endif // !defined(_MIDI_MAPPER_UTIL_H) -- 2.39.2