MidiAudio(InputStream data) throws MidiUnavailableException { getSequencer(); setSequence(data); sequencer.addMetaEventListener(new MetaEventListener() { public void meta(MetaMessage msg) { if (msg.getType() == 47) { try { sequencer.setSequence(sequence); } catch (InvalidMidiDataException e) { ErrorHandler.alert(e); } sequencer.setTickPosition(0); if (loop) { // End of track sequencer.start(); } } } }); AudioFormat base = new AudioFormat(44100, 16, 2, true, false); format = new AudioFileFormat(new Type("MIDI", "mid"), base, (int) (base.getFrameRate() * (sequence.getMicrosecondLength() / 1000000 + 4))).getFormat(); }
@Override public boolean addMetaEventListener(MetaEventListener listener) { synchronized(metaEventListeners) { if (! metaEventListeners.contains(listener)) { metaEventListeners.add(listener); } return true; } }
@Override public void removeMetaEventListener(MetaEventListener listener) { synchronized(metaEventListeners) { int index = metaEventListeners.indexOf(listener); if (index >= 0) { metaEventListeners.remove(index); } } }
private void initSequencer() { // Close the sequencer and synthesizer getSequencer().addMetaEventListener(new MetaEventListener() { public void meta(MetaMessage event) { if (event.getType() == 47) { close(); } } }); }
public boolean addMetaEventListener(MetaEventListener listener) { // TODO Auto-generated method stub return false; }
public void removeMetaEventListener(MetaEventListener listener) { // TODO Auto-generated method stub }