b-rad
02-01-2011, 03:00 PM
Hi, I am having some trouble getting my basic shapes to stay on the GUI. I've done my best to gather help from the examples in these threads:
http://forum.cockos.com/showthread.php?t=42906
http://forum.cockos.com/showthread.php?t=48251
http://forum.cockos.com/showthread.php?t=67735
My code below attempts to draw a line with a coordinate that changes with the kGain parameter. Commented out, there is a similar command to draw a circle whose radius depends on the kGain parameter. These are practice for my end goal of plotting a frequency spectrum using the data from my FFT.
The line appears briefly on the screen every time I reopen the GUI, then disappears (after about say 1/24th or 1/30th of a second, maybe?). The circle appears, but then one quadrant disappears quickly, leaving the other three fourths of the circle on the screen. When I change the gain slider, then close and reopen the GUI, the circle does change radius correctly.
I created a subclass of IControl (called IDistributionGraph after an example), and attached it as control. I put the pGraphics->DrawCircle inside the subclass's Draw method, and made the IsDirty always return true.
//*******my header file
#include "../IPlug_include_in_plug_hdr.h"
#include "fft.h"
class IDistributionGraph : public IControl{
public:
IDistributionGraph(IPlugBase* pPlug, int x, int y, int width, int height, int paramIdx);
bool Draw(IGraphics* pGraphics);
bool IsDirty() {return true;}
private:
IPlugBase *m_pPlug;
};
class IPlugFFT : public IPlug
{
public:
IPlugFFT(IPlugInstanceInfo instanceInfo);
~IPlugFFT() {}
void ProcessDoubleReplacing(double** inputs, double ** outputs, int nFrames);
private:
IDistributionGraph * graph;
int fftbuffersize;
int count, samps;
WDL_FFT_COMPLEX fftbuffer[1024];
WDL_FFT_COMPLEX sortedbuffer[1024];
WDL_FFT_COMPLEX unsortedbuffer[1024];
};
//*******My cpp file
#include "FFT_pg.h"
#include "../IPlug_include_in_plug_src.h"
#include "../IControl.h"
#include "resource.h"
#include <math.h>
#include "fft.h"
enum EParams {
kGain,
kGraphDummy,
kNumParams
};
const int kNumPrograms = 1;
enum ELayout {
kW = 800,
kH = 800,
//gain fader
kFader_Len = 150,
kGain_X = 200,
kGain_Y = 50,
kGraph_X = 400,
kGraph_Y = 400,
kGraph_W = 100,
kGraph_H = 100
};
IDistributionGraph::IDistributionGraph(IPlugBase *pPlug, int x, int y, int width, int height, int paramIdx)
: IControl(pPlug, &IRECT(x,y,width,height ))
{
OutputDebugString("dist graph ctor");
m_pPlug=pPlug;
}
bool IDistributionGraph::Draw(IGraphics* pGraphics){
OutputDebugString("dist graph draw()");
IColor color(255,255,255,255);
double param= m_pPlug->GetParam(kGain)->DBToAmp();
//pGraphics->DrawCircle(&color,400,400,100+100*param);
pGraphics->DrawLine(&color,200,200,300,300+param,0,true);
return true;
}
IPlugFFT::IPlugFFT(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), fftbuffersize(1024), count(0)
{
TRACE; //no idea what this does. Can go to definition.
//***SET UP PARAMETERS***
GetParam(kGain)->InitDouble("Gain", 0.0, -70.0, 12.0, 0.1, "dB");
//***GRAPHICS***
IGraphics* pGraphics = MakeGraphics(this,kW,kH);
pGraphics->AttachBackground(BG_ID, BG_FN);
//Gain fader graphics
IBitmap bitmap = pGraphics->LoadIBitmap(FADER_ID, FADER_FN);
pGraphics->AttachControl(new IFaderControl(this, kGain_X, kGain_Y, kFader_Len, kGain, &bitmap, kVertical));
//Practice Shapes
this->graph = new IDistributionGraph(this, kGraph_X, kGraph_Y, kGraph_W, kGraph_H, kGraphDummy);
pGraphics->AttachControl(this->graph);
//Attach
AttachGraphics(pGraphics);
WDL_fft_init();
MakeDefaultPreset("-", kNumPrograms);
}
void IPlugFFT::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
//not doing anything drawing-related in here
}
I had hoped that having IsDirty() always return true would cause the control's Draw() function to be called every block. Can anyone see where I've gone wrong? Let me know if any part of my description doesn't make sense.
Thanks.
http://forum.cockos.com/showthread.php?t=42906
http://forum.cockos.com/showthread.php?t=48251
http://forum.cockos.com/showthread.php?t=67735
My code below attempts to draw a line with a coordinate that changes with the kGain parameter. Commented out, there is a similar command to draw a circle whose radius depends on the kGain parameter. These are practice for my end goal of plotting a frequency spectrum using the data from my FFT.
The line appears briefly on the screen every time I reopen the GUI, then disappears (after about say 1/24th or 1/30th of a second, maybe?). The circle appears, but then one quadrant disappears quickly, leaving the other three fourths of the circle on the screen. When I change the gain slider, then close and reopen the GUI, the circle does change radius correctly.
I created a subclass of IControl (called IDistributionGraph after an example), and attached it as control. I put the pGraphics->DrawCircle inside the subclass's Draw method, and made the IsDirty always return true.
//*******my header file
#include "../IPlug_include_in_plug_hdr.h"
#include "fft.h"
class IDistributionGraph : public IControl{
public:
IDistributionGraph(IPlugBase* pPlug, int x, int y, int width, int height, int paramIdx);
bool Draw(IGraphics* pGraphics);
bool IsDirty() {return true;}
private:
IPlugBase *m_pPlug;
};
class IPlugFFT : public IPlug
{
public:
IPlugFFT(IPlugInstanceInfo instanceInfo);
~IPlugFFT() {}
void ProcessDoubleReplacing(double** inputs, double ** outputs, int nFrames);
private:
IDistributionGraph * graph;
int fftbuffersize;
int count, samps;
WDL_FFT_COMPLEX fftbuffer[1024];
WDL_FFT_COMPLEX sortedbuffer[1024];
WDL_FFT_COMPLEX unsortedbuffer[1024];
};
//*******My cpp file
#include "FFT_pg.h"
#include "../IPlug_include_in_plug_src.h"
#include "../IControl.h"
#include "resource.h"
#include <math.h>
#include "fft.h"
enum EParams {
kGain,
kGraphDummy,
kNumParams
};
const int kNumPrograms = 1;
enum ELayout {
kW = 800,
kH = 800,
//gain fader
kFader_Len = 150,
kGain_X = 200,
kGain_Y = 50,
kGraph_X = 400,
kGraph_Y = 400,
kGraph_W = 100,
kGraph_H = 100
};
IDistributionGraph::IDistributionGraph(IPlugBase *pPlug, int x, int y, int width, int height, int paramIdx)
: IControl(pPlug, &IRECT(x,y,width,height ))
{
OutputDebugString("dist graph ctor");
m_pPlug=pPlug;
}
bool IDistributionGraph::Draw(IGraphics* pGraphics){
OutputDebugString("dist graph draw()");
IColor color(255,255,255,255);
double param= m_pPlug->GetParam(kGain)->DBToAmp();
//pGraphics->DrawCircle(&color,400,400,100+100*param);
pGraphics->DrawLine(&color,200,200,300,300+param,0,true);
return true;
}
IPlugFFT::IPlugFFT(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), fftbuffersize(1024), count(0)
{
TRACE; //no idea what this does. Can go to definition.
//***SET UP PARAMETERS***
GetParam(kGain)->InitDouble("Gain", 0.0, -70.0, 12.0, 0.1, "dB");
//***GRAPHICS***
IGraphics* pGraphics = MakeGraphics(this,kW,kH);
pGraphics->AttachBackground(BG_ID, BG_FN);
//Gain fader graphics
IBitmap bitmap = pGraphics->LoadIBitmap(FADER_ID, FADER_FN);
pGraphics->AttachControl(new IFaderControl(this, kGain_X, kGain_Y, kFader_Len, kGain, &bitmap, kVertical));
//Practice Shapes
this->graph = new IDistributionGraph(this, kGraph_X, kGraph_Y, kGraph_W, kGraph_H, kGraphDummy);
pGraphics->AttachControl(this->graph);
//Attach
AttachGraphics(pGraphics);
WDL_fft_init();
MakeDefaultPreset("-", kNumPrograms);
}
void IPlugFFT::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
//not doing anything drawing-related in here
}
I had hoped that having IsDirty() always return true would cause the control's Draw() function to be called every block. Can anyone see where I've gone wrong? Let me know if any part of my description doesn't make sense.
Thanks.