Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.24k stars 963 forks source link

Updating tremolo throws depth and frequency is read-only #1214

Closed durbanitas closed 8 months ago

durbanitas commented 8 months ago

Describe the bug

Updating the tremolo effect throws:

Uncaught TypeError: "depth" is read-only

and

Uncaught TypeError: "frequency" is read-only

To Reproduce

I have something like this:

// manage tone.js
const effects = {
    chorus: undefined,
    distortion: undefined,
    reverb: undefined,
    tremolo: undefined,
}

const preload = () => {
    effects.reverb = new Tone.Reverb({
      wet: 1,
    });
    effects.tremolo = new Tone.Tremolo({
      wet: 1,
    });
    effects.chorus = new Tone.Chorus({
      frequency: 2.5,
      delayTime: 0.5,
      depth: 1,
      feedback: 0.3,
      wet: 1,
    });
    effects.distortion = new Tone.Distortion({
      distortion: 1,
      wet: 1,
    });
    // ...
}

const selectedEffects = ['chorus', 'tremolo'] // to respect the order to chain the effects

export const updateEffects = (effectType, effectKey, newVal) => {
  const effect = effects[effectType]; // get effect to be updated
  effect[effectKey] = newVal; // update the value
};
// user interface
const updateReverbDecay = (val) => {
  updateEffects('reverb', 'decay', val); // works as fine
};

const updateTremoloDepth = (val) => {
  updateEffects('tremolo', 'depth', val); // FIXME: depth is read-only
};

Expected behavior Tremolo depth will accept a value that is between [0, 1]

Tremolo frequency will accept a value

What I've tried Updating other effects with the same method like: chorus and delayTime, chorus and depth, distortion and distortion, reverb and decay works as expected.

durbanitas commented 8 months ago

solved.

Had to add .value notation to set the depth or feedback value to the tremolo effect.