Re: odd rhythms - how?
[email protected] ("Noel Lairson") Mon, 12 May 2003 19:03:45 -0700
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <002f01c318f3$e296f790$b6e5fea9@fido> |
Boy, did you ever write at the right time. Odd rhythms with perl is all I'm
doing right now. I'm going to assume you know enough perl and midi::perl so
that I don't have to post a whole lot of source code. Write back if you
need more.
Here's how I do it:
First, change the default tics-per-quarter note:
new_score;
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.
Then I create an array of duration values. Since my programs do this
randomly, it's something like this:
my $number_of_notes = int(rand(9)+1);
my $number_of_tics = (int(rand(9)+1)*480);
#let's say it comes out 9 notes over 3360 tics (7 beats)
my $note_duration = $number_of_tics/$number_of_notes;
#so create an array of note values
for(my $a = 0; $a<$number_of_notes; $a++) {
$notes[$a] = $note_duration;
}
#but since 3360/9 = 373.3333333, you're going to need to add tics. I do it
this way:
$remainder = $number_of_tics % $number_of_notes;
while($remainder > 0) {
$notes[int(rand($#notes)+1)]++;
$remainder--;
}
#this randomly spreads extra tics around the array until all the values in
@note add up to $number_of_tics
#since 1 tic = 1/480 of a quarter note, you're not going to notice the
difference in size
#then burn it:
my $dur = shift @notes;
n $note_number, 'd'.$dur;
Hope that's clear.
Noel
----- Original Message -----
From: <[email protected]>
To: <[email protected]>
Sent: Monday, May 12, 2003 1:32 AM
Subject: odd rhythms - how?
> Hey,
>
> 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.
> Would be great if there is a solution for doing that...
> Best regards,
>
> Nikolai Onken