Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow Users to Specify soundFontUrl through userOptions #40

Open
jllovet opened this issue Oct 28, 2023 · 0 comments
Open

Comments

@jllovet
Copy link

jllovet commented Oct 28, 2023

Currently in cfg.ts the soundFontUrl is hard-coded in the SYNTH_INIT_OPTIONS.

export const SYNTH_INIT_OPTIONS: SynthOptions = {
  // Give it a little more room:
  pan: [-0.25, 0.25],
  
  // Sound "fonts".
  // These could be distributed locally with the plugin, but fair warning, they're large (GBs for all notes, I think)
  // soundFontUrl: 'https://paulrosen.github.io/midi-js-soundfonts/abcjs/', // bright, crisp
  soundFontUrl: 'https://paulrosen.github.io/midi-js-soundfonts/FluidR3_GM/', // loud, deeper
  // soundFontUrl: 'https://paulrosen.github.io/midi-js-soundfonts/MusyngKite/', // muted, more mids?
};

It would be nice to be able to have one of these as a default or have the ability to choose which of them the user wants to use. It would be most desirable to have the option to reference public urls or paths in a vault. (Granted, it would probably be a lot to throw a soundfont into a vault because of the sizes of the files.)

The SYNTH_INIT_OPTIONS are imported in playback_element.ts, where they are passed into this.midiBuffer.init in the following:

  enableAudioPlayback(visualObj: TuneObject) {
    if (!synth.supportsAudio()) return;

    // We need the SynthController to drive NoteHighlighter (CursorControl), even though we don't want the UI controls from SynthController
    this.synthCtrl.load(
      `#${PLAYBACK_CONTROLS_ID}`, //controlsEl, // can be an HTMLElement reference or css selector
      new NoteHighlighter(this.el), // an implementation of a `CursorControl`
    );

    this.midiBuffer.init({ visualObj, options: SYNTH_INIT_OPTIONS })
      .then(() => this.synthCtrl.setTune(visualObj, false, AUDIO_PARAMS))
      .catch(console.warn.bind(console));

    const signal = this.abortController.signal; // for event cleanup
    this.el.addEventListener('click', this.togglePlayback, { signal });
    this.el.addEventListener('dblclick', this.restartPlayback, { signal });
  }

PS: The plugin is delightful, and I'm so glad y'all have worked on it!

@jllovet jllovet changed the title Feature Request: Allow Users to Specify soundFontUrl through userOptions. Feature Request: Allow Users to Specify soundFontUrl through userOptions Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant