jsmidgen icon indicating copy to clipboard operation
jsmidgen copied to clipboard

set tempo not working?

Open nserrino opened this issue 8 years ago • 0 comments

Hi, I am using your library to create a midi file and then play it using midi-js.

I am finding that no matter how I set setTempo, the output midi in midi-js always plays very slowly. Here is my code snippet:

    var TICKS_PER_BEAT = 128;
    var beatsPerSecond = 2;
    var file = new Midi.File();
    var track = new Midi.Track();
    file.addTrack(track);
    track.setTempo(beatsPerSecond * 60, 0);

    console.log(sequence[0]["beat"], typeof sequence[0]["beat"])
    console.log(sequence[0]["midi_note"], typeof sequence[0]["midi_note"])

    for (var i = 0; i < sequence.length; ++i) {
        var midiPitch = sequence[i]['midi_note'],
            noteOnBeat = sequence[i]['beat'],
            noteOffBeat;
        if (i == sequence.length - 1) {
            noteOffBeat = sequence[i]['beat'] + 2;
        } else {
            noteOffBeat = sequence[i + 1]['beat'];
        }

        track.addNoteOn(0, midiPitch, TICKS_PER_BEAT * noteOnBeat, velocity);
        track.addNoteOff(0, midiPitch, TICKS_PER_BEAT * noteOffBeat, velocity);
    }

    return file;

I changed beatsPerSecond to be 5 and the output file sounded the same. Thanks for your time.

nserrino avatar Mar 23 '17 17:03 nserrino