Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Playing the WHOLE midi file

This topic is 6681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using Andre LaMothe's code to play a midi file, but for some reason not all of the tracks play, only like the main track and some auxilery tracks. Big bummer: the drum track doesn't play. When i execute his example apps, it plays fine (maybe its the midi file itself?), but when i copy the code and use it myself, it doesn't work. Here's the code for loading and playing the midi: Loading:
IDirectMusicSegment* LoadMIDISegment(IDirectMusicLoader* pLoader, 
                                     WCHAR *wszMidiFileName )
// this function loads a midi segment off disk

IDirectMusicSegment* pSegment = NULL;
// get current working directory
char szDir[_MAX_PATH];
if(_getcwd( szDir, _MAX_PATH ) == NULL)
  return NULL;
  } // end if

// convert to wide characters
MULTI_TO_WIDE(wszDir, szDir);

// set the search directory
hr = pLoader->SetSearchDirectory(GUID_DirectMusicAllTypes,wszDir, FALSE);

if (FAILED(hr)) 
   return NULL;
   } // end if
// setup object description
ZeroMemory(&ObjDesc, sizeof(DMUS_OBJECTDESC));
ObjDesc.dwSize = sizeof(DMUS_OBJECTDESC);
ObjDesc.guidClass = CLSID_DirectMusicSegment;
wcscpy(ObjDesc.wszFileName, wszMidiFileName );

// load the object and query it for the IDirectMusicSegment interface
// This is done in a single call to IDirectMusicLoader::GetObject
// note that loading the object also initializes the tracks and does 
// everything else necessary to get the MIDI data ready for playback.

hr = pLoader->GetObject(&ObjDesc,IID_IDirectMusicSegment, (void**) &pSegment);

if (FAILED(hr))
// ensure that the segment plays as a standard MIDI file
// you now need to set a parameter on the band track
// Use the IDirectMusicSegment::SetParam method and let 
// DirectMusic find the trackby passing -1 (or 0xFFFFFFFF) in the dwGroupBits method parameter.

hr = pSegment->SetParam(GUID_StandardMIDIFile,-1, 0, 0, (void*)dm_perf);

if (FAILED(hr))
// This step is necessary because DirectMusic handles program changes and 
// bank selects differently for standard MIDI files than it does for MIDI 
// content authored specifically for DirectMusic. 
// The GUID_StandardMIDIFile parameter must be set before the instruments are downloaded. 

// The next step is to download the instruments. 
// This is necessary even for playing a simple MIDI file 
// because the default software synthesizer needs the DLS data 
// for the General MIDI instrument set
// If you skip this step, the MIDI file will play silently.
// Again, you call SetParam on the segment, this time specifying the GUID_Download parameter:

hr = pSegment->SetParam(GUID_Download, -1, 0, 0, (void*)dm_perf);

if (FAILED(hr))

// return the pointer
return pSegment;
} // end LoadSegment
Playing: Basically, IDirectMusicPerformance:: PlaySegmant() ^ gotta watch out for ! Edited by - Zipster on 8/28/00 8:12:16 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!