Last active
December 25, 2015 19:39
-
-
Save dagon666/7029630 to your computer and use it in GitHub Desktop.
mid_converter processing loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while (1) { | |
| my @alsa_event = MIDI::ALSA::input(); | |
| # last event -> exit | |
| last if ($alsa_event[0] == SND_SEQ_EVENT_PORT_UNSUBSCRIBED()); | |
| # midi event to midi score event | |
| my @score_event = MIDI::ALSA::alsa2scoreevent( @alsa_event ); | |
| # filter out empty events | |
| next unless (@score_event && defined $score_event[0] && defined $score_event[4]); | |
| # accept only note events | |
| next unless ('note' eq $score_event[0]); | |
| print Dumper \@score_event; | |
| # accept only events on specified channel | |
| next unless (scalar @ARGV == 0 || grep { $_ == $score_event[3] } @ARGV ); | |
| # calculate the pitch and duration | |
| # some offset since Arduino can't play notes lower than 31 Hz | |
| my $note = int($notes[($score_event[4] % 96) + 32]); | |
| # my $dur = int( $score_event[2]/1000 - 0.5); | |
| my $dur = 160; | |
| my $send = $port->write(slip_send($note, $dur)); | |
| while (!$port->write_drain) {} | |
| my ($count_in, $string_in) = $port->read(5); | |
| print "Sent: [$note/$dur] Recv [$count_in]: " . unpack "H*", $string_in; | |
| print "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment