Jazz-Soft.net

We make it sound!

Home » Examples » Jazz-Plugin » VBA

Jazz-Plugin as VBA control

Though the primary purpose of Jazz-Plugin is enabling MIDI on webpages via Javascript, you can also use it as VBA control from Perl, Python, Visual Basic and other languages.

Perl

Most Perl distributions for Windows include module Win32::OLE that allows work with automated objects. To create a Jazz-Plugin instance, call Win32::OLE->new('JazzPlugin.Ctrl'). All other calls are the same as in Javascript.

The script below querries for available MIDI devices and tests each device by playing a C-major chord on it.

#!/usr/bin/perl
use Win32::OLE;
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";

my $list=$Jazz->MidiOutList();
die "No MIDI Out devices found!\n" unless $list && scalar @$list;

foreach my $dev(@$list)
{ print "\nTesting $dev\n";
  if($Jazz->MidiOutOpen($dev) eq $dev)
  { sleep 1;
    $Jazz->MidiOut(0x90,0x3c,0x7f);
    $Jazz->MidiOut(0x90,0x40,0x7f);
    $Jazz->MidiOut(0x90,0x43,0x7f);
    sleep 2;
    $Jazz->MidiOut(0x80,0x3c,0);
    $Jazz->MidiOut(0x80,0x40,0);
    $Jazz->MidiOut(0x80,0x43,0);
    print "- done!\n";
  }
  else
  { print "- cannot open!\n";
  }
}

Python

Pretty much the same as above. You may need to install Python for Windows extensions to run this script.

#!python (; Special thanks to Michael Dubner ;)
import time
import win32com.client.gencache

jazz_plugin = win32com.client.gencache.EnsureModule('{B08A99FE-0E66-467A-83D8-1E9F23EBC6C7}',0,1,0)
jazz = jazz_plugin.JazzCtrl()
assert jazz

print "Jazz-Plugin ver.", jazz.version;

devlist = jazz.MidiOutList()
if not devlist:
  print "No MIDI Out devices found!"

for dev in devlist:
  print "Testing", dev,
  if jazz.MidiOutOpen(dev) != dev:
    print "- cannot open!"
  else:
    time.sleep(1)
    jazz.MidiOut(0x90,0x3c,0x7f)
    jazz.MidiOut(0x90,0x40,0x7f)
    jazz.MidiOut(0x90,0x43,0x7f)
    time.sleep(2)
    jazz.MidiOut(0x80,0x3c,0)
    jazz.MidiOut(0x80,0x40,0)
    jazz.MidiOut(0x80,0x43,0)
    print "- done!"

Visual Basic

The instructions in this section are for Visual Studio 2008, but all steps must be very similar in other development environments.

To add Jazz-Plugin control to your control palette, go to Tools -> Choose Toolbox Items... -> COM Components, check the Jazz-Plugin checkbox, and press OK.

A new Jazz-Plugin control will appear in the palette among buttons, edit boxes and other widgets. Drag it onto your main form and make it invisible (unless you, same as me, think it looks cool :).

Check here to download the complete VB example.

Your ideas

... are welcome!

See also