Пример #1
0
void GRPositionTag::removeAssociation(GRNotationElement * grnot)
{
	// now we test, if the endElement or startElement
	// is effected ...

	const GRStaff * staff = grnot->getGRStaff();
	if( staff )
	{
		GRSystemStartEndStruct * sse = getSystemStartEndStruct(staff->getGRSystem());
		if (sse)
		{
			if (sse->startElement == grnot)
			{
				sse->startElement = NULL;
				sse->startflag = GRSystemStartEndStruct::NOTKNOWN;
				sse->startpos = NULL;
			}
			if (sse->endElement == grnot)
			{
				sse->endElement = NULL;
				sse->endflag = GRSystemStartEndStruct::NOTKNOWN;
				sse->endpos = NULL;
			}
		}
	}
}
Пример #2
0
/** \brief Deletes the Staff from the sse (if it is found) and returns 1, if no more
	staffs remain, that is sse is empty. Then the positiontag can be deleted.
*/
bool GRPositionTag::DeleteStaff(GRStaff * grstaff)
{
	// if (error) return 1;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(grstaff->getGRSystem());
	if (!sse)
	{
//		assert(false);
		return (mStartEndList.GetCount() == 0);
	}
	// also deletes it ...
	// remove the associations ...
	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	if (el)
	{
		if (sse->startElement)	sse->startElement->removeAssociation(el);
// here we have a real problem: there are some case where the endElement has been freed before this call and of course it crashes :-( 
// since memory management is quite complex (and a bit messy), the only workaround I've found is to look at the associated fields
// with the hope that the memory is not reused in between (that's currently the case)
// a real solution would be to have automatic memory management using smart pointers... 
// it'll have to be done sooner or later [D.F. 2012 march 6]
		if (sse->endElement && sse->endElement->associated())	sse->endElement->removeAssociation(el);
	}
	// mStartEndList.setOwnership(0);
	mStartEndList.RemoveElement(sse);
	// mStartEndList.setOwnership(1);
	// this really deletes the sse ...
	// deleteSSE(sse);
	
	return (mStartEndList.GetCount() == 0);
}
Пример #3
0
void GRPositionTag::setEndElement(const GRStaff * grstaff,
				GRNotationElement * n_element)
{
	GRSystemStartEndStruct * sse =
		getSystemStartEndStruct(grstaff->getGRSystem());

	assert(sse);

	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	assert(el);

	if (sse->endElement)
	{
		sse->endElement->removeAssociation(el);
	}

	if (!error)
	{
		sse->endElement = n_element;
		if (sse->endElement)
		{
			sse->endElement->addAssociation(el);
		}
	}
	else
		sse->endElement = NULL;
}
Пример #4
0
void GRPositionTag::RangeEnd(GRStaff * grstaff)
{
	if (grstaff == 0) return;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(grstaff->getGRSystem());
	assert(sse);
	if (error)
	{
		setStartElement(grstaff,NULL);
		setEndElement(grstaff,NULL);
		return;
	}

	NEPointerList * associated = NULL;
	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	if (el)
		associated = el->getAssociations();
	if (associated == 0) return;

	if (sse->startflag == GRSystemStartEndStruct::LEFTMOST
		&& sse->startElement == NULL)
	{
		setStartElement(grstaff,associated->GetHead());
		sse->startpos = associated->GetHeadPosition();
	}

	setEndElement(grstaff,associated->GetTail());
	sse->endflag = GRSystemStartEndStruct::RIGHTMOST;
	sse->endpos = associated->GetTailPosition();
}
Пример #5
0
void GRDiminuendo::tellPosition(GObject *caller, const NVPoint & newPosition)
{
	GRNotationElement * grel = dynamic_cast<GRNotationElement *>(caller);
	if (grel == 0)
        return;

	GRStaff * staff = grel->getGRStaff();
	if (staff == 0)
        return;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(staff->getGRSystem());
	if (sse == 0)
        return;

	const GRNotationElement * const endElement = sse->endElement;

	if (grel == endElement)
		updateDiminuendo(staff);
}
Пример #6
0
void GRPositionTag::addAssociation(GRNotationElement * grnot)
{
	if (error) return;

	const GRStaff * pstaff = grnot->getGRStaff();
	assert(pstaff);
	GRSystemStartEndStruct * sse= getSystemStartEndStruct(pstaff->getGRSystem());	

	NEPointerList * associated = NULL;
	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	if (el)
		associated = el->getAssociations();

	if (!associated) return;
	
	if (sse && sse->startflag == GRSystemStartEndStruct::OPENLEFT 
		&& sse->startpos == NULL)
		sse->startpos = associated->GetTailPosition();
}
Пример #7
0
void GRPositionTag::StaffFinished(GRStaff * grstaff)
{
	if (!grstaff) return;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(grstaff->getGRSystem());

	assert(sse);

	if (error)
	{
		setStartElement(grstaff,NULL);
		setEndElement(grstaff,NULL);
		lastendElement = NULL;
		return;
	}

	NEPointerList * associated = NULL;
	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	if (el)
		associated = el->getAssociations();
	if (associated == 0) return;


	if (sse->startflag == GRSystemStartEndStruct::LEFTMOST
		&& sse->startElement == NULL)
	{
		setStartElement(grstaff,associated->GetHead());
		sse->startpos = associated->GetHeadPosition();
	}

	lastendflag = sse->endflag;
	lastendElement = sse->endElement;
	lastendpos = sse->endpos;

	// there is no old lastendelement in this case
	assert(lastendElement == NULL);

	setEndElement(grstaff, /*ynamic_cast<GRNotationElement *>*/(grstaff->getEndGlue()));
	sse->endflag = GRSystemStartEndStruct::OPENRIGHT;
	sse->endpos = associated->GetTailPosition();

}
Пример #8
0
void GRCrescendo::OnDraw( VGDevice & hdc) const
{
	if (!mDraw)
		return;

    if (fCrescInfos->points[0].x == fCrescInfos->points[1].x)
        return;

    assert(gCurSystem);

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(gCurSystem);
	if (sse == 0)
		return;

    const VGColor prevTextColor = hdc.GetFontColor();

    if (mColRef) {
        hdc.PushPenColor(VGColor(mColRef));
        hdc.PushFillColor(VGColor(mColRef));
        hdc.SetFontColor(VGColor(mColRef));
    }

    hdc.PushPenWidth(fCrescInfos->thickness);

    hdc.Line(fCrescInfos->points[0].x , fCrescInfos->points[0].y, fCrescInfos->points[1].x , fCrescInfos->points[1].y);
	hdc.Line(fCrescInfos->points[0].x , fCrescInfos->points[0].y, fCrescInfos->points[2].x , fCrescInfos->points[2].y);

    const float xMarkingOffset = fCrescInfos->points[1].x + 30;
    const float yMarkingOffset = fCrescInfos->points[0].y - 277 + (mTagSize - 1) * 25;

    if (fCrescInfos->fMarkingSymbol != 0)
        OnDrawSymbol(hdc, fCrescInfos->fMarkingSymbol, xMarkingOffset, yMarkingOffset, mTagSize);
    
    hdc.PopPenWidth();

    if (mColRef) {
        hdc.SetFontColor(prevTextColor);
        hdc.PopFillColor();
        hdc.PopPenColor();
    }
}
Пример #9
0
void GRDiminuendo::updateDiminuendo(GRStaff * inStaff)
{
	GRSystemStartEndStruct *sse = getSystemStartEndStruct(inStaff->getGRSystem());
	if (sse == 0)
        return;

    // Collects informations about the context
	fDimContext.staff = inStaff;
	getDiminuendoBeginingContext(&fDimContext, sse);
	getDiminuendoEndingContext(&fDimContext, sse);

    ARDiminuendo *arDim = static_cast<ARDiminuendo *>(getAbstractRepresentation());
	const float staffLSpace = inStaff->getStaffLSPACE();
	assert(arDim);
	
	/**** information gathering of parameters from the AR ****/

    const char* dynamicMarking = arDim->getDynamicMarking().c_str();
    if (!strcmp(dynamicMarking,"p"))
		fDimInfos->fMarkingSymbol = kIntensPSymbol;
	else if (!strcmp(dynamicMarking,"f"))
		fDimInfos->fMarkingSymbol = kIntensFSymbol;
	else if (!strcmp(dynamicMarking,"ff"))
		fDimInfos->fMarkingSymbol = kIntensFFSymbol;
	else if (!strcmp(dynamicMarking,"fff"))
		fDimInfos->fMarkingSymbol = kIntensFFFSymbol;
	else if (!strcmp(dynamicMarking,"ffff"))
		fDimInfos->fMarkingSymbol = kIntensFFFFSymbol;
	else if (!strcmp(dynamicMarking,"mf"))
		fDimInfos->fMarkingSymbol = kIntensMFSymbol;
	else if (!strcmp(dynamicMarking,"mp"))
		fDimInfos->fMarkingSymbol = kIntensMPSymbol;
	else if (!strcmp(dynamicMarking,"sf"))
		fDimInfos->fMarkingSymbol = kIntensSFSymbol;
	else if (!strcmp(dynamicMarking,"pp"))
		fDimInfos->fMarkingSymbol = kIntensPPSymbol;
	else if (!strcmp(dynamicMarking,"ppp"))
		fDimInfos->fMarkingSymbol = kIntensPPPSymbol;
	else if (!strcmp(dynamicMarking,"pppp"))
		fDimInfos->fMarkingSymbol = kIntensPPPPSymbol;
    else
        fDimInfos->fMarkingSymbol = 0;

    float dx1     = arDim->getDx1();
	float dx2     = arDim->getDx2();
    float dy      = arDim->getDy();
	float deltaY  = arDim->getDeltaY();

    float XLeft  = 0;
    float XRight = 0;

    if (fDimContext.leftHead)
        XLeft = fDimContext.leftHead->getPosition().x + fDimContext.leftNoteDX;
    else
        XLeft = sse->startElement->getPosition().x;
    if (fDimContext.rightHead)
        XRight = fDimContext.rightHead->getPosition().x + fDimContext.rightNoteDX;
    else
        XRight = sse->endElement->getPosition().x;

    fDimInfos->points[0].x = fDimInfos->points[2].x = XLeft + dx1;
    fDimInfos->points[1].x = XRight + dx2;

    if (fDimInfos->points[0].x > fDimInfos->points[1].x)
    {
        fDimInfos->points[0].x = fDimInfos->points[2].x = XLeft;
        fDimInfos->points[1].x = XRight;
    }

    mPosition.y = (GCoord)(6 * staffLSpace);

    fDimInfos->points[0].y = mPosition.y + dy + deltaY / 2;
	fDimInfos->points[1].y = mPosition.y + dy;
    fDimInfos->points[2].y = mPosition.y + dy - deltaY / 2;

    fDimInfos->thickness = arDim->getThickness();
}
Пример #10
0
/** \brief Called to break a tag at a previously saved PBreak-Location.
	It sets the sse-Positions ...

	(It is somewhat equivalent to StaffFinished,
	with the difference, that assocpos is used). assocpos is the tail-position
	of the associated list at the time of the pbreak-situation.
	Now, this routine is called when a tag needs to be broken
	because the optimum line break algorithm has determined the breaklocation.
*/
void GRPositionTag::BreakTag(GRStaff * grstaff, GuidoPos & assocpos)
{
	if (grstaff == 0) return;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(grstaff->getGRSystem());
	assert(sse);

	if (error)
	{
		setStartElement(grstaff,NULL);
		setEndElement(grstaff,NULL);
		lastendElement = NULL;
		return;
	}

	// now we do something .....
	NEPointerList * associated = 0;
	GRNotationElement * el = dynamic_cast<GRNotationElement *>(this);
	if (el)
		associated = el->getAssociations();

	if (!associated) return;

	// only, if the startElement is not set and
	// we do not have an OPENLEFT, the very first
	// element from the association is made the
	// startElement.
	if (sse->startflag == GRSystemStartEndStruct::LEFTMOST 
		&& sse->startElement == NULL)
	{
		setStartElement(grstaff,associated->GetHead());
		sse->startpos = associated->GetHeadPosition();
	}

	// now, we remeber the last end-setting ...
	lastendElement = sse->endElement;
	lastendflag = sse->endflag;
	lastendpos = sse->endpos;

	// now, we set the new OPENRIGHT and get the
	// endglue ...

	// the old association of the end-element MUST
	// be maintained! -> 
	sse->endElement = NULL;

	setEndElement(grstaff,grstaff->getEndGlue());
	sse->endflag = GRSystemStartEndStruct::OPENRIGHT;
	// this uses assocpos!
	sse->endpos = assocpos;

	sse->grsystem = grstaff->getGRSystem();

	// now, we increment the assocpos, so that
	// we can save this position for
	// the NEW Segment build with ResumeTag
	if (associated && assocpos)
		associated->GetNext(assocpos);

	// I now have to add a new sse-that handles the next system ?

}
Пример #11
0
void GRGlobalStem::RangeEnd( GRStaff * inStaff)
{
	if (error || mFirstEl == 0) return;

	GRPTagARNotationElement::RangeEnd(inStaff);
	if (inStaff == 0) return;

	GRSystemStartEndStruct * sse = getSystemStartEndStruct(inStaff->getGRSystem());

	// this checks, wether all associated elements are
	// on the same staff. If not, we build a new
	// GRSystemTag that gets added to the system
	// so that an update on all positions can be made ....
	// (this is taken from GRBeam)
	GuidoPos syststpos = sse->startpos;
	if (tagtype != GRTag::SYSTEMTAG && syststpos)
	{
		// this is all done so that I really get a correct first staff to
		// test my stuff ...
		while (syststpos && !/*ynamic_cast<GRNotationElement *>*/(mAssociated->GetAt(syststpos)))
		{
			mAssociated->GetNext(syststpos);
		}
//		const GRStaff *tststaff = mAssociated->GetNext(syststpos)->getGRStaff();
		int tststaffnum = mAssociated->GetNext(syststpos)->getStaffNumber(); 
		while (syststpos)
		{
			GRNotationElement * el = mAssociated->GetNext(syststpos);
			if (el)
			{
				if (el->getStaffNumber() != tststaffnum) // el->getGRStaff() != tststaff)
				{
					tagtype = GRTag::SYSTEMTAG;
					GRSystemTag * mysystag = new GRSystemTag(this);
//					sse->grsystem->addSystemTag(mysystag);
					el->getGRSystemSlice()->addSystemTag(mysystag);
					break;
				}
			}		
		}
	}

	if (tagtype != GRTag::SYSTEMTAG)
	{
		// check, whether firstel is on the same staff?
		if (mFirstEl && mAssociated && mAssociated->GetHead())
		{
			if (mFirstEl->getStaffNumber() != mAssociated->GetHead()->getStaffNumber() ) // getGRStaff() != mAssociated->GetHead()->getGRStaff())
			{
					tagtype = GRTag::SYSTEMTAG;
					GRSystemTag * mysystag = new GRSystemTag(this);
//					sse->grsystem->addSystemTag(mysystag);
					mFirstEl->getGRSystemSlice()->addSystemTag(mysystag);
			}
		}
	}

	
	GRNotationElement * el = /*dynamic cast<GRNotationElement *>*/(this);
	
	const NEPointerList * associated = el ? el->getAssociations() : 0;
	if (associated == 0) 
		return;

	// now I have the associations ...
	// I have to build the stem ....
	delete theStem;

	theStem = new GRStem(this);
	if (mColRef)
		theStem->setColRef( mColRef );

	// the Vertical position of the Notes that share a stem
	// must be already set ....

	// mHighestY = mLowestY = -32767;
	int highestlowestset = 0;

	// only if the stemdir has not been set ....
	if (stemdir == dirOFF)
	{
		stemdir = dirUP;
		if (stemstate)
		{
			if (stemstate->getStemState() == ARTStem::UP)
			{
				// we have to determine the direction ourselves.
				stemdir = dirUP;
				
			}
			else if (stemstate->getStemState() == ARTStem::DOWN)
			{
				// we have to determine the direction ourselves.
				stemdir = dirDOWN;
				
			}
			else if (stemstate->getStemState() == ARTStem::OFF)
			{
				// we have to determine the direction ourselves.
				stemdir = dirOFF;
				
			}
		}
		if ( ( stemstate && stemstate->getStemState() == ARTStem::AUTO  )
			|| !stemstate)
		{			
			// we have to determine the direction ourselves.
			
			// this needs to be done with 
			// the direction of notes ...
			GCoord middle = 0;
			int count = 0;
			// determine the lowest and highest position ...
			el = associated->GetTail();
			if (el)
			{
				middle = el->getPosition().y;
				if (tagtype == GRTag::SYSTEMTAG && el->getGRStaff())
				{
					middle += (GCoord)el->getGRStaff()->getPosition().y;
				}
				mHighestY = middle;
				mLowestY = middle;
				++ count;
			}
			
			GuidoPos pos = associated->GetHeadPosition();
			while (pos && pos != associated->GetTailPosition())
			{
				
				GRNotationElement * el = associated->GetNext(pos);
				if (el && !dynamic_cast<GREmpty *>(el))
				{
					GCoord ypos = el->getPosition().y;
					if (el->getGRStaff() && tagtype == GRTag::SYSTEMTAG)
						ypos += el->getGRStaff()->getPosition().y;
					middle += ypos;
					++count ;
					
					if (mLowestY > ypos)	mLowestY = ypos;
					if (mHighestY < ypos)	mHighestY = ypos;
					
				}
			}
			
			highestlowestset = 1;
			
			if (count > 0)
				middle /= count;
			
			const float curLSPACE = (float)(inStaff->getStaffLSPACE());
			
			const float mylowesty = 2 * curLSPACE - mLowestY;
			const float myhighesty = mHighestY - 2 * curLSPACE;
			
			if (mylowesty > myhighesty)
			{
				stemdir = dirDOWN;
			}
			else if (myhighesty > mylowesty)
				stemdir = dirUP;
			else
			{
				if (middle >= curLSPACE * 2)
				{
					stemdir = dirUP;
				}
				else if (middle < curLSPACE * 2)
				{
					stemdir = dirDOWN;
				}
			}
		}
	}
	
    if (dispdur >= DURATION_1)
	{
		stemdir = dirOFF;
	}
	
	theStem->setStemDir(stemdir);
	

	// otherwise it has been set because of auto-stem.
	if (!highestlowestset)
	{
		// determine the lowest and highest position ...
		el = associated->GetTail();
		if (el)
		{
			mLowestY = el->getPosition().y;
			if (tagtype == GRTag::SYSTEMTAG && el->getGRStaff())
			{
				mLowestY += el->getGRStaff()->getPosition().y;
			}
			mHighestY = mLowestY;
		}
		
		GuidoPos pos = associated->GetHeadPosition();
		while (pos)
		{
			
			GRNotationElement * el = associated->GetNext(pos);
			if (el && !dynamic_cast<GREmpty *>(el))
			{
				NVPoint elpos (el->getPosition());
				if (tagtype == GRTag::SYSTEMTAG && el->getGRStaff())
				{
					elpos += el->getGRStaff()->getPosition();

				}
				
				if (mLowestY > elpos.y) 	mLowestY = elpos.y;
				if (mHighestY < elpos.y)	mHighestY = elpos.y;
			}
		}
		
	}

	// now we have the position of the lowest or highest note ...
	if (stemdir == dirUP)
	{
		theStem->setPosition(NVPoint(0, (GCoord)mHighestY));
	}
	else if (stemdir == dirDOWN)
	{
		theStem->setPosition(NVPoint(0, (GCoord)mLowestY));
	}

	// now we have to deal with the length...

	const TagParameterFloat * taglength = 0;
	if (stemstate)
		taglength = stemstate->getLength();
	if (stemstate && taglength  && taglength->TagIsSet())
	{
		// we have a length, that was definitly set...
		theStem->setStemLength((float)(stemstate->getLength()->getValue()));
		stemlengthset = true;
	}
	else
	{
		// length was not set ....
		float length = (float)(mHighestY - mLowestY + inStaff->getStaffLSPACE() * 3.5f * mTagSize);
		theStem->setStemLength( length );
	}

	delete theFlag;

				 // here we have to add the flags ...
	theFlag = new GRFlag(this, dispdur,stemdir,theStem->getStemLength());
	if (mColRef)
		theFlag->setColRef(mColRef);

	if (!mFlagOnOff)
		theFlag->setFlagOnOff(mFlagOnOff);

	if (stemdir == dirUP)
	{
		theFlag->setPosition(NVPoint(0, (GCoord)mHighestY));
	}
	else if (stemdir == dirDOWN)
	{
		theFlag->setPosition(NVPoint(0, (GCoord)mLowestY));
	}

	if (tagtype != GRTag::SYSTEMTAG)
		updateGlobalStem(inStaff);
}