Beispiel #1
0
void Map::initializeOverlays()
{
    ResourceManager *resman = ResourceManager::getInstance();

    for (int i = 0;
         hasProperty("overlay" + toString(i) + "image");
         i++)
    {
        const std::string name = "overlay" + toString(i);

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mOverlays.push_back(
                    new AmbientOverlay(img, parallax, speedX, speedY, keepRatio));

            // The AmbientOverlay takes control over the image.
            img->decRef();
        }
    }
}
Beispiel #2
0
void SpherizeOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

	float radius = getFloatProperty(0);
	float amount = getFloatProperty(1);
	mesh = getInput(0)->mesh->clone();

	for (int i = 0; i < mesh->getNumVertices(); i++)
	{
		Vec3 p = mesh->pos(i);
		Vec3 n = normalize(p) * radius;
		mesh->pos(i) = p + (n - p) * amount;
	}

	mesh->recalculateNormals();
}
Beispiel #3
0
void MLMultiSlider::sendSliderAction (float val, int selector)
{
	ml::Symbol sliderName = ml::textUtils::addFinalNumber("value", selector);
	float currentValue = getFloatProperty(sliderName);
	float newValue = constrainedValue(val);

    if (currentValue != newValue)
    {
		ml::Symbol targetPropertyName = ml::textUtils::addFinalNumber(getTargetPropertyName(), selector);
		setPropertyImmediate(sliderName, newValue);
		sendAction("change_property", targetPropertyName, getProperty(sliderName));
    }
}
Beispiel #4
0
void MLMultiSlider::paint (Graphics& g)
{
	MLLookAndFeel* myLookAndFeel = (&(getRootViewResources(this).mLookAndFeel));
	if (isOpaque()) myLookAndFeel->drawBackground(g, this);	
	float outlineThickness = myLookAndFeel->getGridUnitSize() / 64.f;
	MLRect r = mPos.getLocalOutline();
	const Colour outlineColor (findColour(MLLookAndFeel::outlineColor).withAlpha (isEnabled() ? 1.f : 0.5f));
	
	// draw fills
	// vertical only
	Path full, empty;
	Colour fullColor, emptyColor;
	MLRect fullRect, emptyRect;
	float dialY;
	
	MLRange drawRange(mRange);
	drawRange.convertTo(MLRange(r.height(), 0.));
	
	for (int i=0; i<mNumSliders; ++i)
	{
		MLRect sr = (mPos.getElementBounds(i));

		dialY = drawRange(getFloatProperty(ml::textUtils::addFinalNumber(ml::Symbol("value"), i)));
		fullRect = sr;
		emptyRect = sr;		
		fullRect.setTop(dialY);
	
		fullColor = findColour(trackFullDarkColor);
		emptyColor = findColour(trackEmptyDarkColor);
		
		// groups of 4 
		if (!(i&4))
		{
			emptyColor = emptyColor.brighter(0.10f);
			fullColor = fullColor.brighter(0.20f);
		}
		
		empty.clear();
		empty.addRectangle(MLToJuceRect(emptyRect));
		g.setColour(emptyColor);
		g.fillPath(empty);	
		
		full.clear();
		full.addRectangle(MLToJuceRect(fullRect));
		g.setColour(fullColor);
		g.fillPath(full);	
				
		g.setColour(outlineColor);
		g.strokePath(empty, PathStrokeType (outlineThickness));
	}
}
Beispiel #5
0
void MLMultiSlider::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
	// filter out zero motions from trackpad
	if ((wheel.deltaX == 0.) && (wheel.deltaY == 0.)) return;
	
	if(mCurrDragSlider >= 0) return;
	
	bool doFineAdjust = e.mods.isShiftDown();
	float wheelSpeed = doFineAdjust ? 0.1f : 1.f;
	float wheelDirection = (wheel.isReversed) ? -1.f : 1.f;
	
    if (isEnabled())
	{
		int s = getSliderUnderPoint(Vec2(e.x, e.y));
		if ((s >= 0) && ! isMouseButtonDownAnywhere())
		{
			float currentVal = getFloatProperty(ml::textUtils::addFinalNumber(ml::Symbol("value"), s));
			float minPosDelta = 0.01f;
			float deltaDir = (wheel.deltaY > 0.f) ? 1.f : -1.f;
			float posDelta = (wheel.deltaY + deltaDir*minPosDelta)*wheelSpeed*wheelDirection; 			
			
			const float currentPos = valueToProportionOfLength (currentVal);
			const float newPos = ml::clamp (currentPos + posDelta, 0.f, 1.f);
			float newValue = proportionOfLengthToValue (newPos);

			if(newValue != currentVal)
			{
				if(!isMouseWheelMoving)
				{
					isMouseWheelMoving = true;
					beginGesture();
				}
				mpTimer->startTimer(kWheelTimeoutDuration);

				mCurrDragSlider = s;
				sendSliderAction(snapValue (newValue, false), s);
				mpTimer->startTimer(kWheelTimeoutDuration);
				mCurrDragSlider = -1;
			}
        }
    }
    else
    {
        Component::mouseWheelMove (e, wheel);
    }
}
void MLPluginProcessor::handleHubNotification(MLSymbol action, const float val)
{
	if(action == "connected")
	{
		int protocol = val ? kInputProtocolOSC : kInputProtocolMIDI;
		setInputProtocol(protocol);
	}
	else if(action == "data_rate")
	{
		int r = val;
		if(r != (int)getFloatProperty("data_rate"))
		{
			setProperty("data_rate", r);
			getEngine()->setInputDataRate(r);
		}
	}
}
Beispiel #7
0
void MLProgressBar::paint (Graphics& g)
{
	const Colour fc = findColour(MLLookAndFeel::labelColor);	
	const float progress = getFloatProperty("progress");

	Path gbounds;
	const Rectangle<int> & boundsRect (getLocalBounds());	
	gbounds.addRectangle(boundsRect);
	MLRange xRange(0., 1., boundsRect.getX(), boundsRect.getRight());
	MLRect progressRect = juceToMLRect(boundsRect);
	progressRect.setRight(xRange(progress));
	Rectangle<int> fullRect = MLToJuceRectInt(progressRect);
	Path fullBounds;
	fullBounds.addRectangle(fullRect);
	g.setColour(fc);	
	g.fillPath(fullBounds);	
	g.strokePath(gbounds, PathStrokeType(1.0f));

}
Beispiel #8
0
void MLMenuButton::doPropertyChangeAction(MLSymbol property, const MLProperty& val)
{
	if (property == "text")
	{
		// TODO this file-specific stuff should not be here. 
		std::string processedText;
		const std::string str = val.getStringValue();
		if(getFloatProperty("strip"))
		{
			processedText = stripExtension(getShortName(str));
		}
		else
		{
			processedText = str;
		}
		setProperty("processed_text", processedText);
		repaint();
	}
	else
	{
		MLButton::doPropertyChangeAction(property, val);
	}
}
void MegaExtrudeOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    float distance = getFloatProperty(0);
    unsigned char count = getByteProperty(1);
    D3DXVECTOR3 scaleVector = getVectorProperty(2);
    D3DXVECTOR3 rotationVector = getVectorProperty(3);
    D3DXMATRIX scaleMatrix;
    D3DXMatrixScaling(&scaleMatrix,
                      scaleVector.x,
                      scaleVector.y,
                      scaleVector.z);
    D3DXMATRIX rotationXMatrix;
    D3DXMatrixRotationX(&rotationXMatrix, rotationVector.x);
    D3DXMATRIX rotationYMatrix;
    D3DXMatrixRotationY(&rotationYMatrix, rotationVector.y);
    D3DXMATRIX rotationZMatrix;
    D3DXMatrixRotationZ(&rotationZMatrix, rotationVector.z);
    D3DXMATRIX translationMatrix;
    D3DXMatrixTranslation(&translationMatrix,
                          0.0f,
                          distance / (float)count,
                          0.0f);
    D3DXMATRIX extrudeMatrix = scaleMatrix * rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;

    Mesh *srcMesh = getInput(0)->mesh;

    int numberOfVertices = srcMesh->getNumVertices();
    int numberOfQuads = srcMesh->getNumQuads();

    // Calculate the new number of quads and vertices.
    // The number of triangles will be unchanged.
    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        if (srcMesh->faceSelected(i))
        {
            numberOfQuads += n * count;
            numberOfVertices += n * count;
        }
    }

    mesh = new Mesh(numberOfVertices, srcMesh->getNumTriangles(), numberOfQuads, 1);

    int triangleIndex = 0;
    int quadIndex = 0;

    // Copy the src mesh vertices.
    for (int i = 0; i < srcMesh->getNumVertices(); i++)
    {
        mesh->pos(i) = srcMesh->pos(i);
    }

    int vertexIndex = srcMesh->getNumVertices();
    // Extrude each selected face and add triangles and quads.

    Vec3* lastPositions = new Vec3[4];
    int* lastIndices = new int[4];
    int* currentIndices = new int[4];

    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        for (int f = 0; f < n; f++)
        {
            lastPositions[f] = srcMesh->pos(face[f]);
            lastIndices[f] = face[f];
        }

        if (srcMesh->faceSelected(i))
        {
            // Get our base vectors.
            Vec3 pos1 = srcMesh->pos(face[1]);
            Vec3 pos0 = srcMesh->pos(face[0]);
            Vec3 faceBase1 = normalize(pos1 - pos0);
            Vec3 faceBase2 = normalize(srcMesh->getFaceNormal(i));
            Vec3 faceBase3 = normalize(cross(faceBase2, faceBase1));

            D3DXMATRIX fromFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase1.y, faceBase1.z, 0.0f,
                                            faceBase2.x, faceBase2.y, faceBase2.z, 0.0f,
                                            faceBase3.x, faceBase3.y, faceBase3.z, 0.0f,
                                            0.0f,               0.0f,        0.0f, 1.0f);
            D3DXMATRIX toFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase2.x, faceBase3.x, 0.0f,
                                          faceBase1.y, faceBase2.y, faceBase3.y, 0.0f,
                                          faceBase1.z, faceBase2.z, faceBase3.z, 0.0f,
                                          0.0f,               0.0f,        0.0f, 1.0f);

            D3DXMATRIX toFaceBaseAndOrigoMatrix = toFaceBaseMatrix;
            D3DXMATRIX fromFaceBaseAndToFaceMatrix = extrudeMatrix * fromFaceBaseMatrix;

            for (int c = 0; c < count; c++)
            {
                for (int f = 0; f < n; f++)
                {
                    Vec3 pos = lastPositions[f];
                    Vec3 posInFaceBase;
                    D3DXVec3TransformCoord(&posInFaceBase, &pos, &toFaceBaseAndOrigoMatrix);
                    Vec3 posTransformed;
                    D3DXVec3TransformCoord(&posTransformed, &posInFaceBase, &fromFaceBaseAndToFaceMatrix);
                    mesh->pos(vertexIndex) = posTransformed;
                    currentIndices[f] = vertexIndex;
                    lastPositions[f] = posTransformed;
                    vertexIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    mesh->setQuad(quadIndex,
                                  lastIndices[f],
                                  lastIndices[(f + 1) % n],
                                  currentIndices[(f + 1) % n],
                                  currentIndices[f]);
                    quadIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    lastIndices[f] = currentIndices[f];
                }
            }
        }


        if (n == 3)
        {
            mesh->setTriangle(triangleIndex, lastIndices[0], lastIndices[1], lastIndices[2]);
            triangleIndex++;
        }
        else
        {
            mesh->setQuad(quadIndex, lastIndices[0], lastIndices[1], lastIndices[2],  lastIndices[3]);
            quadIndex++;
        }
    }

    delete[] lastIndices;
    delete[] currentIndices;
    delete[] lastPositions;

    mesh->recalculateNormals();
}
Beispiel #10
0
void MLPluginProcessor::getStateAsXML (XmlElement& xml)
{
	if( !(mEngine.getCompileStatus() == MLProc::OK)) return;
	
#if DEMO	
	xml.setAttribute ("pluginVersion", JucePlugin_VersionCode);	
    xml.setAttribute ("presetName", String("----"));	
#else

  	const unsigned numParams = getNumParameters();

	// TODO use string properties of model instead of these JUCE strings.
	// also move to JSON.
	xml.setAttribute ("pluginVersion", JucePlugin_VersionCode);
	xml.setAttribute ("presetName", String(getStringProperty("preset").c_str()));
	xml.setAttribute ("scaleName", String(getStringProperty("key_scale").c_str()));

	// store parameter values to xml as a bunch of attributes.
	// not XML best practice in general but takes fewer characters.
	for(unsigned i=0; i<numParams; ++i)
	{
		const String paramName = symbolToXMLAttr(getParameterAlias(i));
		const float defaultVal = getParameterDefault(i);
		const float paramVal = getParameter(i);
		if (paramVal != defaultVal)
		{
			xml.setAttribute(paramName, paramVal);		
			//debug() << "setting XML param " << paramName << " to " << paramVal << "\n";
		}
	}

	// store patcher info to xml
	{			
		MLProcList patchers = getPatcherList();
		if (!patchers.empty())
		{
			MLProcPatcher& firstPatcher = static_cast<MLProcPatcher&>(**patchers.begin());
			const int inputs = firstPatcher.getParam("inputs");
			const int outputs = firstPatcher.getParam("outputs");
			String outStr;
			String patcherInput = "patcher_input_";
			
			for(unsigned i=1; i<=inputs; ++i)
			{
				bool differentFromDefault = false;
				outStr = "";
				for(unsigned j=1; j<=outputs; ++j)
				{
					if (firstPatcher.getConnection(i, j))
					{
						outStr += "1";
						differentFromDefault = true;
					}
					else
					{
						outStr += "0";
					}
				}
				if(differentFromDefault)
				{
					String outNum (i); 
					xml.setAttribute(patcherInput + outNum, outStr);	
				}				
			}
		}
	}	
	
	// store editor state to XML if one exists	
	MLPluginEditor* pEditor = static_cast<MLPluginEditor*>(getActiveEditor());
	if(pEditor)
	{
		MLRect r = pEditor->getWindowBounds();
		xml.setAttribute("editor_x", r.x());	
		xml.setAttribute("editor_y", r.y());	
		xml.setAttribute("editor_width", r.getWidth());	
		xml.setAttribute("editor_height", r.getHeight());
		xml.setAttribute("editor_num", getFloatProperty("patch_num"));	
		xml.setAttribute("editor_anim", getFloatProperty("patch_anim"));	
	}
	
	// save blob as most recently saved state
	mpLatestStateLoaded = XmlElementPtr(new XmlElement(xml));
	
#endif

}
Beispiel #11
0
void Map::initializeAmbientLayers()
{
    ResourceManager *resman = ResourceManager::getInstance();

    // search for "foreground*" or "overlay*" (old term) in map properties
    for (int i = 0; /* terminated by a break */; i++)
    {
        std::string name;
        if (hasProperty("foreground" + toString(i) + "image"))
        {
            name = "foreground" + toString(i);
        }
        else if (hasProperty("overlay" + toString(i) + "image"))
        {
            name = "overlay" + toString(i);
        }
        else
        {
            break; // the FOR loop
        }

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mForegrounds.push_back(
                    new AmbientLayer(img, parallax, speedX, speedY, keepRatio));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }


    // search for "background*" in map properties
    for (int i = 0;
         hasProperty("background" + toString(i) + "image");
         i++)
    {
        const std::string name = "background" + toString(i);

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mBackgrounds.push_back(
                    new AmbientLayer(img, parallax, speedX, speedY, keepRatio));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }
}
Beispiel #12
0
void CylinderOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    float radius1 = getFloatProperty(0);
    float radius2 = getFloatProperty(1);
    float length = getFloatProperty(2);
    int slices = getByteProperty(3);
    int stacks = getByteProperty(4);
	int capCircles1 = (radius1 == 0.0f ? 0 : getByteProperty(5));
	int capCircles2 = (radius2 == 0.0f ? 0 : getByteProperty(6));

	int capVerts1 = capCircles1 == 0 ? 0 : capCircles1 * slices + 1;
	int capQuads1 = capCircles2 == 0 ? 0 : capCircles1 * slices;
	int capTriangles1 = slices;
	int capVerts2 = capCircles2 == 0 ? 0 : capCircles2 * slices + 1;
	int capQuads2 = capCircles2 * slices;
	int capTriangles2 = capCircles2 == 0 ? 0 :slices;
	
	int mantleVerts = stacks == 0 ? 0 : (stacks + 1) * (slices + 1);
	int mantleQuads = stacks * slices;

	mesh = new Mesh(capVerts1 + capVerts2 + mantleVerts, capTriangles1 + capTriangles2, capQuads1 + capQuads2 + mantleQuads);

	int capVertBase1 = mantleVerts;
	int capVertBase2 = mantleVerts + capVerts1;

	int capQuadBase1 = mantleQuads;
	int capQuadBase2 = mantleQuads + capQuads1;

	if (mantleVerts > 0)
	{
		int vert = 0, quad = 0;

		for (int x = 0; x <= slices; x++)
		{
			float u = x / (float)slices;
			Vec2 p(cos(u * 2 * M_PI), sin(u * 2 * M_PI));

			for (int y = 0; y <= stacks; y++)
			{
				float v = y / (float)stacks;
				float r = radius1 + (radius2 - radius1) * v;
				
				mesh->pos(vert) = Vec3(p.x * r, v * length, p.y * r);
				mesh->normal(vert) = Vec3(p.x, 0.0f, p.y);
				mesh->uv(vert) = Vec2(u, 1.0f - v);

				if (x != slices && y != stacks)
				{
					mesh->setQuad(quad, vert, vert + 1, vert + stacks + 2, vert + stacks + 1);
					quad++;
				}

				vert++;
			}
		}
	}

	int tri = 0;

	int circles = capCircles1;
	int vertBase = capVertBase1;
	float radius = radius1;
	int quad = capQuadBase1;	
	float h = 0.0f;
	Vec3 n = Vec3(0.0f, -1.0f, 0.0f);
	bool inv = false;

	for (int i = 0; i < 2; i++)
	{
		int vert = 0;

		if (circles)
		{
			for (int x = 0; x < slices; x++)
			{
				float u = (inv ? slices - x - 1 : x) / (float)slices;

				for (int y = 0; y < circles; y++)
				{
					float v = 1.0f - y / (float)circles;
					float r = v * radius;
					
					Vec2 p(cos(u * 2 * M_PI), sin(u * 2 * M_PI));

					mesh->pos(vert + vertBase) = Vec3(p.x * r, h, p.y * r);
					mesh->normal(vert + vertBase) = n;
					Vec2 uv = (p * v + Vec2(1.0f, 1.0f)) * 0.5f;
					mesh->uv(vert + vertBase) = Vec2(uv.x, inv ? 1.0f - uv.y : uv.y);

					if (y != circles - 1)
					{
						int x2 = (x + 1) % slices;
						int y2 = (y + 1) % circles;

						int v1 = x * circles + y;
						int v2 = x2 * circles + y;
						int v3 = x2 * circles + y2;
						int v4 = x * circles + y2;
						mesh->setQuad(quad, v1 + vertBase, v2 + vertBase, v3 + vertBase, v4 + vertBase);
						quad++;
					}
					else
					{
						int x2 = (x + 1) % slices;

						int v1 = x * circles + y;
						int v2 = x2 * circles + y;
						int v3 = slices * circles;
						mesh->setTriangle(tri, v1 + vertBase, v2 + vertBase, v3 + vertBase);
						tri++;
					}

					vert++;
				}
			}
			
			mesh->pos(vert + vertBase) = Vec3(0.0f, h, 0.0f);
			mesh->normal(vert + vertBase) = n;
			mesh->uv(vert + vertBase) = Vec2(0.5f, 0.5f);
			vert++;
		}

		circles = capCircles2;
		vertBase = capVertBase2;
		radius = radius2;
		quad = capQuadBase2;
		h = length;
		n = Vec3(0.0f, 1.0f, 0.0f);
		inv = true;
	}
}
Beispiel #13
0
void Map::initializeAmbientLayers()
{
    ResourceManager *const resman = ResourceManager::getInstance();

    // search for "foreground*" or "overlay*" (old term) in map properties
    for (int i = 0; /* terminated by a break */; i++)
    {
        std::string name;
        if (hasProperty(std::string("foreground").append(
            toString(i)).append("image")))
        {
            name = "foreground" + toString(i);
        }
        else if (hasProperty(std::string("overlay").append(
                 toString(i)).append("image")))
        {
            name = "overlay" + toString(i);
        }
        else
        {
            break;  // the FOR loop
        }

        Image *const img = resman->getImage(getProperty(name + "image"));
        if (img)
        {
            int mask = atoi(getProperty(name + "mask").c_str());
            if (!mask)
                mask = 1;
            const float parallax = getFloatProperty(name + "parallax");
            mForegrounds.push_back(new AmbientLayer(img,
                getFloatProperty(name + "parallaxX", parallax),
                getFloatProperty(name + "parallaxY", parallax),
                getFloatProperty(name + "posX"),
                getFloatProperty(name + "posY"),
                getFloatProperty(name + "scrollX"),
                getFloatProperty(name + "scrollY"),
                getBoolProperty(name + "keepratio"),
                mask));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }

    // search for "background*" in map properties
    for (int i = 0; hasProperty(std::string("background").append(
         toString(i)).append("image")); i ++)
    {
        const std::string name("background" + toString(i));
        Image *const img = resman->getImage(getProperty(name + "image"));

        if (img)
        {
            int mask = atoi(getProperty(name + "mask").c_str());
            if (!mask)
                mask = 1;

            const float parallax = getFloatProperty(name + "parallax");
            mForegrounds.push_back(new AmbientLayer(img,
                getFloatProperty(name + "parallaxX", parallax),
                getFloatProperty(name + "parallaxY", parallax),
                getFloatProperty(name + "posX"),
                getFloatProperty(name + "posY"),
                getFloatProperty(name + "scrollX"),
                getFloatProperty(name + "scrollY"),
                getBoolProperty(name + "keepratio"),
                mask));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }
}
Beispiel #14
0
void SoundplaneModel::doPropertyChangeAction(MLSymbol p, const MLProperty & newVal)
{
	// debug() << "SoundplaneModel::doPropertyChangeAction: " << p << " -> " << newVal << "\n";
	
	int propertyType = newVal.getType();
	switch(propertyType)
	{
		case MLProperty::kFloatProperty:
		{
			float v = newVal.getFloatValue();
			if (p.withoutFinalNumber() == MLSymbol("carrier_toggle"))
			{
				// toggles changed -- mute carriers
				unsigned long mask = 0;
				for(int i=0; i<32; ++i)
				{
					MLSymbol tSym = MLSymbol("carrier_toggle").withFinalNumber(i);
					bool on = (int)(getFloatProperty(tSym));
					mask = mask | (on << i);
				}
				
				mCarriersMask = mask;
				mCarrierMaskDirty = true; // trigger carriers set in a second or so
			}
			
			else if (p == "all_toggle")
			{
				bool on = (bool)(v);
				for(int i=0; i<32; ++i)
				{
					MLSymbol tSym = MLSymbol("carrier_toggle").withFinalNumber(i);
					setProperty(tSym, on);
				}
				mCarriersMask = on ? ~0 : 0;
				mCarrierMaskDirty = true; // trigger carriers set in a second or so
			}
			else if (p == "max_touches")
			{
				mTracker.setMaxTouches(v);
				mMIDIOutput.setMaxTouches(v);
				mOSCOutput.setMaxTouches(v);
			}
			else if (p == "lopass")
			{
				mTracker.setLopass(v);
			}
			
			else if (p == "z_thresh")
			{
				mTracker.setThresh(v);
			}
			else if (p == "z_max")
			{
				mTracker.setMaxForce(v);
			}
			else if (p == "z_curve")
			{
				mTracker.setForceCurve(v);
			}
			else if (p == "snap")
			{
				sendParametersToZones();
			}
			else if (p == "vibrato")
			{
				sendParametersToZones();
			}
			else if (p == "lock")
			{
				sendParametersToZones();
			}
			else if (p == "data_freq_midi")
			{
				// TODO attribute
				mMIDIOutput.setDataFreq(v);
			}
			else if (p == "data_freq_osc")
			{
				// TODO attribute
				mOSCOutput.setDataFreq(v);
			}
			else if (p == "midi_active")
			{
				mMIDIOutput.setActive(bool(v));
			}
			else if (p == "midi_multi_chan")
			{
				mMIDIOutput.setMultiChannel(bool(v));
			}
			else if (p == "midi_start_chan")
			{
				mMIDIOutput.setStartChannel(int(v));
			}
			else if (p == "midi_pressure_active")
			{
				mMIDIOutput.setPressureActive(bool(v));
			}
			else if (p == "osc_active")
			{
				bool b = v;
				mOSCOutput.setActive(b);
				listenToOSC(b ? kDefaultUDPReceivePort : 0);
			}
			else if (p == "osc_send_matrix")
			{
				bool b = v;
				mSendMatrixData = b;
			}
			else if (p == "t_thresh")
			{
				mTracker.setTemplateThresh(v);
			}
			else if (p == "bg_filter")
			{
				mTracker.setBackgroundFilter(v);
			}
			else if (p == "quantize")
			{
				bool b = v;
				mTracker.setQuantize(b);
				sendParametersToZones();
			}
			else if (p == "rotate")
			{
				bool b = v;
				mTracker.setRotate(b);
			}
			else if (p == "retrig")
			{
				mMIDIOutput.setRetrig(bool(v));
				sendParametersToZones();
			}
			else if (p == "hysteresis")
			{
				mMIDIOutput.setHysteresis(v);
				sendParametersToZones();
			}
			else if (p == "transpose")
			{
				sendParametersToZones();
			}
			else if (p == "bend_range")
			{
				mMIDIOutput.setBendRange(v);
				sendParametersToZones();
			}
			else if (p == "debug_pause")
			{
				debug().setActive(!bool(v));
			}
			else if (p == "kyma_poll")
			{
				mMIDIOutput.setKymaPoll(bool(v));
			}
		}
			break;
		case MLProperty::kStringProperty:
		{
			const std::string& str = newVal.getStringValue();
			if (p == "viewmode")
			{
				// nothing to do for Model
			}
			else if (p == "midi_device")
			{
				mMIDIOutput.setDevice(str);
			}
			else if (p == "zone_JSON")
			{
				loadZonesFromString(str);
			}
		}
			break;
		case MLProperty::kSignalProperty:
		{
			const MLSignal& sig = newVal.getSignalValue();
			if(p == MLSymbol("carriers"))
			{
				// get carriers from signal
				assert(sig.getSize() == kSoundplaneSensorWidth);
				for(int i=0; i<kSoundplaneSensorWidth; ++i)
				{
					mCarriers[i] = sig[i];
				}
				mNeedsCarriersSet = true;
			}
			if(p == MLSymbol("tracker_calibration"))
			{
				mTracker.setCalibration(sig);
			}
			if(p == MLSymbol("tracker_normalize"))
			{
				mTracker.setNormalizeMap(sig);
			}

		}
			break;
		default:
			break;
	}
}
Beispiel #15
0
void MLEnvelope::paint (Graphics& g)
{	
	float mDelay = getFloatProperty("delay");
	float mAttack = getFloatProperty("attack");
	float mSustain = getFloatProperty("sustain");
	float mDecay = getFloatProperty("decay");
	float mRelease = getFloatProperty("release");
	float r = getFloatProperty("repeat");
	float mRepeat = (r > 0.f) ? (1.f / (r + 0.0001f)) : 0.f;

	MLLookAndFeel* myLookAndFeel = (&(getRootViewResources(this).mLookAndFeel));
	if (isOpaque()) 
		myLookAndFeel->drawBackground(g, this);	
	
	float margin = myLookAndFeel->getSmallMargin() * myLookAndFeel->getGridUnitSize();
	int w = getWidth()-1;
	int h = getHeight()-1;
	
	float totalTime;
	float startX, delX, attX, decX, susX, relX, repX, endX;
	float attTime, decTime, relTime, susTime;
	float leadIn = 0.01;
	float leadOut = 0.01;
	float susHeight;
	float epsilon = 0.0005;
	float susLevel = mDARMode ? 1.0f : mSustain;
	attTime = mAttack + kMinAttack;
	decTime = mDecay * (1.f - susLevel) + kMinDecay;
	relTime = mRelease * susLevel + kMinDecay;
			
	// get times
	if (mDARMode)
	{
		susTime = (mSustain > 0.5) ? 1.f : 0.f; // is hold on?
		decTime = 0.;
		totalTime = leadIn + mDelay + attTime + susTime + relTime + leadIn + leadOut;
	}
	else
	{
		susTime = 1.f;
		totalTime = leadIn + attTime + decTime + susTime + relTime + leadIn + leadOut;
	}
	
	if (mRepeat > epsilon)
	{
		totalTime = ml::max(totalTime, (float)(leadIn + mDelay + mRepeat + leadOut));
	}
	
	totalTime = ml::max(totalTime, 0.01f);
	
	// get dims
	MLRange vRange(UnityRange);
	MLRange wRange(0.f, totalTime);
	vRange.convertTo(MLRange(h - margin, margin));
	wRange.convertTo(MLRange(margin, w - margin*2));
	float t = 0.;
	startX = wRange(0.);

	delX = wRange(t += mDelay);
	attX = wRange(t += attTime);
	decX = wRange(t += decTime);
	susX = wRange(t += susTime);
	relX = wRange(t += relTime);
	endX = wRange(totalTime);
	repX = wRange(leadIn + mDelay + mRepeat);
	susHeight = vRange(susLevel);
		
	// draw env shape
	Path envPath;
	envPath.startNewSubPath(startX,  floor(h - margin) + 0.5);
	envPath.lineTo(delX,  floor(h - margin) + 0.5);
	envPath.quadraticTo(delX,  floor(margin) + 0.5, attX, floor(margin) + 0.5); // up
	envPath.quadraticTo(attX,  floor(susHeight) + 0.5, decX,  floor(susHeight) + 0.5);  // down
	envPath.quadraticTo(decX,  floor(susHeight) + 0.5, susX,  floor(susHeight) + 0.5); // across
	envPath.quadraticTo(susX,  floor(h - margin) + 0.5, relX,  floor(h - margin) + 0.5); // down
	envPath.quadraticTo(relX,  floor(h - margin) + 0.5, endX,  floor(h - margin) + 0.5); // across
	g.setColour(findColour(MLLookAndFeel::outlineColor));
	g.strokePath(envPath, PathStrokeType (mOutlineThickness));	
	g.setColour(findColour(MLLookAndFeel::outlineColor).withAlpha(0.125f));
	g.fillPath(envPath);
	// lines down
	envPath.clear();
	envPath.startNewSubPath(attX,  floor(margin) + 0.5);
	envPath.lineTo(attX,  floor(h - margin) + 0.5);
	envPath.startNewSubPath(decX,  floor(susHeight) + 0.5);
	envPath.lineTo(decX,  floor(h - margin) + 0.5);
	envPath.startNewSubPath(susX,  floor(susHeight) + 0.5);
	envPath.lineTo(susX,   floor(h - margin) + 0.5);
	g.setColour(findColour(MLLookAndFeel::outlineColor));
	g.strokePath(envPath, PathStrokeType (mOutlineThickness / 2));	

	// draw repeat bracket
	if (mRepeat > epsilon)
	{		
		float thick = margin / 2;
		float high = margin * 1.5;
		envPath.clear();
		envPath.startNewSubPath(floor(delX - thick/2) , floor(h - margin - high));
		envPath.lineTo(floor(delX - thick/2) , floor(h - margin));
		envPath.lineTo(floor( repX + thick/2) , floor(h - margin));
		envPath.lineTo(floor( repX + thick/2) , floor(h - margin - high));
		g.strokePath(envPath, PathStrokeType (mOutlineThickness * 4));	

	}

//debug() << "DEL " << mDelay << " ATT " << attTime << " DEC " << decTime << " SUS " << susTime << " REL " << relTime << " REP " << mRepeat << "\n";
//debug() << "repeatX: " << repX << " delayX: " << delX << "\n";

	/*
	// TEST
	Path tbounds;
	const Rectangle<int> & boundsRect ( getLocalBounds());	
	tbounds.addRectangle(boundsRect);
	g.setColour(Colours::red);	
	g.strokePath(tbounds, PathStrokeType(0.5f));
	*/
}
void TwoDimensionalPlaneOperator::render()
{    
    for (int i = 0; i < numberOfInputs; i++)
        getInput(i)->render();

    Texture* inputTexture = 0;
    
    if (getInput(0) != 0)
        inputTexture = getInput(0)->texture;

    D3DXMATRIX lastViewMatrix;
    D3DXMATRIX lastProjectionMatrix;
    globalDirect3DDevice->GetTransform(D3DTS_VIEW, &lastViewMatrix);
    globalDirect3DDevice->GetTransform(D3DTS_PROJECTION, &lastProjectionMatrix);
    globalDirect3DDevice->SetTransform(D3DTS_VIEW, &identityMatrix);
    globalDirect3DDevice->SetTransform(D3DTS_WORLD, &identityMatrix);
    globalDirect3DDevice->SetTransform(D3DTS_PROJECTION, &projectionMatrix);
    DWORD lastLightning;
    globalDirect3DDevice->GetRenderState(D3DRS_LIGHTING, &lastLightning); 
    globalDirect3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

    D3DXCOLOR color = getColorProperty(0);
    color.a = getByteProperty(1) / 255.0f;

    float x = getFloatProperty(2);
    float width = getFloatProperty(3);
    float y = getFloatProperty(4);
    float height = getFloatProperty(5);
    float z = getFloatProperty(6);
    float uOffset = getFloatProperty(7);
    float vOffset = getFloatProperty(8);
    float uScale = getFloatProperty(9);
    float vScale = getFloatProperty(10);

    float ratio = (globalWindowHeight / (float)globalWindowWidth) / 4.0f;
    float u1 = -ratio + uOffset;
    float u2 = 1.0f + ratio + uOffset;
    float v1 = vOffset;
    float v2 = 1.0f + vOffset;

    if (getByteProperty(11) == 1)
    {
        u1 = 0.0f;
        u2 = 1.0f;
        v1 = 0.0f;
        v2 = 1.0f;
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);
    }
    else
    {
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
        globalDirect3DDevice->SetSamplerState(0,D3DSAMP_ADDRESSW, D3DTADDRESS_BORDER);
    }

    u1 *= uScale;
    u2 *= uScale;
    v1 *= vScale;
    v2 *= vScale;

    TwoDimensionalVertex quad[4];
    quad[0].x = x; 
    quad[0].y = y; 
    quad[0].z = z;
    quad[0].u = u1; 
    quad[0].v = v1; 
    quad[0].color = color;
    
    quad[1].x = x + width; 
    quad[1].y = y; 
    quad[1].z = z;
    quad[1].u = u2; 
    quad[1].v = v1; 
    quad[1].color = color;

    quad[2].x = x + width; 
    quad[2].y = y + height; 
    quad[2].z = z;
    quad[2].u = u2;
    quad[2].v = v2; 
    quad[2].color = color;

    quad[3].x = x; 
    quad[3].y = y + height; 
    quad[3].z = z;
    quad[3].u = u1; 
    quad[3].v = v2; 
    quad[3].color = color;

    DWORD oldFVF;
    globalDirect3DDevice->GetFVF(&oldFVF);
    globalDirect3DDevice->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
    
    globalDirect3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);     
    globalDirect3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    globalDirect3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
    globalDirect3DDevice->SetRenderState(D3DRS_BLENDOP,D3DBLENDOP_ADD);

    if (inputTexture != 0)
        globalDirect3DDevice->SetTexture(0, inputTexture->getD3D9Texture());

    globalDirect3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &quad, sizeof(TwoDimensionalVertex));
    globalDirect3DDevice->SetTexture(0, 0);
    globalDirect3DDevice->SetFVF(oldFVF);

    globalDirect3DDevice->SetTransform(D3DTS_PROJECTION, &lastProjectionMatrix);
    globalDirect3DDevice->SetTransform(D3DTS_VIEW, &lastViewMatrix);
    globalDirect3DDevice->GetRenderState(D3DRS_LIGHTING, &lastLightning); 
}