Advertisement

Playing the WHOLE midi file

Started by August 28, 2000 08:11 PM
0 comments, last by Zipster 24 years, 2 months ago
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

DMUS_OBJECTDESC ObjDesc; 
HRESULT hr;
IDirectMusicSegment* pSegment = NULL;
 
// get current working directory
char szDir[_MAX_PATH];
WCHAR wszDir[_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 );

ObjDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
 
// 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))
   return(0);
 
// 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))
   return(0);
  
// 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(0);

// 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
Are you sure the MIDI channels are set correctly on the MIDI file?

zero
static music




Edited by - LJG on August 29, 2000 5:49:01 PM

This topic is closed to new replies.

Advertisement