How can I run this java program? Please help.
I have jmf installed, sunone running , the file may be in the wrong directory.
It is in some directory nowhere near the java lang dir.
When I try to compile or build i cant. I'm off on a basic thing.
here is the code.
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;
public class MidiNote
/** Flag for debugging messages.
If true, some messages are dumped to the console
during operation.
private static boolean DEBUG = false;
public static void main(String[] args)
try {
// TODO: make settable via command line
int nChannel = 0;
int nKey = 0; // MIDI key number
int nVelocity = 0;
* Time between note on and note off event in
* milliseconds. Note that on most systems, the
* best resolution you can expect are 10 ms.
int nDuration = 0;
int nArgumentIndexOffset = 0;
String strDeviceName = null;
if (args.length == 4)
strDeviceName = args[0];
nArgumentIndexOffset = 1;
else if (args.length == 3)
nArgumentIndexOffset = 0;
else
printUsageAndExit();
nKey = Integer.parseInt(args[0 + nArgumentIndexOffset]);
nKey = Math.min(127, Math.max(0, nKey));
nVelocity = Integer.parseInt(args[1 + nArgumentIndexOffset]);
nVelocity = Math.min(127, Math.max(0, nVelocity));
nDuration = Integer.parseInt(args[2 + nArgumentIndexOffset]);
nDuration = Math.max(0, nDuration);
MidiDevice outputDevice = null;
Receiver receiver = null;
if (strDeviceName != null)
MidiDevice.Info info = getMidiDeviceInfo(strDeviceName, true);
if (info == null)
out("no device info found for name " + strDeviceName);
System.exit(1);
try
outputDevice = MidiSystem.getMidiDevice(info);
outputDevice.open();
catch (MidiUnavailableException e)
if (DEBUG) { out(e); }
if (outputDevice == null)
out("wasn't able to retrieve MidiDevice");
System.exit(1);
try
receiver = outputDevice.getReceiver();
catch (MidiUnavailableException e)
if (DEBUG) { out(e); }
else
/* We retrieve a Receiver for the default
MidiDevice.
try
receiver = MidiSystem.getReceiver();
catch (MidiUnavailableException e)
if (DEBUG) { out(e); }
if (receiver == null)
out("wasn't able to retrieve Receiver");
System.exit(1);
/* Here, we prepare the MIDI messages to send.
Obviously, one is for turning the key on and
one for turning it off.
MidiMessage onMessage = null;
MidiMessage offMessage = null;
try
onMessage = new ShortMessage();
offMessage = new ShortMessage();
((ShortMessage) onMessage).setMessage(ShortMessage.NOTE_ON, nChannel, nKey, nVelocity);
((ShortMessage) offMessage).setMessage(ShortMessage.NOTE_OFF, nChannel, nKey);
/* test for SysEx messages */
//byte[] data = { (byte) 0xF0, (byte) 0xF7, (byte) 0x99, 0x40, 0x7F, 0x40, 0x00 };
//onMessage = new SysexMessage();
//offMessage = new SysexMessage();
//onMessage.setMessage(data, data.length);
//offMessage = (SysexMessage) onMessage.clone();
catch (InvalidMidiDataException e)
if (DEBUG) { out(e); }
* Turn the note on
receiver.send(onMessage, -1);
* Wait for the specified amount of time
* (the duration of the note).
try
Thread.sleep(nDuration);
catch (InterruptedException e)
if (DEBUG) { out(e); }
* Turn the note off.
receiver.send(offMessage, -1);
* Clean up.
receiver.close();
if (outputDevice != null)
outputDevice.close();
} catch (Throwable t) {
out(t);
System.exit(0);
private static void printUsageAndExit()
out("MidiNote: usage:");
out(" java MidiNote [<device name>] <note number> <velocity> <duration>");
out(" <device name>\toutput to named device");
out(" -D\tenables debugging output");
System.exit(1);
private static void listDevicesAndExit(boolean forInput, boolean forOutput) {
if (forInput && !forOutput) {
out("Available MIDI IN Devices:");
else if (!forInput && forOutput) {
out("Available MIDI OUT Devices:");
} else {
out("Available MIDI Devices:");
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {
out(""+i+" "
+(bAllowsInput?"IN ":" ")
+(bAllowsOutput?"OUT ":" ")
+aInfos[i].getName()+", "
+aInfos[i].getVendor()+", "
+aInfos[i].getVersion()+", "
+aInfos[i].getDescription());
catch (MidiUnavailableException e) {
// device is obviously not available...
if (aInfos.length == 0) {
out("[No devices available]");
System.exit(0);
e
* This method tries to return a MidiDevice.Info whose name
* matches the passed name. If no matching MidiDevice.Info is
* found, null is returned.
* If forOutput is true, then only output devices are searched,
* otherwise only input devices.
private static MidiDevice.Info getMidiDeviceInfo(String strDeviceName, boolean forOutput) {
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
if (aInfos[i].getName().equals(strDeviceName)) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsOutput && forOutput) || (bAllowsInput && !forOutput)) {
return aInfos[i];
} catch (MidiUnavailableException mue) {}
return null;
private static void out(String strMessage)
System.out.println(strMessage);
private static void out(Throwable t)
t.printStackTrace();
Please post your code using code tags.
When I try to compile or build i cant.What is your question? Exactly what error message do you get?
Similar Messages
-
How can i run my java program with out java language
Hai to every one ..Iam new to java language ...am using windows xp operating system , i did not installed java language in my system .. how can i run a java program with out installing java language... Which files is requied to run java program..?
any one can help me??Hai to every one ..Iam new to java language ...am
using windows xp operating system , i did not
installed java language in my system .. how can i run
a java program with out installing java language...
you ... can ... not ... do ... this
Which files is requied to run java program..?
any one can help me??a JVM. Download it from sun's website.
[url http://java.sun.com/javase/downloads/index.jsp]Download JavaSE here -
How can i apply this java program for a jsp page?
import java.io.*;
import java.util.*;
public class FileProcessing
//create a vector container for the input variables
Vector variables = new Vector();
//create a vector container for the constants
Vector constants = new Vector();
/*create a string expression container for the equation
as read from the file */
String expression = " ";
//create double result container for the final result
double result = 0;
public boolean processFile(String filename,String delim)
//index for values vector
int num_values = 0;
//index for constants vector
int num_constants = 0;
//current line being read from the external file.
String curline = " ";
//start reading from the external file
try
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
while(true)
curline = br.readLine();
if(curline == null)
break;
//determine the type of current interaction
boolean variable = curline.startsWith("input");
boolean constant = curline.startsWith("constant");
boolean equation = curline.startsWith("equation");
boolean output = curline.startsWith("result");
//on input variables
if(variable)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count=0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==1)
byte b[]= new byte[100];
System.out.println(temp);
System.in.read(b);
String inputval = (new String(b)).trim();
variables.add(num_values,inputval);
num_values++;
count++;
// on constant values
if(constant)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count = 0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==1)
byte b[]= new byte[100];
System.out.println(temp);
System.in.read(b);
String cons = (new String(b)).trim();
constants.add(num_constants,cons);
num_constants++;
count++;
// on equation
if(equation)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count = 0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==2)
this.expression = temp;
count++;
// now we are ready to evaluate the expression
if(output)
org.nfunk.jep.JEP myparser= new org.nfunk.jep.JEP();
myparser.setAllowAssignment(true);
for(int i=1;i<variables.size()+1;i++)
String name = "arg"+Integer.toString(i);
myparser.addVariable(name,new Double(variables.get(i-1)
.toString()).doubleValue());
for(int i=1;i<constants.size()+1;i++)
String name = "arg" +Integer.
toString(i+variables.size());
myparser.addConstant(name,new Double(constants.get(i-1).toString()));
//output is obtained as follows
myparser.parseExpression(expression);
result = myparser.getValue();
System.out.println("Assay value: "+result);
catch(Exception e)
System.out.println(e.toString());
return true;
public static void main(String[] args)
FileProcessing fp = new FileProcessing();
fp.processFile("input.eqn",":");
}//my text file name is: "input.eqn" (given below)
input:Enter Value1:arg1
input:Enter Value2:arg2
input:Enter Value3:arg3
constant:arg4
constant:arg5
Equation:arg1+arg2+arg3
result:how can i apply this java program for a jsp pagewhy do you want to do this ?
Your program reads from a file on the disk and formats based on a patterm.
Jsp is not intended for such stuff.
ram. -
My Ipod doesen't work when I try to connect it on my iTunes! How can I solve this problem? Please help me
Itunes doesen't see the ipod and it is all dark!
-
How can i run my java program in background process?
hi all,
i am working on desktop monitoring so when i start my program on client machine that is visible to all but i want this program client not visible to all instead of this can be run in background process . so, nobody can see that.
so, how i can do this ?
pls pls help me
thanks in advanced to helper
regards
maulik & riteshthis will run the java program in the background.It'll just use the Windows Java Console instead of the command-line console. It has nothing to do with running as a background process.
Edit: though this might be exactly what the OP wants: not "background process" but "no DOS console". -
How can i use this java program to access from a jsp page?
import java.io.*;
import java.util.*;
public class FileProcessing
//create a vector container for the input variables
Vector variables = new Vector();
//create a vector container for the constants
Vector constants = new Vector();
/*create a string expression container for the equation
as read from the file */
String expression = " ";
//create double result container for the final result
double result = 0;
public boolean processFile(String filename,String delim)
//index for values vector
int num_values = 0;
//index for constants vector
int num_constants = 0;
//current line being read from the external file.
String curline = " ";
//start reading from the external file
try
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
while(true)
curline = br.readLine();
if(curline == null)
break;
//determine the type of current interaction
boolean variable = curline.startsWith("input");
boolean constant = curline.startsWith("constant");
boolean equation = curline.startsWith("equation");
boolean output = curline.startsWith("result");
//on input variables
if(variable)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count=0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==1)
byte b[]= new byte[100];
System.out.println(temp);
System.in.read(b);
String inputval = (new String(b)).trim();
variables.add(num_values,inputval);
num_values++;
count++;
// on constant values
if(constant)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count = 0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==1)
byte b[]= new byte[100];
System.out.println(temp);
System.in.read(b);
String cons = (new String(b)).trim();
constants.add(num_constants,cons);
num_constants++;
count++;
// on equation
if(equation)
StringTokenizer st = new StringTokenizer(curline,delim);
int num = st.countTokens();
int count = 0;
while(st.hasMoreTokens())
String temp = st.nextToken();
if(count==2)
this.expression = temp;
count++;
// now we are ready to evaluate the expression
if(output)
org.nfunk.jep.JEP myparser= new org.nfunk.jep.JEP();
myparser.setAllowAssignment(true);
for(int i=1;i<variables.size()+1;i++)
String name = "arg"+Integer.toString(i);
myparser.addVariable(name,new Double(variables.get(i-1)
.toString()).doubleValue());
for(int i=1;i<constants.size()+1;i++)
String name = "arg" +Integer.
toString(i+variables.size());
myparser.addConstant(name,new Double(constants.get(i-1).toString()));
//output is obtained as follows
myparser.parseExpression(expression);
result = myparser.getValue();
System.out.println("Assay value: "+result);
catch(Exception e)
System.out.println(e.toString());
return true;
public static void main(String[] args)
FileProcessing fp = new FileProcessing();
fp.processFile("input.eqn",":");
}here i need to generate the strings like 'enter value1' and respective text boxes dynamically . i should use this java program as business logic and a jsp page for view.
following given is my text file input.eqn
input:enter value1:arg1
input:enter value2:arg2
input:enter value3:arg3
constant:enter constant1:arg4
constant:enter constant2:arg5
equation:enter equation:(arg1+arg2)*(arg3+arg4)*arg5
result:Why do you double post ? http://forum.java.sun.com/thread.jspa?threadID=646988&tstart=0
Why dint that answer satisfy you ? And why dint you say so in that thread rather than posting the same question again ?
ram. -
How can I run a java program on Linux?
I have JBuilder's IDE installed on my Linux partition and it works. However I don't know how to compile and test a program without it. Also I tried to install Limewire on Linux and although I've installed the Java SDK on the system. Once before I installed JBuilder and then JBuilder (I guess) installed it again. However it told me it couldn't find the Java Virtual Machine. Isn't this installed with the JDK? I am able to run programs through JBuilder so I can't see why I'd have a problem. Any answers to the above issues would be greatly appreciated.
Go here and work out how to make a simple app to compile and run on the command line: http://java.sun.com/docs/books/tutorial/getStarted/cupojava/unix.html#2b
(You should find the JDK from a directory under the jbuilder directory so use that and not the /usr/local/jdk1.4 in the example.)
Then find the classes or source code of your project and do the same thing to it. -
I updated my iphone software to IOS 6.2 yesterday and im not sure if it is a coincidence but now, my contact names do not show on incomming calls or messages. Also they do not show on past calls or recent history.
All my contacts in my phonebook still exist and are correct, the problem only occurs when receiving calls or messages. please help i need this fixing
Regards,
FrostyTry to restore your iphone via iTunes or update to ios6.1.2.
If itunes gives an error with restoring (DFU/Recovery or just normal)
try this:
open your computer and search on windows; C://windows/system32/drivers/etc/hosts
open up the hosts file in note pad you will see IP adresses and more add another line and put in this:
#74.208.10.249 gs.apple.com
this is a by-pass to the cydia/saurik restore server, it has nothing to do with jailbreaking over voiding apple's warranty
let me know if succeeded! -
Please help
It might have something to do with Proxies. Have a look in System Preferences>Network, click on your network - either ethernet or wifi - and click on the Proxies tab. Anything selected in there. If so deselect and then try.
Have you tried using another brrowser, maybe Chrome or Firefox? -
Since I updated IOS 7 in my iPad, it doesn´t work and appears the Apple logo in the screen all the time. Any solution?
1) Connect to iTunes on the computer you usually Sync with and “ Restore “...
http://support.apple.com/kb/HT1414
2) If necessary Place the Device into Recovery mode...
http://support.apple.com/kb/ht4097
Note on Recovery Mode.
You may need to try this More than Once...
Be sure to Follow ALL the Steps...
Once you have Recovered your Device...
Re-Sync your Content or Restore from the most Recent Backup...
Restore from Backup
http://support.apple.com/kb/ht1766
NOTE:
Make sure you have the Latest Version of iTunes Installed on your computer ( v 11.1)
iTunes free download from www.itunes.com/download -
How can I run a java-application on starting of Windows 2000
How can I run a java-application without any user on starting of Windows 2000?
For example, if the computer is restarted and nobody enter into it yet, my java-application should run anyway.
How can I do that?Hi, you have to put it in a Windows service.
To do this you have a program, Srvany.exe that allow to insert a .exe or .bat program in a Windows service.
For example, i develop a program, TomcatGuardian and i put it in a service because i need to run it in a server without Administrator logged in.
Regards,
Ivan. -
How do i run a java program an another directory?
How do I run a java program that's in a different directory?
I have been doing this in the command line:
java "C:\Document and Settings\freeOn\Desktop\Java\Test\test"
and I get
Exception in thread "main" java.lang.NoClassDefFoundError:
C:\Document and Settings\freeOn\Desktop\Java\Test\test
I just thought there might be a quick way to do this and not
have to cd to the following dir evertime i want to run an app in
console.
The test.java file is this:
import java.io.*;
public class test {
public static void main(String args[]) {
System.out.println("Testing.....");Ok I looked in the java help and found the classpath, this makes it alittle easier.
java -cp C:\DOCUME~1\freeOn\Desktop\Java\Test\ test
At least i can run this in the run dialog which makes it easier thanks for you help kota balaji -
How can I run external console program, printing output to JTextPane?
How can I run external console program, printing output to JTextPane?
I have a console app. written in C++ and I would like to run in it from java swing app. and I would like to see its output in a JTextPane.I have used this article
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
to successfully pipe output from jboss batch files to a JTextPane. -
i developed app in mac 10.6.8 with xcode 3.2.6.how can i run this app in ipad device
actually i planned to get provisioning profiles from apple by paying 99$ in following website
https://developer.apple.com/programs/start/ios/ and followed by
https://developer.apple.com/programs/start/standard/.
but in last link,following thing were mentioned at bottom -
Technical Requirements
You must have an Intel-based Mac running OS X 10.8 Mountain Lion or later to develop and distribute iOS apps and Mac apps.
but i\m using mac running OS X 10.6.8 snow leopard.
Doubt:can't i run my app in ipad device?\
Thank's in advance.. -
There's green mark has been shown on the left side of the screen on and off . How can I solve this problem ? Please.
iMac (27-inch Mid 2011), Mac OS 8.6 or Earlier
Not possible. Which OS is currently installed on your iMac?
If your iMac came w/DVDs when you originally purchased it, run the Apple Hardware Test and post back the results.
If you are still under warranty and/or have AppleCare, call them. Let them deal w/it.
Maybe you are looking for
-
Best Practice for Using Static Data in PDPs or Project Plan
Hi There, I want to make custom reports using PDPs & Project Plan data. What is the Best Practice for using "Static/Random Data" (which is not available in MS Project 2013 columns) in PDPs & MS Project 2013? Should I add that data in Custom Field (in
-
What is the maximum number of pages in an iweb site
Is there a limit to the number of pages I can put in my iweb site? I managed 30 but ran out of room in the nav bar for more pages. Thanks for helping
-
Two major bugs in Lion - Zoom and Safari auto fill search bar
hey there every since I updated to Lion I've been experiencing two major bugs... zoom randomly stops working (the one where you press control and zoom in and out) even though it's set to work on the settings. Safari is also experincing a problem conc
-
External Java Function with a Result Type
Dear all, I have created a workflow process which use a Function Activity of type "External Java" without a result type and it works fine, but i have created another with the result type of boolean (WFSTD_BOOLEAN) and it doesn't work properly. I will
-
Recomendations for Hard Drive recovery tool
Does any one have a recommendation for a Hard Drive recovery tool? My brothers external Lacie 200MB Firewire drive has crapped out. He has all his family movies (iMovie projects) stored on it so he really needs to recover the files if possible. I hav