I got it to play a chord! It's not pretty, nor is it optimized. It is fairly easy to understand though.
use Win32::MIDI; my $midi_obj = Win32::MIDI->new(); $midi_obj->openDevice(0); indiv(1, 3); # 1 second duration, start at middle C chord(3, 3); # 3 second duration, same chord sleep(1); $midi_obj->closeDevice(); # play_note(NOTE, DURATION, VELOCITY, CHANNEL, ON/OFF, OCTAVE) sub indiv { my $duration = shift; my $octave = shift; # play each note individually $midi_obj->play_note('C', $duration, 127, 1, 1, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('E', $duration, 127, 1, 1, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('G', $duration, 127, 1, 1, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('C', $duration, 127, 1, 1, $octave+1) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); } sub chord { # get the duration to play the C chord my $duration = shift; # get the octave to play the C chord at my $octave = shift; # play the chord $midi_obj->play_note('C', $duration, 127, 1, 0, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('E', $duration, 127, 1, 0, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('G', $duration, 127, 1, 0, $octave) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); $midi_obj->play_note('C', $duration, 127, 1, 1, $octave+1) || print $midi_obj->error() . "\n" and $midi_obj->reset_error(); }
Updated: Moved the individual notes into a different subroutine. Changed ON/OFF flag for final note of chord to 1. Added duration parameter to both subroutines.
In reply to Re: playing chords with MIDI modules...
by Mr. Muskrat
in thread playing chords with MIDI modules...
by primus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |