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

Can I use it in node environment. #26

Open
liudonghua123 opened this issue Nov 22, 2022 · 1 comment
Open

Can I use it in node environment. #26

liudonghua123 opened this issue Nov 22, 2022 · 1 comment

Comments

@liudonghua123
Copy link

I tried to run the demo code on readme using node. But I got the following errors.

// timidity_example_1.js
const Timidity = require('timidity')

const player = new Timidity()
player.load('/my-file.mid')
player.play()

player.on('playing', () => {
  console.log(player.duration) // => 351.521
})
D:\code\node\midi>node timidity_example_1.js
D:\code\node\midi\node_modules\timidity\index.js:32
    this._baseUrl = new URL(baseUrl, window.location.origin).href
                                     ^

ReferenceError: window is not defined
    at new Timidity (D:\code\node\midi\node_modules\timidity\index.js:32:38)
    at Object.<anonymous> (D:\code\node\midi\timidity_example_1.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.12.1

D:\code\node\midi>

I noticed that the readme.

Play MIDI files in the browser w/ Web Audio, WebAssembly, and libtimidity
Play MIDI files in a browser with a simple API.

Is there any chances that it will support for running in node/deno?

@liudonghua123
Copy link
Author

It seems use some web only api like window.location, AudioContext. window.location is used for locating file path/url, maybe easy to make compatible with node. AudioContext have some node implementation like web-audio-api, I am trying to do some tries in depth.

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