Roland Part 2


I decided to modify the K-Gater program in several ways as I began implementing the code for the Roland keyboard controller. First, I split up the code for opening the receiver to the K-Pro from the rest of the initialization so I could make it more modular. This allowed me to add checks for whether a device implements the Sequencer or Synthesizer classes. (Because none of the external hardware I’m using do either, I’m not doing anything special with this new code.) The purpose of getMidiDevice() then is to just receive the name of the desired port as a character string, and return an instance of the MidiDevice class if the port name is found (i.e. – if the device is turned on and plugged into the computer.) I use the testMode variable to determine how much data to print out to the jTextArea1 box (1 = print name, description, vendor, version. 2 = only print the name. 0 = don’t print anything).

initMidiDevices() is where I make the calls to MidiDevice() with the names of each of the desired ports. Note that while the A-300 Pro has three ports (A-PRO 1, A-PRO 2 and A-PRO MIDI IN), only the first two transmit controller data right now. So, I use the aProMaxPorts variable to determine how many ports to connect to. Only using the first two can help speed the program up a little bit later on. Otherwise, this section works pretty much like the original K-Gater code did when I just had the K-Pro.

New methods:

private MidiDevice getMidiDevice(String deviceName, int testMode)
private void initMidiDevices()

As a recap, once we have the K-Pro Midi Device instance, we want to get a receiver and then open it, as shown in the code snippet.

MidiDevice kProDevice = null;
Receiver kProRcvr = null;

kProDevice = getMidiDevice(“KAOSSILATOR PRO 1 SOUND”, 0);
if(kProDevice != null) {
kProRcvr = kProDevice.getReceiver();
}

The difference with the A-300 is that we want to get a transmitter instead of a receiver.

MidiDevice [] a300Device = new MidiDevice[3];
Transmitter [] a300Xmtr = new Transmitter[3];
int aProMaxPorts = 2;
String [] aProPortNames = {“A-PRO 1”, “A-PRO 2”, “A-PRO MIDI IN”};

a300Device[i] = getMidiDevice(aProPortNames[i], 0);
if(a300Device[i] != null) {
a300Xmtr[i] = a300Device[i].getTransmitter();
}

———————– Raw code.

MidiDevice kProDevice = null;
Receiver kProRcvr = null;

MidiDevice [] a300Device = new MidiDevice[3];
Transmitter [] a300Xmtr = new Transmitter[3];
int aProMaxPorts = 2;
String [] aProPortNames = {“A-PRO 1”, “A-PRO 2”, “A-PRO MIDI IN”};

private MidiDevice getMidiDevice(String deviceName, int testMode) {
MidiDevice ret = null;
int holdNo = -1;

MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
if(testMode == 1) jTextArea1.append(infos[i].getDescription() + “\n” + infos[i].getName() + “\n” + infos[i].getVendor() + “\n” + infos[i].getVersion() + “\n\n”);
if(testMode == 2) jTextArea1.append(infos[i].getName() + “\n”);

if(infos[i].getName().contains(deviceName)) {
if(holdNo == -1) { // Only return first match
holdNo = i;
try {
ret = MidiSystem.getMidiDevice(infos[i]);
} catch (MidiUnavailableException e) {
JOptionPane.showMessageDialog(this, “Couldn’t Get Device:” + i, “Device Open Error”, JOptionPane.PLAIN_MESSAGE);
ret = null;
}
if(debug) {
if (ret instanceof Synthesizer) {
JOptionPane.showMessageDialog(this, deviceName + ” is a synthesizer!”, “Whee!”, JOptionPane.PLAIN_MESSAGE);
}
if (ret instanceof Sequencer) {
JOptionPane.showMessageDialog(this, deviceName + ” is a sequencer!”, “Whee!”, JOptionPane.PLAIN_MESSAGE);
}
}
if (! (ret.isOpen())) {
try {
ret.open();
} catch (MidiUnavailableException e) {
JOptionPane.showMessageDialog(this, “Couldn’t Open Device:” + ret.toString(), “Device Open Error”, JOptionPane.PLAIN_MESSAGE);
ret = null;
}
}
}
}
}
return(ret);
}

private void initMidiDevices() {
kProDevice = getMidiDevice(“KAOSSILATOR PRO 1 SOUND”, 0); // Try to open K-Pro
if(kProDevice != null) {
try {
kProRcvr = kProDevice.getReceiver();
} catch (MidiUnavailableException e) {
JOptionPane.showMessageDialog(this, “Couldn’t Open Receiver:” + kProDevice.toString(), “Receiver Open Error”, JOptionPane.PLAIN_MESSAGE);
}
initkProInstrumentList();
} else {
jComboBox1.setEnabled(false); // Deactivate K-Pro related buttons if no K-Pro
for(int i=0; i<11; i++) {
jBList.get(i).setEnabled(false);
}
}

for(int i = 0; i < aProMaxPorts; i++) { // Try to open A-300 Pro ports
a300Device[i] = getMidiDevice(aProPortNames[i], 0); // String: deviceName, testMode 1 = all midi name info; 2 = name only
if(a300Device[i] != null) {
try {
a300Xmtr[i] = a300Device[i].getTransmitter();
} catch (MidiUnavailableException e) {
JOptionPane.showMessageDialog(this, “Couldn’t Open Transmitter:” + a300Device[i].toString(), “Transmitter Open Error”, JOptionPane.PLAIN_MESSAGE);
}
}
}
}

 

Advertisements
Previous Post
Next Post
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: