We make it sound!

Home » Examples » Jazz-Plugin » VBA » MIDI Input

MIDI Input (VBA)

Starting from version 1.3, Jazz-Plugin allows polling MIDI In connections in sequential manner.

The example below is written in Perl, but it works the same way in all VBA-based applications:

- Open the connection by calling MidiInOpen() with no callback specified.

- Call QueryMidiIn() in the cycle to check if any MIDI message had arrived.

How it works

This example creates an instance of VBA object for each MIDI input (if there are more than one) and stores the references in the array.

In the main loop it checks if any keyboard or MIDI input is available until the <Esc> key is pressed.

Source code

use Win32::OLE;
use Term::ReadKey;
use strict;

my $Jazz=Win32::OLE->new('JazzPlugin.Ctrl') or die "Jazz-Plugin not found!\n";
my $ver=$Jazz->version;
print "Jazz-Plugin ver. $ver\n\n";

my $list=$Jazz->MidiInList();
if(!$list || !scalar @$list)
{ print "No MIDI inputs found!\n";

my @devices;
my @names;

for(my $i=0;$i<scalar @$list;$i++)
{ my $name=$list->[$i];
  if($name ne $Jazz->MidiInOpen($name))
  { print "Cannot open $name\n";
  print "Opening $name\n";
  push @devices,$Jazz;
  push @names,$name;
exit(0) if !scalar @devices;

print "\nPress <Esc> to exit...\n\n";

ReadMode 4;
{ my $key=ReadKey(-1);
  last if $key eq "\e"; ### <Esc>
  for(my $i=0;$i<scalar @devices;$i++)
  { my $msg=$devices[$i]->QueryMidiIn();
    next if !$msg || !scalar @$msg;
    print "$names[$i]:";
    for(my $j=1;$j<scalar @$msg;$j++) ### skip the first array element - it's a timestamp
    { printf(" %02x",$msg->[$j]);
    print "\n";
ReadMode 0;

See also