[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Re: Patch: start of ALSA MIDI provider code
From: |
Anthony Green |
Subject: |
[cp-patches] Re: Patch: start of ALSA MIDI provider code |
Date: |
Sun, 02 Oct 2005 08:51:20 -0700 |
On Sun, 2005-10-02 at 01:01 -0700, Anthony Green wrote:
> Here's the start of ALSA MIDI provider code. MIDI IN ports basically
> work. You can read and print events from a MIDI keyboard using the
> standard interfaces. It's not perfect, but it's a start.
>
I you don't have any MIDI gear and still want to try this, you can use a
virtual MIDI keyboard from here:
http://mitglied.lycos.de/iwai/alsa.html
It's a tcl/tk app that implements a GUI software keyboard that hooks
into the ALSA MIDI system. If you're using an RPM based distro, you can
try rebuilding the SRPM here.
http://ccrma.stanford.edu/planetccrma/software/soundapps.html#SECTION000427900000000000000
Be sure to %define your distro at the top of the spec file. For
instance, I added "%define fc4 1"
Fire up vkeybd, and you should see it when you run aconnect like so:
$ aconnect -i -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
Connecting To: 63:0
client 62: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 72: 'USB O2' [type=kernel]
0 'USB O2 MIDI 1 '
client 128: 'Virtual Keyboard' [type=user]
0 'Virtual Keyboard'
Now the following program will hook a MIDI receiver up to the Virtual
Keyboard and print something whenever you press a key on the vkeybd GUI.
Note that the code I submitted last night doesn't understand the NOTEOFF
messages from this keyboard. That's a quick fix. The hardware keyboard
I tested with send NOTEON with velocity of 0 instead of NOTEOFF.
import javax.sound.midi.*;
public class mtest implements Receiver
{
public static void main(String args[]) throws Exception
{
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
MidiDevice inport = null;
for (int i = 0; i < aInfos.length && inport == null; i++)
{
if (aInfos[i].getName().equals ("Virtual Keyboard"))
inport = MidiSystem.getMidiDevice(aInfos[i]);
}
if (inport != null)
{
// Hook the keyboard up to our receiver (this class).
Transmitter t = inport.getTransmitter();
t.setReceiver (new mtest ());
// Just sit and wait until a key is pressed.
System.in.read();
}
else
System.err.println ("Couldn't find Virtual Keyboard");
}
public void close()
{
}
public void send(MidiMessage message, long timeStamp)
throws IllegalStateException
{
// This gets called when we receive a MIDI message.
System.out.println (message);
}
}