Results 1 to 2 of 2
- 05-25-2011, 02:08 AM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
Java won't play midi sequences. How can I get this to work?
Hi,
I am running java on my mac OS X 10.4
I cannot create and play midi notes.
No error is thrown, but no sound comes from my speakers.
Is the problem in my code, or with my mac?
Thanks,
Jack
code:
Java Code:import javax.sound.midi.*; public class MiniMusicCmdLine { static { System.out.println("Initialising..."); } public static void main(String[] args) { MiniMusicCmdLine mini = new MiniMusicCmdLine(); String errorMsg = "Error - Main requires two intigers for input."; try { int instrument = 1; int note = 12; mini.play(instrument, note); } catch(Exception ex){ System.out.println(errorMsg); } System.out.println("End of programme");//wrap up } public void play(int instrument, int note){ try { System.out.println("entering play()"); System.out.println("Initialising variables..."); Sequencer player = MidiSystem.getSequencer(); player.open(); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); MidiEvent event = null; ShortMessage first = new ShortMessage(); first.setMessage(192, 1, instrument, 1000); MidiEvent changeInstrument = new MidiEvent(first, 1); track.add(changeInstrument); ShortMessage a = new ShortMessage(); a.setMessage(144, 1, note, 100); MidiEvent noteOn = new MidiEvent(a, 1); track.add(noteOn); ShortMessage b = new ShortMessage(); b.setMessage(128, 1, note, 100); MidiEvent noteOff = new MidiEvent(b, 1); track.add(noteOff); player.setSequence(seq); System.out.println("Our control flow has reached open() and start()."); player.open(); player.start(); System.out.println("Now calling open(), start() five times..."); try { for (int i = 1 ;i < 6; i++) { player.open(); player.start(); System.out.print(i + " "); } System.out.println("\n"); } catch(Exception ex) { System.out.println("Error Caught while looping. Throwing to play()"); throw(ex); } System.out.println("Calling stop() and close() on our midi sequence"); player.stop(); player.close(); System.out.println("Exiting main()..."); } catch(Exception ex) { System.out.println("Error caught in play..."); ex.printStackTrace(); } } }Last edited by Fubarable; 05-25-2011 at 03:15 AM. Reason: code tags added
- 05-26-2011, 10:14 AM #2
I don't know whether this applies to a Mac, but a soundbank isn't included in the Windows installation of the JRE, only with the JDK.
On Windows, the solution is to copy the file soundbank.gm from <JDK folder>\jre\lib\audio to <JRE folder>\lib\audio. Or download a soundbank (*.gm) and place it in the lib/audio folder.
db
Similar Threads
-
javax.sound play midi
By Dennis in forum Advanced JavaReplies: 6Last Post: 06-08-2010, 04:59 PM -
Create and play midi notes
By tor in forum New To JavaReplies: 0Last Post: 04-26-2010, 12:18 AM -
for loops and escape sequences
By orangefest in forum New To JavaReplies: 1Last Post: 04-19-2009, 08:55 PM -
how to play MIDI in java application?
By oregon in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 02:26 AM -
Oracle sequences
By orchid in forum JDBCReplies: 5Last Post: 04-19-2007, 03:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks