lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
117 stars 28 forks source link

Pixel coordinates & timepos for each measure and each beat #383

Closed cecilios closed 3 months ago

cecilios commented 1 year ago

In discussion #377 it was requested information about how to retrieve a list of associated horizontal pixel coordinates & timepos for each measure and each beat in that measure (for manually controlling the highlight, etc.)

Opening this issue as a remainder to answer this question.

cecilios commented 1 year ago

Perhaps these methods can be used for getting the required information:

    /** Returns the x position for the given timepos. This method only takes notes and
        rests into account, ignoring other staff objects that could exist
        at the same timepos in different locations, such as a barline or a clef before
        the note/rest. The returned value is the x position at which notes/rests are
        vertically aligned with notes/rests at the same timepos in other staves.
        If there are no nets/rests at the requested timepos, this method provides an
        approximated interpolated value.

        The returned value is in logical units, relative to GmoDocPage origin.

        @param timepos Absolute time units for the requested position.

        See get_x_for_barline_at_time()
    */
    LUnits get_x_for_note_rest_at_time(TimeUnits timepos);

    /** Returns the x position for the given timepos. This method takes only barlines
        into account, ignoring other staff objects that could exist at the same timepos
        (e.g. any staffobj after the barline). Therefore, the returned value is the x
        position of the first barline found at the provided @c timepos.

        The returned value is in logical units, relative to GmoDocPage origin.

        @param timepos Absolute time units for the requested position.

        See get_x_for_note_rest_at_time()
    */
    LUnits get_x_for_barline_at_time(TimeUnits timepos);

    /** Returns the timepos at start of this system. */
    TimeUnits start_time();

    /** Returns the timepos at end of this system. */
    TimeUnits end_time();

Method get_x_for_note_rest_at_time() will provide the logical coordinates (relative to GmoDocPage origin) for each beat, by providing the timepos for the beat.

Method start_time() will return the timepos for first measure and with this value you can use previous method to get its x position.

And method get_x_for_barline_at_time() could be used the get the start position for all other measures in the system.

cecilios commented 1 year ago

@npiegdon Did the answer solved your needs? Can I close this issue?

npiegdon commented 1 year ago

Sorry for the wait on this. Between trying to get a major release out the door before I can start on this integration in earnest and real life stuff like my 6 year old being home from school for a few days with the flu, I haven't had a chance to dig into these details.

That said, this does look like a good starting point and you can probably close this for now. Thanks!

cecilios commented 1 year ago

No problem. I'll keep it open until you can test and confirm.

cecilios commented 3 months ago

I am closing this issue due to lack of any feedback. So I assume the issue is solved.