Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple DMusic / Midi problem [Solved]

Started by Stephen R Apr 1, 2004 at 2:00 PM 0 replies 250+ views
Original Post
Stephen R
Stephen R
Hi, I just started DMusic today. All was going well until I tried to play a midi file. As far as I can tell there is no difference, code wise, between loading and playing a wav and a midi. My code is almost entirely straight from the DX9 SDK. It is probably something obvious but i'm stumped. Anyway here's the code. It results in the functions succeeding but not playing the selected midi file. Wavs work grand.
bool InitDSound(){
	CoInitialize(NULL);

	CoCreateInstance(CLSID_DirectMusicLoader, NULL, 
       CLSCTX_INPROC, IID_IDirectMusicLoader8,
       (void**)&g_pLoader);

	CoCreateInstance(CLSID_DirectMusicPerformance, NULL,
       CLSCTX_INPROC, IID_IDirectMusicPerformance8,
       (void**)&g_pPerformance );

	HRESULT hRet;
	hRet = g_pPerformance->InitAudio(NULL,NULL,hWnd,DMUS_APATH_SHARED_STEREOPLUSREVERB,64,DMUS_AUDIOF_ALL,NULL);

	if (FAILED(hRet)){
		return false;
	}

	WCHAR WBuffer[16] = L"Music.mid";
	//WCHAR WBuffer[16] = L"chimes.wav";


	g_pLoader->SetSearchDirectory( 
		GUID_DirectMusicAllTypes,   // Types of files sought.

		NULL,						// Where to look. Null for default

		FALSE                       // Don't clear object data.

	);


	if (FAILED(g_pLoader->LoadObjectFromFile(
		CLSID_DirectMusicSegment, // Class identifier.

		IID_IDirectMusicSegment8, // ID of desired interface.

		WBuffer,             // Filename.

		(LPVOID*) &g_pSegment     // Pointer that receives interface.

	)))
	{
		MessageBox( NULL, "Media not found, sample will now quit.", 
			"DirectMusic Tutorial", MB_OK );
		g_pPerformance->CloseDown();
		g_pLoader->Release(); 
		g_pPerformance->Release();
		CoUninitialize();
		return false;
	}

	if (FAILED(g_pSegment->Download(g_pPerformance))){
		return false;
	}

	if(FAILED(g_pPerformance->PlaySegmentEx(
		g_pSegment,  // Segment to play.

		NULL,        // Not used.

		NULL,        // For transitions. 

		0,           // Flags.

		0,           // Start time; 0 is immediate.

		NULL,        // Pointer that receives segment state.

		NULL,        // Object to stop.

		NULL         // Audiopath, if not default.

		))){

		return false;
	}

	
	return true;
}
Thanks in advance. EDIT - Forgot to actually state my problem. [edited by - stro on April 1, 2004 3:13:04 PM] [edited by - stro on April 1, 2004 3:50:55 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.