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

Having trouble Using hook / handle MIDI-related event data #18

Open
ridleytech opened this issue Nov 7, 2021 · 1 comment
Open

Having trouble Using hook / handle MIDI-related event data #18

ridleytech opened this issue Nov 7, 2021 · 1 comment

Comments

@ridleytech
Copy link

ridleytech commented Nov 7, 2021

I attempted using the hookPlayerMIDIEventsByName method but I'm getting this error. How do I go about fixing this?

synth = new JSSynth.AudioWorkletNodeSynthesizer(); synth.init(context.sampleRate); if (!node) { node = synth.createAudioNode(context); node.connect(context.destination); synth.hookPlayerMIDIEventsByName('myHookPlayerEvents', { secondSFont: soundfontbuffer }); }

I added this code to js-synthesizer.worklet.min.js

AudioWorkletGlobalScope.myHookPlayerEvents = function (s, type, event, data) { if (type === 0xc0) { if (event.getProgram() === 0) { s.midiProgramSelect(event.getChannel(), data.secondSFont, 0, 0); return true; } } return false; };

js-synthesizer.min.js:312 Uncaught (in promise) Error: Name not found
at js-synthesizer.worklet.min.js:1298
at T (js-synthesizer.worklet.min.js:1199)
at js-synthesizer.worklet.min.js:1188

@jet2jet
Copy link
Owner

jet2jet commented Nov 9, 2021

Well, it seems no problem for your code, but I suggest that the function myHookPlayerEvents is placed at the separate script file.

  • foo.js
AudioWorkletGlobalScope.myHookPlayerEvents = function (s, type, event, data) {
  if (type === 0xc0) {
    if (event.getProgram() === 0) {
      s.midiProgramSelect(event.getChannel(), data.secondSFont, 0, 0);
      return true;
    }
  }
  return false;
};
  • main code
await context.audioWorklet.addModule('foo.js'); // add this
await context.audioWorklet.addModule('libfluidsynth-2.2.1.js');
await context.audioWorklet.addModule('js-synthesizer.min.js');
.
.
.

If the problem persists, please use js-synthesizer.worklet.js (non-.min file), set breakpoint around L1901 (the line const fn = (AudioWorkletGlobalScope[name]); in doHookPlayerMIDIEvents method), call synth.hookPlayerMIDIEventsByName (will hit the breakpoint), and dump Object.keys(AudioWorkletGlobalScope). You can verify whether the function myHookPlayerEvents is correctly registered.
(I tried with Google Chrome; I could not debug audio worklet with Firefox.)

P.S. I found the bug around the audio worklet in js-synthesizer and update the package. Please use the version v1.8.4.

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

2 participants