Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Applets
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Applets
MIDI problems when launching applet through browser
Udit Manektala
Ranch Hand
Posts: 30
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
So basically Im trying to play a MIDI Note on the Mouse onClick and it works fine in my eclipse workspace but but doesnt really work when i play it through the browser or the
applet
viewer.
Here's the code
public class FretBoard extends Applet implements MouseListener, MouseMotionListener, Runnable, ActionListener { MIDI midi = new MIDI(); ... ... ... public void mousePressed(MouseEvent arg0) { System.out.println("Play Note"); midi.playSingleNote(60); repaint(); } } //End applet Class //MIDI Class class MIDI { Sequencer sequencer=null; Synthesizer synthesizer=null; Sequence mySeq=null; Track t=null; Thread animator=null; int volume=83; int timeCounter=0; int tempo=120; public static final int END_OF_TRACK = 47; { try{ sequencer = MidiSystem.getSequencer( ); sequencer.open( ); synthesizer = MidiSystem.getSynthesizer( ); synthesizer.open( ); sequencer.getTransmitter( ).setReceiver(synthesizer.getReceiver( )); mySeq=new Sequence(Sequence.PPQ,10 ); t = mySeq.createTrack(); } catch(Exception e) { System.out.println(e); } } public void playSingleNote(int note) { ShortMessage myMsg = new ShortMessage(); ShortMessage myMsg2 = new ShortMessage(); // Start playing the note Middle C (60), // moderately loud (velocity = 93). try{ myMsg.setMessage(ShortMessage.NOTE_ON, 0, note, 93); myMsg2.setMessage(ShortMessage.NOTE_OFF,0, note, 93); long timeStamp = -1; Receiver rcvr = MidiSystem.getReceiver(); //repaint(); rcvr.send(myMsg, timeStamp); Thread.sleep(200); rcvr.send(myMsg2, timeStamp); } catch(Exception e){} } public void setTempo(int bpm) { tempo=bpm; } }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Simple MIDI program - not working?
MIDI
Multiple Sequencers In Applet
Java Class hangs after run
Constructing a MIDI Sequence...tickCounts
More...