19 #include "cicm_wrapper.h"
21 #include "ceammc_globaldata.h"
25 using namespace ceammc;
49 static void canvas_addtolist(
t_canvas* x)
51 x->gl_next = pd_this->pd_canvaslist;
52 pd_this->pd_canvaslist = x;
55 static void canvas_takeofflist(
t_canvas* x)
58 if (x == pd_this->pd_canvaslist)
59 pd_this->pd_canvaslist = x->gl_next;
62 for (z = pd_this->pd_canvaslist; z->gl_next != x; z = z->gl_next)
65 z->gl_next = x->gl_next;
83 map<string, string> methodNames;
84 map<string, string> propertyNames;
85 map<string, string> signalNames;
87 map<string, t_outlet*> methodOutlets;
88 map<string, t_outlet*> methodPointerOutlets;
108 this->canvas->gl_havewindow = 1;
109 this->canvas->gl_isclone = 1;
111 this->symbol =
gensym(class_name.c_str());
112 this->class_name = className;
122 int dollarzero = 1000;
132 this->canvas->gl_owner = 0;
138 return this->methodNames;
142 return this->propertyNames;
146 return this->methodOutlets;
166 if (this->canvas->gl_list) {
170 canvas_paste_class(this->canvas, b);
174 post(
"loaded class: %s ", (
char*)(fileName.c_str()));
192 binbuf_write(b, (
char*)(fileName.c_str()), (
char*)dir, 0);
194 post(
"saved class: %s ", (
char*)(fileName.c_str()));
197 #pragma mark dynamic: methods
201 this->methodNames[methodName] = referenceName;
207 this->methodOutlets[referenceName] = outlet;
213 this->methodPointerOutlets[referenceName] = outlet;
219 if (this->methodOutlets.count(referenceName)) {
221 ret = this->methodOutlets[referenceName];
230 if (this->methodPointerOutlets.count(referenceName)) {
232 ret = this->methodPointerOutlets[referenceName];
240 this->methodNames.erase(methodName);
245 this->methodOutlets.erase(referenceName);
250 this->methodPointerOutlets.erase(referenceName);
255 this->propertyNames[propertyName] = referenceName;
260 this->propertyNames.erase(propertyName);
287 this->parent = p_class;
299 this->signalNames[signalName] = referenceName;
304 this->signalNames.erase(signalName);
312 for (map<string, string>::iterator it = this->propertyNames.begin(); it != this->propertyNames.end(); ++it) {
323 for (map<string, string>::iterator it = this->methodNames.begin(); it != this->methodNames.end(); ++it) {
334 for (map<string, string>::iterator it = this->signalNames.begin(); it != this->signalNames.end(); ++it) {
354 map<t_symbol*, OPOutputs> _methodOutputs;
357 map<t_symbol*, OPOutputs> _getterOutputs;
358 map<t_symbol*, OPOutputs> _setterOutputs;
361 map<t_symbol*, AtomList> _propertyValues;
365 map<string, string> methodNames;
366 map<string, string> propertyNames;
369 map<t_symbol*, t_sample*> _signalBuffers;
372 map<t_symbol*, t_outlet*> _methodPointerOutputs;
391 printf(
"new instance\n");
403 post(
"created parent class instance");
407 this->canvas->gl_havewindow = 1;
408 this->canvas->gl_isclone = 1;
410 int dollarzero = 1000;
420 this->canvas->gl_owner = 0;
425 this->canvasLink->ref() =
this;
428 this->symbolLink->ref() =
this;
435 canvas_paste_class(this->canvas, b1);
438 canvas_addtolist(this->canvas);
446 printf(
"OPInstance + canvas\n");
447 printf(
"canvas: %lu\n", (
long)this->canvas);
460 if (!dyn_class->ref()) {
461 dyn_class->ref() =
new OPClass();
462 dyn_class->ref()->class_name =
"__dynamicStub";
467 map<string, string>::iterator it;
468 for (it = this->methodNames.begin(); it != this->methodNames.end(); ++it) {
469 t_outlet* dyn_out = dyn_class->ref()->getMethodOutletForReferenceName(it->second);
472 this->addMethod(
gensym(it->first.c_str()), dyn_out);
474 t_outlet* dyn_pointer_out = dyn_class->ref()->getMethodPointerOutletForReferenceName(it->second);
477 this->addMethodPointerOut(
gensym(it->first.c_str()), dyn_pointer_out);
485 printf(
"canvas: %lu\n", (
long)this->canvas);
490 canvas_takeofflist(this->canvas);
496 delete this->canvasLink;
497 delete this->symbolLink;
501 printf(
"~OPInstance\n");
502 printf(
"canvas: %lu\n", (
long)this->canvas);
509 this->_methodOutputs[methodName].push_back(outlet);
514 this->_methodOutputs.erase(methodName);
519 this->_methodPointerOutputs[methodName] = outlet;
524 this->_methodPointerOutputs.erase(methodName);
531 t_sample* ret = this->_signalBuffers[signalName];
535 this->_signalBuffers[signalName] = ret;
536 post(
"new buffer: %s %i\n", signalName->
s_name, vec_size);
546 delete (this->_signalBuffers[signalName]);
547 this->_signalBuffers.erase(signalName);
550 #pragma mark properties
554 this->_getterOutputs[propertyName].push_back(getter_out);
555 this->_setterOutputs[propertyName].push_back(setter_out);
557 this->propertyNames[propertyName->
s_name] =
"<none>";
561 this->_getterOutputs.erase(propertyName);
562 this->_setterOutputs.erase(propertyName);
564 this->propertyNames.erase(propertyName->
s_name);
569 this->_propertyValues[propertyName] = list;
574 AtomList list = this->_propertyValues[propertyName];
583 for (map<string, string>::iterator it = this->propertyNames.begin(); it != this->propertyNames.end(); ++it) {
594 this->_instanceOutputs.push_back(outlet);
598 this->_instanceOutputs.erase(
remove(this->_instanceOutputs.begin(), this->_instanceOutputs.end(), outlet), this->_instanceOutputs.end());
603 for (OPOutputs::iterator it = this->_instanceOutputs.begin(); it != this->_instanceOutputs.end(); ++it) {
610 t_symbol* method_name = list[0].asSymbol();
614 OPOutputs* out1 = &this->_methodOutputs[method_name];
617 for (OPOutputs::iterator it = out1->begin(); it != out1->end(); ++it) {
624 t_outlet* out2 = this->_methodPointerOutputs[method_name];
636 t_symbol* property_name = list[0].asSymbol();
659 this->setAtomListProperty(property_name, list2);
661 OPOutputs* out1 = &this->_setterOutputs[property_name];
663 for (OPOutputs::iterator it = out1->begin(); it != out1->end(); ++it) {
670 t_symbol* property_name = list[0].asSymbol();
683 list2.
append(this->getAtomListProperty(property_name));
685 this->multipleOutput(list2);
687 OPOutputs* out1 = &this->_getterOutputs[property_name];
689 for (OPOutputs::iterator it = out1->begin(); it != out1->end(); ++it) {
698 for (map<t_symbol*, OPOutputs>::iterator it = this->_methodOutputs.begin(); it != this->_methodOutputs.end(); ++it) {
709 for (map<string, string>::iterator it = this->methodNames.begin(); it != this->methodNames.end(); ++it) {
716 #pragma mark reference counting
721 printf(
"OPInstance ref count: %i\n", this->_refCount);
728 printf(
"OPInstance ref count: %i\n", this->_refCount);
729 if (this->_refCount == 0)
736 return this->_refCount;
754 #pragma mark canvas additions - C style
756 static bool canvas_is_class(
t_canvas* canvas)
761 static bool canvas_is_instance(
t_canvas* canvas)
785 for (g2 = x->gl_list, nbox = 0; g2; g2 = g2->
g_next)
793 for (g2 = x->gl_list, count = 0; g2; g2 = g2->
g_next, count++)
800 sys_vgui(
"pdtk_canvas_getscroll .x%lx.c\n", x);
EXTERN int canvas_suspend_dsp(void)
EXTERN t_symbol * canvas_getdir(t_glist *x)
map< string, string > getMethodNames()
Definition: oop_common.h:136
AtomList getPropertyList()
Definition: oop_common.h:308
EXTERN void canvas_dirty(t_canvas *x, t_floatarg n)
map< string, string > getPropertyNames()
Definition: oop_common.h:140
EXTERN t_binbuf * binbuf_new(void)
EXTERN void outlet_bang(t_outlet *x)
Definition: oop_common.h:41
void freeMethod(t_symbol *methodName)
Definition: oop_common.h:512
Definition: ceammc_atom.h:23
void freeMethodPointerOutlet(string referenceName)
Definition: oop_common.h:248
t_outlet * getMethodPointerOutletForReferenceName(string referenceName)
Definition: oop_common.h:227
t_namelist * ce_path
Definition: oop_common.h:46
void freeMethodOutlet(string referenceName)
Definition: oop_common.h:243
EXTERN void glist_select(t_glist *x, t_gobj *y)
EXTERN t_symbol * canvas_getcurrentdir(void)
t_canvas * canvas
Definition: oop_common.h:380
AtomList getPropertyList()
Definition: oop_common.h:579
void freeSignal(t_symbol *signalName)
Definition: oop_common.h:542
EXTERN int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas, int crflag)
t_symbol * ce_dir
Definition: oop_common.h:42
~OPInstance()
Definition: oop_common.h:481
t_outlet * getMethodOutletForReferenceName(string referenceName)
Definition: oop_common.h:216
void addMethodPointerOutlet(string referenceName, t_outlet *outlet)
Definition: oop_common.h:210
AtomList getSignalList()
Definition: oop_common.h:330
void freeInstanceOut(t_outlet *outlet)
Definition: oop_common.h:596
GlobalData< OPClass * > OPClasses
class prototype
Definition: oop_common.h:343
EXTERN void glist_noselect(t_glist *x)
OPInstance(OPClass *_opclass)
Definition: oop_common.h:387
#define t_canvas
Definition: m_pd.h:205
static OPInstance * findByCanvas(t_canvas *canvas)
Definition: oop_common.h:740
void output(t_outlet *x) const
AtomList getDynamicMethodList()
Definition: oop_common.h:705
string class_name
Definition: oop_common.h:93
void readFile(string fileName, t_canvas *parent_canvas)
Definition: oop_common.h:151
void freeProperty(string propertyName)
Definition: oop_common.h:258
int ce_argc
Definition: oop_common.h:43
t_canvas * canvas
Definition: oop_common.h:95
t_sample * getBufferFor(t_symbol *signalName, int vec_size)
Definition: oop_common.h:529
void append(const Atom &a)
int ce_dollarzero
Definition: oop_common.h:45
void addProperty(string propertyName, string referenceName)
Definition: oop_common.h:253
GlobalData< OPInstance * > OPInstanceByCanvas
Definition: oop_common.h:348
struct _gobj * g_next
Definition: m_pd.h:212
string to_string(const T &t)
Definition: oop_common.h:32
void callSetter(AtomList list)
Definition: oop_common.h:634
PD_FLOATTYPE t_sample
Definition: m_pd.h:574
AtomList getAtomListProperty(t_symbol *propertyName)
Definition: oop_common.h:572
EXTERN t_symbol * gensym(const char *s)
void callMethod(AtomList list)
Definition: oop_common.h:608
static OPClass * findByCanvas(t_canvas *canvas)
Definition: oop_common.h:265
t_symbol * symbol
Definition: oop_common.h:96
EXTERN void canvas_free(t_canvas *x)
EXTERN void canvas_saveto(t_canvas *x, t_binbuf *b)
GlobalData< OPClass * > OPClassByCanvas
Definition: oop_common.h:77
void addMethod(t_symbol *methodName, t_outlet *outlet)
Definition: oop_common.h:507
vector< t_outlet * > OPOutputs
vector of method boxes outputs
Definition: oop_common.h:71
int getRefCount()
Definition: oop_common.h:734
static OPClass * findBySymbol(t_symbol *symbol)
Definition: oop_common.h:274
void setParentClass(OPClass *p_class)
Definition: oop_common.h:285
AtomList getMethodList()
Definition: oop_common.h:319
Definition: oop_common.h:352
t_atom * toPdData() const
#define t_binbuf
Definition: m_pd.h:195
void addMethodOutlet(string referenceName, t_outlet *outlet)
Definition: oop_common.h:204
EXTERN void canvas_setargs(int argc, t_atom *argv)
OPClass(string className)
Definition: oop_common.h:104
void retain()
Definition: oop_common.h:718
void callGetter(AtomList list)
Definition: oop_common.h:668
OPClass()
Definition: oop_common.h:99
Definition: ceammc_atomlist.h:29
EXTERN void canvas_setcurrent(t_canvas *x)
EXTERN void * getbytes(size_t nbytes)
static OPInstance * findBySymbol(t_symbol *symbol)
Definition: oop_common.h:746
#define t_canvasenvironment
Definition: g_canvas.h:77
#define t_outlet
Definition: m_pd.h:189
void multipleOutput(AtomList list)
Definition: oop_common.h:601
OPClass * getParentClass()
Definition: oop_common.h:290
void addMethodPointerOut(t_symbol *methodName, t_outlet *outlet)
Definition: oop_common.h:517
t_class * t_pd
Definition: m_pd.h:207
Definition: oop_common.h:81
EXTERN void canvas_vis(t_canvas *x, t_floatarg f)
EXTERN void canvas_loadbang(t_canvas *x)
void setAtomListProperty(t_symbol *propertyName, AtomList list)
Definition: oop_common.h:567
EXTERN void post(const char *fmt,...)
EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv)
EXTERN t_symbol s__X
Definition: m_pd.h:276
struct _class ** s_thing
Definition: m_pd.h:113
void release()
Definition: oop_common.h:725
void freeSignal(string signalName)
Definition: oop_common.h:302
char * s_name
Definition: m_pd.h:112
void freeMethod(string methodName)
Definition: oop_common.h:238
t_atom * ce_argv
Definition: oop_common.h:44
EXTERN void canvas_resume_dsp(int oldstate)
AtomList getMethodList()
Definition: oop_common.h:694
void writeFile(string fileName, t_canvas *parent_canvas)
Definition: oop_common.h:185
EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
vector< t_object * > OPProperties
vector of property boxes
Definition: oop_common.h:72
AtomList slice(int start) const
void addMethod(string methodName, string referenceName)
Definition: oop_common.h:199
EXTERN t_symbol s__N
Definition: m_pd.h:275
EXTERN void canvas_editmode(t_canvas *x, t_floatarg state)
EXTERN void sys_vgui(const char *fmt,...)
EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp)
OPInstance * parent
Definition: oop_common.h:385
EXTERN void glist_delete(t_glist *x, t_gobj *y)
GlobalData< OPClass * > OPClassBySymbol
Definition: oop_common.h:79
void addSignal(string signalName, string referenceName)
Definition: oop_common.h:297
void addInstanceOut(t_outlet *outlet)
Definition: oop_common.h:592
t_symbol * symbol
Definition: oop_common.h:382
void freeMethodPointerOut(t_symbol *methodName)
Definition: oop_common.h:522
EXTERN void * subcanvas_new(t_symbol *s)
string class_name
Definition: oop_common.h:379
map< string, t_outlet * > getMethodOutlets()
Definition: oop_common.h:144
void freeProperty(t_symbol *propertyName)
Definition: oop_common.h:559
GlobalData< OPInstance * > OPInstanceBySymbol
Definition: oop_common.h:350
void addProperty(t_symbol *propertyName, t_outlet *getter_out, t_outlet *setter_out)
Definition: oop_common.h:552