fbpx
Skip to main content

MIDI Forum

calculate the durat...
 
Notifications
Clear all

calculate the duration of the notes

14 Posts
5 Users
0 Reactions
7,612 Views
Mark
 Mark
Posts: 27
Eminent Member
Topic starter
 

in the midi file dump below, I have ppqn = 480 and bpm = 120. For a 4/4 note I was expecting 1920 ticks for the first note, instead it's 1823 ticks; the remaining 97 ticks are part of the next ON note: why?
If I read 1823 instead of 1920 (480 * 4) from the file, how do I understand that it is a 4/4 note?

Thank you

[code type=markup]
000000 4d 54 68 64 Chunk ("MThd")
000004 00 00 00 06 length (6)
000008 00 01 Format (1)
00000a 00 01 NumberOfTracks (1)
00000c 01 e0 TimeBase (480)
00000e 4d 54 72 6b Chunk ("MTrk")
000012 00 00 00 6d length (109)
delta : tick :
000016 00 ff 58 04 04 02 18 08 +0 = 0 : Meta:TimeSig (4/4, Metronome=24MIDICLK, 8/32=24MIDICLK)
00001e 00 ff 59 02 00 00 +0 = 0 : Meta:KeySig (0 major = "C Maj")
000024 00 ff 51 03 07 a1 20 +0 = 0 : Meta:SetTempo (500000 = 120)
00002b 00 b0 79 00 +0 = 0 : CtrlChg (ch:1 CC#121(RstALlCtl) val:0)
00002f 00 c0 00 +0 = 0 : ProgChg (ch:1 pg:0)
000032 00 b0 07 64 +0 = 0 : CtrlChg (ch:1 CC#7 (ChVolum) val:100)
000036 00 0a 40 +0 = 0 : CtrlChg (ch:1 CC#10 (Pan ) val:64)(RunStat)
000039 00 5b 00 +0 = 0 : CtrlChg (ch:1 CC#91 (Eff1Dep) val:0)(RunStat)
00003c 00 5d 00 +0 = 0 : CtrlChg (ch:1 CC#93 (Eff3Dep) val:0)(RunStat)
00003f 00 ff 21 01 00 +0 = 0 : Meta:PortPrefix
000044 00 90 40 50 +0 = 0 : NoteOn (ch:1 note:64 velo:80)
000048 8e 1f 40 00 +1823 = 1823 : NoteOn (ch:1 note:64 velo:0)(RunStat)
00004c 61 40 50 +97 = 1920 : NoteOn (ch:1 note:64 velo:80)(RunStat)
00004f 87 0f 40 00 +911 = 2831 : NoteOn (ch:1 note:64 velo:0)(RunStat)
000053 87 71 40 50 +1009 = 3840 : NoteOn (ch:1 note:64 velo:80)(RunStat)
000057 83 47 40 00 +455 = 4295 : NoteOn (ch:1 note:64 velo:0)(RunStat)
00005b 8b 39 40 50 +1465 = 5760 : NoteOn (ch:1 note:64 velo:80)(RunStat)
00005f 81 63 40 00 +227 = 5987 : NoteOn (ch:1 note:64 velo:0)(RunStat)
000063 8d 1d 40 50 +1693 = 7680 : NoteOn (ch:1 note:64 velo:80)(RunStat)
000067 71 40 00 +113 = 7793 : NoteOn (ch:1 note:64 velo:0)(RunStat)
00006a 8e 0f 40 50 +1807 = 9600 : NoteOn (ch:1 note:64 velo:80)(RunStat)
00006e 38 40 00 +56 = 9656 : NoteOn (ch:1 note:64 velo:0)(RunStat)
000071 8e 48 40 50 +1864 = 11520 : NoteOn (ch:1 note:64 velo:80)(RunStat)
000075 1b 40 00 +27 = 11547 : NoteOn (ch:1 note:64 velo:0)(RunStat)
000078 8e 65 40 50 +1893 = 13440 : NoteOn (ch:1 note:64 velo:80)(RunStat)
00007c 0d 40 00 +13 = 13453 : NoteOn (ch:1 note:64 velo:0)(RunStat)
00007f 01 ff 2f 00 +1 = 13454 : Meta:EndOfTrack
[/code]

 
Posted : 17/05/2021 12:40 am
Jonas
Posts: 207
Reputable Member
 

I am not knowledgeable about midi, but when recording live play noone manage to play exact notedivisions/ticks within the chosen ppq and bpm, that is for transcribed sheetnotes ,if you write music?
And it would not sound musical if one did.
I guess you just round the timing value, number of ticks between note on->note off to the nearest full note partitioned value?

 
Posted : 17/05/2021 2:48 am
Mark
 Mark
Posts: 27
Eminent Member
Topic starter
 

sorry Jonas, but that dump of a midi file was not obtained with a live recording, it was written with musescore, so I expected a very precise result. However, if from a midi file I read 1823 ticks instead of 1920 ticks, with ppqn = 480, it becomes difficult to establish that it is a 4/4 note.

Thanks anyway for the information.

 
Posted : 17/05/2021 3:01 am
JohnG
Posts: 226
 

Jonas is quite right.
Most/many sequencing programs do not enter a fuil note but usually about 95% of the full value.
You'll find that a quarter note is about 456 ticks, a half note about 912.
Some sequencers allow you to set the percentage duration.

I suspect that Musescore will change the duration to 100% if you mark the music as being played Legato.

 
Posted : 17/05/2021 3:42 am
Mark
 Mark
Posts: 27
Eminent Member
Topic starter
 

thanks JohnG, I think it's as you say. Perhaps, software such as musescore, avoid inserting very precise ticks so that the less mechanical execution possible, more human.
Every day, a new one is discovered.

 
Posted : 17/05/2021 4:24 am
Jonas
Posts: 207
Reputable Member
 

sorry Jonas, but that dump of a midi file was not obtained with a live recording, it was written with musescore, so I expected a very precise result. However, if from a midi file I read 1823 ticks instead of 1920 ticks, with ppqn = 480, it becomes difficult to establish that it is a 4/4 note.

Thanks anyway for the information.

I think you just calculate the tick amounts for the full note given PPQ and BPM and calculate partial note ticks as fractions, and then you compare which number of ticks closest to the "recorded" value. So for PPQ 480 and BPM 120 it becomes how close your value is to the below that decide what note value it have.
1920=1920/1, 960=1920/2, 480=1920/4, 240=1920/8, 120=1920/16,60=1920/32, 30=1920/64
At least that is the way i should do it.

But if the ticks just between.like 360 ticks... Well i know to little about sheet music to know howto handle that. I have a feeling though when in doubt shorten the note.

 
Posted : 17/05/2021 7:49 am
Jonas
Posts: 207
Reputable Member
 

I will be a little heretic here at midi association another way ot think of it is simply use BPM, and use highest possible "realtime" recording values stored. At playup you will have a maximum polling speed depending on hardware. Changing BPM is a fractional change of your "recording".

BPM is of course just the metronome speed "and also the playup speed" changing between two BPM is a fractional timechange.

PPQ is really not necessary unless "your playup use ticks" i do not think i will rather maximum pollling speed, so there is still ticks of sort but they are not connected to "note length".
I guess you could say the polling speed of the realtime clock is the resolution of the recording, but it is not variable.
I would say it is probably more analog way to do things, "less quantisation?"

Ok enough of heretic rants for the day.

 
Posted : 17/05/2021 8:25 am
Mark
 Mark
Posts: 27
Eminent Member
Topic starter
 

thanks Jonas.

To solve I simply do:

[code type=markup]
if (tick >= 1440 && tick <= 1920)
it's a 4/4 note
if (tick >= 960 && tick <= 1440)
it's a 2/4 note
[/code]

and so on

 
Posted : 17/05/2021 10:31 am
Jonas
Posts: 207
Reputable Member
 

Yeah that is the way i would do it.

 
Posted : 17/05/2021 11:49 am
Mike Kent
Posts: 86
Trusted Member
 

You probably want to leave room for 1/4 notes that last just a little longer than 1920 clicks.

Chair of MIDI 2.0 Working Group

 
Posted : 17/05/2021 12:15 pm
Jonas
Posts: 207
Reputable Member
 

I think you mean 480 clicks Mike 480=1920/4 (parts of full note) ?

 
Posted : 17/05/2021 5:01 pm
JohnG
Posts: 226
 

Also, be prepared to find notes having values greater than their notated length, e.g. 481 or 961, etc.

When using various synths or VST sample players, in order to get musical phrases to sound correct, notes within a phrase are overlapped beyond the start of the next note, in order to cut out the attack portion of succeeding notes. Within such phrased sequences one will often find the MIDI controller CC#68 "on" (>64) before or during the first note of the phrase and off again during the last note. (Some VSTs use CC#64 for the same task.)

 
Posted : 18/05/2021 5:08 am
Yisheng
Posts: 1
New Member
 

triggering of note-off event is not the exact end of the note. it also has to go through the release phase. if it goes note-off at the end of the 1/4 note, it will spill over to the next one.

the interval amount you described is consistent with typical muscore generated midi files.

 
Posted : 19/05/2021 11:49 am
Mark
 Mark
Posts: 27
Eminent Member
Topic starter
 

I find correct what you say Yisheng. I wrote a midi-> wav converter calculating the buffer size for each note using the delta time as the buffer position; but at the end you always have to add a certain amount (0.5 seconds of sound) otherwise the release of the note is cut off.

 
Posted : 20/05/2021 2:02 am
Share: