[directmusic] Playing multiple MIDI segments, aligned

  • From: Abhijit Patait <abhijit_patait@xxxxxxxxx>
  • To: directmusic@xxxxxxxxxxxxx
  • Date: Tue, 11 May 2004 17:43:39 -0700 (PDT)

I am writing an application where I want to play multiple MIDI files 
simultaneously. In order to play these files, I load each file into a segment, 
and call PlaySegmentEx(...) on each of the segments (actually, I am using the 
class CSegment from Todor Fay's book "DirectX 9 Audio Exposed"). I want the 
segments to be aligned to the beginning, and therefore, I play the first 
segment as primary segment and all others as secondary segments with the 
appropriate alignment flags. Here is the code snippet that achieves the above.
 
BOOL bFirstSegment = TRUE;
// Assume that CString filename[] contains names of the MIDI files to be played
 for (i = 0; i < 2; i++)
 {
    WCHAR wzFileName[DMUS_MAX_FILENAME];
    mbstowcs(wzFileName, filename[i].GetBuffer(DMUS_MAX_FILENAME), 
DMUS_MAX_FILENAME);
    CSegment *pSegment = pAudio->LoadSegment(wzFileName);
    // Use default flags for first segment
    if (!bFirstSegment)
     pSegment->SetFlags(DMUS_SEGF_SECONDARY | DMUS_SEGF_SEGMENTEND | 
DMUS_SEGF_ALIGN | DMUS_SEGF_VALID_START_BEAT);
    bFirstSegment = FALSE;
 }
The first segment loads and starts playing, but as soon as the second segment 
starts playing, the first gets muted, even though the two segments are aligned 
as expected. However, I don't understand why the first segment gets muted.
 
I have tried the experiment with the same two MIDI files, with "Segment Jones" 
application provided with the above-mentioned book, and have seen the same 
results (secondary segment muting the primary segment).
 
How can I play both segments simultaneously?
 
I would really appreciate someone helping me on this.
 
Thank you in advance.
 
-Abhijit
 
PS: If needed, I can send additional code snippets and/or the MIDI files that I 
am using for this experiment. The test MIDI files contain a sequence of about 
20 note on/off messages. Both midi files have the same length and same note 
on/off sequence, but on different channels with different patches (instruments).
 

                
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 


Other related posts: