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

set tempo not working? #29

Open
nserrino opened this issue Mar 23, 2017 · 0 comments
Open

set tempo not working? #29

nserrino opened this issue Mar 23, 2017 · 0 comments

Comments

@nserrino
Copy link

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.

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