JZZ-midi-SMF icon indicating copy to clipboard operation
JZZ-midi-SMF copied to clipboard

Typescript no exported member 'SMF'

Open fornof opened this issue 1 year ago • 12 comments

I'm getting an error when I copy paste the example : Module '"jzz-midi-smf"' has no exported member 'SMF' image 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.

fornof avatar Jun 05 '23 04:06 fornof

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');

fornof avatar Jun 05 '23 04:06 fornof

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?

DJthefirst avatar Jul 31 '23 20:07 DJthefirst

Use this for smf , rest of the code is above, ignore the smf import var smf = new JZZ.MIDI.SMF(testFile);

fornof avatar Aug 01 '23 00:08 fornof

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.

DJthefirst avatar Aug 01 '23 01:08 DJthefirst

Use SMF (in capitals) and ignore the warning.

jazz-soft avatar Aug 01 '23 06:08 jazz-soft

I am using Svelte Kit and require does not work.

image

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 image and SMF(); says image I assume because it is not imported correctly.\

The JZZ examples run just fine the problem is in JZZ.MIDI.SMF

DJthefirst avatar Aug 01 '23 13:08 DJthefirst

Call SMF(JZZ); as shown in the example. That will add the missing member.

jazz-soft avatar Aug 01 '23 15:08 jazz-soft

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.

DJthefirst avatar Aug 01 '23 19:08 DJthefirst

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?

DJthefirst avatar Aug 02 '23 19:08 DJthefirst

You can use other libraries to get the names of midi inputs and midi outputs

fornof avatar Aug 02 '23 19:08 fornof