Question about Plugin API's Cursor + adding chords

• Mar 19, 2022 - 06:12

I've run into a problem related to the Plugin's API and adding chords

Using the cursor, I can add an element, but if at that cursor position there is not an equivalently sized segment, then there will be a problem with the overall size of the measure:

As with the image here, for example, if I have an element that is a half-note ready to be added using
cursor::add (Ms::PluginAPI::Element *) and i'm in a 4/4 measure on the last quarter at 4/4, adding that half note will give me an actual half note instead of a quarter note that ties over into the next measure. The measure will be 5/4 afterwards. I couldn't find a flag or something to have this not happen, so I figured damn, I guess I'll have to use the addNote() function that takes an integer pitch and then lose out on the accidental information (using only midi pitch information)

But then even here as shown, if I build up a chord pitch by pitch using that function, the same scenario will give me the built up chord on the next measure post-tie, not both together so that the entire chord ties appropriately.

Is there any way to get this to work like you'd normally expect as a user?

If so, is it not a a crazy work-around? It would've been really nice if adding an element could act like an actual user-interactive form and give expected results. Alternatively, to be able to designate a tonal pitch class + accidental at the cursor like Dbb instead of be bound to MIDI pitch would be nice, but it wouldn't solve the "spill over" problem that works automatically when for example manually copying/pasting a half note at the end of a quarter rest of a 4/4 measure.

I have gotten something to work by pulling a fast one, but it feels kind of crazy: going back to the first cursor position of building a chord, testing if there is a tieForward, and then build up the chord once more if so, and in the process issuing a cmd("tie"); to tie forward for the newly added pitches also. It works, but it feels weird and not sure how it would work if there were more than one tie for like a really long chord.... that'd be another thing in itself...


I attach a plugin that writes chords and that could perhaps help you. (Use an empty piano score & run the plugin from the Plugin Creator window). That a chord written from a plugin does not cross barlines properly is a known issue, but I can't seem to find it now. You can check it by changing the duration in addchord from 1920 to 2880.

Attachment Size
WriteChords.qml 21.9 KB

In reply to by elsewhere

Hey thanks, especially for the affirmation that it's a known issue.

Here's the WriteChords script ran with default:

And here with ticks set to 2880:

And so it seems there's the same issue again. I'll have to experiment with adding Notes instead of pitches (was using chords but that's where i was getting invalid measures like 5/4 without the + sign afterward

In reply to by elsewhere

Although I appreciate the input, standard note entry is no problem here.

What I've been working on is making a plugin that allows for list-selection copy+paste in a way that compresses the components time-wise so that I can Ctrl+Click a few chords scattered abroad or select all similar on beat-1 for example and then copy and paste consecutively into a new measure with two commands of the plugin. Although this is weird since MuseScore can't do that sort of thing normally, it has its "corner-case" uses that help when wanted while experimenting, etc.

It's working fine for the most part, except that if a chord duration is not capable of being fit within the confines of the current cursor position within the given measure for pasting, I quite literally have to manually input the ties through the plugin architecture after verifying that the initial entry of the first note of the chord ended up having a tie, and then cycle backwards and add the chord pitches along with adding forward ties. This works, but thought maybe there would be a better way... and I'm thinking for now there isn't. It's just extra code...

As relates to regular note entry, I'd suggest anyone reading this to always go by the literalness of the moment - so even if a "half-note chord" is tied across a barline as two quarterchords, never attempt to literally enter in a half-duration but rather enter a quarter-duration chord and then press the tie command.

As an aside: I can understand the issue when someone wants to go back to a chord and enter a new pitch or two (based on reading the provided links). It's kind of annoying that you have to put them both onto each chord that is tied and then tie them outside of note entry. But that's how it is, unless I'm missing something:
Those extra two notes for example need also to be manually added to the right-hand side and then outside of note entry require tie commands for each one. Lesson: get the chord built first before tying.

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