static void test_midi_infns(HWND hwnd) { HMIDIIN hm; MMRESULT rc; UINT udev, ndevs = midiInGetNumDevs(); rc = midiInOpen(&hm, ndevs, 0, 0, CALLBACK_NULL); ok(rc==MMSYSERR_BADDEVICEID, "midiInOpen udev>max rc=%s\n", mmsys_error(rc)); if (!rc) { rc = midiInClose(hm); ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc)); } if (!ndevs) { trace("Found no MIDI IN device\n"); /* no skip for this common situation */ rc = midiInOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL); ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiInOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc)); if (!rc) { rc = midiInClose(hm); ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc)); } return; } trace("Found %d MIDI IN devices\n", ndevs); for (udev=0; udev < ndevs; udev++) { trace("** Testing device %d\n", udev); test_midiIn_device(udev, hwnd); Sleep(50); } trace("** Testing MIDI mapper\n"); test_midiIn_device(MIDIMAPPER, hwnd); }
MMRESULT Midi_InOpen(MIDI *midi) { MMRESULT error; int i; if (midi->inPort == -1) { return MMSYSERR_NOERROR; } /* * Open the port. */ m_closing = FALSE; error = midiInOpen(&midi->midiIn, midi->inPort , (DWORD) m_MidiInProc, (DWORD) midi, CALLBACK_FUNCTION); if (error != MMSYSERR_NOERROR) { return error; } /* * Initialize the midi header array. */ for (i = 0; i < midi->bufCnt; i++) { error = midiInPrepareHeader(midi->midiIn, &midi->midiHdrs[i] , sizeof(MIDIHDR)); if (error != MMSYSERR_NOERROR) { for (i--; i >= 0; i--) { midiInUnprepareHeader(midi->midiIn, &midi->midiHdrs[i] , sizeof(MIDIHDR)); } midiInClose(midi->midiIn); return error; } error = midiInAddBuffer(midi->midiIn, &midi->midiHdrs[i] , sizeof(MIDIHDR)); if (error != MMSYSERR_NOERROR) { midiInReset(midi->midiIn); for ( ; i >= 0; i--) { midiInUnprepareHeader(midi->midiIn, &midi->midiHdrs[i] , sizeof(MIDIHDR)); } midiInClose(midi->midiIn); return error; } } /* * Initiate MIDI input. */ error = midiInStart(midi->midiIn); if (error != MMSYSERR_NOERROR) { midiInReset(midi->midiIn); midiInClose(midi->midiIn); return error; } return error; }
static void midirelease(COMMNG self) { CMMIDI midi; midi = (CMMIDI)(self + 1); midiallnoteoff(midi); if (midi->opened & CMMIDI_MIDIOUT) { waitlastexclusiveout(midi); midiOutReset(midi->out.win32.hmidiout); midiOutClose(midi->out.win32.hmidiout); } if (midi->opened & CMMIDI_MIDIIN) { if (midi->opened & CMMIDI_MIDIINSTART) { midiInStop(midi->hmidiin); midiInUnprepareHeader(midi->hmidiin, &midi->hmidiinhdr, sizeof(MIDIHDR)); } midiInReset(midi->hmidiin); midiInClose(midi->hmidiin); midiinhdlunreg(midi); } #if defined(VERMOUTH_LIB) if (midi->opened & CMMIDI_VERMOUTH) { midiout_destroy(midi->out.vermouth); } #endif #if defined(MT32SOUND_DLL) if (midi->opened & CMMIDI_MT32SOUND) { mt32sound_close(); } #endif _MFREE(self); }
Parameter::~Parameter(void) { char string[NUM_PARAMETERS*12]; char tmpString[12]; /* Stop midi */ for (unsigned int devID = 0; devID < numDevices; devID++) { MMRESULT rc; rc = midiInReset(midiInDevice[devID]); rc = midiInStop(midiInDevice[devID]); rc = midiInClose(midiInDevice[devID]); } #if 0 /* Save to clipboard... */ string[0] = 0; for (int par = 0; par < NUM_PARAMETERS; par++) { if (changed[par]) { sprintf(tmpString, "%d:%.2f(%d) ", par, value[par], (int)(value[par]*127.0f + 0.49f)); strcat(string, tmpString); } } CopyToClipboard(string); #endif }
MInputDeviceWin32::~MInputDeviceWin32() { if(hMidiIn) { midiInStop(hMidiIn); midiInClose(hMidiIn); } }
// Plug-in state update function. void ResetPluginIfRequired() { // Reset only if the number of devices was changed. int deviceCount = midiInGetNumDevs(); if (deviceCount == handles.size()) return; // Close the all MIDI handles. for (auto& handle : handles) { midiInClose(handle); } handles.resize(0); // Clear the message queue. std::queue<Message> emptyQueue; std::swap(messageQueue, emptyQueue); // Enumerate the all MIDI devices. for (int i = 0; i < deviceCount; i++) { HMIDIIN handle; MMRESULT result = midiInOpen(&handle, i, reinterpret_cast<DWORD_PTR>(MyMidiInProc), NULL, CALLBACK_FUNCTION); assert(result == MMSYSERR_NOERROR); result = midiInStart(handle); assert(result == MMSYSERR_NOERROR); handles.push_back(handle); } }
static void msw_close_midiin(void) { unsigned int i; /* Stop, reset, close MIDI input. Free callback instance data. */ for (i=0; (i<wNumDevices) && (i<MAXMIDIINDEV); i++) { if (hMidiIn[i]) { if (sys_verbose) post("closing MIDI input %d...", i); midiInStop(hMidiIn[i]); midiInReset(hMidiIn[i]); midiInClose(hMidiIn[i]); FreeCallbackInstanceData(lpCallbackInstanceData[i]); } } /* Free input buffer. */ if (lpInputBuffer) FreeCircularBuffer(lpInputBuffer); if (sys_verbose) post("...done"); wNumDevices = 0; }
MMRESULT Midi_MasterInOpen(MIDI *midi) { MMRESULT error; if (midi->masterInPort == -1 || midi->outPort == -1) { return MMSYSERR_NOERROR; } if (midi->masterInPort == midi->inPort) { return MMSYSERR_NOERROR; } #ifdef MIDI_THRU /* * Open the port. */ error = midiInOpen(&midi->midiMasterIn, midi->masterInPort, 0, 0 , CALLBACK_NULL); if (error != MMSYSERR_NOERROR) { return error; } /* * Connect the master in port to the output port. */ error = midiConnect((HMIDI) midi->midiMasterIn, midi->midiOut, NULL); if (error != MMSYSERR_NOERROR) { midiInClose(midi->midiMasterIn); return error; } #else /* * Open the port. */ error = midiInOpen(&midi->midiMasterIn, midi->masterInPort , (DWORD) m_MidiMasterInProc, (DWORD) midi, CALLBACK_FUNCTION); if (error != MMSYSERR_NOERROR) { return error; } #endif error = midiInStart(midi->midiMasterIn); if (error != MMSYSERR_NOERROR) { midiInReset(midi->midiMasterIn); midiInClose(midi->midiMasterIn); return error; } return error; }
bool Close() { for (int i = 0; i < nMIDIDeviceCount; i++) { midiInStop(hMIDIInput[i]); midiInClose(hMIDIInput[i]); } return true; }
void Close() { if (handle) { midiInUnprepareHeader(handle, &header, sizeof(MIDIHDR)); midiInClose(handle); } }
//---------------------------------------------------------------------------// // End // //---------------------------------------------------------------------------// void CMidiDevice::End() { if (m_Ok) { midiInStop (m_MidiIn); midiInClose(m_MidiIn); m_Ok = false; } }
int rtsyn_synth_start(){ int i; UINT port; #ifdef __W32__ DWORD processPriority; processPriority = GetPriorityClass(GetCurrentProcess()); #endif port=0; sleep(2); for(port=0;port<rtsyn_portnumber;port++){ for (i=0;i<MAX_EXBUF;i++){ IMidiHdr[port][i] = (MIDIHDR *)sIMidiHdr[port][i]; memset(IMidiHdr[port][i],0,sizeof(MIDIHDR)); IMidiHdr[port][i]->lpData = sImidiHdr_data[port][i]; memset((IMidiHdr[port][i]->lpData),0,BUFF_SIZE); IMidiHdr[port][i]->dwBufferLength = BUFF_SIZE; } } evbwpoint=0; evbrpoint=0; mvbuse=0; for(port=0;port<rtsyn_portnumber;port++){ midiInOpen(&hMidiIn[port],portID[port],(DWORD)MidiInProc,(DWORD)port,CALLBACK_FUNCTION); for (i=0;i<MAX_EXBUF;i++){ midiInUnprepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR)); midiInPrepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR)); midiInAddBuffer(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR)); } } #ifdef __W32__ // HACK:midiInOpen()でリセットされてしまうため、再設定 SetPriorityClass(GetCurrentProcess(), processPriority); #endif for(port=0;port<rtsyn_portnumber;port++){ if(MMSYSERR_NOERROR !=midiInStart(hMidiIn[port])){ int i; for(i=0;i<port;i++){ midiInStop(hMidiIn[i]); midiInReset(hMidiIn[i]); midiInClose(hMidiIn[i]); } goto winmmerror; } } mim_start_time = get_current_calender_time(); InitializeCriticalSection(&mim_section); return ~0; winmmerror: ctl->cmsg( CMSG_ERROR, VERB_NORMAL, "midiInStarterror\n" ); return 0; }
/* midi_win32_in_exit: */ void midi_win32_in_exit(int input) { if (midi_in_device != NULL) { midiInStop(midi_in_device); midiInReset(midi_in_device); midiInClose(midi_in_device); midi_in_device = NULL; } }
/*** * Closes the MME MIDI Input port in a safe way */ void MidiInputDeviceMme::MidiInputPortMme::CloseMmeMidiPort(void) { int res; if (MidiInOpened == true) { ExitFlag = true; midiInReset(MidiInHandle); while ((res = midiInClose(MidiInHandle)) == MIDIERR_STILLPLAYING) Sleep(100); midiInUnprepareHeader(MidiInHandle, &midiHdr, sizeof(MIDIHDR)); MidiInOpened = false; } }
static void test_midiIn_device(UINT udev, HWND hwnd) { HMIDIIN hm; MMRESULT rc; MIDIINCAPSA capsA; MIDIHDR mhdr; rc = midiInGetDevCapsA(udev, &capsA, sizeof(capsA)); ok((MIDIMAPPER==udev) ? (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)) : rc==0, "midiInGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc)); if (!rc) { /* MIDI IN capsA.dwSupport may contain garbage, absent in old MS-Windows */ trace("* %s: manufacturer=%d, product=%d, support=%X\n", capsA.szPname, capsA.wMid, capsA.wPid, capsA.dwSupport); } if (hwnd) rc = midiInOpen(&hm, udev, (DWORD_PTR)hwnd, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW); else rc = midiInOpen(&hm, udev, (DWORD_PTR)callback_func, (DWORD_PTR)MYCBINST, CALLBACK_FUNCTION); ok((MIDIMAPPER!=udev) ? rc==0 : (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)), "midiInOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc)); if (rc) return; test_notification(hwnd, "midiInOpen", MIM_OPEN, 0); memset(&mhdr, 0, sizeof(mhdr)); mhdr.dwFlags = 0; mhdr.dwUser = 0x56FA552C; mhdr.dwBufferLength = 70000; /* > 64KB! */ mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength); ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength); if (mhdr.lpData) { rc = midiInPrepareHeader(hm, &mhdr, offsetof(MIDIHDR,dwOffset)-1); ok(rc==MMSYSERR_INVALPARAM, "midiInPrepare tiny rc=%s\n", mmsys_error(rc)); rc = midiInPrepareHeader(hm, &mhdr, offsetof(MIDIHDR,dwOffset)); ok(!rc, "midiInPrepare old size rc=%s\n", mmsys_error(rc)); rc = midiInPrepareHeader(hm, &mhdr, sizeof(mhdr)); ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc)); rc = midiInUnprepareHeader(hm, &mhdr, sizeof(mhdr)); ok(!rc, "midiInUnprepare rc=%s\n", mmsys_error(rc)); trace("MIDIHDR flags=%x when unsent\n", mhdr.dwFlags); HeapFree(GetProcessHeap(), 0, mhdr.lpData); } ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser); rc = midiInReset(hm); /* Return any pending buffer */ ok(!rc, "midiInReset rc=%s\n", mmsys_error(rc)); rc = midiInClose(hm); ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc)); test_notification(hwnd, "midiInClose", MIM_CLOSE, 0); test_notification(hwnd, "midiIn over", 0, WHATEVER); }
void MidiApple::closeDevices() { m_inputSubs.clear(); m_outputSubs.clear(); QMapIterator<QString, MIDIEndpointRef> i( m_inputDevices ); while( i.hasNext() ) { midiInClose( i.next().value() ); } QMapIterator<QString, MIDIEndpointRef> o( m_outputDevices ); while( o.hasNext() ) { midiInClose( o.next().value() ); } m_inputDevices.clear(); m_outputDevices.clear(); }
static void DestroyInputDevice(MFDevice *pDevice) { MFMidiPC_MidiInputDevice *pDev = (MFMidiPC_MidiInputDevice*)pDevice->pInternal; if (pDev->hMidiIn) { MFDebug_Warn(1, MFStr("MIDI output device not closed: %s", pDevice->strings[MFDS_ID])); midiInReset(pDev->hMidiIn); midiInClose(pDev->hMidiIn); } MFHeap_Free(pDev); }
void rtsyn_midiports_close(void){ UINT port; for(port=0;port<rtsyn_portnumber;port++){ if( MMSYSERR_NOERROR!=midiInStop(hMidiIn[port]) ) ctl->cmsg( CMSG_ERROR, VERB_NORMAL,"MIDI Stop Error\n"); if( MMSYSERR_NOERROR!=midiInReset(hMidiIn[port]) ) ctl->cmsg( CMSG_ERROR, VERB_NORMAL,"MIDI Rest Error\n"); if( MMSYSERR_NOERROR!=midiInClose(hMidiIn[port]) ) ctl->cmsg( CMSG_ERROR, VERB_NORMAL,"MIDI Close Error\n"); } }
/* * delete_fluid_winmidi_driver */ int delete_fluid_winmidi_driver(fluid_midi_driver_t* p) { fluid_winmidi_driver_t* dev = (fluid_winmidi_driver_t*) p; if (dev->hmidiin != NULL) { midiInStop(dev->hmidiin); midiInReset(dev->hmidiin); midiInClose(dev->hmidiin); } FLUID_FREE(dev); return 0; }
bool _close() { MMRESULT res; if ( ! _midiIn ) return 0; res = midiInStop( _midiIn ); if ( res ) return _error( res ); res = midiInClose( _midiIn ); if ( res ) return _error( res ); _midiIn = 0; _call = 0; return 1; }
//---------------------------------------------------------------------------// // Init // //---------------------------------------------------------------------------// bool CMidiDevice::Init(int iDevice) { m_Ok = false; if (midiInOpen(&m_MidiIn, iDevice, (DWORD_PTR)MidiDataCallback, (DWORD_PTR)this, CALLBACK_FUNCTION) == MMSYSERR_NOERROR) { if (midiInStart(m_MidiIn) == MMSYSERR_NOERROR) m_Ok = true; else midiInClose(m_MidiIn); } return m_Ok; }
void close() { MMRESULT res; if (m_handle != 0) { res = midiInReset( m_handle ); if (res != MMSYSERR_NOERROR) qDebug() << "midiInReset() err:" << mmErrorString(res); res = midiInClose( m_handle ); if (res != MMSYSERR_NOERROR) qDebug() << "midiInClose() err:" << mmErrorString(res); m_handle = 0; } m_currentInput.clear(); }
void RtMidiIn :: closePort( void ) { if ( connected_ ) { WinMidiData *data = static_cast<WinMidiData *> (apiData_); midiInReset( data->inHandle ); midiInStop( data->inHandle ); for ( int i=0; i<RT_SYSEX_BUFFER_COUNT; ++i ) { int result = midiInUnprepareHeader(data->inHandle, data->sysexBuffer[i], sizeof(MIDIHDR)); delete [] data->sysexBuffer[i]->lpData; delete [] data->sysexBuffer[i]; if ( result != MMSYSERR_NOERROR ) { midiInClose( data->inHandle ); errorString_ = "RtMidiIn::openPort: error closing Windows MM MIDI input port (midiInUnprepareHeader)."; error( RtError::DRIVER_ERROR ); } } midiInClose( data->inHandle ); connected_ = false; } }
BOOL WINAPI control_handler(DWORD control_type) { midiInStop(midi_in); midiInClose(midi_in); Pa_StopStream(audio_stream); Pa_CloseStream(audio_stream); Pa_Terminate(); Beatbox_free(beatbox); return FALSE; }
/* * assume midi is non-null (checked by caller) */ static PmError winmm_in_close(PmInternal *midi) { midiwinmm_type m = (midiwinmm_type) midi->descriptor; if (!m) return pmBadPtr; /* device to close */ if (pm_hosterror = midiInStop(m->handle.in)) { midiInReset(m->handle.in); /* try to reset and close port */ midiInClose(m->handle.in); } else if (pm_hosterror = midiInReset(m->handle.in)) { midiInClose(m->handle.in); /* best effort to close midi port */ } else { pm_hosterror = midiInClose(m->handle.in); } midi->descriptor = NULL; pm_free(m); /* delete */ if (pm_hosterror) { int err = midiInGetErrorText(pm_hosterror, (char *) pm_hosterror_text, PM_HOST_ERROR_MSG_LEN); assert(err == MMSYSERR_NOERROR); return pmHostError; } return pmNoError; }
~MidiInCollector() { stop(); if (deviceHandle != 0) { for (int count = 5; --count >= 0;) { if (midiInClose (deviceHandle) == MMSYSERR_NOERROR) break; Sleep (20); } } }
void JMIDIInObj::close() { cs.lock(); if (!connected) goto CSEND; connected = false; #if defined(WIN32) midiInStop((HMIDIIN)handle); midiInReset((HMIDIIN)handle); midiInUnprepareHeader((HMIDIIN)handle, (MIDIHDR*)(char*)data, sizeof(MIDIHDR)); midiInClose((HMIDIIN)handle); #endif handle = -1; data.Release(); repaint(); CSEND:; cs.unlock(); }
/* closes the MIDI-In device*/ void mididrv_in_close(void) { MMRESULT ret; #ifdef DEBUG log_message(mididrv_log, "in_close"); #endif if (!handle_in) { log_error(mididrv_log, "Attempt to close MIDI-In device that wasn't open!"); return; } /* can theoretically return MMSYSERR_INVALHANDLE */ ret = midiInReset(handle_in); ret = midiInClose(handle_in); if (ret != MMSYSERR_NOERROR) { log_error(mididrv_log, "Couldn't close MIDI-In device."); } handle_in = 0; }
MidiUartWinClass::~MidiUartWinClass() { if (inHandle != (HMIDIIN)-1) { if (midiInStop(inHandle) != MMSYSERR_NOERROR) { throw "Could not stop MIDI input"; } if (midiInReset(inHandle) != MMSYSERR_NOERROR) { throw "Could reset MIDI input"; } if (midiInClose(inHandle) != MMSYSERR_NOERROR) { throw "Could not close MIDI input"; } midiInUnprepareHeader(inHandle, &midiHdr, sizeof(MIDIHDR)); } if (outHandle != (HMIDIOUT)-1) { midiOutClose(outHandle); } }
bool Win32MidiIn::close() { int wResult; wResult = midiInReset(hMidiIn); if (wResult != MMSYSERR_NOERROR) { qDebug() << "Win32MidiIn: Failed to reset MIDI input port"; } wResult = midiInUnprepareHeader(hMidiIn, &MidiInHdr, sizeof(MIDIHDR)); if (wResult != MMSYSERR_NOERROR) { qDebug() << "Win32MidiIn: Failed to unprepare MIDI header"; } wResult = midiInClose(hMidiIn); if (wResult != MMSYSERR_NOERROR) { qDebug() << "Win32MidiIn: Failed to close MIDI input port"; } return true; }