Exemple #1
0
void LCD_drag(Lcd *x, Point pt, short button_down)
{
	Rect	r;
	short		slider;
	Atom	aList[2];
	short 	way;
	
	EnterCallback();
	
#ifdef debug
	post("¥LCD_drag - start");
#endif
	r = x->lcd_box.b_rect;
	
	if (x->local)
	{
		if (button_down) {
			LCD_MoveTo(x,(long)(x->lcd_where.h),(long)(x->lcd_where.v));
			LCD_LineTo(x,(long)(pt.h-r.left),(long)(pt.v-r.top));
		}
		else
			x->lcd_shiftClick = false;
	}
	
	LCD_posToRC(x,pt);

	SETLONG(&aList[0],(long)(pt.h-r.left));
	SETLONG(&aList[1],(long)(pt.v-r.top));
	/* lockouts added by DDZ 12/14/92 */
	way = lockout_set(1);
	outlet_list(x->lcd_outlet,0L,2,aList);
	lockout_set(way);
	ExitCallback();
}
Exemple #2
0
void otudp_output(OTUDP *x) {
	// This is called by the Max clock.  It's guaranteed not to be called
	// at notifier level, although if we're in Overdrive this will be called
	// at interrupt level.
	Atom arguments[2];
	PacketBuffer b;
	short oldLockout;

	
	// BufferSanityCheck(x, 0, 0, 0);

	while (1) {
		oldLockout = AcquireLock(x);
		b = PBFIFODequeue(&(x->pendingBuffers));
		ReleaseLock(x,oldLockout);
		
		if (b == 0) break;
		
		SETLONG(&arguments[0], b->n);
		SETLONG(&arguments[1], (long) b->buf);
		outlet_anything(x->o_outlet, ps_FullPacket, 2, arguments);
		
		oldLockout = AcquireLock(x);
		PacketBufferListPush(b, &(x->freeBuffers));
		ReleaseLock(x,oldLockout);		
		
	}
	
	// BufferSanityCheck(x, 0, 0, 0);
}
Exemple #3
0
void LCD_click(Lcd *x, Point where, short modifiers)
{
	short	i;
	Rect	r;
	Atom	aList[2];
	short		way;
	
	EnterCallback();
	
#ifdef debug
	post("¥LCD_click - start");
#endif
	r = x->lcd_box.b_rect;
	x->lcd_shiftClick = modifiers&shiftKey;

	if (x->local)
		LCD_MoveTo(x,(long)(where.h-r.left),(long)(where.v-r.top));

	LCD_posToRC(x,where);
	wind_drag((void *)LCD_drag,x,where);

	SETLONG(&aList[0],(long)(where.h-r.left));
	SETLONG(&aList[1],(long)(where.v-r.top));
	/* lockouts added by DDZ 12/14/92 */
	way = lockout_set(1);
	outlet_list(x->lcd_outlet,0L,2,aList);
	lockout_set(way);
	ExitCallback();
}	/* ms_click */
static VarEntry *
add_private(ClipMachine * ClipMachineMemory, long hash)
{
    long *p;

    VarEntry *vp, *np;

    ClipFrame *fp;

    if (ClipMachineMemory->inMacro)
        fp = ClipMachineMemory->inMacro;
    else
        fp = ClipMachineMemory->fp;

    if (fp)
    {
        p = fp->privates_of_ClipFrame;
        if (p)
        {
            int n;

            long c;

            for (n = *p, p++; n >= 0; n--, p++)
                if (hash == GETLONG(p))
                {
                    vp = (VarEntry *) HashTable_fetch(ClipMachineMemory->privates, hash);
                    if (vp)
                        return vp;
                }
            p = fp->privates_of_ClipFrame;
            c = GETLONG(p);
            p = (long *) realloc(p, (c + 2) * sizeof(long));

            SETLONG(p, c + 1);
            SETLONG(p + c + 1, hash);
            fp->privates_of_ClipFrame = p;
        }
        else
        {
            p = fp->privates_of_ClipFrame = (long *) malloc(sizeof(long) * 2);

            SETLONG(p, 1);
            SETLONG(p + 1, hash);
        }
    }

    vp = (VarEntry *) HashTable_fetch(ClipMachineMemory->privates, hash);
    np = new_VarEntry(hash);
    if (!vp)
        HashTable_insert(ClipMachineMemory->privates, np, hash);
    else
    {
        np->VarEntry_next_of_VarEntry = vp;
        HashTable_remove(ClipMachineMemory->privates, hash);
        HashTable_store(ClipMachineMemory->privates, np, hash);
    }
    return np;
}
Exemple #5
0
void LCD_MoveTo(Lcd *x, long deltaX, long deltaY)
{	
	Atom a[2];
	
	EnterCallback();
	SETLONG(a,deltaX);
	SETLONG(a+1,deltaY);
	defer(x,(method)LCD_doMoveTo,0L,2,a);
	ExitCallback();
}
Exemple #6
0
void LCD_font(Lcd *x, long font, long size)
{
	Atom a[2];
	
	EnterCallback();
	SETLONG(a,font);
	SETLONG(a+1,size);
	defer(x,(method)LCD_dofont,0L,2,a);
	ExitCallback();
}
Exemple #7
0
// Method for Posting Status
static void teabox_getstatus(t_teabox *x)
{
    t_atom	status_atom;

    if(x->hw_version) {
        SETLONG(&status_atom, 1);
    }
    else {
        SETLONG(&status_atom, 0);
    }
    outlet_anything(x->outlet, gensym("status"), 1, &status_atom);
}
Exemple #8
0
void LCD_frameRect(Lcd *x, long left, long top, long right, long bottom, long color)
{	
	Atom a[5];
	
	EnterCallback();
	SETLONG(a,left);
	SETLONG(a+1,top);
	SETLONG(a+2,right);
	SETLONG(a+3,bottom);
	SETLONG(a+4,color);
	defer(x,(method)LCD_doframeRect,0L,5,a);
	ExitCallback();
}
Exemple #9
0
void LCD_linesegment(Lcd *x, long fromx, long fromy, long tox, long toy, long color)
{	
	Atom a[5];
	
	EnterCallback();
	SETLONG(a,fromx);
	SETLONG(a+1,fromy);
	SETLONG(a+2,tox);
	SETLONG(a+3,toy);
	SETLONG(a+4,color);
	defer(x,(method)LCD_dolinesegment,0L,5,a);
	ExitCallback();
}
Exemple #10
0
void do_output(OTTCP *x) {
	// This is called by the Max clock.  It's guaranteed not to be called
	// at notifier level, although if we're in Overdrive this will be called
	// at interrupt level.
	Atom arguments[2];
	short oldLockout;

	x->o_nextRequest = NO_REQUEST;

#ifdef DEBUG
	printOutput(x);
#endif

	SETLONG(&arguments[0], x->o_bytesRead);
	SETLONG(&arguments[1], (long) x->o_currentReadBuf);
	if (x->o_whatToOutput == GET_NBYTES) {
		outlet_anything(x->o_outlet, ps_OTTCP_nbytes, 2, arguments);
	} else if (x->o_whatToOutput == GET_DELIM) {
		outlet_anything(x->o_outlet, ps_OTTCP_delim, 2, arguments);
	} else {
		post("е OTUDP: error: o_whatToOutput is %ld in do_output", x->o_whatToOutput);
	}
	
	// Now that we finished outputting the buffer, we can reset all our state to be
	// ready for the next one
	oldLockout = AcquireLock(x);
	
	// Swap the double buffers
	if (x->o_currentReadBuf == x->o_ReadBufA) {
		x->o_currentReadBuf = x->o_ReadBufB;
		x->o_nextReadBuf = x->o_ReadBufA;
	} else {
		x->o_currentReadBuf = x->o_ReadBufA;
		x->o_nextReadBuf = x->o_ReadBufB;
	}
	
	x->o_bytesRead = x->o_bytesReadForNextTime;
	x->o_bytesReadForNextTime = 0;
	ChangeState(x, x->o_nextRequest);
	
	ReleaseLock(x,oldLockout);

	if (x->o_state == GET_NBYTES || x->o_state == GET_DELIM) {
		if (SeeIfWeCanAlreadyOutput(x)) return;
	}
	
	if (x->o_datawaiting) {
		// We know there's something in the TCP buffer that we haven't looked at yet.  Now's the time.
		ottcp_handleIncomingData(x);
	}
}
/*------------------------------------ cmd_GetAllVariables ---*/
Pvoid
cmd_GetAllVariables(RcxControlPtr xx)
{
  EnterCallback();
  if (xx)
  {
#if FOR_MAC_PPC
    if (rcxSynchronize(xx))
    {
      Atom  response[RCX_NUM_VARIABLES];
      bool  okSoFar = true;

      for (ushort ii= 0; (ii < RCX_NUM_VARIABLES) && okSoFar; ++ii)
      {
        long value;

        if (rcxGetValue(xx, MAKE_RCX_VALUE(RCX_VARIABLE_TYPE, ii), value))
          SETLONG(response + ii, value);
        else
          okSoFar = false;
      }
      if (okSoFar)
      {
        outlet_bang(xx->fCommandComplete);
        outlet_anything(xx->fDataOut, gAllVariablesSymbol, RCX_NUM_VARIABLES, response);
      }
      else
        outlet_bang(xx->fErrorBangOut);
    }
    else
      outlet_bang(xx->fErrorBangOut);
#endif /* FOR_MAC_PPC */
  }
  ExitMaxMessageHandler()
} /* cmd_GetAllVariables */
Exemple #12
0
void iter_int(t_iter *x, long n)
{
	iter_resize(x,1);
	x->i_ac = 1;
	SETLONG(x->i_av,n);
	outlet_int(x->i_ob.o_outlet,n);
}
Exemple #13
0
void bthresher_dump (t_bthresher *x) {

  t_atom *list_data = x->list_data;
  float *damping_factor = x->damping_factor;
  float *move_threshold = x->move_threshold;

  int i,j, count;
#if MSP
  for( i = 0, j = 0; i < x->N2 * 3 ; i += 3, j++ ) {
    SETLONG(list_data+i,j);
    SETFLOAT(list_data+(i+1),damping_factor[j]);
    SETFLOAT(list_data+(i+2),move_threshold[j]);		
  }	
#endif

#if PD
  for( i = 0, j = 0; i < x->N2 * 3 ; i += 3, j++ ) {
    SETFLOAT(list_data+i,(float)j);
    SETFLOAT(list_data+(i+1),damping_factor[j]);
    SETFLOAT(list_data+(i+2),move_threshold[j]);		
  }
#endif

  count = x->N2 * 3;
  outlet_list(x->list_outlet,0,count,list_data);

  return;
}
Exemple #14
0
void sfGetltinhash(strList *params)
	{
#ifdef WINCIT
	if (pCurScript->TW)
		{
		SETLONG(LogTab[pCurScript->TW->LogOrder[
				evaluateInt(params->string)]].GetInitialsHash());
		}
	else
		{
		SETLONG(LogTab[evaluateInt(params->string)].GetInitialsHash());
		}
#else
	SETINT(LTab(evaluateInt(params->string)).GetInitialsHash());
#endif
	}
Exemple #15
0
/*------------------------------------ cmd_Rate ---*/
Pvoid
cmd_Rate(QtPtr xx,
         long  numerator,
         long  denominator)
{
  Atom avRate[2];

  EnterCallback();
#if defined(TRACE_MESSAGES)
  LOG_POST_1("Rate")
#endif /* TRACE_MESSAGES */
  SETLONG(avRate, numerator);
  SETLONG(avRate + 1, denominator);
  if (xx)
    defer(xx, reinterpret_cast<method>(deferred_Rate), NULL_PTR, 2, avRate);
  ExitMaxMessageHandler()
} /* cmd_Rate */
Exemple #16
0
void thresh_int(t_thresh *x, long n)
{
	if (x->t_ac < MAXSIZE - 1) {
		x->t_time = gettime();
		SETLONG(x->t_av+x->t_ac,n);
		x->t_ac++;
		clock_delay(x->t_clock,x->t_interval);
	}
}
Exemple #17
0
static void
make_func(struct ClipFile *file, ClipCodeVar * dest, long *hash)
{
	char *modbeg = M_OFFS(file->body, 2, 0);

	dest->t.type = PCODE_t;
	dest->t.flags = F_NONE;
	dest->u.block->file = file;
	SETLONG(hash, GETLONG(file->pos + 0));
	dest->u.block->func = modbeg + GETLONG(file->pos + 1);
}
Exemple #18
0
/*------------------------------------ inputCallback ---*/
static void
inputCallback(STANDARD_HID_ARGS_INPUTEVENTHANDLER)
{
 #pragma unused(elementCookie,longValue,longValueSize)
    PhidgRefConPtr    data = reinterpret_cast<PhidgRefConPtr>(refCon);
    PrivatePtr            privateData = reinterpret_cast<PrivatePtr>(data->fPrivateStorage);
    
    if (privateData->fDigitalInputTriggerEnabled)
    {
        Atom    reportList[DIGITAL_REPORT_SIZE];

        // Extract the output bit vector and concatenate with the raw bits
        SETSYM(reportList, data->fDeviceType);
        SETSYM(reportList + 1, data->fThisDevice->fSerialNumber);
        SETSYM(reportList + 2, lDiSymbol);
        SETLONG(reportList + 3, value);
        for (UInt32 ii = 0; ii <= MAX_INDEX; ++ii)
            SETLONG(reportList + ii + 4, (value & (1 << ii)) ? 1 : 0);
        genericListOutput(data->fOutlet, DIGITAL_REPORT_SIZE, reportList);
    }        
} /* inputCallback */
/*------------------------------------ cmd_VoiceMax ---*/
Pvoid
cmd_VoiceMax(SpeakPtr xx)
{
  EnterCallback();
  if (xx)
  {
    Atom  response[1];
    short voiceCount;

    CountVoices(&voiceCount);
    SETLONG(response, long(voiceCount));
    outlet_anything(xx->fResultOut, gVoiceMaxSymbol, 1, response);
  }
  ExitMaxMessageHandler()
} /* cmd_VoiceMax */
Exemple #20
0
void *thresh_new(long interval)
{
	t_thresh *x;
	short i;
	
	x = (t_thresh *)newobject(thresh_class);
	intin(x,1);
	x->t_out = outlet_new((t_object *)x,0); // cause it sends out lists and ints
	x->t_clock = clock_new(x,(method)thresh_tick);
	x->t_time = gettime();
	x->t_interval = interval < 5 ? 5 : interval;
	x->t_av = (t_atom *) sysmem_newptr(MAXSIZE*sizeof(t_atom));
	x->t_ac = 0;
	for (i=0; i < MAXSIZE; i++)
		SETLONG(x->t_av+i,0);
	
	return (x);
}			
/*------------------------------------ cmd_GetSensorValue ---*/
Pvoid
cmd_GetSensorValue(RcxControlPtr xx,
                   long          slot)
{
#if (! FOR_MAC_PPC)
 #pragma unused(slot)
#endif /* not FOR_MAC_PPC */
  EnterCallback();
  if (xx)
  {
#if FOR_MAC_PPC
    if (rcxSynchronize(xx))
    {
      if ((slot > 0) && (slot <= RCX_NUM_SENSORS))
      {
        long value;

        if (rcxGetValue(xx, MAKE_RCX_VALUE(RCX_SENSOR_VALUE_TYPE, slot - 1), value))
        {
          Atom response[1];

          outlet_bang(xx->fCommandComplete);
          SETLONG(response, value);
          outlet_anything(xx->fDataOut, gSensorSymbol, 1, response);
        }
        else
          outlet_bang(xx->fErrorBangOut);
      }
      else
      {
        LOG_ERROR_2(OUTPUT_PREFIX "bad sensor index (%ld)", slot)
        outlet_bang(xx->fErrorBangOut);
      }
    }
    else
      outlet_bang(xx->fErrorBangOut);
#endif /* FOR_MAC_PPC */
  }
  ExitMaxMessageHandler()
} /* cmd_GetSensorValue */
static void choose_ls_tuplets(t_def_ls *x)
     /* selects the loudspeaker pairs, calculates the inversion
        matrices and stores the data to a global array*/
{
  //t_float atorad = (2 * 3.1415927 / 360) ;
  int i,j;
  //t_float w1,w2;
  //t_float p1,p2;
  int sorted_lss[MAX_LS_AMOUNT];
  int exist[MAX_LS_AMOUNT];   
  int amount=0;
  t_float inv_mat[MAX_LS_AMOUNT][4];  // In 2-D ls amount == max amount of LS pairs
  t_float mat[MAX_LS_AMOUNT][4];
  //t_float *ptr;   
  //t_float *ls_table;
  t_ls *lss = x->x_ls;
  long ls_amount=x->x_def_ls_amount;
  long list_length;
  Atom *at;
  long pointer;
  
  for(i=0;i<MAX_LS_AMOUNT;i++){
    exist[i]=0;
  }

  /* sort loudspeakers according their aximuth angle */
  sort_2D_lss(x->x_ls,sorted_lss,ls_amount);

  /* adjacent loudspeakers are the loudspeaker pairs to be used.*/
  for(i=0;i<(ls_amount-1);i++){
    if((lss[sorted_lss[i+1]].azi - 
        lss[sorted_lss[i]].azi) <= (180 - 10)){
      if (calc_2D_inv_tmatrix( lss[sorted_lss[i]].azi, 
                               lss[sorted_lss[i+1]].azi, 
                               inv_mat[i],mat[i]) != 0){
        exist[i]=1;
        amount++;
      }
    }
  }

  if(((360 - lss[sorted_lss[ls_amount-1]].azi) 
      +lss[sorted_lss[0]].azi) <= (180 -  10)) {
    if(calc_2D_inv_tmatrix(lss[sorted_lss[ls_amount-1]].azi, 
                           lss[sorted_lss[0]].azi, 
                           inv_mat[ls_amount-1],mat[ls_amount-1]) != 0) { 
        exist[ls_amount-1]=1;
        amount++;
    } 
  }
  
  
  // Output
  list_length= amount * 10  + 2;
  at= (Atom *) getbytes(list_length*sizeof(Atom));
  
  SETLONG(&at[0], x->x_def_ls_dimension);
  SETLONG(&at[1], x->x_def_ls_amount);
  pointer=2;
  
  for (i=0;i<ls_amount - 1;i++){
    if(exist[i] == 1) {
    	SETLONG(&at[pointer], sorted_lss[i]+1);
    	pointer++;
    	SETLONG(&at[pointer], sorted_lss[i+1]+1);
    	pointer++;
       	for(j=0;j<4;j++) {
       		SETFLOAT(&at[pointer], inv_mat[i][j]);
    		pointer++;
       	}
       for(j=0;j<4;j++) {
       		SETFLOAT(&at[pointer], mat[i][j]);
    		pointer++;
       	}
    }
  }
  if(exist[ls_amount-1] == 1) {
    SETLONG(&at[pointer], sorted_lss[ls_amount-1]+1);
    pointer++;
    SETLONG(&at[pointer], sorted_lss[0]+1);
    pointer++;
    for(j=0;j<4;j++) {
    	SETFLOAT(&at[pointer], inv_mat[ls_amount-1][j]);
    	pointer++;
    }
    for(j=0;j<4;j++) {
    	SETFLOAT(&at[pointer], mat[ls_amount-1][j]);
    	pointer++;
    }
  }
	sendLoudspeakerMatrices(x,list_length, at);
  //outlet_anything(x->x_outlet0, gensym("loudspeaker-matrices"), list_length, at);
  freebytes(at, list_length*sizeof(Atom));
}
Exemple #23
0
t_cmmjl_error cmmjl_osc_formatMessage(void *x, 
				      char *address, 
				      void *v, 
				      long n, 
				      void (*cbk)(void *x, t_symbol *msg, int argc, t_atom *argv))
{
	int i, j, k;
	float *floats;
	long *ints;
	char *chars;
	char *string, *nextString, *typeTags, *thisType;
	//unsigned char *p;
	char *p;
	Symbol *addressSymbol, *argSymbol;

	if(!cbk){
		CMMJL_ERROR(x, CMMJL_FAILURE,
			    "you must pass a callback to cmmjl_osc_formatMessage!");
		return CMMJL_FAILURE;
	}

#define MAXARGS 5000

	Atom args[MAXARGS];
	int numArgs = 0;
	Boolean tooManyArgs = false;
	t_cmmjl_error err;

	addressSymbol = gensym(address);

	/* Go through the arguments a word at a time */
	floats = v;
	ints = v;
	chars = v;

	//if (readTypeStrings && chars[0] == ',' && cmmjl_osc_isNiceString(chars, chars+n)) {
	if (chars[0] == ',' && !cmmjl_osc_isNiceString(chars, chars+n)) {
		/* Interpret the first string argument as a type string */
				
		typeTags = chars;
		if(err = cmmjl_osc_dataAfterAlignedString(chars, chars+n, &p)){
			CMMJL_ERROR(x, err, cmmjl_strerror(err));
			return err;
		}
		
		for (thisType = typeTags+1; *thisType != 0; ++thisType) {
  		   
			switch (*thisType) {
			case 'i': case 'r': case 'm': case 'c':
				SETLONG(&args[numArgs], ntohl(*((int *) p)));
				p += 4;
				break;

			case 'f': 
				{ // Pretend the 32 bits are an int so I can call ntohl()
					long bytesAsInt = ntohl(*((int *) p));
					SETFLOAT(&args[numArgs], *((float *) (& bytesAsInt)));
				}
				p += 4;
				break;

			case 't':
				/* handle typetags in args as they are in bundles */
				/* Could see if the data fits in a 32-bit int and output it like that if so... */
				SETSYM(&args[numArgs], ps_OSCTimeTag);
				numArgs++;
				SETLONG(&args[numArgs], ntohl(*((int *) p)));
				numArgs++;
				p += 4;
				SETLONG(&args[numArgs], ntohl(*((int *) p)));
				p += 4;
				break;
             
			case 'h': 
				/* 64-bit int: interpret as zero since Max doesn't have long ints */
				/* Could see if the data fits in a 32-bit int and output it like that if so... */
				SETLONG(&args[numArgs], 0);
				p += 8;
				break;

			case 'd':
				/* 64-bit float: interpret as zero since Max doesn't have doubles */
				/* Could see if the data fits in a 32-bit float and output it like that if so... */
				SETFLOAT(&args[numArgs], 0.0);
				p += 8;
				break;

			case 's': case 'S':
				if (cmmjl_osc_isNiceString(p, typeTags+n)) {
					SETSYM(&args[numArgs], gensym("¥Bogus_String"));
				} else {
					SETSYM(&args[numArgs], gensym(p));
					if(err = cmmjl_osc_dataAfterAlignedString(p, typeTags+n, &p)){
						CMMJL_ERROR(x, err, cmmjl_strerror(err));
						return err;
					}
				}
				break;
	            
			case 'b':
				{
					// output symbol OSCBlob, int size, int data0 ... int dataN
					int size = ntohl(*((int *) p));
                
					if (p+4+size > chars+n) {
						CMMJL_ERROR(x, CMMJL_OSC_EOVRFLW, 
							    "blob size %ld is too big for packet", 
							    size);
						return CMMJL_OSC_EOVRFLW;
					}
					SETSYM(&args[numArgs], ps_OSCBlob); numArgs++;
                
					if(numArgs + 1 + size > MAXARGS) {
						CMMJL_ERROR(x, CMMJL_OSC_EOVRFLW, 
							    "blob size too big for encoding");
						return CMMJL_OSC_EOVRFLW;
					}
					SETLONG(&args[numArgs], size); numArgs++;

					for(j = 0; j < size; j++) {
						SETLONG(&args[numArgs], ((long) (*(p + 4 + j)))); numArgs++;
					}
                
					numArgs--; // increments again at end of loop
                
					p += cmmjl_osc_effectiveBlobLength(size);

				}
				break;

			case 'T': 
				/* "True" value comes out as the int 1 */
				SETLONG(&args[numArgs], 1);
				/* Don't touch p */
				break;
	           	
			case 'F': 
				/* "False" value comes out as the int 0 */
				SETLONG(&args[numArgs], 0);
				/* Don't touch p */
				break;
	           	            
			case 'N': 
				/* Empty lists in max?  I wish!  How about the symbol "nil"? */
				SETSYM(&args[numArgs], gensym("nil"));
				/* Don't touch p */
				break;
	           	
			case 'I': 
				/* Infinita in Max?  Ha!  How about the symbol "Infinitum"? */
				SETSYM(&args[numArgs], gensym("Infinitum"));
				/* Don't touch p */
				break;


			default:
				CMMJL_ERROR(x, CMMJL_OSC_ETYPTAG, 
					    "Unrecognized type tag %c", *thisType);
				return CMMJL_OSC_ETYPTAG;
			}
			++numArgs;
		}
	} else {
		/* Use type-guessing heuristics */

		for (i = 0; i<n/4; ) {
			if (numArgs >= MAXARGS) {
				CMMJL_ERROR(x, CMMJL_OSC_EARGS, 
					    "message has more than %ld args; droping extra ones", 
					    (long)MAXARGS);
				return CMMJL_OSC_EARGS;
			}

			string = &chars[i*4];
			if  (ints[i] >= -1000 && ints[i] <= 1000000) {
				SETLONG(&args[numArgs], ntohl(ints[i]));
				i++;
			} else if (floats[i] >= -1000.f && floats[i] <= 1000000.f &&
				   (floats[i]<=0.0f || floats[i] >= __FLT_MIN__)) {
				// Pretend the 32 bits are an int so I can call ntohl()
				long bytesAsInt = ntohl(ints[i]);
				SETFLOAT(&args[numArgs], *((float *) (&bytesAsInt)));
				i++;
			} else if (!cmmjl_osc_isNiceString(string, chars+n)) {
				if(err = cmmjl_osc_dataAfterAlignedString(string, chars+n, &nextString)){
					CMMJL_ERROR(x, err, cmmjl_strerror(err));
					return err;
				}
				argSymbol = gensym(string);
				SETSYM(&args[numArgs], argSymbol);
				i += (nextString-string) / 4;
			} else {
				// Assume int if nothing looks good.
				SETLONG(&args[numArgs], ntohl(ints[i]));
				i++;
			}
			numArgs++;
		}
	}
	cbk(x, addressSymbol, numArgs, args);
	return CMMJL_SUCCESS;
}
Exemple #24
0
t_cmmjl_error cmmjl_osc_parse(void *x, 
			      long n, 
			      char *buf,
			      bool topLevel,
			      void (*cbk)(void *x, t_symbol *sym, int argc, t_atom *argv))
{
	long size, messageLen, i;
	char *messageName;
	char *args;
	int t;
	t_cmmjl_error err;
	if(!cbk){
		cbk = cmmjl_post_gimme;
	}

	if ((n % 4) != 0) {
		CMMJL_ERROR(x, CMMJL_OSC_ENO4BYTE, 
			    "packet size (%d) is not a multiple of 4 bytes: dropping", n);
		return CMMJL_OSC_ENO4BYTE;
	}
    
	if(n <= 0) {
		CMMJL_ERROR(x, CMMJL_OSC_EUNDRFLW,
			    "bad OSC packet length: %d", n);
		return CMMJL_OSC_EUNDRFLW;
	}

	/* your object is passing n in, so it should check this before the function is called.
	   if(n > x->b.size) {
	   post("OTUDP: OpenSoundControl n (%d) exceeds buffer size (%d)", n, x->b.size);
	   goto ParseOSCPacket_Error;
	   }
	*/
    
	if(buf == NULL) {
		CMMJL_ERROR(x, CMMJL_ENULLPTR, "OSC packet pointer is NULL");
		return CMMJL_ENULLPTR;
	}
             
	if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) {
		/* This is a bundle message. */
		if (n < 16) {
			CMMJL_ERROR(x, CMMJL_OSC_EBADBNDL, 
				    "bundle is too small (%d bytes) for time tag", n);
			return CMMJL_OSC_EBADBNDL;
		}

		if (topLevel) {
			Atom timeTagLongs[2];
			SETLONG(&timeTagLongs[0], ntohl(*((long *)(buf+8))));
			SETLONG(&timeTagLongs[1], ntohl(*((long *)(buf+12))));
			cbk(x, ps_OSCTimeTag, 2, timeTagLongs);
		}

		i = 16; /* Skip "#bundle\0" and time tag */
		while((i+sizeof(long)) < n) { // next operation will take four bytes -aws
			size = ntohl(*((long *) (buf + i)));
			if ((size % 4) != 0) {
				CMMJL_ERROR(x, CMMJL_OSC_EBNDLNO4, 
					    "bundle size (%d) is not a multiple of 4", size);
				return CMMJL_OSC_EBNDLNO4;
			}
			if ((size + i + 4) > n) {
				CMMJL_ERROR(x, CMMJL_OSC_EBADBNDL, 
					    "bad OSC bundle size %d, only %d bytes left in entire bundle", 
					    size, n - i - 4);
				return CMMJL_OSC_EBADBNDL;
			}
	    
			/* Recursively handle element of bundle */
			t = cmmjl_osc_parse(x, size, buf+i+4, false, cbk);
			if(t != 0) {
				CMMJL_ERROR(x, CMMJL_FAILURE, 
					    "recursive processing of OSC packet failed.  Bailing out.");
				return CMMJL_FAILURE;
			}
			i += 4 + size;
		}
		if (i != n) {
			CMMJL_ERROR(x, CMMJL_FAILURE, 
				    "failed to process entire packet (%d of %d bytes)", i, n);
			return CMMJL_FAILURE;
		}
	} else {
		/* This is not a bundle message */
		messageName = buf;
		if(err = cmmjl_osc_dataAfterAlignedString(messageName, buf+n, &args)){
			CMMJL_ERROR(x, err, cmmjl_strerror(err));
			return err;
		}
		
		messageLen = args-messageName;	    
		cmmjl_osc_formatMessage(x, messageName, (void *)args, n-messageLen, cbk);
	}
    
	if (topLevel) {
		//outlet_bang(x->O_outlet1);
	}
    
	return CMMJL_SUCCESS;
	/*
	  ParseOSCPacket_Error:
    
	  if (topLevel) {
	  //outlet_bang(x->O_outlet1);
	  }
	  return 1;

	*/
}
Exemple #25
0
void sfGetuserwidth(strList *)
	{
	RequiresScriptTW();
	SETLONG(ScriptTW()CurrentUser->GetWidth());
	}
Exemple #26
0
void sfGetusercalltime(strList *)
	{
	RequiresScriptTW();
	SETLONG(ScriptTW()CurrentUser->GetCallTime());
	}
Exemple #27
0
void sfGetusernulls(strList *)
	{
	RequiresScriptTW();
	SETLONG(ScriptTW()CurrentUser->GetNulls());
	}
static void  calculate_3x3_matrixes(t_def_ls *x)
     /* Calculates the inverse matrices for 3D */
{  
  t_float invdet;
  t_ls *lp1, *lp2, *lp3;
  t_float *invmx;
  //t_float *ptr;
  struct t_ls_set *tr_ptr = x->x_ls_set;
  int triplet_amount = 0, /*ftable_size,*/i,pointer,list_length=0;
  Atom *at;
  t_ls *lss = x->x_ls;
  
  if (tr_ptr == NULL)
	{
    error("define-loudspeakers: Not valid 3-D configuration\n");
    return;
  }
	
  /* counting triplet amount */
  while(tr_ptr != NULL)
	{
    triplet_amount++;
    tr_ptr = tr_ptr->next;
  }
  tr_ptr = x->x_ls_set;
  list_length= triplet_amount * 21 + 3;
  at= (Atom *) getbytes(list_length*sizeof(Atom));
  
  SETLONG(&at[0], x->x_def_ls_dimension);
  SETLONG(&at[1], x->x_def_ls_amount);
  pointer=2;
  
  while(tr_ptr != NULL){
    lp1 =  &(lss[tr_ptr->ls_nos[0]]);
    lp2 =  &(lss[tr_ptr->ls_nos[1]]);
    lp3 =  &(lss[tr_ptr->ls_nos[2]]);

    /* matrix inversion */
    invmx = tr_ptr->inv_mx;
    invdet = 1.0 / (  lp1->x * ((lp2->y * lp3->z) - (lp2->z * lp3->y))
                    - lp1->y * ((lp2->x * lp3->z) - (lp2->z * lp3->x))
                    + lp1->z * ((lp2->x * lp3->y) - (lp2->y * lp3->x)));

    invmx[0] = ((lp2->y * lp3->z) - (lp2->z * lp3->y)) * invdet;
    invmx[3] = ((lp1->y * lp3->z) - (lp1->z * lp3->y)) * -invdet;
  	invmx[6] = ((lp1->y * lp2->z) - (lp1->z * lp2->y)) * invdet;
    invmx[1] = ((lp2->x * lp3->z) - (lp2->z * lp3->x)) * -invdet;
    invmx[4] = ((lp1->x * lp3->z) - (lp1->z * lp3->x)) * invdet;
    invmx[7] = ((lp1->x * lp2->z) - (lp1->z * lp2->x)) * -invdet;
    invmx[2] = ((lp2->x * lp3->y) - (lp2->y * lp3->x)) * invdet;
    invmx[5] = ((lp1->x * lp3->y) - (lp1->y * lp3->x)) * -invdet;
    invmx[8] = ((lp1->x * lp2->y) - (lp1->y * lp2->x)) * invdet;
    for(i=0;i<3;i++){
    	SETLONG(&at[pointer], tr_ptr->ls_nos[i]+1);
    	pointer++;
    }
    for(i=0;i<9;i++){
    	SETFLOAT(&at[pointer], invmx[i]);
    	pointer++;
    }
    SETFLOAT(&at[pointer], lp1->x); pointer++;
    SETFLOAT(&at[pointer], lp2->x); pointer++;
    SETFLOAT(&at[pointer], lp3->x); pointer++;
    SETFLOAT(&at[pointer], lp1->y); pointer++;
    SETFLOAT(&at[pointer], lp2->y); pointer++;
    SETFLOAT(&at[pointer], lp3->y); pointer++;
    SETFLOAT(&at[pointer], lp1->z); pointer++;
    SETFLOAT(&at[pointer], lp2->z); pointer++;
    SETFLOAT(&at[pointer], lp3->z); pointer++;
 
    tr_ptr = tr_ptr->next;
  }
	sendLoudspeakerMatrices(x,list_length, at);
//  outlet_anything(x->x_outlet0, gensym("loudspeaker-matrices"), list_length, at);
  freebytes(at, list_length*sizeof(Atom));
}
Exemple #29
0
static void rvbap_bang(t_rvbap *x)            
// top level, vbap gains are calculated and outputted   
{
    t_atom at[MAX_LS_AMOUNT]; 
    t_float g[3];
    long ls[3];
    long i;
    t_float *final_gs, overdist, oversqrtdist;
    final_gs = (t_float *) getbytes(x->x_ls_amount * sizeof(t_float));
    if(x->x_lsset_available ==1){
        vbap(g, ls, x);
        for(i=0;i<x->x_ls_amount;i++)
            final_gs[i]=0.0;  
        for(i=0;i<x->x_dimension;i++){
            final_gs[ls[i]-1]=g[i];  
        }
        if(x->x_spread != 0){
            spread_it(x,final_gs);
        }
        overdist = 1 / x->x_dist;
        oversqrtdist = 1 / sqrt(x->x_dist);
        // build output for every loudspeaker
        for(i=0;i<x->x_ls_amount;i++)
		{
            // first, we output the gains for the direct (unreverberated) signals
            // these just decrease as the distance increases
#ifdef MAXMSP
            SETLONG(&at[0], i); 
            SETFLOAT(&at[1], (final_gs[i] / x->x_dist));
            outlet_list(x->x_outlet0, NULL, 2, at);
#endif
#ifdef PD
            SETFLOAT(&at[0], i);    
            SETFLOAT(&at[1], (final_gs[i] / x->x_dist));
            outlet_list(x->x_outlet0, gensym("list"), 2, at);
#endif
            // second, we output the gains for the reverberated signals
            // these are made up of a global (all speakers) and a local part
#ifdef MAXMSP
            SETLONG(&at[0], i+x->x_ls_amount);  // direct signals come first in matrix~
            SETFLOAT(&at[1], (((oversqrtdist / x->x_dist) * x->x_reverb_gs[i]) + (oversqrtdist * (1 - overdist) * final_gs[i])));
            outlet_list(x->x_outlet0, NULL, 2, at);
#endif
#ifdef PD
            SETFLOAT(&at[0], (i+x->x_ls_amount));   // direct signals come first in matrix~
            SETFLOAT(&at[1], (((oversqrtdist / x->x_dist) * x->x_reverb_gs[i]) + (oversqrtdist * (1 - overdist) * final_gs[i])));
            outlet_list(x->x_outlet0, gensym("list"), 2, at);
#endif
        }
#ifdef MAXMSP
        outlet_int(x->x_outlet1, x->x_azi); 
        outlet_int(x->x_outlet2, x->x_ele); 
        outlet_int(x->x_outlet3, x->x_spread); 
        outlet_float(x->x_outlet4, (double)x->x_dist); 
#endif
#ifdef PD
        outlet_float(x->x_outlet1, x->x_azi); 
        outlet_float(x->x_outlet2, x->x_ele); 
        outlet_float(x->x_outlet3, x->x_spread); 
        outlet_float(x->x_outlet4, x->x_dist); 
#endif
    }
    else
        post("rvbap: Configure loudspeakers first!");
    freebytes(final_gs, x->x_ls_amount * sizeof(t_float)); // bug fix added 9/00
}
Exemple #30
0
/*------------------------------------ performGet ---*/
static bool
performGet(FidgetPtr        xx,
           HIDDeviceDataPtr walkerHID,
           PSymbol          deviceType,
           const short      argc,
           PAtom            argv)
{
    bool                    okSoFar = true;
    OSErr                    result;
    E_PhidgResult    action = kPhidgDoDefault;

    if (walkerHID->fClass)
    {
        PhidgetDescriptorPtr    kind = reinterpret_cast<PhidgetDescriptorPtr>(walkerHID->fClass);

#if defined(COMPILE_FOR_OSX_4)
        action = reinterpret_cast<FpDoGet>(kind->fDoGetFun)(OUR_NAME, deviceType,
                                                                                                                xx->fDataOut, kind->fShared,
                                                                                                                walkerHID->fPrivate, walkerHID,
                                                                                                                short(argc - 2), argv + 2,
                                                                                                                &result);
#endif /* COMPILE_FOR_OSX_4 */
#if defined(COMPILE_FOR_OS9_4)
        action = static_cast<E_PhidgResult>(CallUniversalProc(kind->fDoGetUpp, uppDoGetProcInfo,
                                                                OUR_NAME, deviceType, xx->fDataOut, kind->fShared,
                                                                walkerHID->fPrivate, walkerHID, short(argc - 2), argv + 2,
                                                                &result));
#endif /* COMPILE_FOR_OS9_4 */
    }
    if (action == kPhidgDoDefault)
    {
#if defined(COMPILE_FOR_OSX_4)
        // Note that 'default' is only supported with 'CATS' - there is no reasonable behaviour
        // if we are using a report handler... as we do for non-'CATS'!
        if (argc >= 3)
        {
          long    element = 0;

            if (argv[2].a_type == A_LONG)
                element = argv[2].a_w.w_long;
            else
            {
                okSoFar = false;
                LOG_ERROR_2(OUTPUT_PREFIX "element is not an integer for '%s:get'",
                                        deviceType->s_name);
            }
          if (okSoFar)
          {
              HIDElementDataPtr    anElement = NULL_PTR;
              
              if (element)
              {
                  // Find the matching element:
                     for (anElement = walkerHID->fFirstElement; anElement; anElement = anElement->fNext)
                     {
                         if (anElement->fCookie == reinterpret_cast<IOHIDElementCookie>(element))
                             break;
                             
                     }
              }
              if (anElement)
              {
                     UInt32        extendedLength;
                     Pvoid            extendedValue;
                     IOReturn    result;
                     long            value = getHIDElementValue(OUR_NAME, *walkerHID, *anElement,
                                                                                             extendedLength, extendedValue, result);
                    
                    if (result == KERN_SUCCESS)
                    {
                        if (extendedLength)
                        {
                            PAtom    newList = GETBYTES(extendedLength + 2, Atom);
                            Pchar    longValue = reinterpret_cast<Pchar>(extendedValue);
                            
                            SETSYM(newList, deviceType);
                            SETSYM(newList + 1, walkerHID->fSerialNumber);
                            for (UInt32 ii = 0; ii < extendedLength; ++ii, ++longValue)
                                SETLONG(newList + ii + 2, long(*longValue & 0x00FF));
                      genericListOutput(xx->fDataOut, short(extendedLength + 2), newList);
                      FREEBYTES(newList, extendedLength + 2)
                        }
                        else
                        {
                            Atom    newList[3];
                            
                            SETSYM(newList, deviceType);
                            SETSYM(newList + 1, walkerHID->fSerialNumber);
                            SETLONG(newList + 2, value);
                            genericListOutput(xx->fDataOut, sizeof(newList) / sizeof(*newList),
                                                                newList);        
                      }
                    }
                    if (result)
                        outlet_int(xx->fResultOut, result);                            
              }
              else
              {
                  okSoFar = false;
                  LOG_ERROR_2(OUTPUT_PREFIX "element not found for '%sget'", deviceType->s_name)
              }
          }