"Couldn't write to /dev/sequencer, bad file descriptor
at (....)Realtime.pm line 201.
####
sub send_midi_bytes {
my $self = shift;
my $device = $self->midi_device;
my $stuff = pack('C*',
(map {&SEQ_MIDIPUTC(),
$_,
$device,
0
}
@_
)
);
my $bytes = syswrite(SEQ_FH, $stuff);
if (not $bytes) {
die("Couldn't write to "
. $self->dev
. ": $!"
);
}
return $bytes;
}
####
#!/usr/bin/perl
use warnings;
use strict;
use MIDI::Realtime;
my $midi = MIDI::Realtime->new(dev=>'/dev/sequencer',
midi_device=> 0);
# Play note 47 with maximum velocity on channel 1
$midi->note(47, 127, 1);
# Now have some fun with randomness
my @notes = (37 .. 50);
# use all the channels (with extra drums)
my @channels = (1 .. 16, 10, 10, 10);
my @velocities = (70 .. 100);
for (0 .. 127) {
$midi->note($notes[rand(@notes)],
$channels[rand(@channels)],
$velocities[rand(@velocities)]
);
# Wait for a tenth of a second
select(undef,undef,undef, 0.10);
}