Beispiel #1
0
void QueueRamp::tick()
{
	unsigned long 	currentTime = systime_ms();
	TTUInt32		i;
	double			mapped;
	double			*current = currentValue;
	double			*target = targetValue;
	double			*start = startValue;
	float			ratio;
	
	if(active && functionUnit){
		if(currentTime > targetTime){
			active = 0;
			for(i=0; i < numValues; i++)
				currentValue[i] = targetValue[i];
		}
		else{
			ratio = (currentTime - startTime) / (float)ramptime;
			functionUnit->calculate(ratio, mapped);
			for(i=0; i < numValues; i++)
				current[i] = (target[i] * mapped) + (start[i] * (1 - mapped));
			qelem_set(qelem);							// set the qelem element to run again
		}
		(callback)(baton, numValues, currentValue);		// send the value to the host
	}
}
Beispiel #2
0
void otudp_changeHost(OTUDP *x, Symbol *hostName, long port) {	
	if (!x->o_writer) {
		error("¥ OTUDP: You can only change the host on write objects, not readers.");
		return;
	}
	
	if (x->o_desiredNewHostName != 0) {
		post("¥ OTUDP: Warning: we were already in the middle of changing the host");
		post("  to \"%s\".", x->o_desiredNewHostName);
	}
	
	// We're in the un-ready state until we unbind and rebind
	// (This eliminates the need for locks+semaphores)
	x->o_ready = 0;

	// Stash away new host info
	x->o_desiredNewHostName = hostName->s_name;
	x->o_desiredNewPort = port;
	
	/* Can't call OTUnbind @ Interrupt level or access DNR (to translate new symbolic host to an IP address)
	   at deferred task time, so set a Qelem to do it. */
	qelem_set(x->UnbindQelem);
	
	// post("*** Leaving otudp_changeHost()");
}
Beispiel #3
0
void *simplethread_threadproc(t_simplethread *x) 
{
	// loop until told to stop
	while (1) {

		// test if we're being asked to die, and if so return before we do the work
		if (x->x_systhread_cancel) 
			break;

		systhread_mutex_lock(x->x_mutex);	
		x->x_foo++;																// fiddle with shared data
		systhread_mutex_unlock(x->x_mutex);
		
		qelem_set(x->x_qelem);													// notify main thread using qelem mechanism
		
		
		systhread_sleep(x->x_sleeptime);						// sleep a bit
	}
	
	x->x_systhread_cancel = false;							// reset cancel flag for next time, in case
																				// the thread is created again
	
	systhread_exit(0);															// this can return a value to systhread_join();
	return NULL;
}
Beispiel #4
0
void odisplay_anything(t_odisplay *x, t_symbol *msg, short argc, t_atom *argv)
{
	t_atom av[argc + 1];
	int ac = argc;

	if (msg) {
        ac = argc + 1;
        atom_setsym(av, msg);
        if (argc > 0) {
            memcpy(av + 1, argv, argc * sizeof(t_atom));
        }
	} else {
        memcpy(av, argv, argc * sizeof(t_atom));
	}

    t_osc_msg_u *m = NULL;
    t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&m, msg, argc, argv);
    if(e){
        return;
    }
    t_osc_bndl_u *b = osc_bundle_u_alloc();
    osc_bundle_u_addMsg(b, m);
    t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
    odisplay_newBundle(x, b, bs);

#ifdef OMAX_PD_VERSION
    x->draw_new_data_indicator = 1;
    x->have_new_data = 1;
    jbox_redraw((t_jbox *)x);
#else
    x->draw_new_data_indicator = 1;
    x->have_new_data = 1;
    qelem_set(x->qelem);
