lsei / pioneer-ddj-400

A nodejs lib to interface with your Pioneer DDJ 400
MIT License
11 stars 1 forks source link

pioneerddj.DDJ is not a constructor #1

Open jellohouse opened 1 year ago

jellohouse commented 1 year ago

Hey!

I'm trying to use this module inside of an Electron / React app I'm building.

const pioneerddj = require('pioneer-ddj');

function MyApp(props) {

  const ddj = new pioneerddj.DDJ('DDJ-400');
  //const ddj = new pioneerddj.DDJ('DDJ-400', {});

  ....

}

Unfortunately I get an error saying that: pioneerddj.DDJ is not a constructor on the line where I create a "new" ddj


Also on a side note, there is a good Midi library https://github.com/djipco/webmidi which I think could be worth looking into. (instead of easymidi).

Would love to get this working - any help would be greatly appreciated.

lsei commented 1 year ago

Hey Jellohouse. Great to hear you are interested in this library!

I just tried it in a vanilla node project and it seems to work for me.

Here is my index.js

const pioneerddj = require('pioneer-ddj');

const ddj = new pioneerddj.DDJ('DDJ-400', {});

ddj.on('play', ({ side, state }) => {
    console.log(`Play buton ${state ? 'pressed' : 'released'} on ${side} side!`);
});

which I run with node index.js

Is it possible the electron webpack compiler is doing something funny to the import?

I'm on node v16.

lsei commented 1 year ago

You may still get an error if your device is not plugged in, or can't be found.

Error: No MIDI input found with name: DDJ-400

jellohouse commented 1 year ago

Hey Isei! Thanks for the quick response!

Yeah I think it's highly possible that electron is causing this issue. Something with the way it's imported. I've also tried: import pioneerddj from 'pioneer-ddj' but with no luck.

I'm currently running node v14.5.0 and Electron v19.0.8

lsei commented 1 year ago

Are you importing it in the electron main node.js thread or the renderer? It's possible due to Electron's security policy it won't come up in the renderer and you will need to create a bridge.

Does it work if you import and instantiate the class from the main src/index.js file?

jellohouse commented 1 year ago

Hey man sorry for the late reply. But yes, I am using it in the renderer... I guess that's why. Any idea on how I could make this bridge? Do you have an example of you using it in Electron somehwere?


Also qucik unrelated question - do you know if the controller emits any midi events on beat or about current time? I would like to get the current beat/time in my app :)