简而言之,按下按钮我想使用 aPolySynth
和 a演奏一些音符Sequence
。如果用户反复按下按钮,我希望播放的内容停止,然后重新开始。这很可能是因为信封的衰减/维持。
问题:无论我尝试什么,我都无法完全取消/静音先前播放的音符,以防序列再次开始(再次单击按钮)。
我的合成器:
import { PolySynth } from 'tone'
const synth = new PolySynth(Synth, {
oscillator: {
type: 'sine4',
volume: -6,
},
envelope: {
attack: 0.01,
decay: 0.5,
sustain: 0.1,
release: 1,
},
}).toDestination()
synth.maxPolyphony = 4 // max notes playing at a time, not sure if necessary
我的顺序:
import { Sequence } from 'tone'
// Play the 2 notes individually then play them together
const notes = [
{ note: 'C4', duration: '8n' },
{ note: 'G4', duration: '8n' },
{ note: ['C4', 'G4'], duration: '4n' }
]
// The sequence that should play the notes after one another
const sequence = new Sequence({
subdivision: '8n',
loop: false,
events: notes,
callback: (time, note) => synth.triggerAttackRelease(note.note, note.duration, time),
})
我玩它的方式,这是一个事件处理程序:
import { start, Transport } from 'tone'
// Event handler simply attached to a button's onClick
function onButtonClicked() {
// Call whatever this start is, doc says it can only happen in an event handler
start()
// Try everything to kill current sound
Transport.cancel()
Transport.stop()
// Start it again
Transport.start()
sequence.start()
}
我怎么能在开始播放之前完全杀死所有声音(如果有的话)?