void minimum_bang(t_minimum *x) { long i; t_big_atom themin; long minIndex; long res; double fres; minIndex = 0; themin.a_type = A_NOTHING; systhread_mutex_lock(x->m_mutex); for (i=0; i < x->m_count; i++) minimum_compare(&themin,x->m_args+i, &i, &minIndex); systhread_mutex_unlock(x->m_mutex); outlet_int(x->m_out2, minIndex); if (x->m_outtype==A_LONG) { if (themin.a_type == A_LONG) res = themin.w_long; else res = (long)themin.w_float; outlet_int(x->m_out,res); } else { if (themin.a_type == A_FLOAT) fres = themin.w_float; else fres = (float)themin.w_long; outlet_float(x->m_out,fres); } }
void posit_queryglobal(t_posit *x, t_symbol *s, short ac, t_atom *av) { t_atom *query; query = x->p_query; if (ac > 0) { switch (av[0].a_type) { case A_SYM: x->p_query[0].a_w.w_sym = (t_symbol*)av[0].a_w.w_sym; break; case A_FLOAT: case A_LONG: return; } x->p_state = 0; patcher_eachdo((void *)posit_enumquery, x); switch(x->p_state){ case 0: outlet_int(x->p_outlet3,0); break; case 1: outlet_bang(x->p_outlet2); outlet_int(x->p_outlet3,1); break; } } }
void slide_int(t_slide *x, long n) { long in = SLIDE_PROXY_GETINLET(x); if( in == 0){ // left inlet x->s_insize = 1; if(fabs(x->s_out[0] - (double)n) <= x->s_thresh){ // six digits of precision possible x->s_out[0] = (double)n; x->s_deltaflag[0] = 0; }else{ x->s_out[0] = (x->s_out[0] + (((double)n - x->s_out[0]) * x->s_slide)); x->s_deltaflag[0] = 1; } if((x->s_deltaflag[0] == 0)&&(x->s_stopflag == 1)){ x->s_stopflag = 0; outlet_int(x->s_outlet2, x->s_stopflag); }else if((x->s_deltaflag[0] == 1)&&(x->s_stopflag == 0)){ x->s_stopflag = 1; outlet_int(x->s_outlet2, x->s_stopflag); } x->s_outlist[0].a_w.w_float = x->s_out[0]; outlet_float(x->s_outlet, x->s_outlist[0].a_w.w_float); }else if (in == 1){ // right inlet if(n > 0){ x->s_slide = 1.0/(double)n; } } }
void posit_classglobal(t_posit *x, t_symbol *s, short ac, t_atom *av) { x->p_flag = 0; if (ac > 0){ switch (av[0].a_type) { case A_SYM: x->p_classquery[0].a_w.w_sym = av[0].a_w.w_sym; break; case A_FLOAT: case A_LONG: return; } patcher_eachdo((void *)posit_enumclass, x); switch(x->p_flag){ case 0: outlet_int(x->p_outlet3,0); break; case 1: outlet_bang(x->p_outlet2); outlet_int(x->p_outlet3,1); break; } } }
/*------------------------------------ senseXDoMessage ---*/ void senseXDoMessage(SenseXData * xx) { if (! xx->fStopping) { short prevLock; switch (xx->fState) { case kAwaitingFirstMessage: prevLock = lockout_set(1); if (0 > xx->fOnDelay) { clock_delay(xx->fPollClock, xx->fOnDelay); xx->fState = kBetweenMessages; } else { outlet_int(xx->fResultOut, 1); if (0 > xx->fOffDelay) { clock_delay(xx->fPollClock, xx->fOffDelay); xx->fState = kAfterSecondMessage; } else { outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; } } lockout_set(prevLock); break; case kBetweenMessages: prevLock = lockout_set(1); outlet_int(xx->fResultOut, 1); clock_unset(xx->fPollClock); if (0 < xx->fOffDelay) { clock_delay(xx->fPollClock, xx->fOffDelay); xx->fState = kAfterSecondMessage; } else { outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; } lockout_set(prevLock); break; default: break; } } } // senseXDoMessage
void slice_output(t_slice *x) { t_atom *at; if (x->s_len > x->s_split) { at = x->s_at + x->s_split; if (at->a_type != A_SYM) { if (x->s_len - x->s_split == 1) { if (at->a_type == A_LONG) { outlet_int(x->s_out2, at->a_w.w_long); } else if (at->a_type == A_FLOAT) { outlet_float(x->s_out2, at->a_w.w_float); } } else { outlet_list(x->s_out2,ps_list,x->s_len - x->s_split,at); } } else { outlet_anything(x->s_out2,at->a_w.w_sym,x->s_len - x->s_split - 1,at+1); } } if (x->s_len >= x->s_split) { at = x->s_at; if (x->s_split == 1) { if (at->a_type == A_LONG) { outlet_int(x->s_out1, at->a_w.w_long); } else if (at->a_type == A_FLOAT) { outlet_float(x->s_out1, at->a_w.w_float); } else { outlet_anything(x->s_out1, at->a_w.w_sym, 0, (t_atom *)NIL); } } else if (at->a_type != A_SYM) { outlet_list(x->s_out1,ps_list,x->s_split,at); } else { outlet_anything(x->s_out1, at->a_w.w_sym, x->s_split-1, at+1); } } else { at = x->s_at; if (x->s_split == 1) { if (at->a_type == A_LONG) { outlet_int(x->s_out1, at->a_w.w_long); } else if (at->a_type == A_FLOAT) { outlet_float(x->s_out1, at->a_w.w_float); } else { outlet_anything(x->s_out1, at->a_w.w_sym, 0, (t_atom *)NIL); } } else if (at->a_type != A_SYM) { outlet_list(x->s_out1,ps_list,x->s_len,at); } else { outlet_anything(x->s_out1,at->a_w.w_sym,x->s_len-1,at+1); } } }
void slide_list(t_slide *x, t_symbol *s, short ac, t_atom *av) { t_atom *outlist; short i; long deltacount = 0; long in = SLIDE_PROXY_GETINLET(x); // post("calling anything"); if(x->s_slide == 1.0){ // check for redundancy if slide == 1 then bail out outlet_list(x->s_outlet,0L, ac, av); // output list return; } outlist = x->s_outlist; x->s_insize = ac; // da slide formula : y(n) = y(n-1) + ((x(n) - y(n-1))/slide) for (i=0; i < x->s_insize; i++) { switch(av[i].a_type){ case A_SYM: x->s_in[i] = 0.0; break; case A_FLOAT: x->s_in[i] = (double)av[i].a_w.w_float; break; case A_LONG: x->s_in[i] = (double)av[i].a_w.w_long; break; } if(fabs(x->s_out[i] - x->s_in[i]) <= x->s_thresh){ x->s_out[i] = x->s_in[i]; x->s_deltaflag[i] = 0; }else{ x->s_out[i] = x->s_out[i] + ((x->s_in[i] - x->s_out[i]) * x->s_slide); x->s_deltaflag[i] = 1; } // post("element %ld deltaflag %ld", i, x->s_deltaflag[i]); atom_setfloat(x->s_outlist+i, x->s_out[i]); deltacount = deltacount + x->s_deltaflag[i]; // post("deltacount is %ld", deltacount); } if((deltacount == 0)&&(x->s_stopflag == 1)){ x->s_stopflag = 0; outlet_int(x->s_outlet2, x->s_stopflag); }else if((deltacount != 0)&&(x->s_stopflag == 0)){ x->s_stopflag = 1; outlet_int(x->s_outlet2, x->s_stopflag); } outlet_list(x->s_outlet,0L, x->s_insize, outlist); // output list return; }
// default signal processing method is called 'perform' void perform(double **ins, long numins, double **outs, long numouts, long sampleframes) { // char *this_chordname; std::vector<double> chroma; chroma.resize(12); double rms, rms_tot; int q; rms = 0; rms_tot = 0; for (long channel = 0; channel < numouts; channel++) { double * in = ins[channel]; double * out = outs[channel]; for (long i=0; i < sampleframes; i++) { out[i] = in[i]; // we only want to process on channel 0 if (channel == 0) { if (currentsamples < frameSize - 1) { frame[currentsamples] = in[i]; currentsamples++; } else { currentsamples = 0; for (q = 0; q < frameSize; q++) { rms_tot += pow(frame[q],2); } rms = rms_tot / frameSize; if (rms > rms_cutoff){ c.processAudioFrame(frame); outlet_int(m_outlets[3], 1); } else { outlet_int(m_outlets[3], 0); } if (c.isReady()) { std::vector<double> chroma = c.getChromagram(); chordspotter.detectChord(chroma); currentchord = 10000 * chordspotter.rootNote + chordspotter.chord_num; chord_name = chordspotter.chord_name; const char *this_chordname = chord_name.c_str(); if (currentchord != lastchord) { outlet_anything(m_outlets[0], gensym(this_chordname), 0, NULL); outlet_int(m_outlets[1], currentchord); midilist(chordspotter.rootNote, chordspotter.chord_num); } lastchord = currentchord; } } } } } }
void fftinfo_dsp(t_fftinfo *x, t_signal **sp, short *count) { if (x->x_pfft) { outlet_int(x->x_out[3], (x->x_fullspect = (x->x_pfft->x_fullspect)?1:0)); outlet_int(x->x_out[2], (x->x_ffthop = x->x_pfft->x_ffthop)); outlet_int(x->x_out[1], (x->x_n = sp[0]->s_n)); outlet_int(x->x_out[0], (x->x_fftsize = x->x_pfft->x_fftsize)); } else if (fftinfo_warning) { object_warn((t_object *)x, "fftinfo~ only functions inside a pfft~",0); fftinfo_warning = 0; } }
void bartime_exec(t_bartime *x) { x->s_f6 = fmod(x->s_input, x->s_f4); x->s_f7 = x->s_input * x->s_f4b; x->s_ticks = fmod(x->s_f6, x->s_f3); x->s_sub = 1 + (x->s_f6 * x->s_f3b); x->s_beat = 1 + fmod(x->s_f7, x->s_numerator); x->s_bar = 1 + (x->s_f5 * x->s_f7); if(x->s_beatdivision != x->s_oldbeatdivision){ outlet_int(x->s_outlet1, x->s_beatdivision); x->s_oldbeatdivision = x->s_beatdivision; if(x->s_beatdivision == 0){ outlet_int(x->s_outlet3, x->s_sub); outlet_int(x->s_outlet4, x->s_beat); outlet_int(x->s_outlet5, x->s_bar); } } outlet_int(x->s_outlet2, x->s_ticks); if(x->s_sub != x->s_oldsub){ outlet_int(x->s_outlet3, x->s_sub); x->s_oldsub = x->s_sub; outlet_int(x->s_outlet4, x->s_beat); outlet_int(x->s_outlet5, x->s_bar); } }
void fftinfo_bang(t_fftinfo *x) { if (x->x_pfft) { // just output current values outlet_int(x->x_out[3], x->x_fullspect); // fullspect flag outlet_int(x->x_out[2], x->x_ffthop); outlet_int(x->x_out[1], x->x_n); outlet_int(x->x_out[0], x->x_fftsize); } else if (fftinfo_warning) { object_warn((t_object *)x, "fftinfo~ only functions inside a pfft~",0); fftinfo_warning = 0; } }
// Method for list input (converts a list of bits into a long) void bits_list(t_bits *x, t_symbol *msg, short argc, t_atom *argv) { int i, j; // counters long val = 0; // Our bit-constructed number long temp; Atom templist[3]; // used in matrixctrl mode if(x->mode==ps_bits2ints){ // *** BIT-LIST TO INTEGER(LIST) MODE *** for(i=(argc - 1); i>=0; i--){ temp = argv[i].a_w.w_long; val |= temp<<(argc-(i+1)); // bit shift, then or it with the val } outlet_int(x->my_outlet[0], val); // spit it out } else if(x->mode==ps_matrixctrl2ints){ // *** MATRIX-CTRL TO INTEGER-LIST MODE *** object_post((t_object *)x, "tap.bits: This mode is not yet implemented"); } else if(x->mode==ps_ints2matrixctrl){ // *** INTEGER-LIST TO MATRIX-CTRL MODE *** for(j=0; j<argc; j++){ atom_setlong(templist+1, j); // Store the row in the output list temp = argv[j].a_w.w_long; // Get the value in the input list (for the moment we assume it is an int - should also handle floats) for(i=0; i < x->matrix_width; i++){ atom_setlong(templist+0, i); // Store the column in the output list atom_setlong(templist+2, 1 & temp); // Store the switch value in the output list temp = temp>>1; // Bit shift to the next one outlet_list(x->my_outlet[0], 0L, 3, templist); // output the result } } } else // use the Jitter attribute dumpout outlet to report an error
void change(t_ccext *x) { if(x->c_result != x->c_memory){ outlet_int(x->c_ob.o_outlet,x->c_result); x->c_memory = x->c_result; } }
void output_msg(t_oscroute *x, char *msg, int outlet, long argc, t_atom *argv) { t_symbol *output; if (msg == '\0') { if (argc == 0) { outlet_bang(x->outlets[outlet]); } else if (argc==1) { if (argv->a_type==A_LONG) outlet_int(x->outlets[outlet],argv->a_w.w_long); else if (argv->a_type==A_FLOAT) outlet_float(x->outlets[outlet],argv->a_w.w_float); else if (argv->a_type==A_SYM) outlet_anything(x->outlets[outlet],argv->a_w.w_sym,0,0); } else { if (argv->a_type==A_SYM) { output = argv->a_w.w_sym; argc--; argv++; } else { output = _sym_list; } outlet_anything(x->outlets[outlet], output, argc, argv); } } else outlet_anything(x->outlets[outlet], gensym(msg), argc, argv); }
void akabookmotion_bang(t_akabookmotion *x) { int sms_x, sms_y, sms_z; int result; if (x->type != unknown) { result = read_sms_raw(x->type, &sms_x, &sms_y, &sms_z); if (result) { outlet_int(x->m_zout, sms_z); outlet_int(x->m_yout, sms_y); outlet_int(x->m_xout, sms_x); } } }
// INT INPUT void return_int(t_return *x, long value) { if (!x->attrEnable) return; if (x->common.attr_repetitions == 0) { if (value == atom_getlong(&x->output[1])) return; } if (x->common.attr_clipmode != _sym_none) { if (x->common.attr_clipmode == jps_both) TTLimit<TTInt32>(value, x->common.attr_range[0], x->common.attr_range[1]); else if (x->common.attr_clipmode == jps_low) TTLimitMin<TTInt32>(value, x->common.attr_range[0]); else if (x->common.attr_clipmode == jps_high) TTLimitMax<TTInt32>(value, x->common.attr_range[1]); else if (x->common.attr_clipmode == jps_wrap) value = TTInfWrap<TTInt32>(value,x->common.attr_range[0], x->common.attr_range[1]); else if (x->common.attr_clipmode == jps_fold) value = TTFold<TTInt32>(value, x->common.attr_range[0], x->common.attr_range[1]); } atom_setlong(&x->output[1], value); x->output_len = 2; return_send_feedback(x); outlet_int(x->outlets[k_outlet_thru], value); }
// BANG input void stats_bang(t_stats *x) { double mean, standardDeviation; /* if (x->valueCount < 0) mean = 0; else mean = x->sumOfValues / x->valueCount; if (x->valueCount > 1) standardDeviation = sqrt((x->sumOfSquaredValues - ((x->sumOfValues*x->sumOfValues) / x->valueCount)) / (x->valueCount - 1)); else standardDeviation = 0;*/ /////small optimization by Nils Peters//// if (x->valueCount >= 0) mean = x->sumOfValues / x->valueCount; else mean = 0; if (x->valueCount > 1) standardDeviation = sqrt((x->sumOfSquaredValues - (x->sumOfValues*mean)) / (x->valueCount - 1)); /* i just simplified the equation by using the mean which was already calculated before*/ else standardDeviation = 0; ///// end of small optimization by Nils Peters//// outlet_float(x->outlet5, standardDeviation); outlet_float(x->outlet4, mean); outlet_float(x->outlet3, x->max); outlet_float(x->outlet2, x->min); outlet_int(x->outlet, x->valueCount); }
static void DiceyBang( objDicey* me) { long c = me->nDice, // All of these are non-negative, but will not exceed f = me->nFaces, // kMaxLong, so don't need to declare unsigned. d; // Initialize in if/else below if (f < 2) d = c; // Shortcut for degenerate dice else { tTaus88DataPtr tausData = me->tausData; double ff = f; // Convert long to double now d = 0; while (c-- > 0) { // ULong2Unit_Zo returns value in range [0.0 .. 1.0) // * ff results in range [0.0 .. ff) // + 1.0 results in range [1.0 .. ff + 1.0) // Thus values are equally distributed over [1 .. 2), [2 .. 3), ..., [ff .. f+1) // After truncation to integer we have equiprobably distribution of 1, 2, .. f // QED d += ff * ULong2Unit_Zo(Taus88(tausData)) + 1.0; } } outlet_int(me->coreObject.o_outlet, d); }
void filein_access(t_filein *x, t_symbol *s, short ac, t_atom *av) { OSErr err; Byte data[8]; long count; unsigned long dummy; if (s==ps_int) count = 1; else if (s==ps_in1) count = 2; else count = 4; err = sysfile_setpos(x->f_fh,SYSFILE_FROMSTART,av->a_w.w_long); if (err) object_error((t_object *)x, "seek err %d",err); else { err = sysfile_read(x->f_fh,&count,data); if (err) object_error((t_object *)x, "read err %d",err); else { if (count==1) dummy = data[0]; else sysmem_copyptr(data,&dummy,count); outlet_int(x->f_out,dummy); } } }
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); }
void _defer_delete(t_filesys *x, t_symbol *sym, long argc, t_atom *argv) { TRACE("_defer_delete"); char str_cur[MAX_PATH_CHARS]; t_symbol *sym_cur = atom_getsym(argv); _filesys_get_path(x, sym_cur->s_name, str_cur); // Try deleting the file int err = 0; #ifdef WIN_VERSION err = remove(str_cur); #endif #ifdef MAC_VERSION err = remove(str_cur); #endif // In case of success if (!err) { if (x->a_verbose) { POST("Removing: %s", sym_cur->s_name); } } // ... otherwise post an error message else { switch (errno) { case EACCES: MY_ERR("delete: File is open or read-only: \"%s\"", sym_cur->s_name); break; case ENOENT: MY_ERR("delete: File not found: \"%s\"", sym_cur->s_name); break; default: MY_ERR("delete: Unknown error: %i", errno); break; } } // Send a 0 or 1 message to indicate failure or success outlet_int(x->outl_return, err ? 0 : 1); }
void testequals_float(t_testequals *x, double f) { if (proxy_getinlet((t_object*)x) == 1) x->x_operand = f; else outlet_int(x->x_outlet, testequals_equivalent(x->x_operand, f, x->x_tolerance, x->x_single_precision)); }
static void PfishieBang( objPoisson* me) { long p; switch (me->alg) { case algReject: p = GenPoissonRejTaus88(&me->params.rejParams, me->tausData); break; case algInversion: p = GenPoissonInvTaus88(&me->params.invParams, me->tausData); break; case algDirect: p = GenPoissonDirTaus88(me->params.invParams.thresh, me->tausData); break; default: // Must be algConstZero // Or algUndef, which is an error, but our lambda method prevents that p = 0; break; } outlet_int(me->coreObject.o_outlet, p); }
void urner_bang(t_urner *x) { long rand; long size = sysmem_ptrsize(x->table); // RETURNS SIZE OF POINTER IN BYTES #ifdef WIN_VERSION rand_s(&rand); #else rand = random(); #endif rand = rand % size; if (x->count == size) { outlet_bang(x->bangout); // SEND A BANG WHEN WE'VE HIT MAXIMUM return; } if (x->table[rand] != 0) { // NUMBER HAS ALREADY BEEN CHOSEN do { #ifdef WIN_VERSION rand_s(&rand); #else rand = random(); #endif rand = rand % size; } while (x->table[rand] != 0); } // WE GOT A NUMBER x->table[rand] = 1; // MARK THIS VALUE AS USED x->count++; // INCREMENT OUR COUNT outlet_int(x->out, rand); }
void ar_count(t_ar *x){ t_hashtab *ht; if(!(ht = (t_hashtab *)x->iname_ht->s_thing)){ return; } outlet_int(x->outlets[0], hashtab_getsize(ht)); }
/*------------------------------------ senseXProcessQueue ---*/ static void senseXProcessQueue(SenseXData * xx) { if (xx && (! xx->fStopping)) { short prevLock; switch (xx->fState) { case kBetweenMessages: prevLock = lockout_set(1); xx->fState = kAwaitingFirstMessage; lockout_set(prevLock); break; case kAfterSecondMessage: prevLock = lockout_set(1); outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; lockout_set(prevLock); break; default: break; } #if USE_EVNUM evnum_incr(); #endif /* USE_EVNUM */ } } // senseXProcessQueue
void iter_int(t_iter *x, long n) { iter_resize(x,1); x->i_ac = 1; atom_setlong(x->i_av,n); outlet_int(x->i_ob.o_outlet,n); }
void dummy_bang(t_dummy *x) { switch (x->val.a_type) { case A_LONG: outlet_int(x->out, atom_getlong(&x->val)); break; case A_FLOAT: outlet_float(x->out, atom_getfloat(&x->val)); break; case A_SYM: outlet_anything(x->out, atom_getsym(&x->val), 0, NULL); break; default: break; } }
void fact_int(t_fact *x, int n) { if( (n>0) && (n<200) ) { x->p_result = factorial(n); }else{ x->p_result = 1; } outlet_int(x->p_outlet, x->p_result); }
void deflutter(t_ccext *x) { x->c_delta2 = x->c_delta1; x->c_delta1 = x->c_result - x->c_memory; if(x->c_delta1 != (x->c_delta2 * -1)){ outlet_int(x->c_ob.o_outlet,x->c_result); } x->c_memory = x->c_result; }