1 #ifndef _MIDI_MAPPER_UTIL_H
2 #define _MIDI_MAPPER_UTIL_H 1
4 #include "midi_mapping.pb.h"
6 #include <google/protobuf/descriptor.h>
9 inline bool match_controller_helper(const Proto &msg, int field_number, int controller)
11 using namespace google::protobuf;
12 const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number);
13 const Reflection *reflection = msg.GetReflection();
14 if (!reflection->HasField(msg, descriptor)) {
17 const MIDIControllerProto &controller_proto =
18 static_cast<const MIDIControllerProto &>(reflection->GetMessage(msg, descriptor));
19 return (controller_proto.controller_number() == controller);
22 template <class Proto>
23 inline bool match_button_helper(const Proto &msg, int field_number, int note)
25 using namespace google::protobuf;
26 const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number);
27 const Reflection *reflection = msg.GetReflection();
28 if (!reflection->HasField(msg, descriptor)) {
31 const MIDIButtonProto &button_proto =
32 static_cast<const MIDIButtonProto &>(reflection->GetMessage(msg, descriptor));
33 return (button_proto.note_number() == note);
36 template <class Proto>
37 inline bool match_bank_helper(const Proto &msg, int bank_field_number, int bank)
39 using namespace google::protobuf;
40 const FieldDescriptor *bank_descriptor = msg.GetDescriptor()->FindFieldByNumber(bank_field_number);
41 const Reflection *reflection = msg.GetReflection();
42 if (!reflection->HasField(msg, bank_descriptor)) {
43 // No bank set => in all banks.
46 return reflection->GetInt32(msg, bank_descriptor) == bank;
49 // Find what MIDI note the given light (as given by field_number) is mapped to, and enable it.
50 template <class Proto>
51 void activate_mapped_light(const Proto &msg, int field_number, std::set<unsigned> *active_lights)
53 using namespace google::protobuf;
54 const FieldDescriptor *descriptor = msg.GetDescriptor()->FindFieldByNumber(field_number);
55 const Reflection *reflection = msg.GetReflection();
56 if (!reflection->HasField(msg, descriptor)) {
59 const MIDILightProto &light_proto =
60 static_cast<const MIDILightProto &>(reflection->GetMessage(msg, descriptor));
61 active_lights->insert(light_proto.note_number());
64 #endif // !defined(_MIDI_MAPPER_UTIL_H)