Generating arpeggiated chords in plug-in - dox for

• Apr 30, 2020 - 16:50

I have been tweaking the "Expand Chord Symbols" plug-in by Mark Shepherd. I am now trying to have the generated chords be arpeggiated. A look at a .mscx file shows that I need to have an tag added to the . has a integer that specifies the type of arpeggio.

Mark's code builds chords from an array of MIDI notes. This works fine.

                    cursor.addNote(midiNotes[0]);
                    if (!chord.bassOnly) {
                        for (var j = 1; j < midiNotes.length; j += 1) {
                            cursor.addNote(midiNotes[j], true);
                        }
                    }

I searched the dox for an arpeggio object, but found only Element.ARPEGGIO. I can use newElement(Element.ARPEGGIO) to create an object, but where can I find document on that properties and methods the object has? Element has a "subtype", so I tried adding this after the note loop:

                        // Arpeggiate the chord
                        var e = newElement(Element.ARPEGGIO);
                        e.subtype = 0;
                        cursor.add(e);

But it doesn't affect the score as viewed or saved.

Mark's code builds the chord using Cursor's addNote with a "true" second parameter. I PRESUME that Cursor wraps the notes in a Chord object. So perhaps my Arpeggio is ending up outside the Chord object.

I thought of newElementing a Chord, and populating it with Notes and my Arpeggio. But both Chord and Note have a number of parameters, which Cursor.addNote take care of and whose initialization isn't clear to me from the dox. Is there some other way of making "easy" Note and Chord objects as Cursor.addNote does?

Or is there a way to ask Cursor for the Chord that it presumably has created?


Comments

In reply to by BSG

I prefer to have the arpeggio visible in the score, and I had trouble making Note objects by hand.

I found a partial solution in a comment elsewhere in Mark Shepherd's code: "cursor.addNote advances the cursor, but cursor.add does not." So I call
- cursor.addNote to specify the notes in the chord (addToChord true on all but the first)
- cursor.prev() to back up the cursor to point at what is presumably the CHORD
- cursor.add to add a newElement(Element.ARPEGGIO) to the chord
- cursor.next() to move the cursor past the chord and ready for what follows

The arpeggios now show up. HOWEVER, they are of <subtype> 0. The dox say that Element objects have a "subtype" property. But logging it says "undefined", even after I try to set it using e.subtype = 2.

The dox have nothing about an object created with newElement(Element.ARPEGGIO), and my new friend Object.keys(e) crashes MuseScore when applied to my ARPEGGIO object.

By grepping the source for some text from the Doxygen, I found the associated .h and .cpp files. I clearly have a some Q_PROPERTY learning in my future, but at least I have a path forward.

In reply to by OldBaldGeek

Hi, I'm delighted you are finding my code helpful. Let me know if you figure out how to add arpeggios, maybe we could add this feature to ExpandChordSymbols. BTW I just posted a new version of ExpandChordSymbols at https://musescore.org/en/project/expand-chord-symbols-notes; if you are working in the source code it might be better to have the newer version. But beware, I split the source code into 2 files, and unfortunately if you are using Plugin Creator, the Reload Current Plugin Source button only seems to reload the main .qml file, it does not reload any subsidiary files.

In reply to by markshepherd

I'll take a look at your updates at some point, since a merged plug-in may make sense. My current version can either output the chord with a "squiggly line arpeggio", which sounds reasonably guitar-like, or one-note-at-a-time following a rhythm pattern (using your code), which I am hoping to turn into some sort of "picking pattern" based on the pitches of the rhythm pattern (as you do with bass note).

The "squiggly line arpeggio" is currently limited to upward, since I don't see a way to change the arpeggio-style from a plug-in. That limits the ability to simulate strumming, which needs downward as well as upward arpeggios.

My simple note-at-a-time isn't very convincing, since it doesn't let the notes ring. Notating this would be a pain, so I think I will see if sustain pedal can do anything.

The other remaining feature is capo. This is needed because the voicing of an F chord on a guitar is quite different from a D chord played with the capo on the third fret. Unfortunately, it doesn't seem that a plugin can read the capo setting (or much else) from the Style or Properties of a score, so capo position will probably need to be entered on the plug-in's dialog.

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