MidiWriterJS icon indicating copy to clipboard operation
MidiWriterJS copied to clipboard

VexFlow dotted notes not playing properly

Open sfox-developer opened this issue 1 year ago • 0 comments

Hey there,

thanks for the great lib and the integration with Vexflow.

I faced an issue that my track is not playing dotted notes. So i checked the code and found an issue with the conversion from vexflow to the NoteEvent. I checked the vexflow documentation as well as the midiwriter code. I found the method VexFlow.prototype.convertDuration which is checking for the VexFlow duration and additional modifications like tuplets or dots.

VexFlow.prototype.convertDuration = function (note) {
  return 'd'.repeat(note.dots) + this.convertBaseDuration(note.duration) + (note.tuplet ? 't' + note.tuplet.num_notes : '');
};

The passed note is a Tickable or StaveNote - but i did not find any property for "dots", so overrode the method by checking for the modifiers instead.

/**
 * MidiWriter FIX: note.dots does not exist, so we are checking the modifiers
 */
MidiWriter.VexFlow.prototype.convertDuration = function (note) {
    
    let durationString = "";

    if(note.modifiers.length > 0) {
        // loop through modifiers and check for a dot modifier.attrs.type == "Dot"
        note.modifiers.forEach(modifier => {
            if(modifier.attrs.type == "Dot") {
                durationString += "d";
            }
        })
    }

    return durationString + this.convertBaseDuration(note.duration) + (note.tuplet ? 't' + note.tuplet.num_notes : '');
};

Maybe i am missing something, maybe i can help anyone else out there.

Cheers!

sfox-developer avatar Aug 14 '24 11:08 sfox-developer