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

Node.js: WebMidi not enabling #252

Closed
PimTournaye opened this issue Mar 25, 2022 · 21 comments
Closed

Node.js: WebMidi not enabling #252

PimTournaye opened this issue Mar 25, 2022 · 21 comments
Assignees
Labels
Context: Node.js Problem specific to Node.js Type: dependency Issue that cannot be resolved until a dependency is fixed

Comments

@PimTournaye
Copy link

PimTournaye commented Mar 25, 2022

Getting the following error: (note: I changed filepaths in this report)

ReferenceError: navigator is not defined
    at Object.enable (file:///FILE_PATH/node_modules/webmidi/dist/esm/webmidi.esm.min.js:447:754)
    at file:///FILE_PATH/resonance.js:16:2
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:331:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
WebMidi
.enable()
.then(onEnabled)
.catch(err => console.log(err));

// Function triggered when WebMidi.js is ready
function onEnabled() {
    console.log('WebMIDI enabled!');
    output = WebMidi.getOutputByName("IAC Driver Bus 1");
    channel = output.channels[1];

    console.log(channel);
    channel.playNote('C5', {duration: 5000})
    //active = true;
    //interactiveMode = true;
}

Environment:
Specify the environment where you are witnessing the problem:

  • ESM
  • Node.js v17.2.0
  • JS
  • macOS (Apple Silicon)

I'm using webmidi: "^3.0.0-alpha.26"

@PimTournaye
Copy link
Author

I now realise I was using an outdated version, but in the most recent version on npm webmidi just doesn't want to enable

@djipco djipco self-assigned this Mar 25, 2022
@djipco
Copy link
Owner

djipco commented Mar 25, 2022

I cannot reproduce the problem. Can you provide a little more info? For instance, are you running this code in Node.js or in a browser?

Since you mentioned Node.js v17.2.0, I assume you are running it in Node.js. I just tried running the code below and it worked fine in Node.js v16.11.1 and v17.8.0.

This is using the module approach:

import {WebMidi} from "webmidi";

WebMidi
  .enable()
  .then(onEnabled)
  .catch(err => console.log(err));

function onEnabled() {
  console.log('WebMIDI enabled!');
  const output = WebMidi.outputs[0]
  const channel = output.channels[1];
  console.log(channel);
  channel.playNote('C5', {duration: 5000})
}

This is using the classic approach:

const {WebMidi} = require("webmidi");

WebMidi
  .enable()
  .then(onEnabled)
  .catch(err => console.log(err));

function onEnabled() {
  console.log('WebMIDI enabled!');
  const output = WebMidi.outputs[0]
  const channel = output.channels[1];
  console.log(channel);
  channel.playNote('C5', {duration: 5000})
}

I was using WEBMIDI.js v3.0.15.

@djipco djipco added the Status: info needed Info is needed before moving on label Mar 25, 2022
@PimTournaye
Copy link
Author

I'm running this in Node.js, yes, also running WEBMIDI.js v3.0.15.
I've tried your snippet of the module approach above and sadly still get nothing in the console. I'll link my repo below if you want to dive deeper.

I think in the meantime I'll try to update my node version and try again.

https://github.com/PimTournaye/Resonance

@djipco
Copy link
Owner

djipco commented Mar 25, 2022

I just ran your code and it was working fine for me (I only had to change the name of the MIDI device to match my own). Here's the output I got:

(base) jpcote@DjipBook Resonance-master % node resonance.js
undefined
WebMIDI enabled!
<ref *1> a {
  eventMap: {},
  eventsSuspended: false,
  _output: i {
    eventMap: {},
    eventsSuspended: false,
    _midiOutput: MIDIOutput {
      type: 'output',
      id: 'Apple DLS Synth',
      name: 'Apple DLS Synth',
      manufacturer: 'Apple',
      version: '1.0',
      state: [Getter],
      connection: [Getter],
      onstatechange: [Getter/Setter],
      open: [Function (anonymous)],
      close: [Function (anonymous)],
      clear: [Function (anonymous)],
      send: [Function (anonymous)]
    },
    _octaveOffset: 0,
    channels: [
      <1 empty item>, [Circular *1],
      [a],            [a],
      [a],            [a],
      [a],            [a],
      [a],            [a],
      [a],            [a],
      [a],            [a],
      [a],            [a],
      [a]
    ]
  },
  _number: 1,
  _octaveOffset: 0
}
creating new ball
got "keypress"  { sequence: '\x03', name: 'c', ctrl: true, meta: false, shift: false }
bang!
bang!
bang!
bang!

@PimTournaye
Copy link
Author

Weird, it still doesn't output anything for me. Could it be another Apple Silicon ARM64 thing?
What other information could I provide for you? I don't really know where to look myself but when I have the time I could dig around a bit

@djipco
Copy link
Owner

djipco commented Mar 25, 2022

I don't know why it would be related to the new processor but who knows? Unfortunately, I only have an "old" Macbook to test it on.

Are you still getting the ReferenceError: navigator is not defined error? Do you at least see "WebMidi enabled!" ?

@PimTournaye
Copy link
Author

PimTournaye commented Mar 25, 2022

The ReferenceError: navigator is not defined when away with updating, but no "WebMIDI enabled". When logging the WebMIDI import, it does log but it's like .enable() never even executes...

@PimTournaye PimTournaye changed the title Node: navigator not found Node.js: WebMidi not enabling Mar 25, 2022
@PimTournaye
Copy link
Author

After some more testing, I have a hunch it maybe be an issue on the JZZ-soft side of things. I tried running their test suite and unfortunately only passed one test out of the 28 or something. I've opened an issue on their repo.

jazz-soft/JZZ#59

@djipco
Copy link
Owner

djipco commented Mar 28, 2022

@PimTournaye Thanks for reporting back. If that is indeed the problem, it will most likely affect other users of WEBMIDI.js. Keep me posted!

@PimTournaye
Copy link
Author

Will do! Running the script through a Rosetta terminal makes it work for now! I'll try to see if I can see what causes it to act out on Apple Silicon

@djipco
Copy link
Owner

djipco commented Mar 29, 2022

Interesting. Maybe there is indeed a compatibility issue with Apple Silicon. Let's wait and see what the Jazz-Soft team says.

@djipco
Copy link
Owner

djipco commented May 6, 2022

@PimTournaye Can you try out version 3.0.20 (available now on npm) and see if it fixes your issue. A regression problem has been uncovered (and fixed) and perhaps it relates to your problem.

@djipco djipco added the Context: Node.js Problem specific to Node.js label May 7, 2022
@PimTournaye
Copy link
Author

I've booted up my project again without Rosetta and WebMidi is unfortunately still not enabling.
it is getting imported I think, logging WebMidi from import returns some things at least. I'll try to play around a bit more and report back if I find anything.

@djipco
Copy link
Owner

djipco commented May 7, 2022

@PimTournaye Thanks for taking the time to check it out. An update from the Jazz-Soft team is expected soon. Maybe it'll help with Node.js compatibility...

@PimTournaye
Copy link
Author

Found something weird, when using Vite in my project, WebMidi does enable on a non-Rosseta terminal. Will try to look into this more.

@teropa
Copy link

teropa commented May 24, 2022

I'm also seeing this issue on Apple Silicon. As far as I can tell, jazz-midi does not include a build for darwin arm64, so it fails when trying to load up.

@djipco
Copy link
Owner

djipco commented May 25, 2022

@teropa Thanks for the feedback. I guess we will have to wait for the jazz-midi team...

@djipco
Copy link
Owner

djipco commented Jun 27, 2022

Issue #10 for the jazz-midi module concerns Apple M1 support. I am referencing it here so we can track the progress. As soon as support lands in the jazz-midi module, I will update the dependencies for WEBMIDI.js.

@djipco djipco added Type: dependency Issue that cannot be resolved until a dependency is fixed and removed Status: info needed Info is needed before moving on labels Nov 17, 2022
@AMabona
Copy link

AMabona commented Dec 19, 2022

Hi @djipco , I'm the one who opened the issue you referred to. It seems it should be closed after this commit jazz-soft/jazz-midi@d67f8c3 from two weeks ago.

@djipco
Copy link
Owner

djipco commented Dec 19, 2022

@AMabona Thank you so much for letting me know!

I just released v3.0.24 of WEBMIDI.js which now depends on v1.5.6 of the jzz module which itself relies on v1.7.8 of the jazz-midi module (the one that is now natively compiled for Apple M1 ARM processor).

Unfortunately, I don't have an M1 to test it with. Perhaps @PimTournaye or @teropa could try it out and let me know?

Thanks!

@PimTournaye
Copy link
Author

Did a quick test, so far everything is working from a non-Rosetta process. Thanks for the update! If anyone does experience issues, do keep reporting and feel free to reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Context: Node.js Problem specific to Node.js Type: dependency Issue that cannot be resolved until a dependency is fixed
Projects
None yet
Development

No branches or pull requests

4 participants