void* testrunner_new(t_symbol *name, long argc, t_atom *argv) { t_testrunner *r = (t_testrunner*)object_alloc(s_testrunner_class); if (r) { r->r_qelem = (t_qelem*)qelem_new(r, (method)testrunner_one_integration); r->r_qelem_iter = (t_qelem*)qelem_new(r, (method)testrunner_dointegration); attr_args_process(r, (short)argc, argv); } return r; }
UnpackPtr UnpackNew(SymbolPtr msg, AtomCount argc, AtomPtr argv) { UnpackPtr self; TTValue sr(sys_getsr()); long attrstart = attr_args_offset(argc, argv); // support normal arguments short i; TTValue v; TTErr err; self = UnpackPtr(object_alloc(sUnpackClass)); if (self) { self->maxNumChannels = 2; // An initial argument to this object will set the maximum number of channels if(attrstart && argv) self->maxNumChannels = atom_getlong(argv); ttEnvironment->setAttributeValue(kTTSym_sampleRate, sr); v.setSize(2); v.set(0, TT("thru")); v.set(1, 1); // arg is the number of inlets err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v); //self->audioGraphObject->getUnitGenerator()->setAttributeValue(TT("linearGain"), 1.0); attr_args_process(self, argc, argv); object_obex_store((void*)self, _sym_dumpout, (object*)outlet_new(self, NULL)); // dumpout dsp_setup((t_pxobject*)self, 1); for(i=0; i < self->maxNumChannels; i++) outlet_new((t_pxobject*)self, "signal"); self->qelem = qelem_new(self, (method)UnpackQFn); self->obj.z_misc = Z_NO_INPLACE | Z_PUT_LAST; } return self; }
//---------------------------------------------------------------------------------------------------------------- // object creation void *udmx_new(t_symbol *s, long argc, t_atom *argv) { t_atom *ap; t_int16 n; n = 0; // n = int argument typed into object box (A_DEFLONG) -- defaults to 0 if no args are typed t_udmx *x = (t_udmx *)object_alloc(udmx_class); intin(x,1); // create a second int inlet (leftmost inlet is automatic - all objects have one inlet by default) x->m_clock = clock_new(x,(method)udmx_tick); // make new clock for polling and attach tick function to it x->m_qelem = qelem_new((t_object *)x, (method)find_device); x->msgOutlet = outlet_new(x,0L); //create right outlet x->statusOutlet = outlet_new(x,0L); //create an outlet for connected flag x->correct_adressing = 1; if (argc) { ap = argv; switch (atom_gettype(ap)) { case A_LONG: n = atom_getlong(ap); break; default: break; } ap = &argv[argc-1]; switch (atom_gettype(ap)) { case A_LONG: if (atom_getlong(ap) == 0 ) { x->correct_adressing = 0; } break; default: break; } } if(x->correct_adressing) {n = n - 1;} if (n < 0) n = 0; if (n > 511) n = 511; x->channel = n; x->debug_flag = 0; x->channel_changed_min = 512; x->channel_changed_max = -1; x->clock_running = 0; x->dev_handle = NULL; x->speedlim = SPEED_LIMIT; x->usb_devices_seen = -1; clock_fdelay(x->m_clock,100); usb_init(); return(x); // return a reference to the object instance }
PackPtr PackNew(t_symbol* msg, long argc, t_atom* argv) { PackPtr self; TTValue v; TTErr err; self = PackPtr(object_alloc(sPackClass)); if (self) { object_obex_store((void*)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); self->graphOutlets[0] = outlet_new(self, "graph.connect"); v.resize(2); v[0] = "graph.input"; v[1] = 1; err = TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&self->graphObject, v); ((TTGraphInput*)self->graphObject->mKernel.instance())->setOwner(self->graphObject); if (!self->graphObject->mKernel.valid()) { object_error(SELF, "cannot load Jamoma object"); return NULL; } self->graphDictionary = new TTDictionary; self->graphDictionary->setSchema(TT("none")); self->graphDictionary->append(TT("outlet"), 0); attr_args_process(self, argc, argv); self->qelem = qelem_new(self, (method)PackQFn); // PackStartTracking(self); defer_low(self, (method)PackStartTracking, NULL, 0, NULL); } return self; }
PackPtr PackNew(SymbolPtr msg, AtomCount argc, AtomPtr argv) { PackPtr self; TTValue v; TTErr err; self = PackPtr(object_alloc(sPackClass)); if (self) { object_obex_store((void*)self, _sym_dumpout, (ObjectPtr)outlet_new(self, NULL)); self->graphOutlets[0] = outlet_new(self, "graph.connect"); v.setSize(2); v.set(0, TT("graph.input")); v.set(1, TTUInt32(1)); err = TTObjectInstantiate(TT("graph.object"), (TTObjectPtr*)&self->graphObject, v); ((TTGraphInput*)self->graphObject->mKernel)->setOwner(self->graphObject); if (!self->graphObject->mKernel) { object_error(SELF, "cannot load Jamoma object"); return NULL; } self->graphDictionary = new TTDictionary; self->graphDictionary->setSchema(TT("none")); self->graphDictionary->append(TT("outlet"), 0); attr_args_process(self, argc, argv); self->qelem = qelem_new(self, (method)PackQFn); // PackStartTracking(self); defer_low(self, (method)PackStartTracking, NULL, 0, NULL); } return self; }
InfoPtr InfoNew(t_symbol* msg, long argc, t_atom* argv) { InfoPtr self; TTValue v; TTErr err; self = InfoPtr(object_alloc(sInfoClass)); if (self) { object_obex_store((TTPtr)self, _sym_dumpout, (t_object*)outlet_new(self, NULL)); self->outletNumChannels = outlet_new((t_pxobject*)self, 0); self->outletVectorSize = outlet_new((t_pxobject*)self, 0); self->outletSampleRate = outlet_new((t_pxobject*)self, 0); self->outletSmartSignal = outlet_new((t_pxobject*)self, "audio.connect"); self->qelem = qelem_new(self, (method)InfoQfn); v.resize(2); v[0] = "thru"; v[1] = 1; // we set it up with 1 inlet, and later modify to 2 inlets if the connection is made err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v); if (!self->audioGraphObject->getUnitGenerator().valid()) { object_error(SELF, "cannot load Jamoma DSP object"); return NULL; } attr_args_process(self, argc, argv); } return self; }
PlugOutPtr PlugOutNew(SymbolPtr msg, AtomCount argc, AtomPtr argv) { PlugOutPtr self = PlugOutPtr(object_alloc(sPlugOutClass)); TTValue v; TTErr err; if (self) { v.setSize(2); v.set(0, TT("plugtastic.output")); v.set(1, 2); err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v); v = TTPtr(self->audioGraphObject); object_obex_store((void*)self, _sym_dumpout, (object*)outlet_new(self, NULL)); self->audioGraphOutlet = outlet_new(self, "audio.connect"); self->qelem = qelem_new(self, (method)PlugOutQFn); object_obex_lookup(self, GENSYM("#P"), &self->patcher); self->pluginName = object_attr_getsym(self->patcher, _sym_name); self->pluginVersion = GENSYM("1.0"); self->pluginVersionHex = GENSYM("0x00010000"); self->pluginManufacturer = GENSYM("Plugtastic"); self->pluginManufacturerCode = GENSYM("74Ob"); self->pluginID = GENSYM("ftmp"); attr_args_process(self, argc, argv); } return self; }
/* \param qu determines whether timed messages should be queued (low priority - only when supported by the system). */ flext::Timer::Timer(bool qu): queued(qu), clss(NULL),userdata(NULL), period(0) { #if FLEXT_SYS == FLEXT_SYS_PD clk = (t_clock *)clock_new(this,(t_method)callback); #elif FLEXT_SYS == FLEXT_SYS_MAX clk = (t_clock *)clock_new(this,(t_method)callback); if(queued) qelem = (t_qelem *)qelem_new(this,(method)queuefun); #else #error Not implemented #endif }
void *simplethread_new(void) { t_simplethread *x; x = (t_simplethread *)object_alloc(simplethread_class); x->x_outlet = outlet_new(x,NULL); x->x_qelem = qelem_new(x,(method)simplethread_qfn); x->x_systhread = NULL; systhread_mutex_new(&x->x_mutex,0); x->x_foo = 0; x->x_sleeptime = 1000; return(x); }
OutPtr OutNew(SymbolPtr msg, AtomCount argc, AtomPtr argv) { OutPtr self; TTValue sr(sys_getsr()); long attrstart = attr_args_offset(argc, argv); // support normal arguments //short i; TTValue v; TTErr err; self = OutPtr(object_alloc(sOutClass)); if (self) { self->maxNumChannels = 2; // An initial argument to this object will set the maximum number of channels if(attrstart && argv) self->maxNumChannels = atom_getlong(argv); ttEnvironment->setAttributeValue(kTTSym_sampleRate, sr); // setup the output_buffer according to channnel number self->output_buffer = (t_atom *)malloc(self->maxNumChannels * sizeof(t_atom)); v.setSize(2); v.set(0, TT("thru")); v.set(1, 1); // arg is the number of inlets err = TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&self->audioGraphObject, v); //self->audioGraphObject->getUnitGenerator()->setAttributeValue(TT("linearGain"), 1.0); attr_args_process(self, argc, argv); object_obex_store((void*)self, _sym_dumpout, (object*)outlet_new(self, NULL)); // dumpout self->s_out = listout((t_pxobject *)self); // the list outlet dsp_setup((t_pxobject*)self, 1); self->clock = clock_new(self, (method)OutTick); self->qelem = qelem_new(self, (method)OutQFn); self->obj.z_misc = Z_NO_INPLACE | Z_PUT_LAST; } return self; }
void *hub_new(t_symbol *s, long argc, t_atom *argv) { short i; long attrstart = attr_args_offset(argc, argv); t_hub *x = (t_hub *)object_alloc(s_hub_class); t_symbol *name = _sym_nothing; t_atom a[2]; if(attrstart && argv) atom_arg_getsym(&name, 0, attrstart, argv); else{ t_object* patcher = jamoma_object_getpatcher((t_object*)x); t_symbol* filepath = object_attr_getsym(patcher, _sym_filepath); char pathstr[MAX_PATH_CHARS]; char* filename = 0; strncpy_zero(pathstr, filepath->s_name, MAX_PATH_CHARS); filename = strrchr(pathstr, '.'); if(filename) { *filename = 0; // strip the suffix by setting '.' to terminating NULL char filename = strrchr(pathstr, '/'); if (filename) { // Our module name is the patchers name since the patcher is typically located // at /some/where/nameToUseForModule.maxpat filename++; // get rid of slash name = gensym(filename); } else name = gensym(pathstr); } else { // We are an unnamed jcom.hub inserted into an unsaved max patcher which has // no '.' in it's filename. Just leave as untitled, at least until it is saved. name = gensym("Untitled"); } } if(x){ for(i=k_num_outlets; i > 0; i--) x->outlets[i-1] = outlet_new(x, 0); object_obex_store((void *)x, _sym_dumpout, (t_object *)x->outlets[k_outlet_dumpout]); x->init_qelem = qelem_new(x, (method)hub_qfn_init); // set default attributes x->attr_name = name; x->osc_name = _sym_nothing; x->attr_type = jps_control; x->attr_description = _sym_nothing; x->attr_algorithm_type = jps_default; // poly for audio, jitter for video, control for control x->attr_size = jps_1U_half; x->attr_inspector = 0; x->using_wildcard = false; x->in_object = NULL; // module MUST have a jcom.in object x->out_object = NULL; // the jcom.out object is optional x->gui_object = NULL; // jcom.remote in the gui x->num_parameters = 0; for(i=0; i<MAX_NUM_CHANNELS; i++) x->meter_object[i] = NULL; x->preset = new presetList; // begin with no presets x->subscriber = new subscriberList; // ... and no subscribers attr_args_process(x, argc, argv); // handle attribute args x->jcom_send = NULL; x->jcom_receive = NULL; atom_setsym(a, jps_jcom_remote_fromModule); x->jcom_send = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a); atom_setsym(a, jps_jcom_remote_toModule); x->jcom_receive = (t_object*)object_new_typed(_sym_box, jps_jcom_receive, 1, a); object_method(x->jcom_receive, jps_setcallback, &hub_receive_callback, x); if(!g_jcom_send_notifications){ atom_setsym(a, gensym("notifications")); g_jcom_send_notifications = (t_object*)object_new_typed(_sym_box, jps_jcom_send, 1, a); } x->container = jamoma_object_getpatcher((t_object*)x); // The following must be deferred because we have to interrogate our box, // and our box is not yet valid until we have finished instantiating the object. // Trying to use a loadbang method instead is also not fully successful (as of Max 5.0.6) defer_low(x, (method)hub_examine_context, 0, 0, 0); } return x; }
t_paramui* paramui_new(t_symbol *s, long argc, t_atom *argv) { t_paramui *x = NULL; t_dictionary *d = NULL; long flags; t_atom a[LISTSIZE+34]; long argLen; //t_max_err err = MAX_ERR_NONE; if(!(d=object_dictionaryarg(argc, argv))) return NULL; if(x = (t_paramui*)object_alloc(s_ui_class)){ flags = 0 | JBOX_DRAWFIRSTIN | JBOX_NODRAWBOX // | JBOX_DRAWINLAST | JBOX_TRANSPARENT // | JBOX_NOGROW // | JBOX_GROWY // | JBOX_GROWBOTH // | JBOX_IGNORELOCKCLICK | JBOX_HILITE // | JBOX_BACKGROUND // | JBOX_NOFLOATINSPECTOR | JBOX_TEXTFIELD ; jbox_new(&x->box, flags, argc, argv); x->box.b_firstin = (t_object *)x; x->outlet = outlet_new(x, 0L); x->menu_items = NULL; attr_dictionary_process(x, d); // handle attribute args // a textlayout is used for the displaying the value and the unit x->layout_value = jtextlayout_create(); x->layout_unit = jtextlayout_create(); jbox_ready(&x->box); x = (t_paramui *)object_register(CLASS_BOX, symbol_unique(), x); x->menu_items = (t_linklist *)linklist_new(); paramui_menu_build(x); x->menu_qelem = qelem_new(x, (method)paramui_menu_qfn); // here we create our internal instance of jcom.parameter atom_setsym(a+0, x->attr_name); atom_setsym(a+1, gensym("@type")); atom_setsym(a+2, x->attr_type); atom_setsym(a+3, gensym("@ramp/drive")); atom_setsym(a+4, x->attr_rampDrive); atom_setsym(a+5, gensym("@ramp/function")); atom_setsym(a+6, x->attr_rampFunction); atom_setsym(a+7, gensym("@view/freeze")); atom_setlong(a+8, x->attr_uiFreeze); atom_setsym(a+9, gensym("@value/stepsize")); atom_setfloat(a+10, x->attr_stepsize); atom_setsym(a+11, gensym("@priority")); atom_setlong(a+12, x->attr_priority); atom_setsym(a+13, gensym("@range/bounds")); atom_setfloat(a+14, x->attr_range[0]); atom_setfloat(a+15, x->attr_range[1]); atom_setsym(a+16, gensym("@repetitions/allow")); atom_setlong(a+17, x->attr_repetitions); atom_setsym(a+18, gensym("@range/clipmode")); atom_setsym(a+19, x->attr_clipmode); atom_setsym(a+20, gensym("@description")); atom_setsym(a+21, x->attr_description); atom_setsym(a+22, gensym("@dataspace")); atom_setsym(a+23, x->attr_dataspace); atom_setsym(a+24, gensym("@dataspace/unit/active")); atom_setsym(a+25, x->attr_unitActive); atom_setsym(a+26, gensym("@dataspace/unit/native")); atom_setsym(a+27, x->attr_unitNative); if(x->attr_defaultSize){ atom_setsym(a+28, gensym("@value/default")); sysmem_copyptr(x->attr_default, a+29, sizeof(t_atom) * x->attr_defaultSize); argLen = 29 + x->attr_defaultSize; } else argLen = 28; jcom_core_loadextern(gensym("jcom.parameter"), argLen, a, &x->obj_parameter); } return x; }
void *odisplay_new(t_symbol *msg, short argc, t_atom *argv){ t_odisplay *x; t_dictionary *d = NULL; long boxflags; // box setup if(!(d = object_dictionaryarg(argc, argv))){ return NULL; } boxflags = 0 | JBOX_DRAWFIRSTIN | JBOX_NODRAWBOX | JBOX_DRAWINLAST | JBOX_TRANSPARENT //| JBOX_NOGROW //| JBOX_GROWY //| JBOX_GROWBOTH //| JBOX_HILITE //| JBOX_BACKGROUND //| JBOX_DRAWBACKGROUND //| JBOX_NOFLOATINSPECTOR //| JBOX_MOUSEDRAGDELTA | JBOX_TEXTFIELD ; if((x = (t_odisplay *)object_alloc(odisplay_class))){ jbox_new((t_jbox *)x, boxflags, argc, argv); x->ob.b_firstin = (void *)x; x->outlet = outlet_new(x, NULL); //x->proxy = proxy_new(x, 1, &(x->inlet)); x->bndl_u = NULL; x->bndl_s = NULL; x->newbndl = 0; x->textlen = 0; x->text = NULL; //x->bndl_has_been_checked_for_subs = 0; //x->bndl_has_subs = 0; critical_new(&(x->lock)); x->qelem = qelem_new((t_object *)x, (method)odisplay_refresh); x->new_data_indicator_clock = clock_new((t_object *)x, (method)odisplay_refresh); x->have_new_data = 1; x->draw_new_data_indicator = 0; attr_dictionary_process(x, d); t_object *textfield = jbox_get_textfield((t_object *)x); if(textfield){ object_attr_setchar(textfield, gensym("editwhenunlocked"), 0); textfield_set_readonly(textfield, '1'); textfield_set_selectallonedit(textfield, '1'); textfield_set_textmargins(textfield, 5, 5, 5, 15); textfield_set_textcolor(textfield, &(x->text_color)); } jbox_ready((t_jbox *)x); //odisplay_gettext(x); odisplay_clear(x); return x; } return NULL; }
void *otudp_new(Symbol *s, short argc, Atom *argv) { OTUDP *x; OSStatus err; InetHost host; // These variables will be filled with the args we parse int writer; char *inetHostName = 0; InetPort port = 0; InetPort receivePort = 0; long nbufs = DEFAULT_NUM_BUFFERS; long bufsize = DEFAULT_BUFFER_SIZE; if (ParseArgs(argc, argv, &writer, &inetHostName, &port, &receivePort, &nbufs, &bufsize) == 0) { error("¥ OTUDP usage: \"otudp read <port> [bufsize <nbytes>] [nbufs <n>]\" or " "\"otudp write <hostname> <port> [bufsize <nbytes>] [nbufs <n>]\""); return 0; } if (writer) { if (LookUpInetHost(inetHostName, &host) == 0) { error("otudp: Couldn't make sense of Internet host \"%s\"", inetHostName); return 0; } } x = newobject(otudp_class); /* x->o_a5 = (long) LMGetCurrentA5(); */ x->o_writer = writer; x->o_inetHostName = inetHostName; x->o_inetPort = port; x->o_inetHost = host; x->o_receiveInetPort = receivePort; x->o_desiredNewHostName = 0; x->o_desiredNewPort = 0; x->o_ready = 0; x->o_errorreporting = 1; x->o_ever_dropped_a_packet = 0; x->o_num_dropped_packets = 0; x->o_outlet = outlet_new(x,0L); x->o_clock = clock_new(x, (method) otudp_output); InitPBFIFO(&(x->pendingBuffers)); x->o_complained_about_old_msgs = 0; OTClearLock(&(x->o_readlock)); x->o_semaphoreTest = x->o_semaphoreTestFailureCount = 0; /* Allocate packet buffers */ x->bufsize = bufsize; x->nbufs = nbufs; if (nbufs == 0) { x->allBuffers = x->freeBuffers = 0; } else { x->allBuffers = InitPackets(bufsize, nbufs); if (x->allBuffers == 0) { error("¥ OTUDP: Out of memory (Couldn't allocate buffers to store incoming packets)"); return 0; } x->freeBuffers = x->allBuffers; } x->o_udp_ep = 0; // Indicates endpoint hasn't been created yet. err = OTAsyncOpenEndpointInContext(OTCreateConfiguration(kUDPName), 0, &(x->epinfo), NewOTNotifyUPP(OTUDPNotifier), x, OTContext); if (err != noErr) { error("¥ otudp: Error %d from OTAsyncOpenEndpoint. This is bad.", err); return 0; } // This didn't actually make the endpoint; my notifier should get the T_OPENCOMPLETE // event after the endpoint is opened. /* Create a Qelem that will let us change the host at non-interrupt, non-defered-task-time level */ x->UnbindQelem = qelem_new(x, (method)unbind_from_qelem); return (x); }
void *twiliomax_new(t_symbol *s, long argc, t_atom *argv) { t_twiliomax *x = NULL; if ((x = (t_twiliomax *)object_alloc(twiliomax_class))) { if (argc != 2) { object_error((t_object *)x, "Please provide a twilio account SID and auth token"); } else if (argv[0].a_type != A_SYM || argv[1].a_type != A_SYM) { object_error((t_object *)x, "All arguments should be strings"); } else { x->m_outlet1 = outlet_new((t_object *)x, NULL); x->curl = curl_easy_init(); x->twilio_account_sid = atom_getsym(&argv[0])->s_name; char *twilio_account_auth_token = atom_getsym(&argv[1])->s_name; char userpass[strlen(x->twilio_account_sid)+strlen(twilio_account_auth_token)+1]; sprintf(userpass, "%s:%s", x->twilio_account_sid, twilio_account_auth_token); curl_easy_setopt(x->curl, CURLOPT_USERPWD, userpass); x->twilio_phone_number = calloc(1, sizeof(struct incoming_phone_number)); int get_number_status = get_incoming_phone_number(x->twilio_account_sid, x->curl, x->twilio_phone_number); if (get_number_status < 0) { switch (get_number_status) { case -1: { object_error((t_object *)x, "Unable to communicate with twilio to retrieve inbound phone numbers."); object_error((t_object *)x, "Check your internet connection and your twilio credentials and try again"); break; } case -2: { object_error((t_object *)x, "The JSON response from twilio did not contain any incoming phone numbers"); object_error((t_object *)x, "Make sure your twilio account has at least one paid, active phone number"); break; } default: break; } } if (!x->twilio_phone_number->phone_number || !x->twilio_phone_number->sid) { object_error((t_object *)x, "The JSON response from twilio did not contain any incoming phone numbers"); object_error((t_object *)x, "Make sure your twilio account has at least one paid, active phone number"); } x->mongoose = NULL; x->clocaltunnel = NULL; x->m_receivesms_qelem = qelem_new((t_object *)x, (method)twiliomax_receivesms_qtask); } } return (x); }
QueueRamp::QueueRamp(RampUnitCallback aCallbackMethod, void *aBaton) : RampUnit("ramp.queue", aCallbackMethod, aBaton) { active = 0; qelem = qelem_new(this, (method)queueramp_qfn); // install the queue element }