abcjs icon indicating copy to clipboard operation
abcjs copied to clipboard

Cannot change all the properties of audioParams in SynthController.setTune()

Open charlotrudel opened this issue 4 years ago • 2 comments
trafficstars

Hi, I am using the SynthController as a way to easily change the midi program without touching the ABC string, but it seems that the "options" property is the only one that can be accessed and changed for the audioParams in setTune(). I am unable to affect the following properties of audioParams:

audioContext soundFontUrl soundFontVolumeMultiplier millisecondsPerMeasure visualObj sequence onEnded

I can directly pass in the properties from the "option" property though. I might be missing something, in which case, please enlighten me! This library is absolutely wonderful!

charlotrudel avatar Nov 07 '21 16:11 charlotrudel

I seriously need to simplify this interface.

From looking at the code it looks like it should work, particularly if you have userAction set to true.

If you post a simple example I'll trace through it and figure out what's wrong.

paulrosen avatar Nov 13 '21 21:11 paulrosen

Here is a truncated example from a react class component. As you can see, the audioParams object as written works, but its properties are actually what should be passed as properties to the options property of audioParams.

class Score extends PureComponent {
  constructor() {
    ...
    this.synthControl = new abcjs.synth.SynthController();
   ...
  }

  ...

  loadVisual() {
    return abcjs.renderAbc(
      this.abcjsdiv,
     this.props.abcString},
      {...}
    );
  }

  load() {
    const audioParams = {
      program: this.props.options.instrument,
      midiTranspose: this.props.cardType === 4 ? -33 : 0,
    };
    this.visualObj = this.loadVisual();

    let CursorControl = function (rootSelector, playButton) {
      ...};

    this.cursorControl = new CursorControl(
      `#${this.abcjsdiv}`,
      `#${this.abcjsplay}`
    );

    this.synthControl.load(`#${this.abcjsplay}`, this.cursorControl);

    if (abcjs.synth.supportsAudio()) {
      this.synthControl
        .setTune(this.visualObj[0], true, audioParams)
    }
  }

 ...

Changing the audioParams objet to fit the docs does not work: the options which worked previously now do nothing, and the added options do not work either:

const audioParams = { soundFontVolumeMultiplier: 0.5, options: { program: this.props.options.instrument, midiTranspose: this.props.cardType === 4 ? -33 : 0, }, };

charlotrudel avatar Nov 14 '21 16:11 charlotrudel