read note input and write copy to second staff on the fly?

• May 21, 2021 - 19:09

Please, any ideas, how to read user input and write with a plugin a copy to second staff on the fly?

I am working on scordatura plugin (it is almost done) and now I try to add "on the fly" mode.

So plugin would read every UI input, than translate pitch and write modified to second staff.

Thank you for any ideas!


Comments

I believe selectionChanged is called upon note entry, so perhaps you can do something with that: https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…

You'd have to do something like checking whether the change was in your source staff; if it was, enter a note into the scordatura staff. But if the change was in the scordatura staff (because your plugin just entered a note there for example) then move the cursor back to the original staff to allow your user to do further note entry.

I'm doubtful whether this will not influence normal note entry by the user and think an "after the fact" plugin to run once over an entire staff is likely less error-prone.

In reply to by jeetee

Thank you.

This is exactly, what I tried to do.

But state.selectionChanged itself is not enough. It is triggered also, when user clicks some note.
So I need to check, if MS is in note input mode. But dont know how exactly.

Combinantion with state.startLayoutTick seems to do trick.
But how to check duration of entered note?

I tried to check last selected note. It almost work. But problem comes, if entered note croses barline.

This is snippet, what I have tried.

I would be wery greatfull for any ideas.

onScoreStateChanged: {
    if (state.selectionChanged && !state.undoRedo && state.startLayoutTick > -1){
        console.log("insert");
        var el = score ? score.selection.elements[0] : null;
        if ( el && el.type == Element.NOTE || el.type == Element.REST ) {
 
            var tick = state.startLayoutTick;
            var duration = el.duration || el.parent.duration;
 
            console.log(duration.numerator, duration.denominator, " track: ", el.track);
 
            tcursor.track = el.track + 4;
            tcursor.rewindToTick(tick);
            tcursor.setDuration(duration.numerator, duration.denominator);
 
            score.startCmd();
            if (el.type == Element.NOTE) {
                cursor.addNote(el.pitch);
            }
            else {
                cursor.addRest();
            }
            score.endCmd();
        }
    }
}

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