Accessing fingering info during play event
Is there a way I can access fingering information (number and offset) defined on a note during play? I found some hints from Seq::playEvent, where the data structure elements are being accessed in the following manner. However, I could not find any specific instance in the entire codebase that access fingering numbers.
Staff* staff = note->staff(); Instrument* instr = staff->part()->instrument(note->chord()->tick()); const Channel* a = instr->channel(note->subchannel());
From the XML structure, I can see that the Fingering element is defined within the Note datastructure.
<Chord> <durationType>quarter</durationType> <Note> <Fingering> <offset x="2.54236" y="0.508471"/> <text>1</text> </Fingering> <pitch>60</pitch> <tpc>14</tpc> </Note> </Chord>
I tried to access the fingering info using note()->fingering()->text() - but obviously it did not work. I also see that fingering element has a public method note() to get the parent note, but not the other way around. That is, given a note, find the fingering element associated with it. Any pointers will be greatly appreciated.
Comments
Fingering is part of the elementlist of a note: see internal filtering on e->isFingering and ElementList& el() public method for retrieving it
In reply to Fingering is part of the… by jeetee
Thanks @jeetee. This is a good pointer for me to continue forward. Appreciate a prompt reply.
In reply to Thanks @jeetee. This is a… by svanimisetti
I am able to use the example to determine if the note has fingering associated with it or not - but still unable to get the actual number (1-5) from the note element list. Any hints?
In reply to I am able to use the example… by svanimisetti
Fingering is a subclass of TextBase; so I'd wager plainText() would give you that information.
In reply to Fingering is a subclass of… by jeetee
@jeetee - Thanks a lot. I had to do a dynamic_cast to derived types due to class inhertance (Fingering->TextBase->Element) and essentially the list given by el() was an Element list. Now, I am able to use plainText() to get the finger number specified in the score.
The only issue that I am struggling with right now is to determine fingering visibility. When Visible checkbox for the Element in the Inspector panel is set, I am able to query fingering visibility for each note using Element->visible(). However, I came across the following line, which seems to globally disable fingering.
bool tabFingering = note->staff()->staffType(note->tick())->showTabFingering();
If this is not, then is there indeed a global option that can disable fingering on the whole score? Also, if you can guide on what function call can be used to check such global option, it would be really helpful. Although, at a feature level the functionality is working - I just want to guard against any global settings.
Thanks again for patiently guiding me.
In reply to @jeetee - Thanks a lot. I… by svanimisetti
> "I came across the following line, which seems to globally disable fingering"
It is not a global setting, it is a setting specific to Tablature staves. As those staves already show which fret on which string to display numerically, it is highly unusual to also show addition normal fingering elements on them (which might be confused for notes if not styled special).
In reply to > "I came across the… by jeetee
Ok. Everything is working fine now. I am ignoring any global settings - and just checking if the note is visible for now. There are two remaining questions I have for which your suggestions are welcome.
1. How can I find if the note is the beginning or ending of score (first and last note)?
2. How can I determine if a note is on the bass or treble clef? I see note->staff(), but is there a property from Staff class that I can use to determine if its bass or treble?
In reply to Ok. Everything is working… by svanimisetti
1a.)
score.firstSegment()
, then check SegmentType for ChordRest, usesegment.next
until you find one. Then use elementAt to get the actual Chord/Rest there to see whether it was a rest or a note1b.)
score.lastSegment
then as above but now usingsegment.prev
2.) Not really, as clefs might change throughout a score. But if you wish to differentiate between the top/bottom staff of the instrument, then indeed check the staff and/or track for a note (if you use a Cursor, then that only moves through its assigned track, so you're always within the assigned voice of the assigned staff then).
Although you can also track Clef segments probably..
In reply to 1a. score.firstSegment(),… by jeetee
Thanks for these tips. After a bit of struggle, I got everything working. I also found some hints in the develop handbook.