Ejemplo n.º 1
0
NEPointerList* NEPointerList::getElementsWithShortestDurationNotNull()
{
	assert(!empty());
	NEPointerList* list=new NEPointerList;
	GRNotationElement * e = NULL;
	GuidoPos pos=GetHeadPosition();
	TYPE_DURATION dur(INT_MAX,1);
	while (pos)
	  {
	  e = GetNext(pos);
	  if (e->getDuration() < dur
		&& e->getDuration() > DURATION_0)
		 dur = e->getDuration();
	  }
	pos = GetHeadPosition();
	while (pos)
	  {
	  e = GetNext(pos);
	  if (e->getDuration() == dur)
		 {
		 list->push_back(e);
		 }
	  }
	return list;
}
Ejemplo n.º 2
0
/** \brief returns new Constant
*/
float GRSpring::change_dur(const TYPE_DURATION & ndur)
{
	if (ndur != dur && ndur >= DURATION_0)
	{
		dur = ndur;

		hasDurElement = false;
		// we have to check the hasDurElement-flag
		GuidoPos pos = grolst.GetHeadPosition();
		while (pos)
		{
			GRNotationElement * el = grolst.GetNext(pos);
			if (el->getDuration() == dur)
			{
				hasDurElement = true;
				break;
			}
		}

		return calcconst( 0 );
	}

	// if the duration didn't change, we just have
	// the same hasDurElement value
	return sconst;
}
Ejemplo n.º 3
0
/** \brief Recalculates the bounding box of the page.
*/
void GRPage::updateBoundingBox()
{
	// - Start from a null rectangle
	mBoundingBox.Set( 0, 0, 0, 0 );
	GRNotationElement * el;

	// - Add systems boxes
	SystemPointerList::iterator ptr;
	TYPE_DURATION duration;
	for( ptr = mSystems.begin(); ptr != mSystems.end(); ++ ptr ) {
		el = *ptr;
		NVRect eltBox ( el->getBoundingBox());
		eltBox += el->getPosition();
		mBoundingBox.Merge( eltBox );
		duration += el->getDuration();
		//addToBoundingBox( el );
	}
	setDuration (duration);

	// - Add page and system-tags boxes
	GuidoPos mypos = First();
	if (mypos) {
		GRNotationElement * el = GetNext( mypos );
		NVRect eltBox ( el->getBoundingBox());
		eltBox += el->getPosition();
		mBoundingBox.Merge( eltBox );
		// todo: addToBoundingBox( el );
	}
	mMapping = mBoundingBox;

	// - Add the page margins
/*
	mBoundingBox.left -= getMarginLeft();
	mBoundingBox.top -= getMarginTop();
	mBoundingBox.right += getMarginRight();
	mBoundingBox.bottom += getMarginBottom();
*/
	// This adds some space to the right and at the bottom.
	// The NoteServer can display a nicer picture using this ....
	// maybe this needs to be changed later!?
	//mBoundingBox.right += 5* LSPACE;
	//mBoundingBox.bottom += 5* LSPACE;

}
Ejemplo n.º 4
0
/** \brief Called just as createNewRods is called
	It updates the QP-Matrix for minimizing the Spring-
	energy. This is a first prototype.
*/
int GRVoice::updateMSCMatrix(GRSpaceForceFunction2 * sff,
                             GRSpacingMatrix * spm,
                             GRStaffManager * stfmgr,
                             ISpringVector * sprvect,
                             int startspr, int endspr )
{
    double * mat = spm->getMSCMatrix();
    int n = spm->getMSCMatrixMemSize();

    // now even newer stuff; we distinguish between different
    // phases:
    // first voice just sets the maximum value for each spring
    // (this is the regular gourlay model)
    // we also take care of "neighbourhoods", telling the
    // SpacingMatrix, where same-notedurations occur.

    // 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;
        GetNext(pos);
    }

    GRNotationElement * el = NULL;

    double prevvalue = 0;
    int   prevstartid = -1;
//	int   numneighbours = 0;

    KF_List<int> * neighbourlist = 0;
    while (pos)
    {
        el = GetNext(pos);

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

        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 = GetCompositeElements().GetAt( pos );

            if (!next->getNeedsSpring())
            {
                GetNext(pos);
                continue;
            }

            start = el->getSpringID();

            end = next->getSpringID();

            // now we just determine the necessary value, depending
            // on duration alone ...
            float value = 0;

            const TYPE_DURATION durel (el->getDuration());
//			const TYPE_DURATION &durnext = next->getDuration();

            if (durel > DURATION_0)
            {
                value = 1.0f / (float) durel;

                // now we fill the second entry in the msc-matrix
                // this is needed, so that we can make sure, that
                // spacing is somewhat controlled, when NO groups
                // have been found.

                // this is equivalent to the stuff that was calculated
                // before (see below)
                int cnt;
                for (cnt=start; cnt<end; cnt++)
                {
                    if (value > *(mat + cnt + n*3))
                    {
                        *(mat + cnt + n*3) = value;
                    }
                }

                if (prevvalue == value)
                {
                    if (!neighbourlist)
                    {
                        neighbourlist = new KF_List<int>();
                        neighbourlist->AddTail(prevstartid);
                    }
                    // then we have a neighboor
                    neighbourlist->AddTail(start);
                }
                else
                {
                    if (neighbourlist)
                    {
                        neighbourlist->AddTail(start);
                        spm->AddNeighbourList(neighbourlist);
                        neighbourlist = NULL;
                    }
                    // then we just start a new group ...
                }
            }
            else
            {
                if (neighbourlist)
                {
                    neighbourlist->AddTail(start);
                    spm->AddNeighbourList(neighbourlist);
                    neighbourlist = NULL;
                }
            }

            // this means we are finished with finding the next event
            el = NULL;
            if (durel <= DURATION_4)
                prevvalue = value;
            else
                prevvalue = -1.0f;

            prevstartid = start;

            break;
        }
    }

    if (el && el->getNeedsSpring())
    {
        int start;
        int end;

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

        //float mysconst = GRSpring::onlycalcconst(el);

        float value = 0; // mysconst;

        const TYPE_DURATION durel (el->getDuration());
        if (durel > DURATION_0)
        {
            value = 1.0f / (float) durel;

            int i;
            for (i=start; i<end; i++)
            {
                if (value > *(mat + i + n*3))
                {
                    *(mat + i + n*3) = value;
                }
            }
            // check for neighbours ....

            // maybe this is a hack, but one that makes sense:
            // neighbourhood is only important for durations of up to
            // a quarter note.

            if (prevvalue == value)
            {
                if (!neighbourlist)
                {
                    neighbourlist = new KF_List<int>();
                    neighbourlist->AddTail(prevstartid);
                }
                // then we have a neighboor
                neighbourlist->AddTail(start);
                neighbourlist->AddTail(endspr);

                spm->AddNeighbourList(neighbourlist);
                neighbourlist = NULL;
            }
        }
        if (neighbourlist)
        {
            // the last element was not a neighbour
            neighbourlist->AddTail(start);

            spm->AddNeighbourList(neighbourlist);
            neighbourlist = NULL;
        }
    }

    // if i have a neighbourlist that is still open, something
    // went a little wrong?
    if (neighbourlist)
    {
        assert(false);
        neighbourlist->AddTail(endspr-1);
        spm->AddNeighbourList(neighbourlist);
        neighbourlist = NULL;
    }
    return 0;
}
Ejemplo n.º 5
0
/** \brief Called just as createNewRods is called.

	It updates the QP-Matrix for minimizing the Spring-
	 energy. This is a first prototype.
*/
int GRVoice::updateMSCMatrix( GRSpaceForceFunction * spf,
                              int startspr,int endspr)
{
    double * mat = spf->getMSCMatrix();
    int n = spf->getMSCMatrixMemSize();

    // 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;

    while (pos)
    {
        el = elements->GetNext(pos);

        // 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);
            if (!next->getNeedsSpring())
            {
                elements->GetNext(pos);
                continue;
            }

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

            // then we need the "real" constant:

            //float mysconst = GRSpring::onlycalcconst(el);

            double value = 0; // mysconst;

            const TYPE_DURATION & durel (el->getDuration());

            if (durel > DURATION_0)
            {
                value = 1.0 / (float) durel;
            }

            int i;
            for (i=start; i<end; i++)
            {
                if (value > *(mat + i + n*0))
                {
                    *(mat + i + n*0) = value;
                    *(mat + i + n*1) = durel.getNumerator();
                    *(mat + i + n*2) = durel.getDenominator();
                }
            }

            // 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);

        double value = mysconst;

        const TYPE_DURATION & durel (el->getDuration());
        if (durel > DURATION_0)
        {
            value = (1.0 / value) / durel;
        }
        int i;
        for (i=start; i<end; i++)
        {
            if (value > *(mat + i + n*0))
            {
                *(mat + i + n*0) = value;
                *(mat + i + n*1) = durel.getNumerator();
                *(mat + i + n*2) = durel.getDenominator();
            }

        }
    }

    return 0;
}