[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] SimpleMIDIFile, get the duration and onset-time of the events



Hi Luca,

the "tick" is the standard time unit for MIDI files, according to the SMF format. A tick is a division of a beat. The default division is 1024, meaning 1024 ticks == 1 beat (quarter note), but imported MIDI files can have different division values (for example Sibelius outputs MIDI files with 960 division if I remember correctly). So the actual start / end / duration times of notes of a file in timeMode == 'ticks' depends on the tempo (which is stored in the metaEvents if there are tempo changes in the file, and otherwise in the <midifile>.tempo ). The timeMode_( \seconds ) option is a convenience mode which makes things within SC a lot easier. Setting the timeMode to seconds internally converts the ticks to whole seconds, using the tempo information in the file, for easier manipulation in SC. When a MIDI file is written to disk however, information will be converted back to ticks, and the timing resolution will be dictated by the division setting (ticks are stored as integers). Hope that helps to understand,

cheers,
Wouter

Op 7 mrt. 2019, om 13:07 heeft mr.lucedan@xxxxxxxxxx het volgende geschreven:

Thank you both,

I will try Daniel's method later.
However, I did write a function to do the t0 - t1, and I was not obtaining the correct durations. I see that you suggest that it may be because the time is given in 'ticks'. That's a useful information, thanks (even if I don't get what's a 'tick' :).
I will try to convert it to seconds.

Best
Luca

From: owner-sc-users@xxxxxxxxxxxxxxxx <owner-sc-users@xxxxxxxxxxxxxxxx> on behalf of jamshark70@xxxxxxxxx <jamshark70@xxxxxxxxx>
Sent: 07 March 2019 00:03
To: sc-users
Subject: Re: [sc-users] SimpleMIDIFile, get the duration and onset-time of the events
 
On Wed, Mar 6, 2019 at 10:57 PM <mr.lucedan@xxxxxxxxxx> wrote:
> I am using the SimpleMIDIFile UGen.

It's a language-side class, not a server-side UGen.

> The file does provide information for each event like this: [ 0, 1320, noteOn, 0, 50, 127 ]
> I don't understand how to get the duration of the event.

MIDI represents one note as two events:

- noteOn with note number x at time t0
- noteOff with note number x at time t1

The duration, then, is t1 - t0.

If you are looking at the noteOn event (array format in
SimpleMIDIFile), then you know t0 (= 1320 in your example), but you
don't know t1 yet.

You have to scan forward in the list of notes until you find the next
noteOff with the same note number. Then you have t1.

It's not convenient. MIDI is designed for performance data, not
musical-analytical data.

> I believed that array[1] was the time in ms in which the event happens, but it is not (I have compared it against the actual midi playing).

See `timeMode_()` -- 1320 looks like it's measured in "ticks"
(internal MIDI representation). These are probably not meaningful to
you. But you can set `myMIDIFile.timeMode = \seconds`.

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/