midiInOpen を使用して Windows で midi ポートを開こうとしています。この呼び出しは通常はうまく機能しますが (私は RtMidi ラッパーを使用しており、コードは非常にクリーンです)、Ableton Live が開いている場合は MMSYSERR_NOMEM を返します。マシンには十分な RAM (4GB) が残っており、他のアプリケーションを閉じても効果がないようです。
winmm である種の内部リソース制限に達していますか?
私は新しい Intel 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;
}