[directmusic] Reference_Time & Tempo

  • From: "Ziggy" <ziggy@xxxxxxxxxxxx>
  • To: <directmusic@xxxxxxxxxxxxx>
  • Date: Tue, 31 Dec 2002 11:47:42 +0100

Since Todor told me i can't get a periodic advise from the clock , i try
to use the ReferenceTime timestamp on my midi events.
But there is few things I want to know:
When the midi in port receive an event, I record it into a "Pattern"
(Own made) with the reference_Time given by the clock
      REFERENCE_TIME    rt;
      DWORD                   dwGroup;
      DWORD                   cb;
      BYTE*                   pb;
      while (m_pBuffer->GetNextEvent(&rt, &dwGroup, &cb, &pb) == S_OK)
            if (pb[0] != 0x1A && pb[0] != 0xFE)
                  CALL_EVENTS( MidiInEvent, (this, DMMidiEvent(rt,
dwGroup, cb, pb[0], pb[1], pb[2])) ); // here I create my MidiEvent and
call an event
      m_rtStartTime = m_pDirectMusic->GetMasterClock()->GetTime(&rt);
//this is for retrieve the time when record start
So after recording my Midievents I have to set the reference time
For (int I = 0; I < MyPattern.GetMidiEventCount(); i++)
      // assume pEvent is a valid MidiEvent in the list
            // --- Convert Current time to music time --- //
            MUSIC_TIME Mt     = 0;
Time, &Mt);
            // --- convert the Start Time to music time --- // 
            MUSIC_TIME StartMt      = 0;
      // --- Set the relative time --- //
      pEvent->reftime = pEvent->reftime - m_rtStartTime; //now I have a
relative time
            // --- Set the relative Musictime --- //
      pEvent->m_MusiTime = Mt - StartMt;
for playing I'm doing the same reversed function:
// assume pEvent is a valid MidiEvent in the list
REFERENCE_TIME rt       = 0;
      MUSIC_TIME MtOrigine    = 0;
MUSIC_TIME MtTotale     = 0;
MtOrigine = pEvent->m_MusiTime;
      MtTotale = StartMt + MtOrigine;
      //Convert total to REFERENCE_TIME
      // now send the event to the port
// assume dwMsg is a valid DWORD msg
      hr = m_pBuffer->PackStructured(rt, 1,dwMsg);
hr = m_pPort->PlayBuffer(m_pBuffer);
this work pretty well, the probleme is for playing, it play well but I
can't change the tempo,
if  I do:
// assume fTempo is ok
      hr = m_pDirectMusic->GetPerformanceInterface()->SetGlobalParam(
GUID_PerfMasterTempo, (void*)&fTempo, sizeof(float)); 
So My question is :
Why the tempo of the playback never change ? does the convertion from
MUSIC-TIME to REFERENCE_TIME is dependant of the performance tempo ?
If not what can I do ?
Please HELP !!!
Thanks in advance

Other related posts: