Exemplo n.º 1
0
	void FFTSplineControl::stretchControlPoints(float factor)
	{
		for(unsigned int i = 0; i < controlPoints.size(); i++)
		{
			ControlPoint *cp = controlPoints[i];
			assert(cp != NULL);

			float x = cp->getPosition().getX();
			x *= factor;
			cp->getPosition().setX(x);
		}
	}
Exemplo n.º 2
0
	float SplineControl::getValueFromControlPoint(ControlPoint &cp)
	{
		float legendHeight = height * LEGEND_DIM;
		float legendlessHeight = height - (legendHeight * 2.0f);
		float cpy = 1.0f - ((cp.getPosition().getY() - legendHeight) / legendlessHeight);
		cpy = constrainYVal(cpy);

		return cpy;
	}
Exemplo n.º 3
0
	void SplineControl::snapControlPoint(ControlPoint &cp)
	{
		float cpx = cp.getPosition().getX();
		float cpy = cp.getPosition().getY();

		// clamp x
		if(cpx < 0.0f) cpx = 0.0f;
		else if(cpx > width) cpx = width;

		// clamp y
		float legendDim = (height * LEGEND_DIM);
		if(cpy < legendDim) cpy = legendDim;
		else if(cpy > height - legendDim) cpy = (height - legendDim);

		// snap
		float snapIncrement = InterfaceManager::getBeatLength() / (float)BEAT_SNAP;
		float divs = floorf((cpx + (snapIncrement * 0.5f)) / snapIncrement);
		cpx = snapIncrement * divs;

		cp.getPosition().setX(cpx);
		cp.getPosition().setY(cpy);
	}
Exemplo n.º 4
0
	/*
	void SplineControl::renderSplineControl(float SplineControlWidth)
	{
		glPushAttrib(GL_LINE_BIT | GL_CURRENT_BIT);
		
		glColor4f(1.0f, 1.0f, 1.0, 1.0f);
		glLineWidth(getLineWidth(2.0f));
		
		glEnable(GL_LINE_SMOOTH);
		glBegin(GL_LINE_STRIP);
			float increment = InterfaceManager::getBeatLength() / (float)InterfaceManager::VALUES_PER_BEAT;
			for(float f = 0.0; f <= SplineControlWidth; f+= (increment / (float)UPSAMPLE_FACTOR))
			{		
				float legendlessHeight = height - ((height * LEGEND_DIM) * 2.0f);
				float value = getValue(f);
				float vx = f;
				float vy = (value * legendlessHeight) + (height * LEGEND_DIM);
				glVertex3f(vx, height - vy, 0.0f);
			}
		glEnd();
		glDisable(GL_LINE_SMOOTH);

		glPopAttrib();
	}
	*/
	void SplineControl::savePreset(unsigned int presetType)
	{
		WavesGlobalState *wavesGlobalState = WavesGlobalState::getInstance();
		assert(wavesGlobalState != NULL);

		std::map<unsigned int, SplinePreset *> &splinePresets = wavesGlobalState->getSplinePresets();

		unsigned int numControlPoints = controlPoints.size();
		if(numControlPoints > 0)
		{
			std::vector<const Point2f> points;
			for(unsigned int i = 0; i < numControlPoints; i++)
			{
				ControlPoint *cp = controlPoints[i];
				assert(cp != NULL);

				const Point2f &cPos = cp->getPosition();
				
				float sx = cPos.getX() / width;
				float sy = cPos.getY() / height;
				Point2f sp(sx, sy);
				points.push_back(sp);
			}	
			
			// HACK : assume that if saved and Id in particular range, it must be a default and so save an altered copy
			if((!presetSaved && numControlPoints > 0) || (presetSaved && presetId >= 0 && presetId <= 5))
			{
				unsigned int pId = SplinePreset::generateId();
				
				SplinePreset *preset = new SplinePreset(pId, points, width, (SplinePreset::PresetType)presetType);	
				assert(preset != NULL);

				splinePresets[pId] = preset;
				
				preset->save();
				presetId = pId;
				presetSaved = true;
			}
			else
			{				
				SplinePreset *preset = splinePresets[presetId];
				assert(preset != NULL);

				preset->setPoints(points);
				preset->save();
			}
		}
	}
Exemplo n.º 5
0
	float FFTSplineControl::getValue(float beat)
	{
		float position = beat;
		int size = controlPoints.size();

		if(size <= 0) return 0.5f;
		else if(size <= 1) 
		{
			return getValueFromControlPoint(*controlPoints[0]);
		}
		else
		{
			for(int i = 0; i < size; i++)
			{
				ControlPoint *cp = controlPoints[i];
				assert(cp != NULL);

				if(cp->getPosition().getX() >= position)
				{
					int index0 = i - 2;
					int index1 = i - 1;
					int index3 = i + 1;
					
					if(index0 < 0) index0 = i;
					if(index1 < 0) index1 = i;
					if(index3 >= size) index3 = i;

					float y0 = getValueFromControlPoint(*controlPoints[index0]);
					float y1 = getValueFromControlPoint(*controlPoints[index1]);
					float y2 = getValueFromControlPoint(*controlPoints[i]);
					float y3 = getValueFromControlPoint(*controlPoints[index3]);

					ControlPoint *cpi = controlPoints[index1];
					assert(cpi != NULL);

					float x0 = constrainXVal(index1 == i ? 0.0f : cpi->getPosition().getX());
					float x1 = constrainXVal(cp->getPosition().getX());

					// in case of a wrap around		
					float mu = 1.0f; 
					
					// guard against / 0
					if(x0 != x1) 
					{
						mu = (position - x0) / (x1 - x0);
					}

					if(x0 > x1)
					{
						float interval = x1 + (width - x0);
						mu = (position + (width - x0)) / interval;
					}	

					float returnVal = Interpolator::hermiteInterpolate(y0, y1, y2, y3, mu, Interpolator::DEFAULT_TENSION, 0.0f);
					return constrainYVal(returnVal);
				}
			}
			
			unsigned int index0 = size - 2;
			unsigned int index1 = size - 1;
			if(index0 < 0) index0 = size - 1;

			// for last segment
			float y0 = getValueFromControlPoint(*controlPoints[index0]);
			float y1 = getValueFromControlPoint(*controlPoints[index1]);
			float y2 = getValueFromControlPoint(*controlPoints[index1]);
			float y3 = getValueFromControlPoint(*controlPoints[index1]);

			ControlPoint *cpi = controlPoints[index1];
			assert(cpi != NULL);

			float x0 = constrainXVal(cpi->getPosition().getX());
			float x1 = constrainXVal(width);

			float interval = x1 + (width - x0);
			float mu = (position - x0) / interval;
		
			float returnVal = Interpolator::hermiteInterpolate(y0, y1, y2, y3, mu, Interpolator::DEFAULT_TENSION, 0.0f);
			return constrainYVal(returnVal);
		}
	}