我正在尝试使用 midiInOpen 在 Windows 上打开一个 midi 端口。该调用通常效果很好(我正在使用 RtMidi 包装器,并且代码非常干净),但如果 Ableton Live 已打开,它会返回 MMSYSERR_NOMEM。该机器剩余大量内存(4GB),关闭其他应用程序似乎没有任何效果。
我是否在 winmm 中遇到某种内部资源限制?
我在新的英特尔 NUC 机器上运行 Windows 7,调用来自 RtMidi.cpp,我将它们包装在 CPython 模块中,但没有做任何其他花哨的事情。我是一位经验丰富的 C++ 开发人员,如果有人能指出方向,我可以参与其中。
谢谢!
void MidiInWinMM :: openPort( unsigned int portNumber, const std::string /*portName*/ )
{
if ( connected_ ) {
errorString_ = "MidiInWinMM::openPort: a valid connection already exists!";
error( RtMidiError::WARNING, errorString_ );
return;
}
unsigned int nDevices = midiInGetNumDevs();
if (nDevices == 0) {
errorString_ = "MidiInWinMM::openPort: no MIDI input sources found!";
error( RtMidiError::NO_DEVICES_FOUND, errorString_ );
return;
}
if ( portNumber >= nDevices ) {
std::ostringstream ost;
ost << "MidiInWinMM::openPort: the 'portNumber' argument (" << portNumber << ") is invalid.";
errorString_ = ost.str();
error( RtMidiError::INVALID_PARAMETER, errorString_ );
return;
}
WinMidiData *data = static_cast<WinMidiData *> (apiData_);
MMRESULT result = midiInOpen( &data->inHandle,
portNumber,
(DWORD_PTR)&midiInputCallback,
(DWORD_PTR)&inputData_,
CALLBACK_FUNCTION );
if ( result != MMSYSERR_NOERROR ) {
if(result == MMSYSERR_ALLOCATED) printf("MMSYSERR_ALLOCATED: %i\n", MMSYSERR_ALLOCATED);
if(result == MMSYSERR_BADDEVICEID) printf("MMSYSERR_BADDEVICEID: %i\n", MMSYSERR_BADDEVICEID);
if(result == MMSYSERR_INVALFLAG) printf("MMSYSERR_INVALFLAG: %i\n", MMSYSERR_INVALFLAG);
if(result == MMSYSERR_INVALPARAM) printf("MMSYSERR_INVALPARAM: %i\n", MMSYSERR_INVALPARAM);
if(result == MMSYSERR_NOMEM) printf("MMSYSERR_NOMEM: %i\n", MMSYSERR_NOMEM);
errorString_ = "MidiInWinMM::openPort: error creating Windows MM MIDI input port.";
error( RtMidiError::DRIVER_ERROR, errorString_ );
return;
}
// Allocate and init the sysex buffers.
for ( int i=0; i<RT_SYSEX_BUFFER_COUNT; ++i ) {
data->sysexBuffer[i] = (MIDIHDR*) new char[ sizeof(MIDIHDR) ];
data->sysexBuffer[i]->lpData = new char[ RT_SYSEX_BUFFER_SIZE ];
data->sysexBuffer[i]->dwBufferLength = RT_SYSEX_BUFFER_SIZE;
data->sysexBuffer[i]->dwUser = i; // We use the dwUser parameter as buffer indicator
data->sysexBuffer[i]->dwFlags = 0;
result = midiInPrepareHeader( data->inHandle, data->sysexBuffer[i], sizeof(MIDIHDR) );
if ( result != MMSYSERR_NOERROR ) {
midiInClose( data->inHandle );
errorString_ = "MidiInWinMM::openPort: error starting Windows MM MIDI input port (PrepareHeader).";
error( RtMidiError::DRIVER_ERROR, errorString_ );
return;
}
// Register the buffer.
result = midiInAddBuffer( data->inHandle, data->sysexBuffer[i], sizeof(MIDIHDR) );
if ( result != MMSYSERR_NOERROR ) {
midiInClose( data->inHandle );
errorString_ = "MidiInWinMM::openPort: error starting Windows MM MIDI input port (AddBuffer).";
error( RtMidiError::DRIVER_ERROR, errorString_ );
return;
}
}
result = midiInStart( data->inHandle );
if ( result != MMSYSERR_NOERROR ) {
midiInClose( data->inHandle );
errorString_ = "MidiInWinMM::openPort: error starting Windows MM MIDI input port.";
error( RtMidiError::DRIVER_ERROR, errorString_ );
return;
}
connected_ = true;
}