Adding a chord symbol from a plugin at a position where there is no note.
I’m writing a plugin that would embellish the harmony of a jazz lead sheet. In other words, it wants to add new suitable chord symbols halfway between existing ones where appropriate.
This works when there is a note at this position, but not when there is no note. In that case the new chord symbol gets added at the next note (see attached: added symbol in red).
test.mscz
I borrowed this code from another plugin:
function setCursorToTime(cursor, time){
cursor.rewind(0);
while (cursor.segment) {
var current_time = cursor.tick;
if(current_time>=time){
return true;
}
cursor.next();
}
cursor.rewind(0);
return false;
}// end setcursor To Time
var harmony = newElement(Element.HARMONY);
harmony.text = newchord;
setCursorToTime(cursor, newtime); //newtime = 960 in the example
cursor.add(harmony);
Neither cursor.next (or segment.next) ‘stops’ at this empty space.
Any suggestions? All help appreciated.
Comments
If there is no note in any voice of any staff there, there is no segment, so no surprise you can't get to it. You'd have to create the segment somehow. No idea what might exist to support that within the plugin framework, but a hack might be to add rests in another voice, then add the chord symbol, then delete the rests.
In reply to If there is no note in any… by Marc Sabatella
Thank you Mark. I'll try your hack.
But by selecting the first chord symbol and hitting space twice I can get there... How does that work then? (not that I have seen any plugin that does this kind of thing...)
In reply to Thank you Mark. I'll try… by elsewhere
It works by creating a new segment where necessary, then deleting it if you don't end up actually entering a chord. I doubt that functionality is exposed to plugins, which is why I suggested the idea of forcing the segment to be created by adding rests.
In reply to It works by creating a new… by Marc Sabatella
Your suggestion worked, Marc, thanks!, but I need the rests in voice 1 it seems. No big deal. Thus:
switch voice 1 & 2
fill voice 1 with quarter rests
reverse when done
In reply to Your suggestion worked, Marc… by elsewhere
I just realized I could also set cursor.voice =1 and put the rests in voice 2.