spessasus / SpessaSynth

MIDI SoundFont/DLS synthesizer library written in JavaScript.
https://spessasus.github.io/SpessaSynth/
Other
96 stars 12 forks source link

[ENCHANCEMENT] Create a MIDI file from scratch #41

Closed bxclib2 closed 3 months ago

bxclib2 commented 3 months ago

Documentation Confirmation

Please confirm that you have read the documentation and have not found an answer to your question there.

Yes

Question's Topic

spessasynth_lib

The Question

Is the midi parser in this library able to generate a brand new midi file, like the jsmidgen? jsmidgen

Some examples from jsmidgen like this. I checked the doc and code, it seems no off-the-shelf method to construct a brand new midi file and track. All I can think of is to generate a midi with other library and later use midi-parser of SpessaSynth to re-parse back to midi object of SpessaSynth.

var fs = require('fs');
var Midi = require('jsmidgen');

var file = new Midi.File();
var track = new Midi.Track();
file.addTrack(track);

track.addNote(0, 'c4', 64);
track.addNote(0, 'd4', 64);
track.addNote(0, 'e4', 64);
track.addNote(0, 'f4', 64);
track.addNote(0, 'g4', 64);
track.addNote(0, 'a4', 64);
track.addNote(0, 'b4', 64);
track.addNote(0, 'c5', 64);

fs.writeFileSync('test.mid', file.toBytes(), 'binary');
spessasus commented 3 months ago

Hi, While this isn't currently possible, this looks like a very simple addition. Thanks for the idea, I'll work on it now!

spessasus commented 3 months ago

Hi, I've added the MIDI Builder class: https://github.com/spessasus/SpessaSynth/wiki/Creating-MIDI-Files

I hope this was the feature you were looking for!

bxclib2 commented 3 months ago

Yep, this is what I need. Thanks for your reply. Is this included in the npm library or I need install from GitHub? I will have some tests

spessasus commented 3 months ago

Yes, I've added it to npm too. (I didn't forget index.js this time :-)

bxclib2 commented 3 months ago

Thanks!! I will try and if I encounter some issues I will help report