[rev. 5478] y position of multi-voice rest
I'm working on rev 5478, ove convert, looks like there are many changes in core data structures.
I use to convert rest in multi-voices music, and take the middle line of a staff as 0, and line number upper than middle line as lager than 0, line number below middle line as less than 0, but now they appear at the wrong position.
I take xml import as my reference, it create Rest, then calls setUserYoffset.
cr = new Rest(score);
...
static int table2[7] = { 5, 6, 0, 1, 2, 3, 4 };
int dp = 7 * (octave + 2) + table2[istep];
qDebug("dp=%d", dp);
cr->setUserYoffset((po - dp + 3) * score->spatium() / 2);
...
I can't understand which one of line libmscore take as reference, and calculate the position, anyone can help ? (please come Lasconic...)
Comments
an example
In reply to an example by vanferry
My understanding is that the trunk is smarter in multivoice context and so the reference you are looking for is a moving target and depends on the voice. See Rest::Layout() and note the TODO note.
I wonder if we could make something better for this kind of problem since any importer that want to have precise placement will have to "revert" the musescore layouting to find the good user offset. Maybe the "MuseScore offset" or the "MuseScore layouting" should be swichtable on/off.
In reply to My understanding is that the by [DELETED] 5
If user can move these rests' position after insert them, then I vote to switchable control of precise position.
The position of an element is composed of an "layout position" and an "user offset". The layout position it the position mscore calculates as the normal position of an element. A user can move this position by adding an offset.
In the xml file the relative position of an element to a reference point is saved. This is the addition of layout position and user offset. After read of a score and layouting an element the user offset is calculated back from the saved position and the layout position. The position of an element is only written, if there is a user offset (which means the user has manually changed the element position).
If a later version of MuseScore optimizes the placement of elements, older scores will benefit from it. But if a user has optimized an element position, this position will stay. This may not work well in all situtuations but this is the idea.
If you want to override the automatic placement of elements on import, you have to set Element->_readPos. After layout MuseScore calculates a proper userOffset out of it.
In reply to element positions by [DELETED] 3
after I set element->setReadPos(), they are now at right place. I only set those are not at default position.
Thank you both, lasconic and werner!
In reply to looks like they are at the right place by vanferry
I updated http://musescore.org/en/developers-handbook/references/design-implement… with the info given by Werner. Don't hesitate to contribute to this page.