|
From: Lasse Kärkkäi. <tr...@us...> - 2009-12-24 02:29:52
|
Module: performous
Branch: master
Commit: c276173159dfc982b2aa2ff4f2f5244181d32769
Author: Lasse Karkkainen <tro...@tr...>
Date: Thu Dec 24 04:29:03 2009 +0200
Hardcoded MIDI drum mapping and support for multiple MIDI drum sets (in theory)
---
game/joystick.cc | 20 ++++++++++++++++----
game/joystick.hh | 3 +++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 527f6fc..aa67b08 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -4,10 +4,17 @@
#include <boost/lexical_cast.hpp>
#ifdef USE_PORTMIDI
-input::MidiDrums::MidiDrums(int devId): stream(devId) {
- Private::devices[0x8000] = Private::InputDevPrivate(Private::DRUMS_MIDI);
+input::MidiDrums::MidiDrums(int devId): stream(devId), devnum(0x8000 + devId) {
+ Private::devices[devnum] = Private::InputDevPrivate(Private::DRUMS_MIDI);
event.type = Event::PRESS;
for (unsigned int i = 0; i < BUTTONS; ++i) event.pressed[i] = false;
+ map[35] = map[36] = 0; // Bass drum 1/2
+ map[38] = map[40] = 1; // Snare 1/2
+ map[42] = map[46] = 2; // Hi-hat closed/open
+ map[41] = map[43] = 3; // Tom low 1/2
+ map[45] = map[47] = 3; // Tom mid 1/2
+ map[48] = map[50] = 3; // Tom high 1/2
+ map[49] = map[51] = 4; // Cymbal crash/ride
}
void input::MidiDrums::process() {
@@ -16,9 +23,14 @@ void input::MidiDrums::process() {
if ((ev.message & 0xFF) != 0x99) continue;
unsigned char ch = ev.message >> 8;
//unsigned char vel = ev.message >> 16;
- event.button = ch % 5;
+ Map::const_iterator it = map.find(ch);
+ if (it == map.end()) {
+ std::cout << "Unassigned MIDI drum event: channel " << ch << std::endl;
+ continue;
+ }
+ event.button = it->second;
event.time = now();
- Private::devices[0x8000].addEvent(event);
+ Private::devices[devnum].addEvent(event);
}
}
#endif
diff --git a/game/joystick.hh b/game/joystick.hh
index bde131a..529c6b4 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -165,7 +165,10 @@ namespace input {
void process();
private:
pm::Input stream;
+ unsigned int devnum;
Event event;
+ typedef std::map<unsigned, unsigned> Map;
+ Map map;
};
#endif
|