#include <thread>
#include "audio_mixer.h"
-#include "midi_mapping.pb.h"
+#include "nageru_midi_mapping.pb.h"
+#include "shared/midi_device.h"
#include "shared/midi_mapper_util.h"
#include "shared/text_proto.h"
using namespace std;
using namespace std::placeholders;
-namespace {
-
-double map_controller_to_float(int val)
-{
- // Slightly hackish mapping so that we can represent exactly 0.0, 0.5 and 1.0.
- if (val <= 0) {
- return 0.0;
- } else if (val >= 127) {
- return 1.0;
- } else {
- return (val + 0.5) / 127.0;
- }
-}
-
-} // namespace
-
MIDIMapper::MIDIMapper(ControllerReceiver *receiver)
: receiver(receiver), mapping_proto(new MIDIMappingProto), midi_device(this)
{
void MIDIMapper::controller_received(int controller, int value_int)
{
- const float value = map_controller_to_float(value_int);
+ const float value = map_controller_to_float(controller, value_int);
receiver->controller_changed(controller);
return;
}
- set<unsigned> active_lights; // Desired state.
+ map<MIDIDevice::LightKey, uint8_t> active_lights; // Desired state.
if (current_controller_bank == 0) {
activate_lights_all_buses(MIDIMappingBusProto::kBank1IsSelectedFieldNumber, &active_lights);
}
midi_device.update_lights(active_lights);
}
-void MIDIMapper::activate_lights_all_buses(int field_number, set<unsigned> *active_lights)
+void MIDIMapper::activate_lights_all_buses(int field_number, map<MIDIDevice::LightKey, uint8_t> *active_lights)
{
for (size_t bus_idx = 0; bus_idx < size_t(mapping_proto->bus_mapping_size()); ++bus_idx) {
const MIDIMappingBusProto &bus_mapping = mapping_proto->bus_mapping(bus_idx);