java - 暂停 Java Sequencer 重置节奏

标签 java reset midi javax.sound.midi tempo

我正在编写一些代码,这些代码在运行时会自动开始播放 MIDI 序列,并且用户可以随时通过按键暂停。他们的关键事件处理工作得很好,但是,我遇到了一个非常奇怪的错误,其中暂停了音序器:

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;
}

重置音序器的速度。歌曲/音序器以 120000 MPQ 开始播放(从我的输入加载)并重置为 500000 MPQ。有谁知道为什么会发生这种情况?谢谢。

最佳答案

事实证明,调用 start() 会将音序器的速度重置为默认值 500000 mpq。对于遇到同样问题的任何人,解决方案如下:

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;
}

关于java - 暂停 Java Sequencer 重置节奏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935814/

相关文章:

java - 如何在 java 中重置 FileReader 而无需大幅更改我的程序?

c# - 什么样的定时器最适合MIDI定时?

创建一个 wav。来自 MIDI 文件的文件并将其提供给 NWEB

java - Hawtio 未启动

java - FileChannel.tryLock 有时会抛出 AccessDeniedException

python - 在Python中重置(重新初始化)整数列表(至0)的最佳方法是什么

CSS重置问题

java - 单击时如何更改 JButton 上的图像?

java - Runnable 和 ScheduledExecutorService 的内存泄漏

android - 使用软件合成器将MIDI文件转换为原始音频