Fix bugs in MIDI In

This commit is contained in:
Henrik Rydgard 2012-04-12 13:22:13 +02:00
parent 9684be3257
commit 0f050d50f0
2 changed files with 20 additions and 6 deletions

View File

@ -1,14 +1,17 @@
#ifdef _WIN32
// Windows implementation.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <MMSystem.h>
#include <vector>
#include <string>
#include "base/basictypes.h"
#include "base/logging.h"
#include "midi/midi_input.h"
std::vector<std::string> MidiInGetDevices() {
int numDevs = midiInGetNumDevs();
std::vector<std::string> devices;
@ -33,9 +36,10 @@ static void CALLBACK MidiCallback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstan
ILOG("Got MIDI Close message");
break;
case MM_MIM_DATA:
cmd[0] = dwParam2 & 0xFF;
cmd[1] = (dwParam2 >> 8) & 0xFF;
cmd[2] = (dwParam2 >> 16) & 0xFF;
cmd[0] = dwParam1 & 0xFF;
cmd[1] = (dwParam1 >> 8) & 0xFF;
cmd[2] = (dwParam1 >> 16) & 0xFF;
// time = dwParam2 & 0xFFFF;
ILOG("Got MIDI Data: %02x %02x %02x", cmd[0], cmd[1], cmd[2]);
listener->midiEvent(cmd);
break;
@ -60,6 +64,13 @@ void MidiInStop(MidiDevice device) {
#else
#include <vector>
#include <string>
#include "base/basictypes.h"
#include "base/logging.h"
#include "midi/midi_input.h"
// Stubs for other platforms.
std::vector<std::string> MidiInGetDevices() {

View File

@ -1,11 +1,14 @@
// MIDI input utilities.
// MIDI input.
//
// Currently, this is just a platform-clean wrapper around the Win32 MIDI input facilities.
// Thus, it only supports Windows. Other platforms will get an empty list of midi in devices.
#pragma once
#include <vector>
#include <string>
#include "base/basictypes.h"
typedef void *MidiDevice;
@ -13,7 +16,7 @@ typedef void *MidiDevice;
class MidiListener
{
public:
virtual void midiEvent(const uint8_t *cmd);
virtual void midiEvent(const uint8_t *cmd) = 0;
};
// Gets the names of the devices in a vector. The device identifier is the index in the vector.