Calculating the most desirable note duration
[email protected] (Alex Lee) Fri, 11 Apr 2003 23:25:55 -0700
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <000801c300bc$603566f0$6401a8c0@pc2000> |
Hi, I have been trying to come up with a formula that could calculate the most "desirable/real" note duration (as seen on musical score), since notated duration can't be calculated as easy as...
unreal duration = noteOFF delta - noteON delta
...most likely, this woudn't yield the absolute duration as a result (half note, quarter note, 8th note, etc.); it would probably yield result like 7th note and 4.3th note (which should most likely be 8th note and quarter(4th) note).
This is what I have so far, but it doesn't convert all on-off event correctly:
closer-to-real-duration = 4*$PPQN*int($notedelta*$Granularity/(4*$PPQN) + .5)/$Granularity;
where $PPQN = beat per quarter note, $Granularity = resolution (eg.16th, 32th), $notedelta = the "unreal" duration.
This forumla wouldn't give prefect result like most notation softwares do. Could anyone point me out if I am missing something? Like tempo change, etc.? I think this could be as complicated as involving more than just 1 single formula. Any suggestion/help is greatly appreciated!
Alex