re: Problems converting a score back to midi
[email protected] ("Noel Lairson") Sun, 17 Aug 2003 14:50:50 -0700
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <000501c36509$a03e62e0$b6e5fea9@fido> |
Dave -
It looks like you are using the 'n' function in a way it is not meant to be
used.
'n' works horizontally (i.e. across time). It takes a set of parameters and
adds them to an array that will eventually be parsed into MIDI. All
considerations of time are handled internally in the 'n' function, and can't
really be manipulated from the parameter set. 'n' advances the time by 'd'
every time it is called, so on the offchance that calling it with 2 sets of
parameters even works:
#called at time = 192
n V64, c2, d96, n62, V96, c1, d192, n32 ;
it should yield this in the array:
['note', 192, 96, 2, 62, 64]
['note', 288, 192, 1, 32, 96]
#[event, time, duration, channel, note number, velocity]
Which is not what you want. In order to make 'n' behave vertically - i.e.
chords - you need to jump through some hoops. This is what the synch();
call is for. synch(); takes references to subroutines as arguments - it
runs the first code, then resets the time to what it was when you called
synch(); and runs the next subroutine.
If you _know_ exactly what notes you wish to use, you could do this:
synch(\&ch1, \&ch2);
sub ch1 {
noop c1; #all notes happen on channel 1
n V96, d96, n37; # 0 - quarter note
n V96, d96, n41; # 96 - "
n V96, d96, n39; # 192 - "
n V96, d192, n32 ;#288 - half note
}
sub ch2 {
noop c2; #all notes happen on channel 2
r d192; #a rest, duration 192
n V64, d96, n62; #a quarter note
}
This will render 4 notes, 3 quarter notes and a half note. On the 4th beat,
channel 2 plays a quarternote. Which is what you seem to be trying to do.
Another approach to creating chords is this:
synch(\&$one, \&$two, \&$three);
my $one = sub{
#code to create note
#end result should be an 'n' or 'r' call, so
n 48, 'v58', c1, d192; #MIDI::Simple will read '48' as 'n48'
}
my $two = sub {
#same idea
n 53, c1, 'v52', d96;
n 52, c1, 'v49', d96;
}
my $three = sub {
#etc
r d96;
n 55, c1, 'v60', d96;
}
This uses 3 anonymous subroutines to call the 'n' function, and synch(); to
start each subroutine at the time it was called. I constructed a Csus4
moving to a C chord; $one played a C for a half note, $two played an F
quarter note follwed by an E quarter note, $three rested, then hit a G
simultaneous to $two's E.
Clear? Unclear? Hope this helped.
Noel