public void playStop() { if (sequence != null) { if (playState == PLAYING || playState == PAUSED) { sequencer.stop(); sequencer.close(); playState = STOPPED; } } }
public void playLoop() { if (sequence != null) { double playStartTime = (player.getSeekTime() / 100) * (playGetLength()); sequencer.setMicrosecondPosition((long) playStartTime); if (playState != PLAYING) { sequencer.start(); playState = PLAYING; } } }
public void playResume() { if (sequence != null) { if (playState == PAUSED) { sequencer.start(); playState = PLAYING; } } }
public void playPause() { if (sequence != null) { if (playState == PLAYING) { sequencer.stop(); playState = PAUSED; } } }
public void close() { System.out.println("midi closing"); if (synthesizer != null) { synthesizer.close(); } if (sequencer != null) { sequencer.close(); } sequencer = null; synthesizer = null; instruments = null; channels = null; }
public boolean play() { try { if (playState != STOPPED) playStop(); if (sequence == null) return false; if (sequencer == null) return false; sequencer.open(); sequencer.setSequence(sequence); double playStartTime = (player.getSeekTime() / 100) * (playGetLength()); sequencer.setMicrosecondPosition((long) playStartTime); sequencer.start(); playState = PLAYING; return true; } catch (Exception ex) { ex.printStackTrace(); playState = STOPPED; return false; } }
public boolean open() { try { if (synthesizer == null) { if ((synthesizer = MidiSystem.getSynthesizer()) == null) { System.out.println("getSynthesizer() failed!"); return false; } } synthesizer.open(); sequencer = MidiSystem.getSequencer(); sequencer.addMetaEventListener(new ProcessMeta()); sequence = new Sequence(Sequence.PPQ, 10); } catch (Exception ex) { System.out.println("midi exception 1 "); ex.printStackTrace(); return false; } System.out.println("midi opening"); Soundbank sb = synthesizer.getDefaultSoundbank(); if (sb != null) { instruments = synthesizer.getDefaultSoundbank().getInstruments(); synthesizer.loadInstrument(instruments[0]); } MidiChannel midiChannels[] = synthesizer.getChannels(); numChannels = midiChannels.length; channels = new ChannelData[midiChannels.length]; if (channels.length == 0) return false; for (int i = 0; i < channels.length; i++) { channels[i] = new ChannelData(midiChannels[i], i); } cc = channels[0]; return true; }
public void playSetSeek(double seekTime) { if (sequence != null) { sequencer.setMicrosecondPosition((long) (seekTime * 1000.0)); } }
public double playGetTime() { if (sequence != null) { return ((double) sequencer.getMicrosecondPosition()) / 1000.0; } return 0; }