#endif
}
Beispiel #5
0
/*------------------------------------ senseXProcessClock ---*/
static void
senseXProcessClock(SenseXData * xx)
{
    if (xx && (! xx->fStopping))
    {
        qelem_set(xx->fPollQueue);
    }
} // senseXProcessClock
Beispiel #6
0
/*------------------------------------ spaceballProcessClock ---*/
static void
spaceballProcessClock(SpaceballData * xx)
{
    if (xx && (! xx->fStopping))
    {
        qelem_set(xx->fPollQueue);
    }
} // spaceballProcessClock
Beispiel #7
0
/*------------------------------------ x10ProcessClock ---*/
static void
x10ProcessClock(X10ControlData * xx)
{
    if (xx && (! xx->fStopping))
    {
        qelem_set(xx->fPollQueue);
    }
} // x10ProcessClock
Beispiel #8
0
void gspline_dsp(t_gspline *x, t_signal **sp, short *count)
{
	x->x_sr = sys_getsr();
	
	x->x_maxdomain = MIN(x->x_maxdomain, x->x_sr);
	
	qelem_set(x->x_qelem);
}
Beispiel #9
0
MaxErr PlugOutNotify(PlugOutPtr self, SymbolPtr s, SymbolPtr msg, ObjectPtr sender, TTPtr data)
{
	if (sender == self->patcherview) {
		if (msg == _sym_attr_modified) {
			SymbolPtr name = (SymbolPtr)object_method((ObjectPtr)data, _sym_getname);
			if (name == _sym_dirty) {
				qelem_set(self->qelem);
			}
		}
		else if (msg == _sym_free)
			self->patcherview = NULL;
	}
	else {
		if (msg == _sym_free) {
			ObjectPtr	sourceBox;	
			ObjectPtr	sourceObject;
			long		sourceOutlet;
			ObjectPtr	destBox;		
			ObjectPtr	destObject;	
			long		destInlet;

			if (self->patcherview)
				goto out; // if there is no patcherview, then we are freeing the whole thing and can skip this

			#ifdef DEBUG_NOTIFICATIONS
			object_post(SELF, "patch line deleted");
			#endif // DEBUG_NOTIFICATIONS

			// get boxes and inlets
			sourceBox = jpatchline_get_box1(sender);
			if (!sourceBox)
				goto out;
			sourceObject = jbox_get_object(sourceBox);
			sourceOutlet = jpatchline_get_outletnum(sender);
			destBox = jpatchline_get_box2(sender);
			if (!destBox)
				goto out;
			destObject = jbox_get_object(destBox);
			destInlet = jpatchline_get_inletnum(sender);

			// if both boxes are audio graph objects 
			if ( zgetfn(sourceObject, GENSYM("audio.object")) && zgetfn(destObject, GENSYM("audio.object")) ) {
				#ifdef DEBUG_NOTIFICATIONS
				object_post(SELF, "deleting audio graph patchline!");
				#endif // DEBUG_NOTIFICATIONS

				object_method(destObject, GENSYM("audio.drop"), destInlet, sourceObject, sourceOutlet);
			}
		out:		
			;
		}
	}
	return MAX_ERR_NONE;
}
Beispiel #10
0
MaxErr UnpackNotify(UnpackPtr self, SymbolPtr s, SymbolPtr msg, ObjectPtr sender, TTPtr data)
{
	if (sender == self->patcherview) {
		if (msg == _sym_attr_modified) {
			SymbolPtr name = (SymbolPtr)object_method((ObjectPtr)data, _sym_getname);
			if (name == _sym_dirty) {
				qelem_set(self->qelem);
			}
		}
		else if (msg == _sym_free)
			self->patcherview = NULL;
	}
	else {
		if (msg == _sym_free) {
			ObjectPtr	sourceBox;	
			ObjectPtr	sourceObject;
			long		sourceOutlet;
			ObjectPtr	destBox;		
			ObjectPtr	destObject;	
			long		destInlet;			
			
			#ifdef DEBUG_NOTIFICATIONS
			object_post(SELF, "patch line deleted");
			#endif // DEBUG_NOTIFICATIONS

			// get boxes and inlets
			sourceBox = jpatchline_get_box1(sender);
			if (!sourceBox)
				goto out;
			sourceObject = jbox_get_object(sourceBox);
			sourceOutlet = jpatchline_get_outletnum(sender);
			destBox = jpatchline_get_box2(sender);
			if (!destBox)
				goto out;
			destObject = jbox_get_object(destBox);
			destInlet = jpatchline_get_inletnum(sender);
			
			// if both boxes are audio graph objects 
			if ( zgetfn(sourceObject, gensym("audio.object")) && zgetfn(destObject, gensym("audio.object")) ) {
				#ifdef DEBUG_NOTIFICATIONS
				object_post(SELF, "deleting audio graph patchline!");
				#endif // DEBUG_NOTIFICATIONS
				
				object_method(destObject, gensym("audio.drop"), destInlet, sourceObject, sourceOutlet);
                UnpackReset(self,  self->vectorSize);      // attempt for http://redmine.jamoma.org/issues/1248
			}
		out:		
			;
		}
	}
	return MAX_ERR_NONE;
}
Beispiel #11
0
t_max_err PackNotify(PackPtr self, t_symbol* s, t_symbol* msg, t_object* sender, TTPtr data)
{
	if (sender == self->patcherview) {
		if (msg == _sym_attr_modified) {
			t_symbol* name = (t_symbol*)object_method((t_object*)data, _sym_getname);
			if (name == _sym_dirty) {
				qelem_set(self->qelem);
			}
		}
		else if (msg == _sym_free)
			self->patcherview = NULL;
	}
	else {
		if (msg == _sym_free) {
			t_object*	sourceBox;
			t_object*	sourceObject;
			long		sourceOutlet;
			t_object*	destBox;
			t_object*	destObject;
			long		destInlet;

			#ifdef DEBUG_NOTIFICATIONS
			object_post(SELF, "patch line deleted");
			#endif // DEBUG_NOTIFICATIONS

			// get boxes and inlets
			sourceBox = jpatchline_get_box1(sender);
			if (!sourceBox)
				goto out;

			sourceObject = jbox_get_object(sourceBox);
			sourceOutlet = jpatchline_get_outletnum(sender);
			destBox = jpatchline_get_box2(sender);
			if (!destBox)
				goto out;
			destObject = jbox_get_object(destBox);
			destInlet = jpatchline_get_inletnum(sender);

			// if both boxes are graph objects
			if ( zgetfn(sourceObject, gensym("graph.object")) && zgetfn(destObject, gensym("graph.object")) ) {
				#ifdef DEBUG_NOTIFICATIONS
				object_post(SELF, "deleting graph patchline!");
				#endif // DEBUG_NOTIFICATIONS

				object_method(destObject, gensym("graph.drop"), destInlet, sourceObject, sourceOutlet);
			}
		out:
			;
		}
	}
	return MAX_ERR_NONE;
}
Beispiel #12
0
void testrunner_dointegration(t_testrunner *r)
{
	if (r->r_running)
		; // need to wait until the current test is done before starting the next one...
	else {
		if (s_current_test_index >= r->r_numtestnames)
			return;
			
		testrunner_one_integration(r, r->r_testnames[s_current_test_index]);
		s_current_test_index++;
	}
	qelem_set(r->r_qelem_iter);
}
Beispiel #13
0
void odisplay_doFullPacket(t_odisplay *x, long len, char *ptr)
{
	osc_bundle_s_wrap_naked_message(len, ptr);
	long copylen = len;
	char *copyptr = osc_mem_alloc(len);
	memcpy(copyptr, ptr, len);
	t_osc_bndl_s *b = osc_bundle_s_alloc(copylen, copyptr);
	odisplay_newBundle(x, NULL, b);
#ifdef OMAX_PD_VERSION
    jbox_redraw((t_jbox *)x);
#else
	qelem_set(x->qelem);
#endif
}
Beispiel #14
0
void otudp_changeReceivePort(OTUDP *x, long port) {
	if (x->o_writer) {
		error("¥ OTUDP: You can only change the receive port on read objects, not writers.");
		return;
	}

	// We're in the un-ready state until we unbind and rebind
	x->o_ready = 0;
	
	// Stash away new port so we can rebind when the Unbind completes.
	x->o_receiveInetPort = port;


	/* Unbinding happens via a Qelem (because for the case of "write" objects, the Unbind could
	   require DNR, which can't happen at interrupt or deferred-task time). */
	qelem_set(x->UnbindQelem);
}
Beispiel #15
0
void QueueRamp::go(TTUInt32 inNumValues, TTFloat64 *inValues, TTFloat64 time)
{
	TTUInt32 i;
	
	ramptime 	= time;
	startTime	= systime_ms();
	targetTime	= startTime + time;

	setNumValues(inNumValues);
	for(i=0; i<numValues; i++){
		targetValue[i] = inValues[i];
		startValue[i] = currentValue[i];
	}
	normalizedValue = 0.0;	// set the ramp to the beginning
	active = 1;
	qelem_set(qelem);		// Start the ramp!
}
//! \brief Callback function for system clock.
void flext::Timer::callback(Timer *tmr)
{
#if FLEXT_SYS == FLEXT_SYS_MAX
    if(tmr->queued) 
        qelem_set(tmr->qelem);
    else
#endif
        tmr->Work();

    if(tmr->period) {
		// reschedule
#if FLEXT_SYS == FLEXT_SYS_PD 
        clock_delay(tmr->clk,tmr->period*1000.);
#elif FLEXT_SYS == FLEXT_SYS_MAX
        clock_fdelay(tmr->clk,tmr->period*1000.);
#else
    #error Not implemented
#endif
    }
}
Beispiel #17
0
void paramui_menu_do(t_paramui *x, t_object *patcherview, t_pt px, long modifiers)
{
	t_jpopupmenu 		*p;
	t_symobject			*item;
	long				size, i;
	int 				selectedId;
	t_jfont 			*font;
	int					coord_x=0, coord_y=0;
	t_pt				pt;

	jbox_set_mousedragdelta((t_object *)x, 0);
	p = jpopupmenu_create();

	font = jfont_create(JAMOMA_MENU_FONT,
						JGRAPHICS_FONT_SLANT_NORMAL,
						JGRAPHICS_FONT_WEIGHT_NORMAL,
						JAMOMA_MENU_FONTSIZE);
	jpopupmenu_setfont(p, font);
	jfont_destroy(font);
	size = linklist_getsize(x->menu_items);
	for(i=0; i<size; i++){
		item = (t_symobject *)linklist_getindex(x->menu_items, i);
		if(!item->sym || (item->sym->s_name[0] == '\0') || item->sym->s_name[0] == '-')//{
			jpopupmenu_addseperator(p);
		else
			jpopupmenu_additem(p, i+1, item->sym->s_name, NULL, 0, item->flags, NULL);
	}

	object_method(patcherview, gensym("canvastoscreen"), 0.0, 0.0, &coord_x, &coord_y);	
	coord_x += x->box.b_patching_rect.x;
	coord_y += x->box.b_patching_rect.y;
	pt.x = coord_x;
	pt.y = coord_y;
	selectedId = jpopupmenu_popup_nearbox(p, (t_object*)x, patcherview, x->menu_selection+1); 
	if(selectedId){
		x->menu_selection = selectedId -1;
		qelem_set(x->menu_qelem);
	}

	jpopupmenu_destroy(p);
}
Beispiel #18
0
void testrunner_one_integration(t_testrunner *r, t_symbol *testname)
{
	t_testdb	*db = (t_testdb*)((t_testmaster*)(ps_testmaster->s_thing))->m_db;
	t_symbol	*pound_t = gensym("#T");
	
	if (!r->r_running) { // start it
		t_testunit	*testunit = (t_testunit*)testunit_new(NULL, 0, NULL);
		
		r->r_testid = testdb_createcase(db, testname->s_name);
		testunit->o_db = db;
		testunit->o_id = r->r_testid;
		testdb_log(db, r->r_testid, "preparing to run %s", testname->s_name);

		pound_t->s_thing = (t_object*)testunit;
		object_method(_sym_max->s_thing, _sym_openfile, symbol_unique(), testname, 0);
		
		object_attach_byptr_register(r, testunit, _sym_nobox);
		r->r_testunit = (t_test*)testunit;
		r->r_running = true;
	}
	else { // try to finish it
		if (r->r_terminated) {
			t_max_err	err = MAX_ERR_NONE;
			
			// moved to here from the block above because when loading a maxzip the patcher instantiation maybe deferred/asynchronous
			pound_t->s_thing = NULL;

			testdb_log(db, r->r_testid, "concluding test");
			
			err = object_free(r->r_testunit);
			
			testdb_log(db, r->r_testid, "test patcher freed with status %i", err);
			testdb_closecase(db, r->r_testid);	

			r->r_running = false;
			return;
		}
	}
	qelem_set(r->r_qelem);
}
//----------------------------------------------------------------------------------------------------------------
// clock tick
void udmx_tick(t_udmx *x) {

    if (!(x->dev_handle)) {
        qelem_set(x->m_qelem);
      //  clock_fdelay(x->m_clock,4000); //check again periodically
        return;
    }

    if (x->channel_changed_min < 512) { // there was a change since we last sent something
        
        if (x->channel_changed_max - x->channel_changed_min) {
            udmx_send_range(x,x->channel_changed_min,x->channel_changed_max);
        } else {
            udmx_send_single(x,x->channel_changed_min);
        }
        
    }
    
    x->channel_changed_min = 512;
    x->channel_changed_max = -1;
    x->clock_running = 0;
    
}
Beispiel #20
0
void InfoBang(InfoPtr self)
{
	qelem_set(self->qelem);
}
Beispiel #21
0
void twiliomax_receivesms(t_twiliomax *x, t_symbol *s, long argc, t_atom *argv) {
    qelem_set(x->m_receivesms_qelem);
}
Beispiel #22
0
// TODO: When running in the debugger, it seems like we are iterating through this function a whole bunch of times!
// Can we put it in a qelem or something so that it only gets called once? [TAP]
// But actually, maybe it is just a Max 4.6 funky Runtime thing?  Let's take a look again when we get to Max 5
void hub_examine_context(t_hub *x)
{
	AtomCount	argc = 0;
	AtomPtr		argv = NULL;
	SymbolPtr	context = jamoma_patcher_getcontext(x->container);

	// Try to get OSC Name of module from an argument
	jamoma_patcher_getargs(x->container, &argc, &argv);	// <-- this call allocates memory for argv
	if(argc){
		x->osc_name = atom_getsym(argv+(argc-1));
		sysmem_freeptr(argv);
	}
	else
		x->osc_name = _sym_nothing;
	
	// Try to get OSC Name of module from scripting name
	if(x->osc_name == _sym_nothing)
		x->osc_name = jamoma_patcher_getvarname(x->container);

	// In this case we overwrite whatever happened above
	if(context == gensym("toplevel")){
		x->osc_name = gensym("/editing_this_module");
		x->editing = true;
	}
	else{
		t_object*	patcher = jamoma_object_getpatcher((t_object*)x);
		t_object*	box = object_attr_getobj(patcher, jps_box);
		t_object*	ui = NULL;
		t_symbol*	objclass = NULL;
		
		x->editing = false;		
		ui = object_attr_getobj(patcher, gensym("firstobject"));
		while(ui){
			objclass = object_attr_getsym(ui, gensym("maxclass"));
			if(objclass == gensym("jcom.ui"))
				break;
			ui = object_attr_getobj(ui, gensym("nextobject"));
		}
		
		if(ui){
			t_rect	boxRect;
			t_rect	uiRect;
			
			if(context == gensym("bpatcher")){
				object_attr_get_rect(ui, _sym_presentation_rect, &uiRect);
				object_attr_get_rect(box, _sym_patching_rect, &boxRect);
				boxRect.width = uiRect.width;
				boxRect.height = uiRect.height;
				object_attr_set_rect(box, _sym_patching_rect, &boxRect);

				object_attr_get_rect(box, _sym_presentation_rect, &boxRect);
				boxRect.width = uiRect.width;
				boxRect.height = uiRect.height;
				object_attr_set_rect(box, _sym_presentation_rect, &boxRect);
			}
			else if(context == gensym("subpatcher")){
				object_attr_get_rect(ui, _sym_presentation_rect, &uiRect);
				object_attr_get_rect(patcher, _sym_defrect, &boxRect);
				boxRect.width = uiRect.width;
				boxRect.height = uiRect.height;
				object_attr_set_rect(patcher, _sym_defrect, &boxRect);				
				object_attr_setchar(patcher, _sym_toolbarvisible, 0);				
			}
		
		}
	}

	object_attr_setsym(x, _sym_name, x->osc_name);
	
	hub_subscriptions_refresh(x);
	hub_internals_create(x);

	qelem_unset(x->init_qelem);		// clear the last thing to make sure we don't call into this a bunch of times
	qelem_set(x->init_qelem);		// flag the queue for initialization
}
Beispiel #23
0
// we get the text, convert it to an OSC bundle, and then call the paint
// function via qelem_set which converts the OSC bundle back to text.
// We do this so that it's formatted nicely with no unnecessary whitespace
// and tabbed subbundles, etc.
void odisplay_gettext(t_odisplay *x)
{
	long size	= 0;
	char *text	= NULL;
#ifdef OMAX_PD_VERSION
	text = x->textbox->text;
#else
	t_object *textfield = jbox_get_textfield((t_object *)x);
	object_method(textfield, gensym("gettextptr"), &text, &size);
#endif
    
	odisplay_clearBundles(x);
	size = strlen(text); // the value returned in text doesn't make sense
	if(size == 0){
		return;
	}
	char *buf = text;

	if(text[size - 1] != '\n'){
		buf = alloca(size + 2);
		memcpy(buf, text, size);
		buf[size] = '\n';
		buf[size + 1] = '\0';
		size += 2;
	}

	t_osc_bndl_u *bndl_u = NULL;
	t_osc_err e = osc_parser_parseString(size, buf, &bndl_u);
	if(e){
#ifdef OMAX_PD_VERSION
//		x->parse_error = 1;
#endif
		object_error((t_object *)x, "error parsing bundle\n");
		return;
	}
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u);
	t_osc_bndl_s *bndl_s = NULL;
	osc_bundle_s_deepCopy(&bndl_s, bs);
	odisplay_newBundle(x, bndl_u, bndl_s);
#ifdef OMAX_PD_VERSION
    x->have_new_data = 1;
	jbox_redraw((t_jbox *)x);
#else
	x->have_new_data = 1;
	qelem_set(x->qelem);
#endif
	/*
	if(size > 2){
		int i;
		char *r = text + 1;
		char *w = text + 1;
		char *rm1 = text;
		for(i = 0; i <= size; i++){
			if(*rm1 == ' ' && *r == ' '){
				r++;
			}else{
				*w++ = *r++;
			}
			rm1++;
		}
	}
	*/
}