Java MIDI message problem

O

omalley.ronan

I wrote this code to transmit a single MIDI message to a user specified
receiver,

Control Change, Chanel 16, Controller 0 , Data = 127

0xBF , 0x00, 0x7F

But instead of sending these three bytes its sending loads of bytes.
Seems like its sending at least one hundred. Heres the code, all help
greatly appreeciated.

Ronan

/*
* Main.java
*
* Created on 24 March 2006, 15:02
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package miditest;


import javax.sound.midi.*;
import javax.swing.JOptionPane;
/**
*
* @author Ron
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("JAVA MIDI TEST APPLICATION");
System.out.println("________________________________________");

// Obtain information about all the installed synthesizers.

MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();

MidiDevice device = null;


for (int i = 0; i < infos.length; i++)
{
System.out.println(i + ". " + infos);
System.out.println("Name: " + infos.getName());
System.out.println("Description: " +
infos.getDescription());
System.out.println("Vendor: " + infos.getVendor());
System.out.println("Version: " + infos.getVersion());

System.out.println("---------------------------------------");
System.out.println("");
}

String s = JOptionPane.showInputDialog("Input index of chosen
MIDI device");

int index = Integer.parseInt(s);

try
{
device = MidiSystem.getMidiDevice(infos[index]);
}
catch (MidiUnavailableException mue2)
{
System.out.println("ROM: Exception 2");
System.out.println(mue2);
}


if (!(device.isOpen()))
{
try
{
device.open();
System.out.println("device opened successfully");

}
catch (Exception e)//(MidiUnavailableException mue3)
{
System.out.println("ROM: Exception 3");
System.out.println(e);
}
}


ShortMessage m = new ShortMessage();

try
{
// m.setMessage(ShortMessage.CONTROL_CHANGE, 15, 0, 127);
//m.setMessage(0xbf,0x07,0x7f);
m.setMessage(191,7,127);
}
catch(InvalidMidiDataException imde1)
{
System.out.println("ROM: Exception 4");
System.out.println(imde1);
}

Receiver r = null;


//List rxrs = device.getReceivers();
/*
while(Iterator it = rxrs.listIterator(); it.hasNext(); )
{
MidiDevice ddd = it.next();
System.out.println(ddd);
}
*/

try
{

//r = MidiSystem.getReceiver();
r = device.getReceiver();


System.out.println(MidiSystem.getReceiver());
}
catch (MidiUnavailableException mue4)
{
System.out.println("ROM: Exception 5");
System.out.println(mue4);
}

r.send(m,-1L);

try
{
Thread.sleep(200);
}
catch(InterruptedException e)
{
System.out.println(e);
}

r.close();
device.close();

}// public static void main
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top