view Source/modded_plot/PolarPlot.cpp @ 11:76e2e62635b4

Fixed the automation problem when a control isn't a child.
author martinm_home <martin.morrell@eecs.qmul.ac.uk>
date Thu, 27 Sep 2012 12:33:46 +0100
parents 503cbcdd0b2a
children
line wrap: on
line source
/* VVMicVST - A VST plugin to derive virtual microphones from b-format.
 *
 * Copyright (c) 2005 David McGriffy <david@mcgriffy.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

// PolarPlot.cpp : implementation file
//

//#include "AVVMic.hpp"
#include "GUI.h"
#include <stdio.h>
#include <vstgui.h>
#include "PolarPlot.hpp"

#include <stdio.h>
#include <math.h>

double tsin(double ang);
double tcos(double ang);
double trig[360];

#define ln10 (2.302585092994)

float inline db2level(float db)
{
	return  (float)exp(ln10 * ((double)db / 20.0));
}

float inline level2db(float level)
{
	return (float)(20.0f * log((double)level) / ln10);
}

//float inline parm2halfpi (float x)
//{
//	return (pie * x) - (piover2);
//}
//
//float inline parm2pi (float x)
//{
//	return ((float)twopi * x) - (pie);
//}

enum {
	kPolarElevX = 13,
	kPolarElevY = 19,
	kPolarAziX = 18,
	kPolarAziY = 19,
	kCircleSize = 90
};


//CColor darkColors[6] = {196,0,0}, {0,196,0}, {0,0,196}, {196,196,0},{196,0,196},{0,196,196}};
//CColor lightColors [6] = {{128,0,0}, {0,128,0}, {0,0,128}, {128,128,0},{128,0,128},{0,128,128}};

/////////////////////////////////////////////////////////////////////////////
// CPolarPlot

CPolarPlot::CPolarPlot(CRect& size, CControlListener* listener, int tag, 
					   CBitmap* hBackground, CPoint &offset)
	: CControl(size, listener, tag)
{
	//--initialize trig table - used for display only-----------------------
	for (short ang = 0; ang < 360; ang++)
		//trig[ang] = sin(ang * deg2rad);
	this->hBackground = hBackground;
	this->offset = offset;
}

CPolarPlot::~CPolarPlot()
{

}

//-----------------------------------------------------------------------------

void CPolarPlot::draw(CDrawContext* context)
{

		//bool dispMics = effect->getParameter(1) != 0.0f;//kDispMics
		//bool dispTotal = effect->getParameter(2) != 0.0f;//kDispTotal
		//bool dispVU = effect->getParameter(3) != 0.0f;//kDispVU

		// render to an offscreen context
		// this must be local
		//COffscreenContext *dc = new COffscreenContext (
		//	getParent (), 300, 500, kBlackCColor);
		//CDrawContext *dc = context;
		//CBitmap *bg = new CBitmap(*getParent(),
			//hBackground->getWidth(), hBackground->getHeight());
		//COffscreenContext *dc = new COffscreenContext(context, bg);
		CRect rect = CRect(0, 0, hBackground->getWidth(), hBackground->getHeight()/2);
		CPoint off = CPoint(0, hBackground->getHeight()/2);
		//if (dispVU)
		//	hBackground->draw(dc, rect, off);
		//else
		//	hBackground->draw(dc, rect);

		// create brushes & pens
		//CColor backPen = {252,252,248};
		//CColor blackPen = {0,0,0};
		//CColor greyPen = {128,128,128};
		//CColor redPen = {196,0,0};
		//CColor bluePen = {0,0,196};
		//CColor redDashedPen = {255,160,160};
		//CColor blueDashedPen = {160,160,255};
		//CColor *darkPen, *lightPen;

		// draw elevation picture picture
		int elevCenterX = kPolarElevX;
		int elevCenterY = kPolarElevY+ kCircleSize;
		//dc->setFrameColor(blackPen);
		//dc->setFillColor(backPen);
		//dc->setLineWidth(2);
		CRect rectElev(kPolarElevX - kCircleSize, kPolarElevY,
			kPolarElevX + kCircleSize, kPolarElevY + (kCircleSize * 2));
		CPoint p1(kPolarElevX, kPolarElevY + (kCircleSize * 2));
		CPoint p2(kPolarElevX, kPolarElevY);
		//dc->fillArc(rectElev, p1, p2);
		//dc->drawArc(rectElev, p1, p2);

		// draw azimuth picture circle
		int aziCenterX = kPolarAziX + (2 * kCircleSize);
		int aziCenterY = kPolarAziY + kCircleSize;
		CRect rectAzi(kPolarAziX + kCircleSize, kPolarElevY,
			kPolarAziX + (3 * kCircleSize), kPolarAziY + (kCircleSize * 2));
		int delta = kCircleSize / 2;
		//dc->fillEllipse(rectAzi);
		rectAzi(rectAzi.left + delta, rectAzi.top + delta, rectAzi.right - delta, rectAzi.bottom - delta);
		//dc->setFrameColor(greyPen);
		//dc->drawEllipse(rectAzi);
		//dc->setLineWidth(2);


		// draw response curves
		// note that some effort was required to be fast enough to not disturb play
		// probably have to implement a seperate display thread eventually
		//dc->setFrameColor(redPen);
		//dc->moveTo(CPoint(aziCenterX, aziCenterY - kCircleSize));
		int x, y;
		int inverted = false; // true while drawing negative response
		// for each mic
		double totalresp [37];  // total response at each point around the circle
		for (int deg = 0; deg <= 360; deg += 10)
			totalresp [deg / 10] = 0.0;
		//int m_nNumOuts = (int)(effect->getParameter(kNumMics) * MICDIVISOR) + 1;
		//int m_nCurOut  = (int)(effect->getParameter(kCurMic) * MICDIVISOR) + 1;
		//int last = dispTotal ? m_nNumOuts : m_nNumOuts - 1;
//		for (short mic = 0; mic <= last; mic++) // last one draws total
//		{
//			// select a color for this mic
//			if (mic < m_nNumOuts)
//			{
//				darkPen = &darkColors[mic % 6];
//				lightPen = &lightColors[mic % 6];
//			}
//			else
//			{
//				darkPen = &blackPen;
//				lightPen = &greyPen;
//			}
//			dc->setFrameColor(*darkPen);
//			// draw rect of selected mic
//			/*if (mic == (m_nCurOut - 1))
//			{
//				CRect micBox (260, 265, 280, 290);
//				dc->fillRect(micBox);
//				dc->drawRect(micBox);
//				char strMicNum[80];
//				sprintf(strMicNum, "%d", m_nCurOut);
//				micBox.top += 2;
//				dc->drawString( strMicNum, micBox);
//			}*/
//
//			// compute bass parameter index for the current mic
//			int nMicOffset = kNumMasterParams + (mic * kNumMicParams);
//
//			// compute gain or vu
//			float gain;
//			if (dispVU)
//				gain = max(0.0f, (level2db(effect->getVuMic(mic)) + 60.0f)) / 60.0f;
//			else
//				//gain = min(1.0f, db2level((effect->getParameter(nMicOffset + kGain) * 24.0f) - 12.0f));
//				gain = db2level((effect->getParameter(nMicOffset + kGain) * 24.0f) - 12.0f);
//
//			// draw elevation line for this mic
//			if (mic < m_nNumOuts) // no total elevation
//			{
//				dc->moveTo(CPoint(elevCenterX, elevCenterY));
//				float elev = parm2halfpi(effect->getParameter (nMicOffset + kElevation));
//				float r = (float)(gain * (kCircleSize-1));
//				r = min(kCircleSize - 2, r);
//				int x = elevCenterX + (int)(tcos(elev) * r);
//				int y = elevCenterY - (int)(tsin(elev) * r);
//				CPoint thePoint = CPoint(x, y);
//				dc->lineTo(thePoint);
//			}
//
//			// around the circle
//			for (int deg = 0; deg <= 360; deg += 10)
//			{
//				if (mic == 0)
//					totalresp [deg / 10] = 0.0;
//				double rad = (deg * deg2rad);
//				double resp;
//				if (mic < m_nNumOuts)
//				{
//					// drawing one mic
//					float width;
////					if (m_bLinkPairs)
////						width = m_width[mic] / 2 * (mic%2 ? -1 : 1);
//					if (true)
//						width = effect->getParameter(nMicOffset + kWidth) / 2 * (mic%2 ? -1 : 1);
//					else
//						width = 0.0f;
//					float directivity = 2 * effect->getParameter(nMicOffset + kDirectivity);
//					float azimuth = parm2pi(effect->getParameter(nMicOffset + kAzimuth));
//					width = parm2pi(width);
//					resp = gain * (2 - directivity 
//						+ (directivity * tcos(rad + azimuth + width)))
//						* (kCircleSize - 2) / 2;
//					totalresp [deg / 10] += resp / (double)m_nNumOuts;
//					resp = min(kCircleSize - 2, resp);
//				}
//				else
//				{
//					// drawing total
//					resp = min(kCircleSize - 2, totalresp [deg / 10]);
//				}
//				if (resp > 0 && inverted)
//				{
//				
//					// drawing normal polarity
//					dc->setFrameColor(*darkPen);
//					inverted = false;
//				}
//				if (resp < 0 && !inverted)
//				{
//					// drawing inverted polarity
//					inverted = true;
//					dc->setFrameColor(*lightPen);
//				}
//				if (inverted)
//					resp = -resp;
//				x = aziCenterX - (int)(tsin(rad) * resp);
//				y = aziCenterY + (int)(tcos(rad) * resp);
//				if (dispMics || (mic == m_nNumOuts))
//					if (deg == 0)
//						dc->moveTo(CPoint(x, y));
//					else
//						dc->lineTo(CPoint(x, y));
//			}
//		}
//		dc->copyFrom(context, size);
//		delete dc;
//		delete bg;
}

// table driven trig for display purposes
double tsin(double ang)
{
//	if (ang < 0)
//		ang += twopi; // ms's mod doesn't do negatives right
//	return trig[((int)(ang / deg2rad) % 360)];
        return 0;
}

double tcos(double ang)
{
//	if (ang < 0)
//		ang += twopi; // ms's mod doesn't do negatives right
//	int tmp = (((int)(ang / deg2rad) + 90) % 360);
//	double tmp2 = trig[tmp];
//	return trig[(((int)(ang / deg2rad) + 90) % 360)];
    return 0;
}

//void CPolarPlot::setEffect(AVVMic *newEffect)
//{
//	effect = newEffect;
//}

//AVVMic* CPolarPlot::getEffect()
//{
//	return this->effect;
//}

//CColor CPolarPlot::getColor(int i)
//{
//	return darkColors[i];
//}

//-----------------------------------------------------------------------------