Example #1
0
File: midi.c Project: thomcom/wine
static void test_midi_outfns(HWND hwnd)
{
    HMIDIOUT hm;
    MMRESULT rc;
    UINT udev, ndevs = midiOutGetNumDevs();

    rc = midiOutOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
    ok(rc==MMSYSERR_BADDEVICEID, "midiOutOpen udev>max rc=%s\n", mmsys_error(rc));
    if (!rc) {
        rc = midiOutClose(hm);
        ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
    }
    if (!ndevs) {
        MIDIOUTCAPSA capsA;
        skip("Found no MIDI out device\n");

        rc = midiOutGetDevCapsA(MIDIMAPPER, &capsA, sizeof(capsA));
        /* GetDevCaps and Open must return compatible results */
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiOutGetDevCaps MAPPER with no MIDI rc=%s\n", mmsys_error(rc));

        rc = midiOutOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
        if (rc==MIDIERR_INVALIDSETUP) todo_wine /* Wine without snd-seq */
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k*/), "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
        else
        ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*w2k sound disabled*/),
           "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
        if (!rc) {
            rc = midiOutClose(hm);
            ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
        }
        return;
    }
    trace("Found %d MIDI OUT devices\n", ndevs);

    test_midi_mci(hwnd);

    for (udev=0; udev < ndevs; udev++) {
        MIDIOUTCAPSA capsA;
        rc = midiOutGetDevCapsA(udev, &capsA, sizeof(capsA));
        if (rc || strcmp(capsA.szPname, "Creative Sound Blaster MPU-401") != 0 || ! on_vmware()) {
            trace("** Testing device %d\n", udev);
            test_midiOut_device(udev, hwnd);
            Sleep(800); /* Let the synth rest */
            test_midiStream(udev, hwnd);
            Sleep(800);
        }
        else
            win_skip("Skipping this device on VMware, driver problem\n");
    }
    trace("** Testing MIDI mapper\n");
    test_midiOut_device(MIDIMAPPER, hwnd);
    Sleep(800);
    test_midiStream(MIDIMAPPER, hwnd);
}
Example #2
0
MIDIPlayer::MIDIPlayer(){
	if(midiOutOpen(&mid,(UINT)-1,0,0,0))
		exit(1);
		
	velocity = 127;
	setVoice(0); // default
}
Example #3
0
BOOL CMidiDevice::OpenDevOut(UINT uDeviceOutID)
{
	// makes sure the previous device is closed
    CloseDevOut();

    // open midi output device
    MMRESULT Result = midiOutOpen(&m_hMidiOut, 
		                  uDeviceOutID, 
                          0L,
                          0L,
                          0L
						  );

    // change current state
    if(Result == MMSYSERR_NOERROR)
    {
        m_StateOut = OPENEDOUT;
	}
	else
	{
		return FALSE;
	}

	return TRUE;
}
static void msw_open_midiout(int nmidiout, int *midioutvec)
{
    UINT result, wRtn;
    int i;
    int dev;
    MIDIOUTCAPS midioutcaps;
    if (nmidiout > MAXMIDIOUTDEV)
        nmidiout = MAXMIDIOUTDEV;

    dev = 0;

    for (i = 0; i < nmidiout; i++)
    {
        MIDIOUTCAPS mocap;
        int devno =  midioutvec[i];
        result = midiOutOpen(&hMidiOut[dev], devno, 0, 0, 
            CALLBACK_NULL);
        wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
            sizeof(mocap));
        if (result != MMSYSERR_NOERROR)
        {
            fprintf(stderr,"midiOutOpen: %s\n",midioutcaps.szPname);
            msw_midiouterror("midiOutOpen: %s\n", result);
        }
        else
        {
            if (sys_verbose)
                fprintf(stderr,"midiOutOpen: Open %s as Port %d\n",
                    midioutcaps.szPname, dev);
            dev++;
        }
    }
    msw_nmidiout = dev;
}
Example #5
0
File: midi.c Project: 173210/px68k
// -----------------------------------------------------------------------
//   しょきか〜
// -----------------------------------------------------------------------
void MIDI_Init(void) {

	memset(DelayBuf, 0, sizeof(DelayBuf));
	DBufPtrW = DBufPtrR = 0;

	MIDI_SetModule();
	MIDI_RegHigh = 0;		// X68K
	MIDI_Vector = 0;		// X68K
	MIDI_IntEnable = 0;
	MIDI_IntVect = 0;
	MIDI_IntFlag = 0;
	MIDI_R05 = 0;

	MIDI_CTRL = MIDICTRL_READY;
	MIDI_LAST = 0x80;
	MIDI_EXCVWAIT = 0;

	if (!hOut) {
		if (midiOutOpen(&hOut, MIDI_MAPPER, 0, 0, CALLBACK_NULL)
							== MMSYSERR_NOERROR) {
			midiOutReset(hOut);
		}
		else
			hOut = 0;
	}
}
void MIDIDeviceOutJack::open()
{
	MMRESULT result = midiOutOpen((HMIDIOUT*)&m_handle, id(), 0, 0, 0);

	if (result != MMSYSERR_NOERROR)
		error("MIDIDeviceOutJack::open", result);
}
Example #7
0
/* opens a MIDI-Out device, returns handle */
int mididrv_out_open(void)
{
    MMRESULT ret;

    log_message(mididrv_log, "Opening MIDI-Out device #%d", midi_out_dev);
    if (handle_out) {
        mididrv_out_close();
    }

    if (midi_out_dev != -1) {
        ret = midiOutOpen(&handle_out, midi_out_dev, 0, 0, CALLBACK_NULL);
        if (ret != MMSYSERR_NOERROR) {
            log_error(mididrv_log, "Cannot open MIDI-Out device #%d!", midi_out_dev);
            handle_out = 0;
            return -1;
        }
    } else {
        handle_out = 0;
        return -1;
    }

    /* reset buffer */
    out_index = 0;

    return (DWORD)handle_out;
}
bool QMidiOut::connect(QString outDeviceId)
{
	if (fConnected)
		disconnect();
	fMidiPtrs = new NativeMidiInstances;

    unsigned int err;
    HMIDIOUT out;
    qint32 msg = 4209808;

    err = midiOutOpen(&fMidiPtrs->midiOutPtr, outDeviceId.toInt(), 0, 0, CALLBACK_NULL);

    if (err != MMSYSERR_NOERROR)
           qDebug() << "error opening MIDI Mapper: %d\n" + err;
        else
            qDebug() << "successfully opened MIDI Mapper\n";

//    midiOutShortMsg(fMidiPtrs->midiOutPtr, (DWORD)msg);
//    Sleep(1000);
//    midiOutShortMsg(fMidiPtrs->midiOutPtr, 0x00003C90);

	fDeviceId = outDeviceId;
	fConnected = true;
	return true;
}
Example #9
0
void MidiWinMM::openDevices()
{
	m_inputDevices.clear();
	for( unsigned int i = 0; i < midiInGetNumDevs(); ++i )
	{
		MIDIINCAPS c;
		midiInGetDevCaps( i, &c, sizeof( c ) );
		HMIDIIN hm = 0;
		MMRESULT res = midiInOpen( &hm, i, (DWORD_PTR) &inputCallback,
						(DWORD_PTR) this,
							CALLBACK_FUNCTION );
		if( res == MMSYSERR_NOERROR )
		{
			m_inputDevices[hm] = qstrdup( c.szPname );
			midiInStart( hm );
		}
	}

	m_outputDevices.clear();
	for( unsigned int i = 0; i < midiOutGetNumDevs(); ++i )
	{
		MIDIOUTCAPS c;
		midiOutGetDevCaps( i, &c, sizeof( c ) );
		HMIDIOUT hm = 0;
		MMRESULT res = midiOutOpen( &hm, i, 0, 0, CALLBACK_NULL );
		if( res == MMSYSERR_NOERROR )
		{
			m_outputDevices[hm] = qstrdup( c.szPname );
		}
	}
}
Example #10
0
/* midi_win32_init:
 */
int midi_win32_init(int input, int voices)
{
   MMRESULT hr;
   int id;

   /* deduce our device number from the driver ID code */
   if ((midi_driver->id & 0xFF) == 'M')
      /* we are using the midi mapper (driver id is WIN32M) */
      id = MIDI_MAPPER;
   else
      /* actual driver */
      id = (midi_driver->id & 0xFF) - 'A';

   /* open midi mapper */
   hr = midiOutOpen(&midi_device, id, 0, 0, CALLBACK_NULL);
   if (hr != MMSYSERR_NOERROR) {
      _TRACE(PREFIX_E "midiOutOpen failed (%x)\n", hr);
      goto Error;
   }

   /* resets midi mapper */
   midiOutReset(midi_device);

   return 0;

 Error:
   midi_win32_exit(input);
   return -1;
}
Example #11
0
int midi_open_port(HMIDIOUT * midiout, int portnum)
{
	if (midiout) midiOutClose(* midiout);
	if (midiOutOpen(midiout,portnum-1,0,0,CALLBACK_NULL)==MMSYSERR_NOERROR) 
	   return TRUE;
	return FALSE;
}
Example #12
0
bool QMidi::initMidiOut(QString outDeviceId)
{
#if defined(Q_OS_WIN)
    midiOutOpen(&midiOutPtr,outDeviceId.toInt(),0,0,CALLBACK_NULL);
#elif defined(Q_OS_LINUX)
    int err = snd_seq_open(&midiOutPtr, "default", SND_SEQ_OPEN_OUTPUT, 0);
    if(err < 0) { return false; }
    snd_seq_set_client_name(midiOutPtr, "QtMidi");

    snd_seq_create_simple_port(midiOutPtr, "Output Port",
                               SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC);

    QStringList l = outDeviceId.split(":");
    int client = l.at(0).toInt();
    int port = l.at(1).toInt();
    snd_seq_connect_to(midiOutPtr, 0, client, port);
#elif defined(Q_OS_HAIKU)
	midiOutConsumer = BMidiRoster::FindConsumer(outDeviceId.toInt());
	if(midiOutConsumer == NULL) { return false; }
	midiOutLocProd = new BMidiLocalProducer("QtMidi");
	if(!midiOutLocProd->IsValid()) { midiOutLocProd->Release(); return false; } // some error ??
	midiOutLocProd->Register();
	if(midiOutLocProd->Connect(midiOutConsumer) != B_OK) { return false; }
#endif
    myOutDeviceId = outDeviceId;
    return true;
}
Example #13
0
void RtMidiOut :: openPort( unsigned int portNumber, const std::string /*portName*/ )
{
  if ( connected_ ) {
    errorString_ = "RtMidiOut::openPort: a valid connection already exists!";
    error( RtError::WARNING );
    return;
  }

  unsigned int nDevices = midiOutGetNumDevs();
  if (nDevices < 1) {
    errorString_ = "RtMidiOut::openPort: no MIDI output destinations found!";
    error( RtError::NO_DEVICES_FOUND );
  }

  std::ostringstream ost;
  if ( portNumber >= nDevices ) {
    ost << "RtMidiOut::openPort: the 'portNumber' argument (" << portNumber << ") is invalid.";
    errorString_ = ost.str();
    error( RtError::INVALID_PARAMETER );
  }

  WinMidiData *data = static_cast<WinMidiData *> (apiData_);
  MMRESULT result = midiOutOpen( &data->outHandle,
                                 portNumber,
                                 (DWORD)NULL,
                                 (DWORD)NULL,
                                 CALLBACK_NULL );
  if ( result != MMSYSERR_NOERROR ) {
    errorString_ = "RtMidiOut::openPort: error creating Windows MM MIDI output port.";
    error( RtError::DRIVER_ERROR );
  }

  connected_ = true;
}
Example #14
0
int midi_open_port(HMIDIOUT * midiout, int portnum)
{
	if (midiout) midiOutClose(* midiout);
	if (midiOutOpen(midiout,portnum-1,0,0,CALLBACK_NULL)==MMSYSERR_NOERROR) 
	   return TRUE;

	write_logfile("could not open midi port"); 
	return FALSE;
}
Example #15
0
ArchMidi* archMidiOutCreate(int device)
{
    Properties* pProperties = propGetGlobalProperties();
    char* propName = device == 0 ? pProperties->sound.MidiOut.name : pProperties->sound.MidiOut.name;
    ArchMidi* archMidi = (ArchMidi*)calloc(1, sizeof(ArchMidi));

    if (device != 0) {
        return archMidi;
    }

    if (midi.out.current[device] == NULL) {
        int i;
        for (i = 0; i < midi.out.count; i++) {
            if (strcmp(midi.out.dev[i].idString, propName) == 0) {
                if (midiOutOpen((HMIDIOUT*)&midi.out.dev[i].handle, midi.out.dev[i].id, 0, 0 ,0) == MMSYSERR_NOERROR) {
                    midi.out.current[device] = &midi.out.dev[i];
                }
                break;
            }
        }
        if (midi.out.current[device] == NULL && midi.out.count > 0) {
            if (midiOutOpen((HMIDIOUT*)&midi.out.dev[0].handle, midi.out.dev[0].id, 0, 0 ,0) == MMSYSERR_NOERROR) {
                midi.out.current[device] = &midi.out.dev[0];
            }
            strcpy(propName, midi.out.dev[0].idString);
        }

        if (midi.out.current[device] != NULL) {
            midiOutGetVolume((HMIDIOUT)midi.out.current[device]->handle, &midi.out.current[device]->origVolume);
        }
        archMidiEnable(midi.enabled);

        // Clear history
        memset(midi.out.history.data, 0, sizeof(midi.out.history.data));
    }

    if (midi.out.current[device] != NULL) {
        midi.out.current[device]->refCount++;
    }

    archMidi->devInfo = midi.out.current[device];

    return archMidi;
}
Example #16
0
MF_API bool MFMidi_OpenOutput(MFDevice *pDevice)
{
	MFDebug_Assert(pDevice->type == MFDT_MidiOutput, "Not a MIDI device!");

	if (pDevice->state == MFDevState_Ready)
	{
		MFDebug_Warn(1, "Midi output device already opened!");
		return false;
	}
	if (pDevice->state != MFDevState_Available)
	{
		MFDebug_Warn(1, "Unable to open midi output device!");
		return false;
	}

	MFMidiPC_MidiOutputDevice *pMidi = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal;

	// find and open the device
	// TODO: FIXME! this won't work if there are 2 instances of the same device attached to the PC!!!
	UINT numOutputDevices = midiOutGetNumDevs();
	UINT i = 0;
	for (; i < numOutputDevices; ++i)
	{
		MIDIOUTCAPS caps;
		MMRESULT r = midiOutGetDevCaps(i, &caps, sizeof(caps));
		if (r != MMSYSERR_NOERROR)
			continue;

		if (caps.wMid == pMidi->mid && caps.wPid == pMidi->pid)
			break;
	}
	if (i == numOutputDevices)
	{
		MFDebug_Log(0, MFStr("Midi output device '%s' not found!", pDevice->strings[MFDS_ID]));
		pDevice->state = MFDevState_Unknown; // set this flag?
		return false;
	}

	MMRESULT r = midiOutOpen(&pMidi->hMidiOut, i, (DWORD_PTR)MidiOutProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION);
	if (r != MMSYSERR_NOERROR)
	{
		pMidi->hMidiOut = NULL;
		pDevice->state = MFDevState_Unknown;

		wchar_t errorBuffer[256];
		midiOutGetErrorText(r, errorBuffer, sizeof(errorBuffer));
		MFDebug_Warn(1, MFStr("Failed to open MIDI output device: %s", MFString_WCharAsUTF8(errorBuffer)));

		return false;
	}

	pDevice->state = MFDevState_Ready;

	return true;
}
Example #17
0
MOutputDeviceWin32::MOutputDeviceWin32(int deviceId)
{
	hMidiOut = 0;
	// get the devs caps
	midiOutGetDevCaps(deviceId,&midiOutCaps,sizeof(MIDIOUTCAPS));

	// open the device
	HRESULT err = midiOutOpen(&hMidiOut,deviceId,0,0,CALLBACK_NULL);
	if(err != MMSYSERR_NOERROR)
		throw Resound::Exception();
}
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_openPort(JNIEnv* env, jobject obj, jlong ptr, jint device)
{
	midi_handle_t *handle = NULL;
	memcpy(&handle, &ptr, sizeof(handle));
	if(handle != NULL && handle->out == NULL){
		handle->out = (HMIDIOUT *)malloc( sizeof(HMIDIOUT) );
		if ( midiOutOpen(handle->out, (UINT)device, 0, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR ){
			free( handle->out );
			handle->out = NULL;
		}
	}
}
Example #19
0
//***********************************************************************
void MidiNoteOpen( void )
//***********************************************************************
{
	if ( hMidiOut )
		return;

//	UINT wNumDevs = midiOutGetNumDevs();
//	MIDIOUTCAPS moc;
//	UINT wError = midiOutGetDevCaps( MIDIMAPPER/*nDevice*/, &moc, sizeof(moc) );
	UINT wError = midiOutOpen( &hMidiOut, MIDIMAPPER/*nDevice*/,
		NULL/*dwCallback*/, 0L/*dwInst*/, 0L/*dwFlags*/ );
}
Example #20
0
CIntervalPage::CIntervalPage() : CPropertyPage(CIntervalPage::IDD), m_dwElapse(ELAPSE_TIME)
{
	//{{AFX_DATA_INIT(CIntervalPage)
	m_csResult = _T("");
	m_nInputInterval = 0;
	m_csNotesPlayed = _T("");
	//}}AFX_DATA_INIT

	if (MMSYSERR_NOERROR != midiOutOpen(&m_hMidiOut, MIDIMAPPER, 0, 0, 0))
	{
		AfxMessageBox("Unable to open Midi O/P device");
		return ;
	}
}
Example #21
0
bool MIDIDevice::open()
{
	bool result = false;
	MMRESULT res;

	if (m_handle != NULL)
		return true;

	res = midiOutOpen(&m_handle, m_id, 0, 0, 0);
	if (res == MMSYSERR_ALLOCATED)
	{
		qDebug() << QString("Unable to open %1:").arg(m_name)
			 << QString("Resource is already allocated.");
		m_handle = NULL;
		result = false;
	}
	else if (res == MMSYSERR_BADDEVICEID)
	{
		qDebug() << QString("Unable to open %1:").arg(m_name)
			 << QString("Bad device ID.");
		m_handle = NULL;
		result = false;
	}
	else if (res == MMSYSERR_INVALFLAG)
	{
		qDebug() << QString("Unable to open %1:").arg(m_name)
			 << QString("Invalid flags.");
		m_handle = NULL;
		result = false;
	}
	else if (res == MMSYSERR_INVALPARAM)
	{
		qDebug() << QString("Unable to open %1:").arg(m_name)
			 << QString("Invalid parameters.");
		m_handle = NULL;
		result = false;
	}
	else if (res == MMSYSERR_NOMEM)
	{
		qDebug() << QString("Unable to open %1:").arg(m_name)
			 << QString("Out of memory.");
		result = false;
	}
	else
	{
		result = true;
	}

	return result;
}
Example #22
0
bool CMidiDevice::SetDevice (const char *pcszDevice_)
{
    if (m_hMidiOut)
    {
        midiOutClose(m_hMidiOut);
        m_hMidiOut = NULL;
    }

    // Open the supplied device number
    if (*pcszDevice_)
        midiOutOpen(&m_hMidiOut, atoi(pcszDevice_), 0, 0, CALLBACK_NULL);

    return m_hMidiOut != NULL;
}
Example #23
0
void midiInitialize(char *inputDeviceStr, char *outputDeviceStr) {
  int inputDevice = atoi(inputDeviceStr);
  int outputDevice = atoi(outputDeviceStr);
  char name[256];
  getOutDeviceName(outputDevice, name, sizeof(name));
  unsigned long result = midiOutOpen(&outHandle, outputDevice, 0, 0, CALLBACK_NULL);
  if (result) {
    logPrintf(LOG_ERROR,
	      "Error opening output device %s with ID %d, aborting\n", name, outputDevice);
    exit(-1);
  } else {
    debugPrintf(1, "Opened output device %s.\n", name);
  }

  getInDeviceName(inputDevice, name, sizeof(name));
  result = midiInOpen(&inHandle, inputDevice, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);
  if (result) {
    logPrintf(LOG_ERROR,
	      "Error opening input device %s with ID %d, aborting\n", name, inputDevice);
    exit(-1);
  } else {
    debugPrintf(1, "Opened input device %s.\n", name);
  }

  sleepCount = 0;
  
  midiHdr.lpData = inputBuffer;
  midiHdr.dwBufferLength = sizeof(inputBuffer);
  midiHdr.dwFlags = 0;
  result = midiInPrepareHeader(inHandle, &midiHdr, sizeof(MIDIHDR));

  if (result) {
    logPrintf(LOG_ERROR, "Could not prepare input buffer\n");
    exit(-1);
  }

  result = midiInAddBuffer(inHandle, &midiHdr, sizeof(MIDIHDR));

  if (result) {
    logPrintf(LOG_ERROR, "could not add input buffer\n");
    exit(-1);
  }

  result = midiInStart(inHandle);
  if (result) {
    logPrintf(LOG_ERROR, "Could not start recording on input\n");
    exit(-1);
  }
}
Example #24
0
void Win32MidiOutputDevice::open()
{
    qDebug() << Q_FUNC_INFO;

    if (m_handle != NULL)
        return;

    MMRESULT result = midiOutOpen(&m_handle, m_id, 0, 0, 0);
    if (result != MMSYSERR_NOERROR)
    {
        qWarning() << Q_FUNC_INFO << "Unable to open MIDI output device with id:" << m_id
                   << "name:" << name() << ":" << result;
        m_handle = NULL;
    }
}
Example #25
0
int MidiDriver_WIN::open() {
	if (_isOpen)
		return MERR_ALREADY_OPEN;

	_streamEvent = CreateEvent(NULL, true, true, NULL);
	MMRESULT res = midiOutOpen((HMIDIOUT *)&_mo, _device, (DWORD_PTR)_streamEvent, 0, CALLBACK_EVENT);
	if (res != MMSYSERR_NOERROR) {
		check_error(res);
		CloseHandle(_streamEvent);
		return MERR_DEVICE_NOT_AVAILABLE;
	}

	_isOpen = true;
	return 0;
}
 /* open the midi device
  * this must be called prior to any other functions in this class 
  */
 virtual bool open()
 {
    unsigned long result;
 
    /* Open the MIDI Mapper */
    result = midiOutOpen(&mHandle, (UINT)-1, (DWORD)MidiOutProc, (DWORD)this, CALLBACK_FUNCTION);
    if (result)
    {
       printf("There was an error opening MIDI Mapper!\r\n");
       return false;
    }
    else
    {
       return true;
    }
 }
Example #27
0
int MidiOutPort_visual::open(void) {
   if (getPort() == -1) {
      return 2;
   }

   if (getPortStatus() == 0) {
      int flag;
      flag = midiOutOpen(&device[getPort()], getPort(), 0, 0, CALLBACK_NULL);
      if (flag == MMSYSERR_NOERROR) {
         openQ[getPort()] = 1;
         return 1;
      } else { // faied to open
         openQ[getPort()] = 0;
         device[getPort()] = NULL;
         return 0;
      }
   } else { // already open
      return 1;
   }
}
Example #28
0
static int midi_init(void){

	MIDIHDR mhMidi;

	/* GMリセット用データ */
	BYTE abyGMReset[] = {0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7};


	/* MIDIデバイスオープン */
	if (midiOutOpen(&g_hMidi, MIDIMAPPER, 0, 0, 0) != MMSYSERR_NOERROR) {
		return 0;
	}

	ZeroMemory(&mhMidi, sizeof(mhMidi));

	/* GMリセット送信用バッファ設定 */
	mhMidi.lpData = (LPSTR)abyGMReset;
	mhMidi.dwBufferLength = 6;
	mhMidi.dwBytesRecorded = 6;
	midiOutPrepareHeader(g_hMidi, &mhMidi, sizeof(mhMidi));

	/* GMリセットメッセージ送信 */
	if (midiOutLongMsg(g_hMidi, &mhMidi, sizeof(mhMidi)) != MMSYSERR_NOERROR) {

		midiOutUnprepareHeader(g_hMidi, &mhMidi, sizeof(mhMidi));

		std::cout<<"MIDI音源の初期化に失敗しました。"<<std::endl;
		midiOutClose(g_hMidi);

		return 0;

	}

		/* GMリセット完了待機 */
		while ((mhMidi.dwFlags & MHDR_DONE) == 0);

		midiOutUnprepareHeader(g_hMidi, &mhMidi, sizeof(mhMidi));


		return 0;
}
Example #29
0
MidiDevice *
openMidiDevice (int errorLevel, const char *device) {
  MidiDevice *midi;
  MMRESULT error;
  int id = 0;
  static const char *const defaultDevice = "default";

  if (!*device) device = defaultDevice;

  if (strcmp(device, defaultDevice) == 0) {
    id = -1;
  } else if (!isInteger(&id, device) || (id < 0) || (id >= midiOutGetNumDevs())) {
    int count = midiOutGetNumDevs();
    for (id=0; id<count; ++id) {
      MIDIOUTCAPS cap;
      if (midiOutGetDevCaps(id, &cap, sizeof(cap)) == MMSYSERR_NOERROR)
        if (strncasecmp(device, cap.szPname, strlen(device)) == 0)
          break;
    }

    if (id == count) {
      logMessage(errorLevel, "invalid MIDI device number: %s", device);
      return NULL;
    }
  }

  if ((midi = malloc(sizeof(*midi)))) {
    if ((error = midiOutOpen(&midi->handle, id, 0, 0, CALLBACK_NULL)) == MMSYSERR_NOERROR) {
      midi->note = 0;
      midi->count = 0;
      return midi;
    } else {
      logMidiOutError(error, errorLevel, "MIDI device open");
    }

    free(midi);
  } else {
    logSystemError("MIDI device allocation");
  }
  return NULL;
}
Example #30
0
int main()
{
    UINT outs = midiOutGetNumDevs();
//    UINT ins = midiInGetNumDevs();

    MIDIOUTCAPS outcaps;
//    MIDIINCAPS incaps;

    int c;

    HMIDIOUT Handle = NULL;
    UINT Result;

    printf("MIDI output devices: %d\n", outs);

    for (c = 0; c < outs; c ++)
    {
        if (midiOutGetDevCaps(c, &outcaps, sizeof(MIDIOUTCAPS)) == MMSYSERR_NOERROR)
            printf("Device #%d: %s\n", c, outcaps.szPname);
    }

    printf("Opening MIDI output #0\n");

    Result = midiOutOpen(&Handle, 0, 0, 0, CALLBACK_NULL);
    printf("Result == %d Handle == %p\n", Result, Handle);

    // play something:
    midiOutShortMsg(Handle, 0x007f3090);

/*
    printf("\nMIDI input devices: %d\n", ins);

    for (c = 0; c < ins; c ++)
    {
        midiInGetDevCaps(c, &incaps, sizeof(incaps));
        printf("Device #%d: %s\n", c, incaps.szPname);
    }
*/
    return 0;
}