Beispiel #1
0
//-----------------------------------------------------------------------------
// Name: DPUtil_OpenSession()
// Desc: Wrapper for DirectPlay OpenSession API. 
//-----------------------------------------------------------------------------
HRESULT DPUtil_OpenSession( GUID* pSessionGUID )
{
    if( NULL == g_pDP)
        return DPERR_NOINTERFACE;

    DPSESSIONDESC2 dpDesc;
    ZeroMemory( &dpDesc, sizeof(dpDesc) );
    dpDesc.dwSize = sizeof(dpDesc);
    if( g_bUseProtocol )
        dpDesc.dwFlags = DPSESSION_DIRECTPLAYPROTOCOL;

    // Set the session guid
    if( pSessionGUID )
        dpDesc.guidInstance = (*pSessionGUID);
    // Set the application guid
    dpDesc.guidApplication = g_AppGUID;

    // Open it
    HRESULT hr = g_pDP->Open( &dpDesc, DPOPEN_JOIN );

    // Check for Async message support
    if( SUCCEEDED(hr) )
        CheckCaps();

    return hr;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Name: DPUtil_CreateSession()
// Desc: Wrapper for DirectPlay CreateSession API.Uses the global application
//       guid.
//-----------------------------------------------------------------------------
HRESULT DPUtil_CreateSession( TCHAR* strSessionName )
{
    if( NULL == g_pDP )
        return DPERR_NOINTERFACE;

    DPSESSIONDESC2 dpDesc;
    ZeroMemory( &dpDesc, sizeof(dpDesc) );
    dpDesc.dwSize  = sizeof(dpDesc);
    dpDesc.dwFlags = DPSESSION_MIGRATEHOST | DPSESSION_KEEPALIVE;
    if( g_bUseProtocol )
        dpDesc.dwFlags |= DPSESSION_DIRECTPLAYPROTOCOL;

#ifdef UNICODE
    dpDesc.lpszSessionName  = strSessionName;
#else
    dpDesc.lpszSessionNameA = strSessionName;
#endif

    // Set the application guid
    dpDesc.guidApplication = g_AppGUID;

    HRESULT hr = g_pDP->Open( &dpDesc, DPOPEN_CREATE );

    // Check for Async message support
    if( SUCCEEDED(hr) )
        CheckCaps();

    return hr;
}
void MIDIStreamer::Play(bool looping, int subsong)
{
	DWORD tid;
	EMidiDevice devtype;

	m_Status = STATE_Stopped;
	m_Looping = looping;
	EndQueued = 0;
	VolumeChanged = false;
	Restarting = true;
	InitialPlayback = true;

	assert(MIDI == NULL);
	devtype = SelectMIDIDevice(DeviceType);
	if (DumpFilename.IsNotEmpty())
	{
		if (devtype == MDEV_GUS)
		{
			MIDI = new TimidityWaveWriterMIDIDevice(DumpFilename, 0);
		}
	}
	else
	{
		MIDI = CreateMIDIDevice(devtype);
	}
	
#ifndef _WIN32
	assert(MIDI == NULL || MIDI->NeedThreadedCallback() == false);
#endif

	if (MIDI == NULL || 0 != MIDI->Open(Callback, this))
	{
		Printf(PRINT_BOLD, "Could not open MIDI out device\n");
		return;
	}

	SetMIDISubsong(subsong);
	CheckCaps(MIDI->GetTechnology());

	if (MIDI->Preprocess(this, looping))
	{
		StartPlayback();
		if (MIDI == NULL)
		{ // The MIDI file had no content and has been automatically closed.
			return;
		}
	}

	if (0 != MIDI->Resume())
	{
		Printf ("Starting MIDI playback failed\n");
		Stop();
	}
	else
	{
#ifdef _WIN32
		if (MIDI->NeedThreadedCallback())
		{
			PlayerThread = CreateThread(NULL, 0, PlayerProc, this, 0, &tid);
			if (PlayerThread == NULL)
			{
				Printf ("Creating MIDI thread failed\n");
				Stop();
			}
			else
			{
				m_Status = STATE_Playing;
			}
		}
		else
#endif
		{
			m_Status = STATE_Playing;
		}
	}
}