Seconds to delta offset in midi file

Discussion in 'comp.music.midi' started by Peter Zegelin, Jun 28, 2003.

  1. Hi,
    I need to figure out how to convert an offset expressed in seconds to
    a delta time within a list of midi events.
    I thought it would be quite straight forward but it looks like tempo
    changes would complicate things a bit. Is it really just a case of
    accumulating a total time in seconds based on a particular conversion
    rate until a tempo change event is found, calculating a new conversion
    rate, and continuing until the desired time is reached? Or am I missing
    something here?
    Can anyone help me with the calculations required?

    Many thanks!

    Peter
  2. I think you've got the idea. The MIDI file header tells you how many
    quanta per quarter-note pertain in that particular file. The tempo
    change events tell you how many microseconds duration is each quarter
    note. By accumulating deltas, you keep track of how many quarter notes
    have elapsed. By doing simple arithmetic, you convert those quarters to
    seconds. You establish a new "baseline" for calculations whenever you
    encounter a tempo change event.

    So, your given time, minus the time at which the most recent tempo
    change occurred, converted to quanta, plus the quantum at which the
    most recent tempo change occurred, is the quantum where your given time
    occurs. OK?

    Philip.

    In article <peter-58D45D.14212528062003@iridium.webone.com.au>, Peter
    Zegelin <peter@fracturedsoftware.com> wrote:

    > Hi,
    > I need to figure out how to convert an offset expressed in seconds to
    > a delta time within a list of midi events.
    > I thought it would be quite straight forward but it looks like tempo
    > changes would complicate things a bit. Is it really just a case of
    > accumulating a total time in seconds based on a particular conversion
    > rate until a tempo change event is found, calculating a new conversion
    > rate, and continuing until the desired time is reached? Or am I missing
    > something here?
    > Can anyone help me with the calculations required?
    >
    > Many thanks!
    >
    > Peter
  3. Thanks Philip!
    Yes it makes sense. I wanted to confirm the general idea and make
    sure I wasnt missing anything. Now to try it in the real world!

    Thanks again for your explanation,

    Peter


    >In article <280620030058258672%philip@chorus.I_LOVE_SPAM.net>,
    > Philip Delaquess <philip@chorus.I_LOVE_SPAM.net> wrote:


    > I think you've got the idea. The MIDI file header tells you how many
    > quanta per quarter-note pertain in that particular file. The tempo
    > change events tell you how many microseconds duration is each quarter
    > note. By accumulating deltas, you keep track of how many quarter notes
    > have elapsed. By doing simple arithmetic, you convert those quarters to
    > seconds. You establish a new "baseline" for calculations whenever you
    > encounter a tempo change event.
    >
    > So, your given time, minus the time at which the most recent tempo
    > change occurred, converted to quanta, plus the quantum at which the
    > most recent tempo change occurred, is the quantum where your given time
    > occurs. OK?
    >
    > Philip.
    >
    > In article <peter-58D45D.14212528062003@iridium.webone.com.au>, Peter
    > Zegelin <peter@fracturedsoftware.com> wrote:
    >
    > > Hi,
    > > I need to figure out how to convert an offset expressed in seconds to
    > > a delta time within a list of midi events.
    > > I thought it would be quite straight forward but it looks like tempo
    > > changes would complicate things a bit. Is it really just a case of
    > > accumulating a total time in seconds based on a particular conversion
    > > rate until a tempo change event is found, calculating a new conversion
    > > rate, and continuing until the desired time is reached? Or am I missing
    > > something here?
    > > Can anyone help me with the calculations required?
    > >
    > > Many thanks!
    > >
    > > Peter

Share This Page