[directmusic] Re: Reference_Time & Tempo

  • From: "Todor Fay" <todor@xxxxxxxxxxxxx>
  • To: <directmusic@xxxxxxxxxxxxx>
  • Date: Thu, 2 Jan 2003 10:51:35 -0800

You don't need an interrupt to find out what the current time is. Just
call GetTime() and it will return an accurate number (within a
millisecond) for the current time. 

For tempo conversion, establish a start time and then base everything
off of it. This can be at the beginning when your application starts
running. You do need to work with the concept of tempo change events.
Whenever the tempo changes, mark down both the music and reference time,
as calculated from the previous tempo marker, and then install the new
tempo rate, which will be used to calculate all time conversions after
this point. Typically, the start of playback of a sequence installs a
tempo marker with the sequence tempo at its very start.

-----Original Message-----
From: directmusic-bounce@xxxxxxxxxxxxx
[mailto:directmusic-bounce@xxxxxxxxxxxxx] On Behalf Of siegfried
Sent: Thursday, January 02, 2003 4:19 AM
To: directmusic@xxxxxxxxxxxxx
Subject: [directmusic] Re: Reference_Time & Tempo


Hello all , Have a good year !

I would thak you Toddor for your usfull help.

So I've found a turn around for matching to tempo changes , I just pass
a DMU_TEMPO message to the graph of the performance , it work well , but
not in real time :( so I think I' have to follow you advise : make my
own function to covert music_time to reference time....

If I anderstand well, the music_time represent the numer of "ticks"
generated by the clock at a defined resolution of 768 PPQ and at defined
tempo.
But I can't see how calculate the translation between referencr_time and
music_time since I can't gain acces to the interrupt of the clock

The formula I found look like this :

Genereted ticks =3D redolution(768) * (1 / tempo) * 1000 * period

I miss the period....

Another question, can I define an other PPQ ? (this is really optional)

Thanks for your help

Ziggy.

-----Original Message-----
From: directmusic-bounce@xxxxxxxxxxxxx
[mailto:directmusic-bounce@xxxxxxxxxxxxx] On Behalf Of Todor Fay
Sent: mardi 31 d=E9cembre 2002 18:02
To: directmusic@xxxxxxxxxxxxx
Subject: [directmusic] Re: Reference_Time & Tempo


Yes, the conversion of music time to reference time is determined by the
tempo.=20

If you are trying to sequence music as part of the Performance Layer,
then you really should be doing with your own track that is inserted
within a segment that can then have a tempo track. Then, you can take
advantage of all the DirectMusic technologies, like styles and
scripting, etc. And, the tempo is all taken care of for you.

But, it looks like you are working at a lower a level, essentially
writing your own sequencing engine, which is also what we expected some
people would want to do. In that case you don't need the performance at
all. But, one responsibility of a sequencing engine is to maintain its
own tempo map and do its own reference to music time conversions.

Todor

-----Original Message-----
From: directmusic-bounce@xxxxxxxxxxxxx
[mailto:directmusic-bounce@xxxxxxxxxxxxx] On Behalf Of Ziggy
Sent: Tuesday, December 31, 2002 2:48 AM
To: directmusic@xxxxxxxxxxxxx
Subject: [directmusic] Reference_Time & Tempo

Hello,
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:
=20
When the midi in port receive an event, I record it into a "Pattern"
(Own made) with the reference_Time given by the clock
=20
      REFERENCE_TIME    rt;
      DWORD                   dwGroup;
      DWORD                   cb;
      BYTE*                   pb;
=20
      while (m_pBuffer->GetNextEvent(&rt, &dwGroup, &cb, &pb) =3D=3D =
S_OK)
      {
            if (pb[0] !=3D 0x1A && pb[0] !=3D 0xFE)
            {
                  CALL_EVENTS( MidiInEvent, (this, DMMidiEvent(rt,
dwGroup, cb, pb[0], pb[1], pb[2])) ); // here I create my MidiEvent and
call an event
            }
      }
=20
      //---------------------
     =20
      OnInitRecord()
{
      m_rtStartTime =3D m_pDirectMusic->GetMasterClock()->GetTime(&rt);
//this is for retrieve the time when record start
}
//--------------------
=20
So after recording my Midievents I have to set the reference time
correctly:
=20
//--------------------
=20
For (int I =3D 0; I < MyPattern.GetMidiEventCount(); i++)
{
      // assume pEvent is a valid MidiEvent in the list
=20
            // --- Convert Current time to music time --- //
            MUSIC_TIME Mt     =3D 0;
=20
m_pDMusic->GetPerformanceInterface()->ReferenceToMusicTime(pEvent->m_Ref
Time, &Mt);
=20
            // --- convert the Start Time to music time --- //=20
            MUSIC_TIME StartMt      =3D 0;
=20
m_pDMusic->GetPerformanceInterface()->ReferenceToMusicTime(m_llPlayTime,
&StartMt);
=20
      // --- Set the relative time --- //
      pEvent->reftime =3D pEvent->reftime - m_rtStartTime; //now I have
=
a
relative time
=20
            // --- Set the relative Musictime --- //
      pEvent->m_MusiTime =3D Mt - StartMt;
}
=20
=20
for playing I'm doing the same reversed function:
=20
// assume pEvent is a valid MidiEvent in the list
REFERENCE_TIME rt       =3D 0;
      MUSIC_TIME MtOrigine    =3D 0;
MUSIC_TIME MtTotale     =3D 0;
=20
MtOrigine =3D pEvent->m_MusiTime;
      MtTotale =3D StartMt + MtOrigine;
=20
      //Convert total to REFERENCE_TIME
m_pDMusic->GetPerformanceInterface()->MusicToReferenceTime(MtTotale,
&rt);
=20
=20
      // now send the event to the port
// assume dwMsg is a valid DWORD msg
=20
      hr =3D m_pBuffer->PackStructured(rt, 1,dwMsg);
hr =3D m_pPort->PlayBuffer(m_pBuffer);
=20
this work pretty well, the probleme is for playing, it play well but I
can't change the tempo,
if  I do:
=20
// assume fTempo is ok
      hr =3D m_pDirectMusic->GetPerformanceInterface()->SetGlobalParam(
GUID_PerfMasterTempo, (void*)&fTempo, sizeof(float));=20
=20
So My question is :
=20
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 ?
=20
Please HELP !!!
=20
Thanks in advance
=20
=20
=20
=20
=20
=20









Other related posts: