Пример #1
0
  public void go() {
    setUpGui();

    try {

      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      // make a sequencer and open
      sequencer.addControllerEventListener(m1, new int[] {127});
      Sequence seq = new Sequence(Sequence.PPQ, 4);
      Track track = seq.createTrack();

      int r = 0;
      for (int i = 0; i < 300; i += 4) {

        r = (int) ((Math.random() * 50) + 1);
        track.add(makeEvent(144, 1, r, 100, i));
        track.add(makeEvent(176, 1, 127, 0, i));
        track.add(makeEvent(128, 1, r, 100, i + 2));
      } // end loop

      sequencer.setSequence(seq);
      sequencer.start();
      sequencer.setTempoInBPM(120);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  } // close method
Пример #2
0
 /**
  * This method is called by the sound system when a meta event occurs. In this case, when the
  * end-of-track meta event is received, the sequence is restarted if looping is on.
  *
  * @param event
  */
 public void meta(MetaMessage event) {
   if (event.getType() == END_OF_TRACK_MESSAGE) {
     if (sequencer != null && sequencer.isOpen() && loop) {
       sequencer.start();
     }
   }
 }
Пример #3
0
 /** Configura o estado de pausa. A música pode não parar imediatamente. */
 public void setPaused(boolean paused) {
   if (this.paused != paused && sequencer != null) {
     this.paused = paused;
     if (paused) {
       sequencer.stop();
     } else {
       sequencer.start();
     }
   }
 }
Пример #4
0
  public void playResume() {

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

        sequencer.start();
        playState = PLAYING;
      }
    }
  }
Пример #5
0
 /**
  * Plays a sequence, optionally looping. This method returns immediately. The sequence is not
  * played if it is invalid.
  *
  * @param sequence
  * @param loop
  */
 public void play(Sequence sequence, boolean loop) {
   if (sequencer != null && sequence != null && sequencer.isOpen()) {
     try {
       sequencer.setSequence(sequence);
       sequencer.start();
       this.loop = loop;
     } catch (InvalidMidiDataException ex) {
       ex.printStackTrace();
     }
   }
 }
Пример #6
0
  public void playLoop() {

    if (sequence != null) {
      double playStartTime = (player.getSeekTime() / 100) * (playGetLength());
      sequencer.setMicrosecondPosition((long) playStartTime);
      if (playState != PLAYING) {
        sequencer.start();
        playState = PLAYING;
      }
    }
  }
Пример #7
0
 public void go() {
   try {
     sq.open();
     Sequence seq = new Sequence(Sequence.PPQ, 4);
     Track track = seq.createTrack();
     track.add(addNote(144, 9, 56, 100, 1));
     track.add(addNote(128, 9, 56, 100, 4));
     sq.setSequence(seq);
     sq.setTempoInBPM(tempo);
     sq.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
     sq.start();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Пример #8
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;
    }
  }
Пример #9
0
 /** Plays back the song. */
 public void play() throws MidiUnavailableException {
   sequencer.start();
 }