Can a plugin control which string in a TAB staff to write a note to?

• Jan 14, 2021 - 23:03

Trying to make a plugin that writes to a TAB staff. Does anyone know if there is a way to control which TAB string to write a note to from within a plugin? For example, in some cases, for playability, I'd want to specify that the note be fretted on a string different from that which Musescore puts it on.


In reply to by rocchio

Update: I've not been able to specify a TAB string for a note. I've tried a few things, but they won't do the trick. I have also inspected some source code for clues and based on that I have concluded there is no such provision. In particular it appears to me that stringdata.cpp is the module where string/fret assignment is controlled. stringdata.cpp seems to be doing the right thing in terms of working out the best string to use given the note pitch so I've no complaints - just observing that you really just have to let it do it's thing. As this need is an infrequent case, a nice to have, I'm going to let this go and just accept that some manual fix-up will occasionally be needed for my purposes.

As an aside, jeetee: Fretboard.qml is a pretty cool plugin! I think I'm going to be able to put it to good use, even for my 3-string Mountain Dulcimer chords.

In reply to by Marc Sabatella

I believe jeetee to be correct - it uses the cmd function. Which I suppose I could try, tho I am trying to do this in pure 'batch' mode. And certainly I could be missing something. In Fretboard's addNoteWithCursor() function there is:

        for (var i = 0; i < fretView.strings; ++i)

Here is what I've tried:

    function addNewForcedToString(measures, notesToWrite, pitch, string, cursor) {
        console.log("In funct addNewForcedToString");

        cursor.setDuration(1, 4);
        notesToWrite = measures * 4; // assuming 4/4 time sig.
        var oNote = newElement(Element.NOTE);

        console.log("oNote string: ",oNote.string, " | pitch: ", oNote.pitch);
        //console.log("oNote pitch: ",oNote.pitch);

        cursor.rewind(Cursor.SELECTION_START); //<-- I am presuming we have selected a measure
        if (cursor.element.type === Element.CHORD) { //<-- am presuming the cursor is sitting on a chord element in score.
            var chord = cursor.element;
            var notes = cursor.element.notes;
            var numNotes = notes.length;
            console.log("# Notes in Chord:", numNotes);
            var oNote = newElement(Element.NOTE);
            oNote.string = string;
            oNote.pitch = pitch;
            console.log("oNote string: ",oNote.string, " | pitch: ", oNote.pitch);
        else {
            console.log("Cursor not sitting on a chord");
        // RESULT of the above test is that pre-setting a string number on the note object
        // has no effect on where Musescore places the note on the TAB.

Complete plugin code attached.

Attachment Size
jeffForStudy_WriteToTABstaff.qml 3.14 KB

In reply to by rocchio

You're not yet setting the note.fret property.

Quick test changes on my end:
function addNewForcedToString(measures, notesToWrite, pitch, string, **fret,** cursor) {
oNote.string = string;
oNote.fret = fret;
oNote.pitch = pitch;

addNewForcedToString(1, 1, 62, 2, 7, cursor);
addNewForcedToString(1, 1, 62, 1, 3, cursor);
addNewForcedToString(1, 1, 62, 4, 17, cursor);

all seems to work, regardless of having selected the chord in the standard staff or in the tablature staff

[EDIT] PS: so the cmd() things were only there for MuseScore versions prior to 3.3.4 in which those properties were exposed.

In reply to by jeetee

That works! Ok, so I had a mental block - I was steadfast in a belief that you couldn't 'over specify' among the three parameters. That is, if I'm specifying string + pitch then that has used up all the degrees of freedom so to also specify fret would be wrong. I now see that you actually must specify all three, and they must match up correctly (meaning that string + fret must correctly match the pitch you provide). In playing around it appears that if any of the three are inconsistent with other two than Musescore will use pitch to set the string/fret.

Thanks for breaking my logjam jeetee.

Do you still have an unanswered question? Please log in first to post your question.