// ----------------------------------------------------------------------------
void 
GRARCompositeNotationElement::updateBoundingBox()
{
	mLeftSpace = 0;	// should probably not be done here
	mRightSpace = 0;

	mBoundingBox.Set( 0, 0, 0, 0 );

	// - Check note sub parts
	GuidoPos pos = First();
	while (pos)
	{
		// - TODO: take the position in account ! following code wrongly assumes
		// that the elements are exactly at the same position.
		GRNotationElement * e = GetNext(pos);
		if (e->getRightSpace() > mRightSpace)	mRightSpace = e->getRightSpace();
		if (e->getLeftSpace() > mLeftSpace)		mLeftSpace = e->getLeftSpace();

		// 
		
		addToBoundingBox( e );
		
		/* was ->
		const NVRect & eltBox  = e->getBoundingBox();
		if( eltBox.top < mBoundingBox.top)			mBoundingBox.top = eltBox.top;
		if( eltBox.bottom > mBoundingBox.bottom)	mBoundingBox.bottom = eltBox.bottom;
		*/
		//
	}
}
Ejemplo n.º 2
0
//____________________________________________________________________________________
void GRSingleNote::setPosition( const NVPoint & inPos )
{
	// - Call inherited
	GRNote::setPosition( inPos );

	// - Notify Ornament
	if ( mOrnament )
	{
		mOrnament -> tellPosition( this, getPosition() );
	}

	// - Watch for the Accidentals
	GRAccidentalList accList;
	extractAccidentals( &accList );

	GuidoPos pos = accList.GetHeadPosition();
	NVPoint pnt ( getPosition());
	pnt.x -= mNoteBreite * 0.5f;
	while (pos)
	{
		// if more than one accidental (like
		// natural AND sharp/flat)
		pnt.x -= LSPACE / 5;
		GRNotationElement * e = accList.GetNext(pos);
		e->setPosition(pnt);
		pnt.x -= // old: e->getSizeX();
			e->getLeftSpace() + e->getRightSpace();
	}
	updateBoundingBox(); // DEBUG
}
Ejemplo n.º 3
0
//____________________________________________________________________________________
void GRSingleNote::updateBoundingBox()
{
	traceMethod("updateBoundingBox");
	// - Call inherited
	GRNote::updateBoundingBox();

	// - Check for notebreite (?)
	if( mBoundingBox.left > (-mNoteBreite * 0.5f))
		mBoundingBox.left = (-mNoteBreite * 0.5f);	// (JB) test, was: 0

	if( mBoundingBox.right < (mNoteBreite * 0.5f))
		mBoundingBox.right = (mNoteBreite * 0.5f);	// width of the note. (JB) test, was: 0

	// - Check for ledger lines
	//  (note that the bounding box does not take account of ledger lines, for now)
	if (mNumHelpLines > 0 )
	{
		const float theSize = (mNoteBreite * 0.8f * mSize); // harcoded

		if (mLeftSpace < theSize)	mLeftSpace  = theSize;
		if (mRightSpace < theSize )	mRightSpace = theSize;
	}

	// - Check for stem
	if (mGlobalStem)
	{
		GRNotationElement * e = mGlobalStem->getGRFlag();
		if( e )
		{
			if (e->getRightSpace() > mRightSpace)
				mRightSpace = e->getRightSpace();

			if (e->getLeftSpace() > mLeftSpace)
				mLeftSpace = e->getLeftSpace();
		}
	}
	mBoundingBox -= getOffset();

	float scale = getSize();
	mMapping.left = mPosition.x - mNoteBreite / 2 * scale;
	mMapping.right = mMapping.left + mNoteBreite * scale;
	mMapping.top = mPosition.y - LSPACE/2 * scale;
	mMapping.bottom = mMapping.top + LSPACE * scale;
	mMapping += getOffset();
}
Ejemplo n.º 4
0
/** \brief Creates all rods from the startspr until the endspr.

It is called by the StaffManager (BuildSPF)
we have to make sure that firstrod and
lastrod is created correctly.
We do not need to take care of rods with
starting positions that are smaller than startspr.
optForce is the guido layout settings
*/
int GRVoice::createNewRods(GRStaffManager * stfmgr, int & startspr, int & endspr, float optForce)
{
    if (lastrod)
    {
        // so the calling function knows,
        // where the restretching must start.

        assert(lastrod->mSpr2 == startspr);

        // startspr = lastrod->spr1;

        // this removes the rod from the rod-list.
        // it is done, because the lastrod was
        // a connection to the end, which is now
        // moved further....
        // no, no longer removal
        // stfmgr->deleteRod(lastrod);

        // this sets the startspr, so the staffmgr
        // knows, which offset needs to be restrechted.

        // will be really deleted by owner
        // (stfmgr or grsystem).
        lastrod = NULL;
    }

    if (firstrod)
    {
        // old firstrod ...
        // will be deleted by real owner ...
        // (which is stfmgr or grsystem)

        firstrod = NULL;
    }

    // this setting just remembers, if it is the first run ....
    // for the first run, there must be a special handling (remembering
    // the first rod position)
    GuidoPos pos;
    if (lastsprpos == NULL)
    {
        // there has been no previous rod, that
        // is there has been no element in this
        // voice yet, that is attached to a string.
        if (mIsNewLine)
        {
            // then, there has been no element
            // added yet!
            return -1;
        }
        pos = firstPositionInLine;
    }
    else
    {
        // iterate to the next element....
        pos = lastsprpos;
        GetNext(pos);
    }

    GRNotationElement * el = 0;
    float spacedistance = 0;
    bool spaceactive = false;

    while (pos)
    {
        lastsprpos = pos;
        el = GetNext( pos );

        // is this element a Space-Tag?
        GRSpace * spc = dynamic_cast<GRSpace *>(el);
        if (spc)
        {
            // this can only happen, if we are at the very start ..
            assert(!firstrod);
            spacedistance += spc->getARSpace()->getValue();
            spaceactive = true;
        }

        // does this element have a spring;
        // if not, than there can't be a rod
        // attached to it.
        if (!el->getNeedsSpring())
        {
            continue;
        }

        // if (beginsAtHead)
        // {

        if (!firstrod)
        {
            GRRod * rod;
            // this may need to change, so that
            // glue- elements get a chance as  well ...
            // maybe we have to create another rod somewhere ?
            // not only the glue, but this MUST
            // be the distance of the last element ....
            // otherwise, we do not get enough space ...
            float dist = (LSPACE * 0.5f);
            if (dynamic_cast<GRClef*>(el))
            {
                dist = 50; // the same as the begin glue
                // this is a wild hack ...
            }

            rod = new GRRod(
                dist + el->getLeftSpace(),
                el->getSpringID()-1,el->getSpringID(), optForce);

            if (spaceactive)
            {
                // the space at the beginning is ignored completely.
                // in the case of merging, the firstrod is removed,
                // otherwise, it is just  the regular space needed
                // in the case of no space-tag  at all.

                // old:
                // the space has been taken care of before (hopefully)
                // (if this is called in reaction to pbreak ...)
                spaceactive = 0;
                spacedistance = 0;

                // space-active....
                rod->setIsSpaceRod( true );
                stfmgr->addRod(rod,1);
            }
            else
            {
                stfmgr->addRod(rod,0);
            }

            if (rod->getSpr1() < startspr)
                startspr = rod->getSpr1();

            // the very first rod is a copy of the one added to the stfmgr.
            firstrod = rod;
        }


        // this is done, as long as the NEXT
        // element needs a spring ...
        while (pos)
        {
            GRNotationElement * next = GetCompositeElements().GetAt(pos);

            GRSpace * spc = dynamic_cast<GRSpace *>(next);
            if (spc)
            {
                // then this element is a space-tag ...
                // all between is added ...
                spacedistance += spc->getARSpace()->getValue();
                spaceactive = true;
            }
            if (!next->getNeedsSpring())
            {
                GetNext(pos);
                continue;
            }
            // it needs a spring. Now we add a Rod ...
            GRRod * rod = 0;
            if (spaceactive)
            {
                rod = new GRRod( el, next, 0, spacedistance, optForce);
                rod->setIsSpaceRod( true );
                spaceactive = false;
                spacedistance = 0;
                // spaceactive!
                stfmgr->addRod( rod,1 );
            }
            else
            {
                rod = new GRRod( el, next, 0, optForce);
                // no space active
                stfmgr->addRod(rod,0);
            }

            if( rod->getSpr1() < startspr )
                startspr = rod->getSpr1();

            lastrod = rod;

            // finish the inner cycle
            break;


        } // while (pos);

        // if we are moved out


    } // while (pos);

    // there is an element ...
    // then we need to add a Rod from this
    // to the end. This rod is going to
    // be the lastrod ...
    if (el && el->getNeedsSpring())
    {
        GRRod * rod;
        if (spaceactive)
        {
            // the rod is of the length of
            // the following space tag...
            rod = new GRRod( spacedistance, el->getSpringID(), endspr, optForce);
            rod->setIsSpaceRod( true );

            // space active!
            stfmgr->addRod(rod,1);
        }
        else
        {
            rod = new GRRod(el->getRightSpace(), el->getSpringID(), endspr, optForce);
            // no space active
            stfmgr->addRod(rod,0);
        }

        if (rod->getSpr1() < startspr)
            startspr = rod->getSpr1();
        lastrod = rod;
    }

    return 0;
}
Ejemplo n.º 5
0
/** \brief cthis routine is called just as createNewRods is called
	It updates the QP-Matrix for minimizing the Spring-
	energy. This is a first prototype ...
*/
int GRVoice::updateQPMatrix(GRSpaceForceFunction * spf,
                            ISpringVector * sprvect,
                            int startspr, int endspr)
{
    double * mat = spf->getMatrix();
    int n = spf->getMatrixMemSize();

    int firstrun = 1;

    // this setting just remembers, if it is the first run ....
    // for the first run, there must
    // be a special handling (remembering the first rod)
//	int beginsAtHead = 0;
    GuidoPos pos;
    if (lastsprpos == NULL)
    {
        // there has been no previous rod, that
        // is there has been no element in this
        // voice yet, that is attached to a string.
        if (mIsNewLine)
        {
            // then, there has been no element
            // added yet!
            return -1;
        }
        pos = firstPositionInLine;
//		beginsAtHead = 1;
    }
    else
    {
        // iterate to the next element....
        pos = lastsprpos;
        elements->GetNext(pos);
    }

    GRNotationElement * el = NULL;
    float spacedistance = 0;
    bool spaceactive = false;

    while (pos)
    {

        el = elements->GetNext(pos);


        // is this element a Space-Tag?
        GRSpace * spc = dynamic_cast<GRSpace *>(el);
        if (spc)
        {
            spacedistance += spc->getARSpace()->getValue();
            spaceactive = true;
        }

        // does this element have a spring;
        // if not, than there can't be a rod attached to it.
        if (!el->getNeedsSpring())
        {
            continue;
        }

        // if (beginsAtHead)
        // {

        int start; // the spring where the current element starts
        int end; // the spring where the current element ends


        // this is done, as long as the NEXT
        // element needs a spring ...
        while (pos)
        {
            GRNotationElement * next = elements->GetAt(pos);

            GRSpace * spc = dynamic_cast<GRSpace *>(next);
            if (spc)
            {
                // then this element is a space-tag ...
                // all between is added ...
                spacedistance += spc->getARSpace()->getValue();
                spaceactive = true;
            }
            if (!next->getNeedsSpring())
            {
                elements->GetNext(pos);
                continue;
            }

            start = el->getSpringID();
            end = next->getSpringID();

            // then we need the "real" constant:

            float mysconst = GRSpring::onlycalcconst(el);

            // complex-rod ...
            int i,j;
            for (i=start; i<end; i++)
            {
//					*(mat+i + n*i) += 0.5*mysconst;

                /* This version is one, which works
                   only with added constraints
                   (equality of subgroups in one voice
                   not yet clear, how to to this automatically
                   */
                for (j=i; j<end; j++)
                {
                    *(mat + i + n*j) += 0.5*mysconst;

                }
            }

            // it needs a spring. Now we add a Rod ...
            if (spaceactive)
            {

                spf->addConstraint(start,end,spacedistance);

                //rod = new GRRod(el,next,0,spacedistance);
                //rod->setIsSpaceRod(true);
                spaceactive = false;
                spacedistance = 0;
                // spaceactive!
                // stfmgr->addRod(rod,1);
            }
            else
            {
                double length = el->getRightSpace() + next->getLeftSpace();
                spf->addConstraint(start,end,length);
                // rod = new GRRod(el,next,0);
                // no space active
                // stfmgr->addRod(rod,0);
            }

            // finish the inner cycle
            break;

        } // while (pos);

        // if we are moved out

    } // while (pos);

    // there is an element ...
    // then we need to add a Rod from this
    // to the end. This rod is going to
    // be the lastrod ...
    if (el && el->getNeedsSpring())
    {
        int start;
        int end;

        start = el->getSpringID();
        end = endspr;

        float mysconst = GRSpring::onlycalcconst(el);

        // complex-rod ...
        int i,j;
        for (i=start; i<end; i++)
        {
//					*(mat + i + n*i) += mysconst;
            for (j=start; j<end; j++)
            {
                *(mat+ i + n*j)+= 0.5 * mysconst;
            }
        }
        // }

        if (spaceactive)
        {
            spf->addConstraint(start,end,spacedistance);
            // the rod is of the length of
            // the following space tag...
            //rod = new GRRod(spacedistance,
            //	el->getSpringID(),endspr);
            //rod->setIsSpaceRod(true);

            // space active!
            //stfmgr->addRod(rod,true);
        }
        else
        {
            double length = el->getRightSpace();
            spf->addConstraint(start,end,length);
            //rod = new GRRod(el->getRightSpace(),
            //	el->getSpringID(),endspr);
            // no space active
            //stfmgr->addRod(rod,0);
        }

    }
    return 0;
}
Ejemplo n.º 6
0
/** \brief Gets another spring and then figures out, how much distance
	should be put inbetween this spring and nextspring. 
	
	It looks at GRSpringCollider to find those areas, where a collision
	might (or does) occur.
*/
float GRSpring::GetMaxDistance(GRSpring * nextspring)
{
	if (this->hasType(typeid(GRGlue)))
	{
		// the first spring is a glue-spring.
		// then we just need the maximum leftspace
		// of the second spring and thats it ...
		float max = 0;
		GuidoPos pos = nextspring->grolst.GetHeadPosition();
		while (pos)
		{
			GRNotationElement * el = nextspring->grolst.GetNext(pos);
			if (el->getLeftSpace() > max)
				max = el->getLeftSpace();
		}
		return max;
	}
	if (nextspring->hasType(typeid(GRGlue)))
	{
		// then the next is a glue, then we just need the maxrightspace
		// of this spring ....
		float max = 0;
		GuidoPos pos = grolst.GetHeadPosition();
		while (pos)
		{
			GRNotationElement * el = grolst.GetNext(pos);
			if (el->getRightSpace() > max)
				max = el->getRightSpace();
		}
		return max;
	}

	float maxright = 0;
	float maxleft = 0;
	float max = 0;
	int count = KF_VECTOR_MININDEX;
	if (sprcol && nextspring && nextspring->sprcol)
	{
		poslist * pl1 = NULL;
		poslist * pl2 = NULL;
		bool cont = true;
		do
		{
			maxright = maxleft = 0;
			sprcol->GetMatchingPoslists(count,nextspring->sprcol, &pl1, &pl2);
			if (pl1 && pl2)
			{
				// I have matching poslists ....
				GuidoPos pospl1 = pl1->GetHeadPosition();
				while (pospl1)
				{
					GuidoPos evpos = pl1->GetNext(pospl1);
					GRNotationElement * el = grolst.GetAt(evpos);
					if (el->getRightSpace() > maxright)
						maxright = el->getRightSpace();

				}
				GuidoPos pospl2 = pl2->GetHeadPosition();
				while (pospl2)
				{
					GuidoPos evpos = pl2->GetNext(pospl2);
					GRNotationElement * el = nextspring->grolst.GetAt(evpos);
					if (el->getLeftSpace() > maxleft)
						maxleft = el->getLeftSpace();
				}
			}
			if (count==KF_VECTOR_MININDEX) 
				cont = false;
			if (maxright + maxleft > max)
				max = maxright + maxleft;
		} 
		while (cont);
	}
	return max;
}