@@ -1726,6 +1726,9 @@ function Synth() {
17261726 console . debug ( "Error triggering note:" , e ) ;
17271727 }
17281728 } else {
1729+ const effectChain = [ ] ;
1730+ synth . disconnect ( ) ;
1731+
17291732 if ( paramsFilters !== null && paramsFilters !== undefined ) {
17301733 numFilters = paramsFilters . length ; // no. of filters
17311734 for ( let k = 0 ; k < numFilters ; k ++ ) {
@@ -1736,7 +1739,7 @@ function Synth() {
17361739 paramsFilters [ k ] . filterRolloff
17371740 ) ;
17381741 temp_filters . push ( filterVal ) ;
1739- synth . chain ( temp_filters [ k ] , Tone . Destination ) ;
1742+ effectChain . push ( temp_filters [ k ] ) ;
17401743 }
17411744 }
17421745
@@ -1752,26 +1755,22 @@ function Synth() {
17521755 1 / paramsEffects . vibratoFrequency ,
17531756 paramsEffects . vibratoIntensity
17541757 ) ;
1755- synth . chain ( vibrato , Tone . Destination ) ;
1758+ effectChain . push ( vibrato ) ;
17561759 effectsToDispose . push ( vibrato ) ;
17571760 }
17581761
17591762 if ( paramsEffects . doDistortion ) {
1760- distortion = new Tone . Distortion (
1761- paramsEffects . distortionAmount
1762- ) . toDestination ( ) ;
1763- synth . connect ( distortion , Tone . Destination ) ;
1763+ distortion = new Tone . Distortion ( paramsEffects . distortionAmount ) ;
1764+ effectChain . push ( distortion ) ;
17641765 effectsToDispose . push ( distortion ) ;
17651766 }
17661767
17671768 if ( paramsEffects . doTremolo ) {
17681769 tremolo = new Tone . Tremolo ( {
17691770 frequency : paramsEffects . tremoloFrequency ,
17701771 depth : paramsEffects . tremoloDepth
1771- } )
1772- . toDestination ( )
1773- . start ( ) ;
1774- synth . chain ( tremolo ) ;
1772+ } ) . start ( ) ;
1773+ effectChain . push ( tremolo ) ;
17751774 effectsToDispose . push ( tremolo ) ;
17761775 }
17771776
@@ -1780,8 +1779,8 @@ function Synth() {
17801779 frequency : paramsEffects . rate ,
17811780 octaves : paramsEffects . octaves ,
17821781 baseFrequency : paramsEffects . baseFrequency
1783- } ) . toDestination ( ) ;
1784- synth . chain ( phaser , Tone . Destination ) ;
1782+ } ) ;
1783+ effectChain . push ( phaser ) ;
17851784 effectsToDispose . push ( phaser ) ;
17861785 }
17871786
@@ -1790,8 +1789,8 @@ function Synth() {
17901789 frequency : paramsEffects . chorusRate ,
17911790 delayTime : paramsEffects . delayTime ,
17921791 depth : paramsEffects . chorusDepth
1793- } ) . toDestination ( ) ;
1794- synth . chain ( chorus , Tone . Destination ) ;
1792+ } ) ;
1793+ effectChain . push ( chorus ) ;
17951794 effectsToDispose . push ( chorus ) ;
17961795 }
17971796
@@ -1847,6 +1846,12 @@ function Synth() {
18471846 }
18481847 }
18491848
1849+ if ( effectChain . length > 0 ) {
1850+ synth . chain ( ...effectChain , Tone . Destination ) ;
1851+ } else {
1852+ synth . toDestination ( ) ;
1853+ }
1854+
18501855 if ( ! paramsEffects . doNeighbor ) {
18511856 if ( setNote !== undefined && setNote ) {
18521857 if ( synth . oscillator !== undefined ) {
0 commit comments