public void PlayMidiFile(String name, String filename) { Sequencer seq = null; Transmitter seqTrans = null; Synthesizer synth; Receiver synthRcvr = null; File midiFile = null; try { seq = MidiSystem.getSequencer(); seqTrans = seq.getTransmitter(); synth = MidiSystem.getSynthesizer(); synthRcvr = synth.getReceiver(); midiFile = new File(filename); if (seq == null) { Debug.showMessage("MidiCSD::PlayMidiFile: Sequencer nicht gefunden!"); } else { seq.open(); seqTrans.setReceiver(synthRcvr); Sequence mySeq; mySeq = MidiSystem.getSequence(midiFile); new Player(name, seq, mySeq, synth, m_playing).start(); } } catch (MidiUnavailableException e) { Debug.showException(e, "MidiCSD::PlayMidiFile: MidiUnavailable" + e.getMessage()); } catch (InvalidMidiDataException e) { Debug.showException(e, "MidiCSD::PlayMidiFile: InvalidMidiDataException" + e.getMessage()); } catch (IOException e) { Debug.showException(e, "MidiCSD::PlayMidiFile:IOException (fn:" + filename + ")"); } }
/** 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); } }
public void close() { transmitter.close(); device.close(); // this.mrftd.close(); // this.transmitter.close(); }
public void closeObjectDevice() { transmitterDevice.close(); }
public void closeObjectMidiSystem() { transmitterMidiSystem.close(); }