@@ -63,6 +63,7 @@ export class TinySoundFont implements IAudioSampleSynthesizer {
6363 public currentTempo : number = 0 ;
6464 public timeSignatureNumerator : number = 0 ;
6565 public timeSignatureDenominator : number = 0 ;
66+ private _metronomeChannel : number = SynthConstants . DefaultChannelCount - 1 ;
6667
6768 public constructor ( sampleRate : number ) {
6869 this . outSampleRate = sampleRate ;
@@ -188,8 +189,8 @@ export class TinySoundFont implements IAudioSampleSynthesizer {
188189 while ( ! this . _midiEventQueue . isEmpty ) {
189190 const m : SynthEvent = this . _midiEventQueue . dequeue ( ) ! ;
190191 if ( m . isMetronome && this . metronomeVolume > 0 ) {
191- this . channelNoteOff ( SynthConstants . MetronomeChannel , SynthConstants . MetronomeKey ) ;
192- this . channelNoteOn ( SynthConstants . MetronomeChannel , SynthConstants . MetronomeKey , 95 / 127 ) ;
192+ this . channelNoteOff ( this . _metronomeChannel , SynthConstants . MetronomeKey ) ;
193+ this . channelNoteOn ( this . _metronomeChannel , SynthConstants . MetronomeKey , 95 / 127 ) ;
193194 } else if ( m . event ) {
194195 this . processMidiMessage ( m . event ) ;
195196 }
@@ -204,7 +205,7 @@ export class TinySoundFont implements IAudioSampleSynthesizer {
204205 // exception. metronome is implicitly added in solo
205206 const isChannelMuted : boolean =
206207 this . _mutedChannels . has ( channel ) ||
207- ( anySolo && channel !== SynthConstants . MetronomeChannel && ! this . _soloChannels . has ( channel ) ) ;
208+ ( anySolo && channel !== this . _metronomeChannel && ! this . _soloChannels . has ( channel ) ) ;
208209
209210 if ( ! buffer ) {
210211 voice . kill ( ) ;
@@ -261,18 +262,19 @@ export class TinySoundFont implements IAudioSampleSynthesizer {
261262 }
262263
263264 public get metronomeVolume ( ) : number {
264- return this . channelGetMixVolume ( SynthConstants . MetronomeChannel ) ;
265+ return this . channelGetMixVolume ( this . _metronomeChannel ) ;
265266 }
266267
267268 public set metronomeVolume ( value : number ) {
268- this . setupMetronomeChannel ( value ) ;
269+ this . setupMetronomeChannel ( this . _metronomeChannel , value ) ;
269270 }
270271
271- public setupMetronomeChannel ( volume : number ) : void {
272- this . channelSetMixVolume ( SynthConstants . MetronomeChannel , volume ) ;
272+ public setupMetronomeChannel ( channel :number , volume : number ) : void {
273+ this . _metronomeChannel = channel ;
274+ this . channelSetMixVolume ( channel , volume ) ;
273275 if ( volume > 0 ) {
274- this . channelSetVolume ( SynthConstants . MetronomeChannel , 1 ) ;
275- this . channelSetPresetNumber ( SynthConstants . MetronomeChannel , 0 , true ) ;
276+ this . channelSetVolume ( channel , 1 ) ;
277+ this . channelSetPresetNumber ( channel , 0 , true ) ;
276278 }
277279 }
278280
0 commit comments