Re: odd rhythms - how?

[email protected] ("Sean M. Burke") Mon, 12 May 2003 19:31:24 -0800
Newsgroups perl.midi
Message-ID <[email protected]>
At 07:03 PM 2003-05-12 -0700, Noel Lairson wrote:
>>I am just trying to write some code to create rhythms like 5:3 or 3:2 - 
>>so five beats in the same time of three beats or three in the same of two.
>[...]Tempo(480);
>The basic idea is that more tics gives more opportunities fot the math to
>work out even (or make it less obvious when it doesn't).  I use 480 because
>it's the highest Cakewalk can handle, in case I have to dump the file in for
>editing).  You can use more but it should generally be a multiple of 96.[...]

In case anyone missed the logic there, here's more of a hint:  intervals in 
MIDI are expressed in "ticks", an arbitrary unit of time that is a level or 
two removed from being an actual unit of time (like microseconds), via a 
detour thru two variables:  ticks-per-quarter-note, and 
quarter-notes-per-second (well, actually it's how many 
milliseconds-per-quarter-note, but don't think too much about that).

So be able to slice a quarter note into N parts, the ticks-per-quarter-note 
has to be a multiple of N -- so if you want to have a third of a quarter 
note, you'll need ticks-per-quarter-note to be a multiple of three.
The normal value is 96, which is 2*2*2*2*2 * 3.  So if you want to have a 
6th of a qn, or an 8th of a qn, or a 24th of a qn, this is fine, because 6 
is 2*3, and there's a 2 and a 3 in 2*2*2*2*2 * 3; ditto 8 (2*2*2); and 
ditto 24 (2*2*2 * 3).

But if you want a 5th of a quarter-note, you're in trouble, because 96 
isn't a multiple of 5.  Now, you could just change ticks-per-quarter-note 
to 5, and you could express a fifth of a quarter note as being 1 tick 
long.  But then you wouldn't be able to express an eighth note, because 5 
isn't evenly divisible by 2.  So to get all the expressive power of current 
note stuff (as determined by the fact it's based on 96), it's safest to 
just multiply 96 by whatever numbers you'll be wanting to slice on (like 5).

In a pinch, you could probably just make it a multiple of 48 (2*2*2*2 * 3), 
since the situations where you'd need to have all five 2's in the 
ticks-per-quarter-note are very rare.  I think it comes up only when you're 
trying to do a double-dotted 64th-note.

Of course, this all assumes your notes last exactly as long as a textbook 
plain/dotted/doubledotted/triplet whole/half/quarter/8th/16th/32nd/64th 
note.  MIDI data captured from actual hands-moving-on-an-instrument will 
likely have no particular relationship to these ideal durations.


So... so... where's all the fun things people are writing with 
MIDI-Perl?  I want to hear!  I promise to say only nice things -- since I 
am endlessly and reliably entertained by whatever kookoo stuff people do 
with MIDI-Perl.

--
Sean M. Burke    http://search.cpan.org/~sburke/