| Hi list, Istvan,
I discussed the same issue a few days ago on the csound
list. I wrote an opcode for the time-domain representation
of audio signals using fltk and opengl. I create the window
in the init function of the window-opcode using the new
operator to construct the class. I don't know how to take
care about the allocated memory. After having a look into
widgets.cpp I can't see that this is done in any of these
opcodes. The constructor allocates the buffer for the points
to draw. Even so I would use the AUXCH structure to allocate
the memory for the points I would have the constructor of
the class which uses the new operator. I mean the opcode
performs well this way but is it also a recommanded way to
go?
Any hints would be highly appreciated
Thanks Simon
The complete code and a the csd tu run it can be found here:
http://www.schampijer.de/howto/FLtimeamp.zip
Or this is the init function and the window class
definition:
-------------------------------------------------------------------
extern "C" int fl_timeampWindow_init(ENVIRON *csound,
FLTIMEAMPWINDOW *p)
{
char *widgetName = GetString(csound, p->iname,
p->XSTRCODE);
int sr = (int)(csound->GetSr)(csound);
int x = (int) *p->ix, y = (int) *p->iy,
width = (int) *p->iwidth, height = (int) *p->iheight;
if (width <0) width = 300; //default
if (height <0) height = 200;
timeamp_window *opgl = new timeamp_window(x, y, width,
height, widgetName, sr);
if (*p->ired != 0.0)
{
/* when the opcode is called without specifying these
arguments, they are optional arguments, defaulting to 0
*/
opgl->red = *p->ired;
opgl->green = *p->igreen;
opgl->blue = *p->iblue;
}
if(*p->ibgcolor!=0 && *p->ibgcolor!=1)
opgl->bgcolor=1.0;
else
opgl->bgcolor=*p->ibgcolor;
AddrSetValue.push_back(ADDR_SET_VALUE(0, 0, 0,
(void *) opgl, (void *) p));
*p->ihandle = AddrSetValue.size()-1;
return OK;
}
-------------------------------------------------------------------
class timeamp_window : public Fl_Gl_Window{
void draw();
void drawText();
public:
timeamp_window::timeamp_window(int x, int y, int w, int
h, const char* label, int sr):
Fl_Gl_Window(x, y, w, h, label)
{
buffersize = sr;
pbuffer = new float[buffersize];
for(int i=0; i |