示例#1
0
/** \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;
}
示例#2
0
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;
}
示例#3
0
/** \brief Returns true if the system was added to the page false otherwise.
*/
bool GRPage::addSystem( GRSystem * inSystem, float * ioUsedSystemDistance )
{
	assert(inSystem->getGRPage() == this);
	GRSystem * lastSystem = mSystems.empty() ? 0 : mSystems.back(); // get the current last system
	const NVRect & newSystemBox = inSystem->getBoundingBox();
	
	NVPoint newPos;
	if( lastSystem ) {
		if (*ioUsedSystemDistance > 0) {
			newPos.y = lastSystem->getPosition().y + *ioUsedSystemDistance;
			*ioUsedSystemDistance = -1;
		}
		else {
			newPos.y = lastSystem->getPosition().y + lastSystem->getBoundingBox().bottom;
			// this should be handled by "springs" as well... and there should be a "minimum" distance...
			newPos.y -= newSystemBox.top;
			// the default distance ...
			// it is later distributed evenly between mSystems ...
			newPos.y += settings.systemsDistance;
		}
		m_totalsystemheight += newSystemBox.Height();
	}
	else // So this is the first system of the page
	{	
		newPos.y = - newSystemBox.top;
		m_totalsystemheight = newSystemBox.Height(); // TODO: bottom - newPos.y;
	}
	inSystem->setPosition( newPos );

	if( mSystems.empty())	mDebugPageDate = inSystem->mDebugSystemDate;
	mSystems.push_back( inSystem );
	updateBoundingBox();
	return true;
}
示例#4
0
/** \brief Draws the score page.
*/
void GRPage::OnDraw( VGDevice & hdc ) const
{	
// TODO: test if the element intersect with the clipping box
	GuidoPos pagepos = First();

	while (pagepos)
		GetNext(pagepos)->OnDraw(hdc);

	// - Convert from centimeter to logical.
	const float tstx = mLeftMargin;	// (JB) sign change
	const float tsty = mTopMargin;		// (JB) sign change

	// this resets the window-origin, so that left and top margins are correct ...
	// dont forget to set the clipping-rectangle!
	gClipRect.left -= tstx;
	gClipRect.top -= tsty;
	gClipRect.right -= tstx;
	gClipRect.bottom -= tsty;

	// The following sets the WindowOrigin so that
	// 0,0 is at the top left (including margins)
	//
	//  ---------------
	//  |    mt       |
	//  |  x-------   |
	//  |  |      | mr|
	//  |ml|      |   |
	//  |  --------   |
	//  |    mb       |
	//  |-------------|

	hdc.OffsetOrigin( tstx, tsty ); 

	GRSystem * theSystem;
	SystemPointerList::const_iterator ptr;
	for( ptr = mSystems.begin(); ptr != mSystems.end(); ++ ptr )
	{
		theSystem = *ptr;
		const NVPoint & pos = theSystem->getPosition();
		NVRect br (theSystem->getBoundingBox());
		br += pos;
			
		if( br.Collides( gClipRect ) == false )
			continue;

		gCurSystem = theSystem;
	    theSystem->OnDraw(hdc);
	}

	if (gBoundingBoxesMap & kPageBB)
		DrawBoundingBox( hdc, kPageBBColor);
	hdc.OffsetOrigin( -tstx, -tsty ); 
}
示例#5
0
// ----------------------------------------------------------------------------
void GRPage::trace(VGDevice & hdc) const
{
    NVRect r;
    cout << "Page trace - page " << r << " " << getPosition() << endl;
    cout << "    => page num systems : " << getSystems()->size() << endl;
    SystemPointerList::const_iterator ptr;
    for( ptr = getSystems()->begin(); ptr != getSystems()->end(); ++ptr ) {
        GRSystem * system = *ptr;
        r = system->getBoundingBox();
        r += system->getPosition();
        cout << "    system " << r << endl;
        SSliceList * slices = system->getSlices();

        if (slices) {
            GuidoPos pos = slices->GetHeadPosition();
            while (pos) {
                GRSystemSlice * ss = slices->GetNext(pos);
                r = ss->getBoundingBox();
                r += ss->getPosition();
                cout << "    slice " << r << endl;

                StaffVector * sv = ss->getStaves();           // get the staves list
                if (sv) {
                    for( int i = sv->GetMinimum(); i <= sv->GetMaximum(); ++i) {
                        GRStaff * staff = sv->Get(i);
                        if (staff) {
                            cout << "      - staff " << staff->getBoundingBox() << " " << staff->getPosition()  << endl;
/*                            NEPointerList * selts = staff->getElements();
                            if (selts) {
                                GuidoPos pos = selts->GetHeadPosition();
                                while (pos) {
                                    GRNotationElement * nelt = selts->GetNext(pos);
                                    if (nelt) {
                                        cout << *nelt;
                                        nelt->DrawBoundingBox (hdc, GColor(0, 0, 255));
                                    }
                                    else cout << "==> GRStaff notation element is NULL" << endl;
                                }
                            }
                            else cout << "==> GRStaff elements is NULL" << endl;
*/
                        }
                        else cout << "==> GRStaff is NULL" << endl;
                    }								
                }
                else cout << "==> StaffVector is NULL" << endl;
            }
        }
        else cout << "==> no slices in system" << endl;
    }
}
示例#6
0
void GRSingleRest::tellPosition( GObject * caller, const NVPoint & newPosition )
{
    if (mFillsBar && caller == secondbar)
    {
        // then we have a bar filler ....

        // now we need to check, wether the firstbar exists ...
        // if not, we need the horizontal position of the firstglue
        // of the first systemslice ....
        float posx = -1;
        if (firstbar)
        {
            // we need to check, if the systems of the firstbar
            // and secondbar are identical ....
            GRSystem * sys1 = firstbar->getGRStaff()->getGRSystem();
            GRSystem * sys2 = secondbar->getGRStaff()->getGRSystem();
            if (sys1 == sys2)
                posx = firstbar->getPosition().x;
        }
        if ((posx < 0 || !firstbar) && mGrStaff)
        {
            // this will only work, if we are at
            // the very beginning, and there was no
            // "artificial" begin-slice.
            GRGlue * myglue = mGrStaff->getSecondGlue();
            if (myglue)
                posx = myglue->getPosition().x;
            else
            {
                GRSystem * grsystem = mGrStaff->getGRSystem();
                // take the first systemslice ....
                if (grsystem)
                {
                    GRSystemSlice * grsysslc = grsystem->getFirstGRSystemSlice();
                    if (grsysslc)
                    {
                        myglue = grsysslc->getEndGlue();
                        if (myglue)
                            posx = myglue->getPosition().x;
                    }
                }
            }
        }
        setHPosition((float)((secondbar->getPosition().x - posx) * 0.5f + posx));
        return;
    }

    if ( mNeedsSpring == 0 && mSpringID == -1)
        setHPosition(newPosition.x);
}
示例#7
0
//____________________________________________________________________________________
char * GRSingleNote::getGGSInfo( int infotype ) const
{
	// now we find out, where the next spring is ....
	// our sprid is set ....
	const GRSpring * prevspring = mGrStaff->getGRSystem()->getGRSpring(mSpringID - 1);
	const GRSpring * nextspring = mGrStaff->getGRSystem()->getGRSpring(mSpringID + 1);

	const GRSpring * myspring   = mGrStaff->getGRSystem()->getGRSpring(mSpringID);

	int left = (int)myspring->posx;
	int right = (int)myspring->posx;

	if (prevspring)	left = (int)prevspring->posx;
	if (nextspring)	right = (int)nextspring->posx;

	char * buf = new char[100];

	GRSystem * cursystem = mGrStaff->getGRSystem();

#ifdef VC2005
	snprintf(buf, 100, 100, "%d,%d,%d,%d,%ld,%d,%ld,%d\n",
		(int)cursystem->getGRPage()->getMarginLeft(),
		(int)cursystem->getPosition().x,
		(int)mPosition.x,
		(int)myspring->posx,
		(long int)prevspring,
		(int)left,
		(long int)nextspring,	// <- !!! pointer to int !!!
		(int)right);
#else
	snprintf(buf, 100, "%d,%d,%d,%d,%ld,%d,%ld,%d\n",
		(int)cursystem->getGRPage()->getMarginLeft(),
		(int)cursystem->getPosition().x,
		(int)mPosition.x,
		(int)myspring->posx,
		(long int)prevspring,
		(int)left,
		(long int)nextspring,	// <- !!! pointer to int !!!
		(int)right);
#endif
	return buf;
}
示例#8
0
/** \brief Distributes the systems of the page
	evenly .... but only, if the distance will be less than
	(10 * LSPACE) between mSystems 

	\bug does not take account of the page title .
*/
void GRPage::finishPage( bool islastpage )
{
	if (settings.systemsDistribution == kNeverDistrib) {
		SystemPointerList::iterator ptr;
		for( ptr = mSystems.begin(); ptr != mSystems.end(); ++ ptr )
			(*ptr)->FinishSystem();
		return;
	}

	const size_t systemCount = mSystems.size();
	float pagesizey = getInnerHeight();
	float dist = pagesizey - m_totalsystemheight;
	if (systemCount > 1)
		dist = dist / (float(systemCount - 1));

	if (dist > 0) {
		if ((settings.systemsDistribution == kAlwaysDistrib)
			|| (settings.systemsDistribution == kAutoDistrib) // DF added on Feb 13 2011 to force correct mapping
			|| settings.optimalPageFill
			|| (!islastpage) || (dist <= (0.1f * pagesizey)))
		{
			const float distribLimit =settings.systemsDistribLimit * pagesizey;
			if(( settings.systemsDistribution == kAutoDistrib ) && ( dist > distribLimit ))
			{
				// We are here because the distance between systems is too large
				if( false ) // islastpage )
				{
					return;
				}
				else {
					// this is auto ...
					dist = 0.075f * pagesizey; // Hardcoded
				}
			}

			// then we put the mSystems at these distances ...
			float cury = 0;
			for(SystemPointerList::iterator i = mSystems.begin(); i != mSystems.end(); i++ ) {
				GRSystem * system = *i;
				if (cury > 0) {
					NVPoint newpos;
					newpos.y = cury - system->getBoundingBox().top;
					system->setPosition( newpos );
					cury += system->getBoundingBox().Height();
				}
				else // So this is the first system. Just get its bottom.
				{
					cury += system->getPosition().y + system->getBoundingBox().bottom;
				}				
				cury += dist;
                system->FinishSystem();
			}
		}
	}
	else {
		SystemPointerList::iterator ptr;
		for( ptr = mSystems.begin(); ptr != mSystems.end(); ++ ptr )
			(*ptr)->FinishSystem();
	}
	// hack to get correct time position for the page [DF - May 26 2010]
	setRelativeTimePosition ( (*mSystems.begin())->getRelativeTimePosition() );
}