Exemple #1
0
  public void playStop() {

    if (sequence != null) {
      if (playState == PLAYING || playState == PAUSED) {
        sequencer.stop();
        sequencer.close();
        playState = STOPPED;
      }
    }
  }
Exemple #2
0
  public void playLoop() {

    if (sequence != null) {
      double playStartTime = (player.getSeekTime() / 100) * (playGetLength());
      sequencer.setMicrosecondPosition((long) playStartTime);
      if (playState != PLAYING) {
        sequencer.start();
        playState = PLAYING;
      }
    }
  }
Exemple #3
0
  public void playResume() {

    if (sequence != null) {
      if (playState == PAUSED) {

        sequencer.start();
        playState = PLAYING;
      }
    }
  }
Exemple #4
0
  public void playPause() {

    if (sequence != null) {
      if (playState == PLAYING) {

        sequencer.stop();
        playState = PAUSED;
      }
    }
  }
Exemple #5
0
 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;
 }
Exemple #6
0
  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;
    }
  }
Exemple #7
0
  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;
  }
Exemple #8
0
  public void playSetSeek(double seekTime) {

    if (sequence != null) {
      sequencer.setMicrosecondPosition((long) (seekTime * 1000.0));
    }
  }
Exemple #9
0
 public double playGetTime() {
   if (sequence != null) {
     return ((double) sequencer.getMicrosecondPosition()) / 1000.0;
   }
   return 0;
 }