コード例 #1
0
ファイル: GRVoice.cpp プロジェクト: anttirt/guidolib
GRPage * GRVoice::getPageNum(int num,int denom)
{
    // I have to travers the voice and find the element
    // at the position num/denom. Then I have to find the
    // pagenumber of that element.

    const TYPE_TIMEPOSITION tpsearch ( num,denom );
    GuidoPos pos = First();
    while (pos)
    {
        GRNotationElement * el = GetNext(pos);
        GREvent * ev = GREvent::cast(el);
        if (ev)
        {
            if (ev->getRelativeTimePosition() == tpsearch)
            {
                GRStaff * stf = ev->getGRStaff();
                GRSystem * sys = stf->getGRSystem();
                GRPage * page = sys->getGRPage();
                return page;
            }
            else if (ev->getRelativeTimePosition() > tpsearch)
                return NULL;
        }
    }
    return NULL;
}
コード例 #2
0
ファイル: GRVoice.cpp プロジェクト: anttirt/guidolib
/** \brief Returns a page corresponding to a time position.

	It finds the musical element which time position is immediately before or equal to
	the input time position. Then it returns the page of that musical element.

	getPageForTimePos() always try to return a page, while getPageNum() only returns
	a page when the input time position match the time position of an existing
	musical element.

	TODO: Check if the page keeps track of both its start timepos and end timepos,
			therefore we could directly jump from one page to another


	\bug The last system of a page point to the next page instead of its parent page.

*/
GRPage * GRVoice::getPageForTimePos( int num, int denom ) const
{
    GRPage * outPage = 0;
    TYPE_TIMEPOSITION inTime ( num, denom );
    GuidoPos pos = First();

    // - Find the event which best match the input date
    GREvent * bestEv = 0;
    while (pos)
    {
        GRNotationElement * el = GetNext(pos);
        GREvent * ev = GREvent::cast(el);
        if( ev )
        {
            const TYPE_TIMEPOSITION & currTime = ev->getRelativeTimePosition();
            if( currTime <= inTime )
                bestEv = ev;
            else
                break;	// (JB) I suppose that all next elements have a greater time pos.
        }
    }

    // - Get the page corresponding to the event found

    if( bestEv )
    {
        GRStaff * staff = bestEv->getGRStaff();
        GRSystem * sys = staff->getGRSystem();
        outPage = sys->getGRPage();
    }

    return outPage;
}