writting opus to file.

[email protected] Mon, 8 Nov 2004 20:05:28 -0000 (GMT)
Newsgroups perl.midi
Message-ID <[email protected]>
Hello,
        i just starded using midi perl, and i am new to perl too; i am
        having an error when calling opus->write_to_file function:

Bad index while coercing array into hash at MIDI/Opus.pm line 409.


Bellow is my code listing. I'm using perl midi 0.8 and  perl v5.8.3. Any
help?

Thanks in advance,
-Riba


for my $f ( 0 .. $#musics){
    my $midi_track = MIDI::Track->new;          # preparing to save the
generated data.
    my $midi_file = MIDI::Opus->new;            # to write tracks to file.
    my $midi_instrument = MIDI_INSTRUMENT;      # instrument to be played.
    my $dt = my $dton = my $dtoff = 0;          # delta (delay) time.
    my $chan = 1;                               # channel to play.
    my $von = 96, my $voff=0;                   # on and off note velocities.
    my @aevents;                                # vector of events.
    @music = @{$musics[$f]};
    @melody = @{$music[0]};
        $dtoff = my $donote = MIDI_DONOTE;

    push @aevents, ['text_event', $dt, "generated music $f."];
    push @aevents, ['patch_change', $dt, $chan , $midi_instrument ];
    for my $g ( 0 .. $#melody ){
        push @aevents, ['note_on', $dton, $chan, $melody[$g], $von];
        push @aevents, ['note_off', $dtoff, $chan, $melody[$g], $voff];
    }
    $midi_track->events(@aevents);
        #everything is tested and fine 'till here.
    $midi_file->format(MIDI_FORMAT);
    $midi_file->ticks(MIDI_NOT);
    $midi_file->tracks([$midi_track]);
    $midi_file->write_to_file("tinga.mid"); #if i supress this line, there
is no error (but no file
+too!).
}