title: Tone.js problems with changing Tone.Polysynth
body: <p>In Tone.js I have made a class that creates a synth instance where <code>.play()</code> is called in a sequencer function, thereby playing a sound. In the class below there are absolutely no problems when <code>this.synth</code> in <code>updateSynthType</code> is a monophonic <code>Tone.Synth</code>, but the whole thing breaks when it is <code>Tone.Polysynth</code> and I receive the following error when trying to call <code>updateSynthType</code>.</p>
  <pre><code>Uncaught Error: Synth was already disposed
      at ti (Tone.js:1)
      at ra._scheduleEvent (Tone.js:21)
      at Object.callback (Tone.js:21)
      at Gi._timeoutLoop (Tone.js:21)
      at Gi.emit (Tone.js:7)
  </code></pre>
  <p>I don't understand why this never happens with a regular <code>Tone.Synth</code> but when I try to change a <code>Tone.PolySynth</code> an error appears. I am trying to update the settings to change between the type of polysynth (e.g. <code>Synth, AMSynth, MetalSyth</code> etc). How can I stop this problem? Why does this class only work for a regular <code>Tone.Synth</code>? Is there a better way of updating the PolySynth type in this class?</p>
  <p>Here is the class in question:</p>
  <pre><code>class PolyInstrument {
    constructor(){
      this.synth = null
      this.gain = new Tone.Gain()
      this.gain.toDestination()
    }
  
    play(note = null, beat, time = null){
      if (this.synth){
        if (note === null){
          time ? this.synth.triggerAttackRelease(beat, time) : this.synth.triggerAttackRelease(beat)
        } else { 
          time ? this.synth.triggerAttackRelease(note, beat, time) : this.synth.triggerAttackRelease(note, beat)
        }
      } else {
        alert('error: no synth')
      }
    }
  
    get defaultSettings(){
      return {
        Synth: {
          oscillator: {
            type: 'triangle'
          },
          envelope: {
            attack: 0.005,
            decay: 0.1,
            sustain: 0.3,
            release: 1
          }
        },
        AMSynth: {
          harmonicity: 3 ,
          detune: 0 ,
          oscillator: {
            type: 'sine'
          },
          envelope: {
            attack: 0.01 ,
            decay: 0.01 ,
            sustain: 1 ,
            release: 0.5
          },
          modulation: {
            type: 'square'
          },
          modulationEnvelope: {
            attack: 0.5 ,
            decay: 0 ,
            sustain: 1 ,
            release: 0.5
          }
        }
      }
    }
  
    updateSynthType(synthType){
      if (this.synth){
        this.synth.disconnect(this.gain)
        this.synth.dispose()
      }
      let settings = this.defaultSettings[synthType] || {}
      this.synth = new Tone.PolySynth(Tone[synthType], settings)
      this.synth.connect(this.gain)
      this.play()
    }
  }
  </code></pre>
  <p>Thanks for reading.</p>