Imported Upstream version 0.85

parents
This diff is collapsed.
This diff is collapsed.
------------------------------
GEM and MARKEX
------------------------------
These are objects from GEM which don't have any dependencies besides libc.
What is here is the entire contents of Gem/src/MarkEx except [hsv2rsb] and
the vector lib. Hopefully they will be removed from Gem once they become a
proper part of this repository.
#N canvas 286 197 499 284 10;
#X obj 19 108 sig~;
#X obj 71 133 loadbang;
#X obj 71 157 metro 100;
#X obj 71 181 snapshot~;
#X floatatom 19 87 5 0 0 0 - - -;
#X floatatom 71 206 7 0 0 0 - - -;
#X text 316 257 updated for Pd version 0.42.;
#X obj 20 132 abs~;
#X obj 21 14 abs~;
#X text 60 14 - absolute value;
#X text 82 33 Passes nonnegative values unchanged \, but replaces negative
ones with their (positive) inverses.;
#X text 81 66 (turn DSP on to test):;
#X connect 0 0 7 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 3 0 5 0;
#X connect 4 0 0 0;
#X connect 7 0 3 0;
/*
* Copyright (c) 1997-1999 Mark Danks.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution.
*/
#include "m_pd.h"
#include <math.h>
/* ------------------------- abs~ -------------------------- */
static t_class *abs_class;
typedef struct _abs
{
t_object x_obj;
} t_abs;
static t_int *abs_perform(t_int *w)
{
//t_abs *x = (t_abs *)(w[1]);
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
while (n--)
{
float f = *in++;
if (f < 0) f = -f;
*out++ = f;
}
return (w+5);
}
static void abs_dsp(t_abs *x, t_signal **sp)
{
dsp_add(abs_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void *abs_new(void)
{
t_abs *x = (t_abs *)pd_new(abs_class);
outlet_new(&x->x_obj, &s_signal);
return (x);
}
void abs_tilde_setup(void)
{
abs_class = class_new(gensym("abs~"), (t_newmethod)abs_new, 0,
sizeof(t_abs), 0, A_NULL);
class_addmethod(abs_class, (t_method)nullfn, &s_signal, A_NULL);
class_addmethod(abs_class, (t_method)abs_dsp, gensym("dsp"), A_NULL);
}
#N canvas 47 22 568 493 10;
#X obj 4 439 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header alternate 3 12
0 18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlet 15 12 0 13
-228856 -1 0;
#N canvas 779 22 498 348 META 0;
#X text 12 65 TEMPLATE template-help.pd v0.1;
#X text 12 85 PLATFORM windows macosx gnulinux;
#X text 12 25 KEYWORDS control alternate;
#X text 12 45 LICENSE GPLv2 or later;
#X text 12 105 DATATYPE any message;
#X text 12 125 LIBRARY markex;
#X restore 504 441 pd META;
#X obj 3 299 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0
13 -228856 -1 0;
#X obj 3 389 cnv 3 550 3 empty \$0-pddp.cnv.argument argument 15 12
0 13 -228856 -1 0;
#N canvas 309 454 609 478 guts 0;
#X obj 117 95 textfile;
#X msg 116 24 symbol template-HCS.pd;
#X msg 116 54 read \$1 \, rewind \, bang;
#X obj 117 141 trigger bang anything;
#X obj 58 117 bang;
#X obj 240 162 route #X;
#X obj 240 183 route text;
#X obj 240 250 route DESCRIPTION;
#X obj 239 276 print;
#X obj 140 277 print TEXT;
#X connect 0 0 3 0;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
#X connect 3 1 5 0;
#X connect 4 0 0 0;
#X connect 5 0 6 0;
#X connect 7 0 8 0;
#X restore 453 441 pd guts;
#X obj 488 -14 alternate;
#X obj 437 5 pddp/pddplink http://pdpedia.org/en/markex/alternate -text
pdpedia: alternate;
#X text 15 6 description: alternates messages between its two outlets
;
#X obj 74 351 cnv 17 3 25 empty \$0-pddp.cnv.let.0 1 5 9 0 16 -228856
-162280 0;
#X obj 74 321 cnv 17 3 25 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X obj 315 152 cnv 10 57 16 empty \$0-pddp.cnv.highlight empty 20 12
0 14 -262126 -66577 0;
#X obj 63 115 cnv 10 57 16 empty \$0-pddp.cnv.highlight empty 20 12
0 14 -262126 -66577 0;
#X msg 309 56 1;
#X obj 315 152 alternate;
#X msg 262 55 bang;
#X msg 349 123 reset;
#X msg 342 56 symbol blah;
#X obj 366 174 pddp/print;
#X obj 315 201 pddp/print;
#X obj 63 115 alternate;
#X obj 63 143 bng 25 250 50 0 empty empty empty 0 -6 0 10 -262144 -1
-1;
#X obj 114 143 bng 25 250 50 0 empty empty empty 0 -6 0 10 -262144
-1 -1;
#X obj 63 80 bng 25 250 50 0 empty empty empty 0 -6 0 10 -204786 -1
-1;
#X msg 352 83 1 2 3 4;
#X text 105 257 any message can be send to [alternate] \, it will just
pass it through to the outlets;
#X text 102 407 [alternate] ignores all arguments;
#X text 105 317 first message that was received on the inlet \, and
all following messages that are numbered odd in the sequence;
#X text 105 348 second message that was received on the inlet \, and
all following messages that are numbered even in the sequence;
#X connect 14 0 15 0;
#X connect 15 0 20 0;
#X connect 15 1 19 0;
#X connect 16 0 15 0;
#X connect 17 0 15 0;
#X connect 18 0 15 0;
#X connect 21 0 22 0;
#X connect 21 1 23 0;
#X connect 24 0 21 0;
#X connect 25 0 15 0;
/*
* Copyright (c) 1997-1999 Mark Danks.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution.
*/
#include "m_pd.h"
/* -------------------------- alternate ------------------------------ */
/* instance structure */
static t_class *alternate_class;
typedef struct _alternate
{
t_object x_obj; /* obligatory object header */
int a_which; /* which outlet to go out 0 = left, 1 = right */
t_outlet *t_out1; /* the outlet */
t_outlet *t_out2; /* the other outlet */
} t_alternate;
static void alternate_list(t_alternate *x, t_symbol *s, int argc, t_atom *argv)
{
static t_symbol *listSym = NULL;
if (!listSym)
listSym = gensym("list");
if (!x->a_which) outlet_list(x->t_out1, listSym, argc, argv);
else outlet_list(x->t_out2, listSym, argc, argv);
x->a_which++;
x->a_which = (x->a_which > 1) ? 0 : x->a_which;
}
static void alternate_float(t_alternate *x, t_floatarg n)
{
if (!x->a_which) outlet_float(x->t_out1, n);
else outlet_float(x->t_out2, n);
x->a_which++;
x->a_which = (x->a_which > 1) ? 0 : x->a_which;
}
static void alternate_bang(t_alternate *x)
{
if (!x->a_which) outlet_bang(x->t_out1);
else outlet_bang(x->t_out2);
x->a_which++;
x->a_which = (x->a_which > 1) ? 0 : x->a_which;
}
static void alternate_reset(t_alternate *x)
{
x->a_which = 0;
}
static void *alternate_new(t_symbol *s) /* init vals in struc */
{
t_alternate *x = (t_alternate *)pd_new(alternate_class);
x->t_out1 = outlet_new(&x->x_obj, 0);
x->t_out2 = outlet_new(&x->x_obj, 0);
x->a_which = 0;
return (x);
}
void alternate_setup(void)
{
alternate_class = class_new(gensym("alternate"), (t_newmethod)alternate_new, 0,
sizeof(t_alternate), 0, A_NULL);
class_addfloat(alternate_class, (t_method)alternate_float);
class_addbang(alternate_class, (t_method)alternate_bang);
class_addmethod(alternate_class, (t_method)alternate_reset, gensym("reset"), A_NULL);
class_addmethod(alternate_class, (t_method)alternate_list,
gensym("list"), A_GIMME, A_NULL);
#if PD_MINOR_VERSION < 37
class_sethelpsymbol(alternate_class, gensym("alternate-help.pd"));
#endif
}
#N canvas 271 381 600 500 10;
#X text 124 68 GEM object;
#X obj 123 298 print out1;
#X obj 123 220 average;
#X floatatom 123 160 0 0 0;
#X msg 184 162 bang;
#X msg 247 164 reset 5;
#X msg 345 168 clear;
#X text 89 408 The initial argument is the number to average together.
The default is 10 numbers.;
#X obj 421 231 average 20;
#X text 139 23 [average];
#X text 81 371 [average] together a series of numbers.;
#X connect 2 0 1 0;
#X connect 3 0 2 0;
#X connect 4 0 2 0;
#X connect 5 0 2 0;
#X connect 6 0 2 0;
/*
* Copyright (c) 1997-1999 Mark Danks.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution.
*/
#include "m_pd.h"
/* -------------------------- alternate ------------------------------ */
/* instance structure */
static t_class *average_class;
typedef struct _average
{
t_object x_obj; /* obligatory object header */
int a_total; /* number of numbers to average */
int a_whichNum; /* which number are pointing at */
float a_numbers[100]; /* numbers to average, 100 maximum */
t_outlet *t_out1; /* the outlet */
} t_average;
void average_bang(t_average *x)
{
float average = 0.0f;
int n;
for (n = 0; n < x->a_total; n++) average = average + x->a_numbers[n];
average = average / (float)x->a_total;
outlet_float(x->t_out1, average);
}
void average_float(t_average *x, t_floatarg n)
{
if (x->a_whichNum >= x->a_total) x->a_whichNum = 0;
x->a_numbers[x->a_whichNum] = n;
x->a_whichNum++;
average_bang(x);
}
void average_total(t_average *x, t_floatarg n)
{
x->a_total = (int)n;
}
void average_reset(t_average *x, t_floatarg newVal)
{
int n;
for (n=0; n < 100; n ++) x->a_numbers[n] = newVal;
}
void average_clear(t_average *x)
{
int n;
for ( n = 0; n < 100; n ++) x->a_numbers[n] = 0.0f;
}
void *average_new(t_floatarg f) /* init vals in struc */
{
t_average *x = (t_average *)pd_new(average_class);
x->t_out1 = outlet_new(&x->x_obj, 0);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1"));
average_clear(x);
if (f) x->a_total = (int)f;
else x->a_total = 10;
x->a_whichNum = 0;
return (x);
}
void average_setup(void)
{
average_class = class_new(gensym("average"), (t_newmethod)average_new, 0,
sizeof(t_average), 0, A_DEFFLOAT, 0);
class_addbang(average_class, (t_method)average_bang);
class_addfloat(average_class, (t_method)average_float);
class_addmethod(average_class, (t_method)average_total, gensym("fl1"), A_FLOAT, 0);
class_addmethod(average_class, (t_method)average_clear, gensym("clear"), A_NULL);
class_addmethod(average_class, (t_method)average_reset, gensym("reset"), A_FLOAT, 0);
#if PD_MINOR_VERSION < 37
#endif
}
#N canvas 597 145 600 590 10;
#X text 124 68 GEM object;
#X obj 123 298 print out1;
#X text 138 23 counter;
#X msg 123 97 bang;
#X text 58 362 counter counts the number of bangs;
#X obj 123 220 counter 0 5;
#X msg 319 154 bang;
#X text 58 394 The third argument is the direction 1 == up 2 == down 3 == up and down;
#X obj 319 297 print out2;
#X obj 319 219 counter 0 5 3;
#X obj 195 265 print done1;
#X obj 405 267 print done2;
#X text 58 439 The right outlet sends a bang when the counter rolls over. The bang occurs after the left inlet sends the value.;
#X msg 147 129 direction;
#X msg 171 154 low value;
#X msg 195 182 high value;
#X msg 71 176 reset;
#X msg 26 177 clear;
#X text 58 524 A reset message will set the counter back to the starting value and send the value out the left outlet.;
#X text 58 486 A clear message will set the counter back to the starting value.;
#X text 331 189 count from 0 to 5 and back down to 0;
#X connect 3 0 5 0;
#X connect 5 0 1 0;
#X connect 5 1 10 0;
#X connect 6 0 9 0;
#X connect 9 0 8 0;
#X connect 9 1 11 0;
#X connect 13 0 5 1;
#X connect 14 0 5 2;
#X connect 15 0 5 3;
#X connect 16 0 5 0;
#X connect 17 0 5 0;
/*
* Copyright (c) 1997-1999 Mark Danks.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution.
*/
#include "m_pd.h"
/* -------------------------- counter ------------------------------ */
/* instance structure */
static t_class *counter_class;
typedef struct _counter
{
t_object x_obj; /* obligatory object header */
int c_current; /* current number */
int c_high; /* highest number */
int c_low; /* lowest number */
int c_updown; /* 0 = going up, 1 = going down */
int c_dir; /* counter dir. 1=up, 2=down, 3=up/down */
t_outlet *t_out1; /* the outlet */
t_outlet *t_out2; /* the outlet */
} t_counter;
void counter_bang(t_counter *x)
{
int sendBang = 0;
switch(x->c_dir)
{
// count up
case 1:
x->c_current++;
if (x->c_current > x->c_high)
x->c_current = x->c_low;
else if (x->c_current < x->c_low)
x->c_current = x->c_low;
else if (x->c_current == x->c_high)
sendBang = 1;
break;
// count down
case 2:
x->c_current--;
if (x->c_current < x->c_low)
x->c_current = x->c_high;
else if (x->c_current > x->c_high)
x->c_current = x->c_high;
else if (x->c_current == x->c_low)
sendBang = 1;
break;
// count up and down
case 3:
// going up
if (x->c_updown == 0)
{
x->c_current++;
if (x->c_current > x->c_high)
{
x->c_current = x->c_high - 1;
x->c_updown = 1;
}
else if (x->c_current < x->c_low)
x->c_current = x->c_low;
else if (x->c_current == x->c_high)
sendBang = 1;
}
// going down
else if (x->c_updown == 1)
{
x->c_current--;
if (x->c_current < x->c_low)
{
x->c_current = x->c_low + 1;
x->c_updown = 0;
}
else if (x->c_current > x->c_high)
x->c_current = x->c_high;
else if (x->c_current == x->c_low)
sendBang = 1;
}
else
{
error("up/down wrong");
return;
}
break;
default:
error("dir wrong");
return;
}
outlet_float(x->t_out1, (float)x->c_current);
if (sendBang)
outlet_bang(x->t_out2);
}
void counter_dir(t_counter *x, t_floatarg n)
{
if (n == 1 || n == 2 || n == 3) x->c_dir = (int)n;
else error("bad dir");
}
void counter_high(t_counter *x, t_floatarg n)
{
x->c_high = (int)n;
}
void counter_low(t_counter *x, t_floatarg n)
{
x->c_low = (int)n;
}
void counter_reset(t_counter *x, t_symbol *s, int argc, t_atom *argv)
{
if (!argc)
{
switch(x->c_dir)
{
case 1:
x->c_current = x->c_low;
break;
case 2:
x->c_current = x->c_high;
break;
case 3:
if (x->c_updown == 0) x->c_current = x->c_low;
else if (x->c_updown == 1) x->c_current = x->c_high;
break;
default:
return;
}
}
else
{
switch(argv[0].a_type)
{
case A_FLOAT :
x->c_current = (int)argv[0].a_w.w_float;
break;
default :
error ("counter: reset not float");
break;
}
}
outlet_float(x->t_out1, (float)x->c_current);
}
void counter_clear(t_counter *x, t_symbol *s, int argc, t_atom *argv)
{
if (!argc)
{
switch(x->c_dir)
{
case 1:
x->c_current = x->c_low - 1;
break;
case 2:
x->c_current = x->c_high + 1;
break;
case 3:
if (x->c_updown == 0) x->c_current = x->c_low - 1;
else if (x->c_updown == 1) x->c_current = x->c_high + 1;
break;
default:
break;
}
}
else
{
switch(argv[0].a_type)
{
case A_FLOAT :
x->c_current = (int)argv[0].a_w.w_float - 1;
break;
default :
error ("counter: reset not float");
break;
}
}
}
void *counter_new(t_floatarg f, t_floatarg g, t_floatarg h) /* init vals in struc */
{
t_counter *x = (t_counter *)pd_new(counter_class);
x->t_out1 = outlet_new(&x->x_obj, 0);
x->t_out2 = outlet_new(&x->x_obj, 0);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl3"));
x->c_current = 0;
x->c_updown = 0;
if (h)
{
counter_low(x, f);
counter_high(x, g);
counter_dir(x, h);
}
else if (g)
{
x->c_dir = 1;
counter_low(x, f);
counter_high(x, g);
}
else if (f)
{
x->c_dir = x->c_low = 1;
counter_high(x, f);
}
else
{
x->c_dir = x->c_low = 1;
x->c_high = 10;
}
return (x);
}
void counter_setup(void)
{
counter_class = class_new(gensym("counter"), (t_newmethod)counter_new, 0,
sizeof(t_counter), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addbang(counter_class, (t_method)counter_bang);
class_addmethod(counter_class, (t_method)counter_dir, gensym("fl1"), A_FLOAT, 0);
class_addmethod(counter_class, (t_method)counter_low, gensym("fl2"), A_FLOAT, 0);
class_addmethod(counter_class, (t_method)counter_high, gensym("fl3"), A_FLOAT, 0);
class_addmethod(counter_class, (t_method)counter_reset, gensym("reset"), A_GIMME, 0);
class_addmethod(counter_class, (t_method)counter_clear, gensym("clear"), A_GIMME, 0);
#if PD_MINOR_VERSION < 37
#endif
}
#N canvas 344 338 481 346 10;
#X obj 127 223 unpack 0 0 0;
#X floatatom 206 245 5 0 0 1 Blue - -;
#X floatatom 166 265 5 0 0 1 Green - -;
#X floatatom 127 288 5 0 0 1 Red - -;
#X obj 127 184 hsv2rgb;
#X msg 167 119 0 1 1;
#X msg 189 143 0.6 1 0.5;
#X floatatom 182 48 5 0 1 1 Value - -;
#X floatatom 145 30 5 0 1 1 Saturation - -;
#X floatatom 127 12 5 0 1 1 Hue - -;
#X obj 127 97 pack 0 0 0;
#X obj 145 65 t b f;
#X obj 182 65 t b f;
#X connect 0 0 3 0;
#X connect 0 1 2 0;
#X connect 0 2 1 0;
#X connect 4 0 0 0;
#X connect 5 0 4 0;
#X connect 6 0 4 0;
#X connect 7 0 12 0;
#X connect 8 0 11 0;
#X connect 9 0 10 0;
#X connect 10 0 4 0;
#X connect 11 0 10 0;
#X connect 11 1 10 1;
#X connect 12 0 10 0;
#X connect 12 1 10 2;
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// mark@danks.org
//
// Copyright (c) 1997-1999 Mark Danks.
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt" in this distribution.
//
/////////////////////////////////////////////////////////
#include "m_pd.h"
#include <math.h>
static inline float FLOAT_CLAMP(float x) { return((x > 1.f) ? 1.f : ( (x < 0.f) ? 0.f : x)); }
/////////////////////////////////////////////////////////
//
// hsv2rgb
//
/////////////////////////////////////////////////////////
// instance structure
static t_class *hsv2rgb_class;
typedef struct _hsv2rgb
{
t_object x_obj; // obligatory object header
t_outlet *t_out1; // the outlet
}t_hsv2rgb;
static void hsv2rgb_float(t_hsv2rgb *x, t_floatarg h, t_floatarg s, t_floatarg v)
{
t_atom argv[3];
float r=0, g=0, b=0;
h = FLOAT_CLAMP(h);
s = FLOAT_CLAMP(s);
v = FLOAT_CLAMP(v);
// convert hue to degrees
h *= 360.f;
if (s == 0.0) // black and white
{
r = g = b = v;
}
else
{
if (h == 360.0) // 360 == 0 degrees
h = 0.0f;
h /= 60.0f; // hue is now [0, 6]
{
int i = (int)floor(h);
float f = h - i; // f is the fractional part of h
float p = v * (1 - s);
float q = v * (1 - s * f);
float t = v * (1 - s * (1 - f));
switch (i)
{
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;