Adding notes/rest and increase the measure length
Hi,
Is there a (simple) way to have the cursor.addNote adding a note and increasing the measure length ?
Like with the "Insert" mode:
Similary, is there a way to remove an element, even if it leads to shortened measure ?
Thanks,
Comments
I haven't tried it, but my understanding is you can executable any named command from a plugin, so running the "insert-a" command should work, and conversely "time-delete" (internal name for "remove selected range").
In reply to I haven't tried it, but my… by Marc Sabatella
Thanks. The only thing I'm not able to manage is the duration of the inserted notes.
As these commands are not working at the cursor level (
curScore.newCursor
), settingcursor.setDuration(1,8)
does not affect the duration of the inserted notes.Other observation, using a "insert-a" command let the UI in that insert mode. How can I programmatically leave that insert mode (i.e. simulate the user pressing the "Escape" key) ?
In reply to Thanks. The only thing I'm… by parkingb
cmd("escape")
?You can check shortcuts.xml for the internal name of any command triggered by a particular shortcut key.
In reply to cmd("escape") ? You can… by Dylan Nicholson1
That though lists only those commands that have a shortcut assigned. And even that only if at least one shortcut got changed from the default IIRC.
The full list is in the source code and there only as far as I can tell (although ISTR a forum post that metioned them all)
In reply to That though lists only those… by Jojo-Schmitz
It has all the default shortcut assignments in it. But no, I wasn't claiming it was every available command.
In reply to That though lists only those… by Jojo-Schmitz
Can you point me to the right file in the source ? I'm sometimes in bit lost...
In reply to Can you point me to the… by parkingb
See https://musescore.org/en/node/320974#comment-1080038
In reply to Can you point me to the… by parkingb
https://github.com/musescore/MuseScore/blob/3.6.2/mscore/shortcut.cpp
In reply to Thanks. The only thing I'm… by parkingb
I assume the insert-a command needs your to first select a duration, like any other note input command. So you'd need to give the commands to enter note input mode, then select a duration, then insert the note.
In my attempt to add a rest at the end of the score, I've tried this:
I've got a strange result:
The 5th beat is empty : no note, no rest. And I can find why to get there in order to add a note or a rest. Neither with the mouse nor by code:
While when doing the same action from UI the 5th beat is filled with a rest:
Any idea on how to adapt the code for 1) either having the rest adapted automatically, 2) or being able to select that "empty space" and a rest or a note ?
In reply to In my attempt to add a rest… by parkingb
My guess is there is something else you would need to do to actually get the rest insert in your code - they would normally be separate steps internally. From the UI, probably it would work to exchange voices twice, or other of the standard tricks for repairing corruption.
In reply to My guess is there is… by Marc Sabatella
I'll try to fix this with a cut/paste in it. From the UI, it works. However, from the API, I'm still stuck with the cmd("cut") that crashes MS.
In reply to I'll try to fix this with a… by parkingb
Crashes on corrupt scores are not uncommon. So not surprising that doesn't work. Better to understand the source of the corruption and address that. Unfortunately I don't have any real insight there.
In reply to Crashes on corrupt scores… by Marc Sabatella
The crash I'm referring too are actually on my try-outs on a brand new and sound file. See this thread.
In reply to The crash I'm referring too… by parkingb
Looks like you need to call score->endCmd() after using selectRange(...), but yeah, obviously shouldn't crash.
In reply to In my attempt to add a rest… by parkingb
Naively, I'd guess you need to position your "cursor" there (that's kind of a made-up plugin-ism, it's really just a segment & track pair I suspect), then add the rest. Not sure how that is done or if it would truly work or not.
In reply to In my attempt to add a rest… by parkingb
I believe I encountered the same issue when attempting to enforce time signatures. The "fill" command that is used when someone changes the actual duration of a measure with the UI was just not available to Plugins if I recall correctly.
https://musescore.org/en/project/time-signature-enforcer uses a different technique (adding note, deleting it, then swap) but I think that is likely to not work in many situations either (the plugin was intended for empty scores only).
In reply to I believe I encountered the… by jeetee
Makes sense. What about selecting the entire contents of the measure, cutting, then pasting it back? Or swapping voices twice? Those are normally pretty safe potential fixes for other types of corruption.
In reply to Makes sense. What about… by Marc Sabatella
These are working. Both. However, switching the voices, doesn't give a nice result, because all sudden you get a rest on voice 2 while at first you hadn't any..
Furthermore, if your score as 5 staves, you must do this for all the staves.
Other limitation, every call to
cmd(xyz)
leads to 1 Undo step. So undoing this single action (increasing the measure length by API) will lead to 1+N undo, N being the number of staves.But it works.
Knowing that that a reload of the scores fills all the holes automatically is a good news, and reduced the needs to tackle that within the plugin itself.
In reply to These are working. Both… by parkingb
Right, just as when doing this "for real", I'd expect you'd want to delete that voice 2 after the exchange. And yes, you need to do it for each staff - but, that's like two more lines of code to put it in a loop, right? For that matter, can't you just do all staves at once - and that pretty much addresses the undo issue also.