/** Gets the default transmitter and receiver, and then links them. */ private void linkTransmitterToReceiver() { try { // Set up the sequencer (including its tempo) sequencer.open(); sequencer.setSequence(sequence); sequencer.setTempoInBPM(song.getBPM()); // Get the system's default synthesizer and set that up, too. Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); // Get the receiver and transmitter to use and set those up. Receiver receiver = synth.getReceiver(); Transmitter transmitter = sequencer.getTransmitter(); transmitter.setReceiver(receiver); } catch (Exception ex) { // Something went wrong. ex.printStackTrace(); System.exit(1); } }
/** Plays back the song. */ public void play() throws MidiUnavailableException { sequencer.start(); }