gpt4 book ai didi

java - 暂停 Java Sequencer 重置节奏

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:08 25 4
gpt4 key购买 nike

我正在编写一些代码,这些代码在运行时会自动开始播放 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com