编辑:更新其他尝试。下面问题的关键部分是行sampler.triggerRelease(["A1"], 'now'),它不起作用。我尝试过的其他事情包括:
sampler.releaseAll(Tone.now())sampler.releaseAll()sampler.triggerRelease(["A1"], Tone.now())Tone.js文档的相关部分是这里。
不能工作的是sampler.dispose(),因为它实际上切断了采样仪器与输出的连接。但我需要继续使用取样器重新触发相同的音符后不久,关闭它。
我试图使用按钮按下停止播放‘采样器’音符,而它目前正在播放。我认为触发发布阶段会做到这一点(如下面的代码所示),但这似乎没有任何效果。我尝试过很多方法。这个问题没有回答我的问题,部分原因是因为它是为了“多元合成器”而不是“采样器”。提前感谢!
const readyOverlay = document.querySelector('#readyOverlay')
readyOverlay.addEventListener('click', async () => {
readyOverlay.style.display = 'none'
await Tone.start()
const sampler = new Tone.Sampler({
urls: {
A1: "A1.mp3"
},
baseUrl: "https://tonejs.github.io/audio/casio/",
onload: () => {
sampler.triggerAttackRelease(["A1"], 5);
}
}).toDestination();
sampler.release = 0
document.querySelector('#stop').addEventListener('click', () => {
sampler.triggerRelease(["A1"], 'now')
})
}) #readyOverlay {
position: absolute;
z-index: 9;
width: 100%;
height: 100%;
background: white;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
}<script src="https://unpkg.com/tone@14.7.77/build/Tone.js"></script>
<div id="readyOverlay">Press anywhere to start!</div>
<button id="stop" >stop</button>
发布于 2022-02-08 21:56:48
将triggerAttackRelease替换为只使用triggerAttack是可行的:
const readyOverlay = document.querySelector('#readyOverlay')
readyOverlay.addEventListener('click', async () => {
readyOverlay.style.display = 'none'
await Tone.start()
const sampler = new Tone.Sampler({
urls: {
A1: "A1.mp3"
},
baseUrl: "https://tonejs.github.io/audio/casio/",
onload: () => {
sampler.triggerAttack(["A1"]);
}
}).toDestination();
sampler.release = 0;
document.querySelector('#stop').addEventListener('click', () => {
sampler.triggerRelease(["A1"]);
})
}) #readyOverlay {
position: absolute;
z-index: 9;
width: 100%;
height: 100%;
background: white;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
}<script src="https://unpkg.com/tone@14.7.77/build/Tone.js"></script>
<div id="readyOverlay">Press anywhere to start!</div>
<button id="stop" >stop</button>
triggerAttackRelease只是triggerAttack和triggerRelease调用的序列。这意味着您已经在初始示例中的onload回调中计划了一个便笺发布。
Tone.js忽略了第二个发布调用,因为sampler已经将"A1“标记为released (语句确保只在攻击后释放一次注释。)。
https://stackoverflow.com/questions/71007688
复制相似问题