1

I'm writing some code that will when run, auto-starts playback of a midi sequence, and that the user can pause at any time by pressing a key. They key event handling works just fine, however, I'm getting a very bizarre error, where pausing the sequencer with:

public void pause() {
    // if the sequencer is playing, pause its playback
    if (this.isPlaying) {
        this.sequencer.stop();
    } else { // otherwise "restart" the music
        this.sequencer.start();
    }

    this.isPlaying = !this.isPlaying;
}

resets the sequencer's tempo. The song/sequencer starts playing at 120000 MPQ (as loaded from my input) and gets reset to 500000 MPQ. Does anyone know why this might be happening? Thanks.

  • Stopping is not pausing. And why the code in your implementation does this is known only by its author. – CL. Jun 21 '16 at 07:05

1 Answers1

1

Turns out that calling start() resets the sequencer's tempo to the default of 500000 mpq. For anyone who's having the same issue, here's the solution:

public void pause() {
    // if the sequencer is playing, pause its playback
    if (this.isPlaying) {
        this.sequencer.stop();
    } else { // otherwise "restart" the music
        // store the tempo before it gets reset
        long tempo = this.sequencer.getTempoInMPQ();

        // restart the sequencer
        this.sequencer.start();

        // set/fix the tempo
        this.sequencer.setTempoInMPQ(tempo);
    }

    this.isPlaying = !this.isPlaying;
}