JZZ-midi-SMF
JZZ-midi-SMF copied to clipboard
Typescript no exported member 'SMF'
I'm getting an error when I copy paste the example :
Module '"jzz-midi-smf"' has no exported member 'SMF'
I did 'import JZZ from "jzz" and that gets live audio working.
I could not get the jzz-midi-smf to work though.
I'm using Typescript/ Nodejs, compiling down in react and phaser and rendering to the browser. I did notice this one: https://github.com/jazz-soft/JZZ/issues/62 I might be able to help out if there is no quick solution to this.
update: Fixed it. the ES6/Typescript import is broken somehow. using require works fine. This is my working example for typescript.
import {promises as fs} from 'fs'
var JZZ = require('jzz')
var SMF = require('jzz-midi-smf')
let testFile = await fs.readFile("test/data/testScale1.mid", "binary")
var midiout = JZZ().openMidiOut(); //I think this is just for player.play()
var smf = new JZZ.MIDI.SMF(testFile);
var player = smf.player();
player.connect(midiout);
//player.play();
fs.writeFile('test/data/out.mid', smf.dump(), 'binary');
I am using TypeScript in my project and have encountered the same problem. The require() solution however unfortunately does not work for me.
var JZZ = require('jzz') works fine but var SMF = require('jzz-midi-smf') throws Could not find a declaration file for module 'jzz-midi-smf'. I assume because index.d.ts is missing. I know it is a lot of work to convert the js to TS but is there some online generator to do it?
Use this for smf , rest of the code is above, ignore the smf import
var smf = new JZZ.MIDI.SMF(testFile);
I now get
Property 'SMF' does not exist on type 'Constructor'. Did you mean 'smf'?
I then tried var smf = JZZ.MIDI.smf();
but the var player = smf.player();
says Property 'player' does not exist on type 'MIDI'
The new keyword also did not work with/without.
Use SMF (in capitals) and ignore the warning.
I am using Svelte Kit and require does not work.
the code runs if I comment out var smf = new JZZ.MIDI.SMF();
so it can import jzz just fine. The jzz-midi-smf gives me
and SMF(); says
I assume because it is not imported correctly.\
The JZZ examples run just fine the problem is in JZZ.MIDI.SMF
Call SMF(JZZ); as shown in the example. That will add the missing member.
I still get the same error no change. I assume the error is in the import and TS can't find the package to load.
I was able to get it the typescript errors are just cosmetic.
On a different note is there a way to access the array of available midi in and out ports?
And/Or recreate this function that updates on port change to get a dropdown menu of available ports?
async initMidiPorts(){
await navigator.requestMIDIAccess()
.then((midiAccess) => {
this.midiAccess = midiAccess;
this.updateMidiOptions();
midiAccess.onstatechange = (event) => this.updateMidiOptions();
});
}
If not it is no big deal. I appreciate the work you have done on this library. I didn't see it in the docs but could revealing midiAccess.inputs.values() allow this?
You can use other libraries to get the names of midi inputs and midi outputs