diff options
author | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-06-19 17:00:34 +0000 |
---|---|---|
committer | Thomas O Fredericks <mrtof@users.sourceforge.net> | 2009-06-19 17:00:34 +0000 |
commit | e0267013c4de07cf495b4488a66181e4027d88a4 (patch) | |
tree | 750de46dd8d97625f4ff902ca6edbe1fd701ecc9 | |
parent | d285825bc8d34f791f3adc07caa836457b66b7bd (diff) |
Added a few externals to tof
svn path=/trunk/externals/tof/; revision=11801
-rw-r--r-- | help/argument-abs.pd | 29 | ||||
-rw-r--r-- | help/argument-help.pd | 47 | ||||
-rw-r--r-- | help/crossfade~-help.pd | 39 | ||||
-rw-r--r-- | help/increment-help.pd | 49 | ||||
-rw-r--r-- | help/iterate-help.pd | 61 | ||||
-rw-r--r-- | help/listUnfold-help.pd | 20 | ||||
-rw-r--r-- | help/path-help.pd | 94 | ||||
-rw-r--r-- | help/streamMinMax-help.pd | 28 | ||||
-rw-r--r-- | help/wrapper-help.pd | 27 | ||||
-rw-r--r-- | src/argument.c | 119 | ||||
-rw-r--r-- | src/crossfade~.c | 137 | ||||
-rw-r--r-- | src/increment.c | 151 | ||||
-rw-r--r-- | src/iterate.c | 105 | ||||
-rw-r--r-- | src/listUnfold.c | 88 | ||||
-rw-r--r-- | src/path.c | 252 | ||||
-rw-r--r-- | src/streamMinMax.c | 107 | ||||
-rw-r--r-- | src/wrapper.c | 81 |
17 files changed, 1434 insertions, 0 deletions
diff --git a/help/argument-abs.pd b/help/argument-abs.pd new file mode 100644 index 0000000..0e209a4 --- /dev/null +++ b/help/argument-abs.pd @@ -0,0 +1,29 @@ +#N canvas 336 203 614 414 10; +#X obj 158 36 inlet; +#X obj 158 92 t b b b; +#X text 220 105 first; +#X text 159 192 second; +#X text 73 282 third; +#X obj 11 303 argument 3 500; +#X obj 210 130 argument 1; +#X text 279 131 <-Outputs the first parent argument "symbol a"; +#X obj 158 67 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 134 213 argument 2 100; +#X text 231 208 <-Outputs "100" because the types of the second argument +("symbol b") and the default argument ("float 100") do not match.; +#X text 200 29 Please note that the current parent arguments are: a +b; +#X text 101 305 <- Outputs "500" because there is not third parent +argument; +#X obj 210 166 print arg1; +#X obj 129 258 print arg2; +#X obj 11 342 print arg3; +#X connect 0 0 8 0; +#X connect 1 0 5 0; +#X connect 1 1 9 0; +#X connect 1 2 6 0; +#X connect 5 0 15 0; +#X connect 6 0 13 0; +#X connect 8 0 1 0; +#X connect 9 0 14 0; diff --git a/help/argument-help.pd b/help/argument-help.pd new file mode 100644 index 0000000..c274ce8 --- /dev/null +++ b/help/argument-help.pd @@ -0,0 +1,47 @@ +#N canvas 305 118 476 537 10; +#X obj 66 482 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj -11 19 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text -6 75 author: mrtoftrash@gmail.com; +#X text -6 96 version: 2009-04-14 (initial release); +#X text -7 60 tags: initialization; +#X text -6 18 description: outputs an inital argument. Outputs a default +one if no initial argument is set. Can also check that an argument +is of a particular type.; +#X obj 13 187 argument 1; +#X text 5 247 If a second argument is set \, its value will be used +as the default value. The default value is used only if there is no +parent argument OR if the type of the parent argument does not match +the type of the default one.; +#X obj 4 322 argument 1 32; +#X obj 12 167 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 4 298 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 4 349 print; +#X obj 13 208 print; +#X text 6 135 The first argument selects the nth parent argument to +output.; +#X text 92 321 <-Will output 32 because there are no parent arguments. +; +#X text 87 183 <-Should output the first parent argument. But in this +case \, the parent (the containing patch) has no arguments and this +example will not output anything.; +#X text 137 428 -- Example --; +#X text 5 449 Inside the following abstraction \, three [argument] +objects are linked to arguments 1 \, 2 and 3; +#X obj 158 347 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X obj 158 369 argument; +#X obj 158 395 print; +#X text 218 370 <-Outputs the \$0 as symbol; +#X text 172 506 <- open it; +#X obj 66 506 argument-abs a b; +#X connect 0 0 23 0; +#X connect 6 0 12 0; +#X connect 8 0 11 0; +#X connect 9 0 6 0; +#X connect 10 0 8 0; +#X connect 18 0 19 0; +#X connect 19 0 20 0; diff --git a/help/crossfade~-help.pd b/help/crossfade~-help.pd new file mode 100644 index 0000000..488b0e9 --- /dev/null +++ b/help/crossfade~-help.pd @@ -0,0 +1,39 @@ +#N canvas 339 91 631 441 10; +#X floatatom 323 276 5 0 0 0 - - -; +#X obj 123 292 crossfade~ 2; +#X obj 32 -13 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 37 21 author: mrtoftrash@gmail.com; +#X text 37 32 version: 2009-06-04 (initial release); +#X obj 36 164 osc~ 100; +#X obj 123 388 dac~; +#X obj 197 189 noise~; +#X obj 93 163 osc~ 500; +#X obj 248 189 osc~ 200; +#X obj 122 361 *~ 0.5; +#X obj 193 360 *~ 0.5; +#X obj 229 338 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 0 1; +#X text 35 142 First source: signal inlets to the left.; +#X text 187 170 Second source: signal inlets to the right.; +#X obj 326 255 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 0 1; +#X text 334 234 Crossfade: 0-1; +#X text 261 215 The right most inlet controls the linear crossfade +value.; +#X text 38 10 tags: signal mix; +#X text 37 -14 description: crossfades 2 multi-channel sources; +#X text 41 104 Argument: The number of channels for each source (defaults +to 2); +#X connect 0 0 1 4; +#X connect 1 0 10 0; +#X connect 1 1 11 0; +#X connect 5 0 1 0; +#X connect 7 0 1 2; +#X connect 8 0 1 1; +#X connect 9 0 1 3; +#X connect 10 0 6 0; +#X connect 11 0 6 1; +#X connect 12 0 10 1; +#X connect 12 0 11 1; +#X connect 15 0 0 0; diff --git a/help/increment-help.pd b/help/increment-help.pd new file mode 100644 index 0000000..d7fb6ed --- /dev/null +++ b/help/increment-help.pd @@ -0,0 +1,49 @@ +#N canvas 1174 80 640 574 10; +#X obj 22 -23 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 27 11 author: mrtoftrash@gmail.com; +#X text 27 22 version: 2009-05-07 (initial release); +#X msg 101 166 3; +#X msg 62 166 6; +#X obj 291 328 print; +#X text 27 -24 description: increment a number.; +#X text 28 0 tags: flow counter; +#X obj 27 216 increment; +#X msg 147 199 1; +#X msg 179 199 -1; +#X obj 27 120 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 27 244 print; +#X obj 290 268 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X obj 291 297 increment 10 3; +#X text 22 89 First inlet:; +#X text 22 100 Bang: Outputs and increments the value.; +#X text 60 147 Second inlet: sets the value; +#X text 148 179 Third inlet: sets the step(incrementation) amount; +#X obj 49 479 print; +#X obj 49 321 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X msg 72 349 set 43; +#X msg 96 376 step 5; +#X msg 125 402 reset; +#X obj 49 448 increment 10 3; +#X text 283 229 Argument 1: start value (defaults to 0); +#X text 283 244 Argument 2: step(incrementation) value (defaults to +1); +#X text 118 349 Set the start value; +#X text 144 376 Set the step value; +#X text 171 400 Reset to the start value; +#X connect 3 0 8 1; +#X connect 4 0 8 1; +#X connect 8 0 12 0; +#X connect 9 0 8 2; +#X connect 10 0 8 2; +#X connect 11 0 8 0; +#X connect 13 0 14 0; +#X connect 14 0 5 0; +#X connect 20 0 24 0; +#X connect 21 0 24 0; +#X connect 22 0 24 0; +#X connect 23 0 24 0; +#X connect 24 0 19 0; diff --git a/help/iterate-help.pd b/help/iterate-help.pd new file mode 100644 index 0000000..c5d5be7 --- /dev/null +++ b/help/iterate-help.pd @@ -0,0 +1,61 @@ +#N canvas 1184 0 638 689 10; +#X obj 12 -33 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 17 1 author: mrtoftrash@gmail.com; +#X text 17 12 version: 2009-05-07 (initial release); +#X text 293 244 Optional argument 1: start value; +#X text 17 -10 tags: stream flow; +#X obj 51 151 iterate; +#X obj 51 182 print; +#X msg 22 116 3; +#X msg 77 113 6; +#X obj 313 148 iterate; +#X obj 386 150 sel 4; +#X obj 313 191 print; +#X msg 312 120 6; +#X text 286 85 Bang: A bang will stop the iteration before it ends. +; +#X text 21 85 Float: Iterates that many times.; +#X obj 35 339 iterate; +#X obj 35 370 print; +#X obj 329 369 print; +#X msg 329 304 4; +#X obj 329 338 iterate 20 2; +#X text 36 242 Inlet 2: start value; +#X msg 34 282 5; +#X msg 67 284 10; +#X msg 98 283 3; +#X msg 110 309 1; +#X msg 148 311 -1; +#X msg 361 419 10 100 3; +#X obj 361 455 iterate; +#X obj 361 495 print; +#X obj 361 575 iterate; +#X obj 361 615 print; +#X msg 360 539 start 15 \, step -0.5 \, 5; +#X text 17 -34 description: iterates through numbers (as a "for" loop). +; +#X text 35 227 Inlet 1: iterations; +#X text 89 452 Iterate 10 times from 100 with a step of 3:; +#X text 89 560 Iterate 5 times from 15 with a step of -0.5:; +#X text 293 259 Optional argument 2: step value; +#X text 36 256 Inlet 3: step value; +#X connect 5 0 6 0; +#X connect 7 0 5 0; +#X connect 8 0 5 0; +#X connect 9 0 11 0; +#X connect 9 0 10 0; +#X connect 10 0 9 0; +#X connect 12 0 9 0; +#X connect 15 0 16 0; +#X connect 18 0 19 0; +#X connect 19 0 17 0; +#X connect 21 0 15 0; +#X connect 22 0 15 1; +#X connect 23 0 15 1; +#X connect 24 0 15 2; +#X connect 25 0 15 2; +#X connect 26 0 27 0; +#X connect 27 0 28 0; +#X connect 29 0 30 0; +#X connect 31 0 29 0; diff --git a/help/listUnfold-help.pd b/help/listUnfold-help.pd new file mode 100644 index 0000000..f837bc5 --- /dev/null +++ b/help/listUnfold-help.pd @@ -0,0 +1,20 @@ +#N canvas 154 102 524 446 10; +#X obj 196 327 listUnfold; +#X obj 165 388 print value; +#X obj 277 385 print index; +#X msg 199 277 anything works too; +#X msg 154 208 5 3 2 8 4; +#X msg 185 237 symbol test; +#X obj 62 22 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 67 77 author: mrtoftrash@gmail.com; +#X text 67 88 version: 2009-06-07 (initial release); +#X text 67 66 tags: list flow tof; +#X text 68 22 description: output the individual elements of a list +one after the other while simultaneously doing so with their indices. +; +#X connect 0 0 1 0; +#X connect 0 1 2 0; +#X connect 3 0 0 0; +#X connect 4 0 0 0; +#X connect 5 0 0 0; diff --git a/help/path-help.pd b/help/path-help.pd new file mode 100644 index 0000000..4c3cfc3 --- /dev/null +++ b/help/path-help.pd @@ -0,0 +1,94 @@ +#N canvas 0 24 1018 689 10; +#X obj 54 585 print RESULT; +#X obj 54 334 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 95 353 samples/; +#X msg 113 509 C:/Documents and Settings/tom/My Documents/pd/parent.test.pd +; +#X obj 54 558 path; +#X obj 52 12 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 57 57 author: mrtoftrash@gmail.com; +#X text 57 68 version: 2009-06-07 (initial release); +#X text 79 330 <- a bang will output the root patch's path; +#X text 159 352 <- Sending a relative path will append that path to +the root patch's path; +#X text 113 427 Linux and OS X; +#X text 120 467 Windows; +#X msg 114 448 /unchanged/because/of/the/slash/at/the/start; +#X msg 113 487 C:/unchanged/because/of/the/:/as/second/char; +#X obj 544 44 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 593 158 samples/; +#X text 569 42 <- a bang will output the root patch's path; +#X obj 570 112 openpanel; +#X obj 570 92 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X symbolatom 570 134 50 0 0 0 - - -; +#X symbolatom 544 233 50 0 0 0 - - -; +#X text 575 60 Anything else will be treated as a path; +#X obj 544 202 path relative; +#X text 653 156 <- Relative paths are unchanged; +#X text 111 414 Absolute paths are unchanged; +#X obj 545 282 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 545 395 print CURRENT; +#X obj 545 368 path current; +#X text 575 282 <- a bang will output the current patch's path; +#X text 58 12 description: outputs or transform paths.; +#X text 57 46 tags: file tof; +#X text 49 114 [path] can convert relative paths to absolute paths +or the other way around. The base path can be either the path of the +current patch \, or the path of the root patch.; +#X text 196 157 -- keywords --; +#X text 47 220 current: use the current patch's path (instead of using +the root patch's path).; +#X text 47 254 relative: transform absolute paths into relative paths +(instead of the other way around).; +#X text 177 306 -- default behavior --; +#X text 710 260 -- current --; +#X msg 573 315 samples/; +#X text 637 314 <- Sending a relative path will append that path to +the current patch's path; +#X text 685 9 -- relative --; +#X obj 545 455 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 594 569 samples/; +#X obj 571 523 openpanel; +#X obj 571 503 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X symbolatom 571 545 50 0 0 0 - - -; +#X symbolatom 545 634 50 0 0 0 - - -; +#X text 576 471 Anything else will be treated as a path; +#X text 654 567 <- Relative paths are unchanged; +#X text 680 427 -- relative & current --; +#X obj 545 603 path relative current; +#X text 48 176 You can use the "current" and "relative" keywords to +change the default behavior. The order of the keywords is not important. +; +#X text 570 453 <- a bang will output the current patch's path; +#X text 591 82 Absolute paths will be made relative to the root patch's +path; +#X text 596 494 Absolute paths will be made relative to the current +patch's path; +#X connect 1 0 4 0; +#X connect 2 0 4 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 12 0 4 0; +#X connect 13 0 4 0; +#X connect 14 0 22 0; +#X connect 15 0 22 0; +#X connect 17 0 19 0; +#X connect 18 0 17 0; +#X connect 19 0 22 0; +#X connect 22 0 20 0; +#X connect 25 0 27 0; +#X connect 27 0 26 0; +#X connect 37 0 27 0; +#X connect 40 0 49 0; +#X connect 41 0 49 0; +#X connect 42 0 44 0; +#X connect 43 0 42 0; +#X connect 44 0 49 0; +#X connect 49 0 45 0; diff --git a/help/streamMinMax-help.pd b/help/streamMinMax-help.pd new file mode 100644 index 0000000..a9a613d --- /dev/null +++ b/help/streamMinMax-help.pd @@ -0,0 +1,28 @@ +#N canvas 425 210 412 446 10; +#X obj 118 267 streamMinMax; +#X floatatom 82 146 5 0 0 0 - - -; +#X obj 199 195 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X floatatom 118 297 5 0 0 0 minimum - -; +#X floatatom 188 322 5 0 0 0 maximum - -; +#X text 216 193 reset; +#X text 61 124 number stream; +#X obj 2 -43 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 7 1 author: mrtoftrash@gmail.com; +#X text 7 -44 description: outputs the minimum and maximum float of +a stream of numbers.; +#X text 7 -10 tags: stream; +#X text 7 12 version: 2009-05-07 (initial release); +#X obj 9 95 streamMinMax 45 100; +#X text 210 145 set minimum and maximum; +#X text 4 74 Argument 2: maximum value at start (defaults to none) +; +#X text 4 59 Argument 1: minimum value at start (defaults to none) +; +#X msg 168 144 43 90; +#X connect 0 0 3 0; +#X connect 0 1 4 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 16 0 0 0; diff --git a/help/wrapper-help.pd b/help/wrapper-help.pd new file mode 100644 index 0000000..06abf4d --- /dev/null +++ b/help/wrapper-help.pd @@ -0,0 +1,27 @@ +#N canvas 226 243 486 349 10; +#X text 114 176 Wraps between 0 and 1 by default; +#X text 137 276 This instance wraps the input between 2 and 8; +#X floatatom 52 205 5 0 0 0 - - -; +#X floatatom 50 138 5 0 0 0 - - -; +#X floatatom 91 138 5 0 0 0 - - -; +#X floatatom 134 140 5 0 0 0 - - -; +#X floatatom 50 242 5 0 0 0 - - -; +#X floatatom 92 243 5 0 0 0 - - -; +#X floatatom 136 242 5 0 0 0 - - -; +#X floatatom 50 306 5 0 0 0 - - -; +#X obj 52 177 wrapper; +#X obj 50 277 wrapper 2 8; +#X obj 42 2 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577 +0; +#X text 47 36 author: mrtoftrash@gmail.com; +#X text 48 2 description: wraps a number around a range; +#X text 47 47 version: 2009-06-07 (initial release); +#X text 47 25 tags: math range tof; +#X connect 3 0 10 0; +#X connect 4 0 10 1; +#X connect 5 0 10 2; +#X connect 6 0 11 0; +#X connect 7 0 11 1; +#X connect 8 0 11 2; +#X connect 10 0 2 0; +#X connect 11 0 9 0; diff --git a/src/argument.c b/src/argument.c new file mode 100644 index 0000000..0c7df4b --- /dev/null +++ b/src/argument.c @@ -0,0 +1,119 @@ +/* + * argument.c + * + * Copyright 2009 Thomas O Fredericks <tom@hp> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "tof.h" + +t_class *argument_class; + +typedef struct argument +{ + t_object x_ob; + //t_canvas * x_canvas; + t_outlet* x_outlet; + t_atom x_a; + int has_value; +} t_argument; + +static void argument_bang(t_argument *x) +{ + + if (x->has_value) { + if ( IS_A_SYMBOL(&(x->x_a),0) ) { + outlet_symbol(x->x_outlet,atom_getsymbol(&(x->x_a))); + } else { + outlet_float(x->x_outlet,atom_getfloat(&(x->x_a))); + } + } + + +} + + +static void argument_free(t_argument *x) { + + //freebytes(x->x_a, sizeof(t_atom)); +} + + +//static void *argument_new(t_floatarg level) +static void *argument_new(t_symbol *s, int argc, t_atom *argv) +{ + t_argument *x = (t_argument *)pd_new(argument_class); + + + t_canvas *canvas=tof_get_canvas(); + + x->x_outlet = outlet_new(&x->x_ob, &s_list); + //x->x_a = (t_atom *)getbytes(sizeof(t_atom)); + + x->has_value = 0; + int i = 0; + + // Check argument i and default value + if ( argc >= 1 && IS_A_FLOAT(argv,0) ) { + i = atom_getfloat(argv); + } + + // Get the canvas' arguments + int ac; + t_atom *av; + tof_get_canvas_arguments(canvas,&ac, &av); + + + // Check arguments + + if ( i == 0) { //Is the argument index 0? + // Get the dollar zero + SETSYMBOL(&(x->x_a),tof_get_dollar(canvas,gensym("$0"))); + x->has_value = 1; + } else { + //if ( ac >= i ) { + if ( argc > 1 ) { //Is there a default argument? + //Are the parent and default arguments the same type? + if ( ac >= i && (av+(i-1))->a_type == (argv+1)->a_type) { + x->x_a = av[i-1]; //Use the parent value + } else { + x->x_a = argv[1]; //Use the default value + } + x->has_value = 1; + } else { //No default argument, so no type check + if ( ac >= i ) { //Are there enough parent arguments? + x->x_a = av[i-1]; //Use the parent value + x->has_value = 1; + } + } + + //} + } + + return (void *)x; +} + +void argument_setup(void) +{ + + argument_class = class_new(gensym("argument"), + (t_newmethod)argument_new, (t_method)argument_free, + sizeof(t_argument), CLASS_DEFAULT, A_GIMME,0); + class_addbang(argument_class, argument_bang); + +} + diff --git a/src/crossfade~.c b/src/crossfade~.c new file mode 100644 index 0000000..75cd9b6 --- /dev/null +++ b/src/crossfade~.c @@ -0,0 +1,137 @@ +#include "m_pd.h" + +//Create one input for each channel + + + +static t_class *crossfade_tilde_class; + +typedef struct _crossfade_tilde { + t_object x_obj; + t_float mix; //The mix value (0: input 1, 1:input2) + int n_in; + int channels; + t_sample **in; + int n_out; + t_sample **out; + t_sample f; + t_sample* buffer; //Input frame buffer: one sample of every input +} t_crossfade_tilde; + + + +// Perform +static t_int *crossfade_tilde_perform(t_int *w) +{ + + t_crossfade_tilde *x = (t_crossfade_tilde *)(w[1]); + int n = (int)(w[2]); + + if (x->mix < 0) x->mix = 0; + if (x->mix > 1) x->mix = 1; + t_float inv_mix = 1-x->mix; + + + + int i; + int j; + t_sample* out; + + + for ( j =0; j < n; j++) { + + // Copy one sample of all the inputs + for ( i=0; i < x->n_in;i++ ) { + x->buffer[i] = (t_sample) x->in[i][j]; + } + + for ( i=0; i < x->channels;i++ ) { + + out = (t_sample *)(x->out[i]); + out[j] = (x->buffer[i] * inv_mix) + (x->buffer[i+x->channels] * x->mix) ; + } + } + + + + return (w+3); + +} + + +// Annouce signal inputs and outputs to the DSP chain +static void crossfade_tilde_dsp(t_crossfade_tilde *x, t_signal **sp) +{ + + int n; + t_sample **dummy=x->in; + for(n=0;n<x->n_in;n++)*dummy++=sp[n]->s_vec; + + dummy=x->out; + for(n=0;n<x->n_out;n++)*dummy++=sp[n+x->n_in]->s_vec; + + + dsp_add(crossfade_tilde_perform, 2, x, sp[0]->s_n); + +} + +static void crossfade_tilde_free( t_crossfade_tilde *x) { + + freebytes(x->in, x->n_in * sizeof(t_sample *)); + freebytes(x->out, x->n_out * sizeof(t_sample *)); + + freebytes(x->buffer,x->n_in * sizeof( * x->buffer)); +} + +static void *crossfade_tilde_new(t_floatarg f) +{ + t_crossfade_tilde *x = (t_crossfade_tilde *)pd_new(crossfade_tilde_class); + + + x->channels = (int) f; + if ( x->channels < 1 ) x->channels = 2; + + + + x->n_in = x->channels * 2; + x->in = (t_sample **)getbytes(x->n_in * sizeof(t_sample *)); + int i=x->n_in; + while(i--)x->in[i]=0; + + x->n_out = x->channels; + x->out = (t_sample **)getbytes(x->n_in * sizeof(t_sample *)); + i=x->n_out; + while(i--)x->out[i]=0; + + + x->buffer = getbytes(x->n_in * sizeof( * x->buffer)); + + + + for (i=0; i < x->n_in - 1; i++) { + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + } + + for (i=0; i < x->n_out; i++) { + outlet_new(&x->x_obj, &s_signal); + } + + + floatinlet_new (&x->x_obj, &x->mix); + + + return (void *)x; +} + + void crossfade_tilde_setup(void) { + + crossfade_tilde_class = class_new(gensym("crossfade~"), + (t_newmethod)crossfade_tilde_new, + (t_method)crossfade_tilde_free, sizeof(t_crossfade_tilde), + 0, A_DEFFLOAT, 0); + + class_addmethod(crossfade_tilde_class, + (t_method)crossfade_tilde_dsp, gensym("dsp"), 0); + // class_addmethod(crossfade_tilde_class, nullfn, gensym("signal"), 0); + CLASS_MAINSIGNALIN(crossfade_tilde_class, t_crossfade_tilde, f); +} diff --git a/src/increment.c b/src/increment.c new file mode 100644 index 0000000..25e7924 --- /dev/null +++ b/src/increment.c @@ -0,0 +1,151 @@ +#include "m_pd.h" + +static t_class *increment_class; + +typedef struct _increment { + t_object x_obj; + int reset; + t_float value; + t_float inc; + t_outlet* outlet1; + t_float start; + //t_outlet* outlet2; +} t_increment; + + +static void increment_bang(t_increment *x) +{ + + if ( x->reset) { + x->reset = 0; + } else { + x->value = x->value + x->inc; + } + outlet_float(x->outlet1,x->value); + + + +} +/* +static void increment_float(t_increment *x, t_float f) +{ + x->inc = f; + increment_bang(x); +} +*/ + +static void increment_step(t_increment *x, t_float f) +{ + x->inc = f; + +} + +static void increment_reset(t_increment *x) +{ + + //post("before"); + // post("start:%d",(int)x->start); + // post("value:%d",(int)x->value); + + x->value = x->start; + x->reset = 1; + + // post("after"); + //post("start:%d",(int)x->start); + //post("value:%d",(int)x->value); +} + +static void increment_set(t_increment *x, t_float f) +{ + + + + x->value = f; + x->start = f; + x->reset = 1; + + + +} + + + + +/* +void increment_list(t_increment *x,t_symbol *s, int argc, t_atom *argv) +{ + + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } + + +} +*/ + +static void increment_free(t_increment *x) +{ + + +} + +void *increment_new(t_symbol *s, int argc, t_atom *argv) +{ + t_increment *x = (t_increment *)pd_new(increment_class); + + x->reset = 1; + x->value = 0; + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->value = atom_getfloat(argv); + x->inc = 1; + } else { + x->value = 0; + x->inc = 1; + } + + x->start = x->value; + + //post("start:%d",(int)x->start); + //post("value:%d",(int)x->value); + + inlet_new(&x->x_obj, &x->x_obj.ob_pd, + gensym("float"), gensym("set")); + + floatinlet_new(&x->x_obj, &x->inc); + + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + //x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void increment_setup(void) { + increment_class = class_new(gensym("increment"), + (t_newmethod)increment_new, + (t_method)increment_free, sizeof(t_increment), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (increment_class, increment_bang); + //class_addfloat (increment_class, increment_float); + class_addmethod(increment_class, + (t_method)increment_set, gensym("set"), + A_DEFFLOAT, 0); + class_addmethod(increment_class, + (t_method)increment_step, gensym("step"), + A_DEFFLOAT, 0); + class_addmethod(increment_class, + (t_method)increment_reset, gensym("reset"), + 0); + + //class_addlist (increment_class, increment_list); + +} diff --git a/src/iterate.c b/src/iterate.c new file mode 100644 index 0000000..8fee7ac --- /dev/null +++ b/src/iterate.c @@ -0,0 +1,105 @@ +#include "m_pd.h" + +static t_class *iterate_class; + +typedef struct _iterate { + t_object x_obj; + + t_float start; + t_float step; + t_int iterating; + t_outlet* outlet1; + //t_outlet* outlet2; +} t_iterate; + + +static void iterate_bang(t_iterate *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} + + +static void iterate_start(t_iterate *x, t_float f) { + + x->start = f; +} + + +static void iterate_step(t_iterate *x, t_float f) { + + x->step = f; +} + +static void iterate_float(t_iterate *x, t_float f) +{ + + if ( f < 0 ) f = 0; + + int i; + t_float value = x->start; + x->iterating = 1; + + for ( i = 0; i < f; i++) { + if ( !(x->iterating) ) break; + + outlet_float(x->outlet1, value); + value = value + x->step; + } + +} + + +static void iterate_free(t_iterate *x) +{ + + +} + +static void *iterate_new(t_symbol *s, int argc, t_atom *argv) +{ + t_iterate *x = (t_iterate *)pd_new(iterate_class); + + x->iterating = 0; + if ( argc >= 2) { + x->start = atom_getfloat(argv); + x->step = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->start = atom_getfloat(argv); + x->step = 1; + } else { + x->start = 0; + x->step = 1; + } + + floatinlet_new(&x->x_obj, &x->start); + floatinlet_new(&x->x_obj, &x->step); + x->outlet1 = outlet_new(&x->x_obj, &s_float); + //x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void iterate_setup(void) { + iterate_class = class_new(gensym("iterate"), + (t_newmethod)iterate_new, + (t_method)iterate_free, sizeof(t_iterate), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (iterate_class, iterate_bang); + class_addfloat (iterate_class, iterate_float); + + class_addmethod(iterate_class, + (t_method)iterate_start, gensym("start"), + A_DEFFLOAT, 0); + + class_addmethod(iterate_class, + (t_method)iterate_step, gensym("step"), + A_DEFFLOAT, 0); + + //class_addlist (iterate_class, iterate_list); + +} diff --git a/src/listUnfold.c b/src/listUnfold.c new file mode 100644 index 0000000..579f645 --- /dev/null +++ b/src/listUnfold.c @@ -0,0 +1,88 @@ +#include "m_pd.h" +#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL) +#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT) + + +static t_class *listUnfold_class; + +typedef struct _listUnfold { + t_object x_obj; + + //t_float start; + //t_float step; + t_int iterating; + t_outlet* outlet1; + t_outlet* outlet2; +} t_listUnfold; + + +void listUnfold_bang(t_listUnfold *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} + + +void listUnfold_anything(t_listUnfold *x, t_symbol* s, int ac, t_atom* av) +{ + int i = 0; + int count = 0; + x->iterating = 1; + + if ( s != &s_list && s != &s_float && s != &s_symbol ) { + outlet_float(x->outlet2,0); + outlet_symbol(x->outlet1,s); + count++; + } + + for ( ; i < ac; i++ ) { + if ( !(x->iterating) ) break; + outlet_float(x->outlet2,count); + count++; + if ( IS_A_FLOAT(av,i) ) { + outlet_float(x->outlet1,atom_getfloat(av+i)); + } else { + outlet_symbol(x->outlet1,atom_getsymbol(av+i)); + } + + } + + +} + + +static void listUnfold_free(t_listUnfold *x) +{ + + +} + +void *listUnfold_new(t_symbol *s, int argc, t_atom *argv) +{ + t_listUnfold *x = (t_listUnfold *)pd_new(listUnfold_class); + + x->iterating = 0; + + + //floatinlet_new(&x->x_obj, &x->start); + //floatinlet_new(&x->x_obj, &x->step); + x->outlet1 = outlet_new(&x->x_obj, &s_list); + x->outlet2 = outlet_new(&x->x_obj, &s_float); + + + return (void *)x; +} + +void listUnfold_setup(void) { + listUnfold_class = class_new(gensym("listUnfold"), + (t_newmethod)listUnfold_new, + (t_method)listUnfold_free, sizeof(t_listUnfold), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (listUnfold_class, listUnfold_bang); + class_addanything (listUnfold_class, listUnfold_anything); + //class_addlist (listUnfold_class, listUnfold_list); + +} diff --git a/src/path.c b/src/path.c new file mode 100644 index 0000000..d0dc7ef --- /dev/null +++ b/src/path.c @@ -0,0 +1,252 @@ + +#include "tof.h" +#define SLASH '/' + +static t_class *path_class; + +typedef struct _path { + t_object x_obj; + //char buffer[MAXPDSTRING]; + t_outlet* outlet1; + //t_canvas* canvas; + t_symbol* dir; + t_symbol* mode; + t_symbol* dirmode; + t_symbol* s_current; + t_symbol* s_relative; +} t_path; + + +// Code from http://www.codeguru.com/cpp/misc/misc/fileanddirectorynaming/article.php/c263#more +static void getRelativeFilename(char* relativeFilename, char *currentDirectory, char *absoluteFilename) +{ + // declarations - put here so this should work in a C compiler + int afMarker = 0, rfMarker = 0; + int cdLen = 0, afLen = 0; + int i = 0; + int levels = 0; + //static char relativeFilename[MAX_FILENAME_LEN+1]; + + cdLen = strlen(currentDirectory); + afLen = strlen(absoluteFilename); + + + // Handle DOS names that are on different drives: + if(currentDirectory[0] != absoluteFilename[0]) + { + // not on the same drive, so only absolute filename will do + strcpy(relativeFilename, absoluteFilename); + return; + } + + // they are on the same drive, find out how much of the current directory + // is in the absolute filename + i = 1;//ABSOLUTE_NAME_START; + while(i < afLen && i < cdLen && currentDirectory[i] == absoluteFilename[i]) + { + i++; + } + + if(i == cdLen && (absoluteFilename[i] == SLASH || absoluteFilename[i-1] == SLASH)) + { + // the whole current directory name is in the file name, + // so we just trim off the current directory name to get the + // current file name. + if(absoluteFilename[i] == SLASH) + { + // a directory name might have a trailing slash but a relative + // file name should not have a leading one... + i++; + } + + strcpy(relativeFilename, &absoluteFilename[i]); + return; + } + + + // The file is not in a child directory of the current directory, so we + // need to step back the appropriate number of parent directories by + // using "..\"s. First find out how many levels deeper we are than the + // common directory + afMarker = i; + levels = 1; + + // count the number of directory levels we have to go up to get to the + // common directory + while(i < cdLen) + { + i++; + if(currentDirectory[i] == SLASH) + { + // make sure it's not a trailing slash + i++; + if(currentDirectory[i] != '\0') + { + levels++; + } + } + } + + // move the absolute filename marker back to the start of the directory name + // that it has stopped in. + while(afMarker > 0 && absoluteFilename[afMarker-1] != SLASH) + { + afMarker--; + } + + + + // add the appropriate number of "..\"s. + rfMarker = 0; + for(i = 0; i < levels; i++) + { + relativeFilename[rfMarker++] = '.'; + relativeFilename[rfMarker++] = '.'; + relativeFilename[rfMarker++] = SLASH; + } + + // copy the rest of the filename into the result string + strcpy(&relativeFilename[rfMarker], &absoluteFilename[afMarker]); + + //return relativeFilename; +} + + +// BANG: output the current root path +static void path_bang(t_path *x) +{ + + outlet_symbol(x->outlet1, x->dir ); + + +} + +static void path_anything(t_path *x, t_symbol *s, int ac, t_atom* av) { + + + + int length = tof_anything_to_string(s,ac,av,tof_buf_temp_a); + t_symbol* result; + + if ( x->mode == x->s_relative ) { + + // TRANSFORM ABSOLUTE PATHS TO RELATIVE PATHS + + // Is this a relative path? + // Checks for a starting / or a : as second character + if ( tof_path_is_absolute(tof_buf_temp_a,length )) { + getRelativeFilename(tof_buf_temp_b,x->dir->s_name,tof_buf_temp_a); + result = gensym(tof_buf_temp_b); + } else { + result = gensym(tof_buf_temp_a); + } + + } else { + + // TRANFORM RELATIVE PATHS TO ABSOLUTE PATHS + + // Is this a relative path? + if ( tof_path_is_absolute(tof_buf_temp_a,length) ) { + result = gensym(tof_buf_temp_a); + } else { + strcpy(tof_buf_temp_b,x->dir->s_name); + strcat(tof_buf_temp_b,tof_buf_temp_a); + result = gensym(tof_buf_temp_b); + } + } + + outlet_symbol(x->outlet1, result); +} + + + + +/* +void path_list(t_path *x,t_symbol *s, int argc, t_atom *argv) +{ + + + if ( argc >= 2) { + x->value = atom_getfloat(argv); + x->inc = atom_getfloat(argv+1); + } + + +} +*/ + + + + + +static void path_free(t_path *x) +{ + + //binbuf_free(x->binbuf); + +} + +void *path_new(t_symbol *s, int argc, t_atom *argv) +{ + t_path *x = (t_path *)pd_new(path_class); + + + x->s_current = gensym("current"); + x->s_relative = gensym("relative"); + + int i; + t_symbol * mode_temp; + for ( i = 0; i < argc; i++) { + if ( IS_A_SYMBOL(argv,i) ) { + mode_temp = atom_getsymbol(argv+i); + if ( mode_temp == x->s_current ) x->dirmode = x->s_current; + if ( mode_temp == x->s_relative) x->mode = x->s_relative; + } + } + + if ( x->dirmode == x->s_current) { + x->dir = tof_get_dir(tof_get_canvas()); + } else { + x->dir = tof_get_dir(tof_get_root_canvas(tof_get_canvas())); + + } + strcpy(tof_buf_temp_a,x->dir->s_name); + strcat(tof_buf_temp_a,"/"); + x->dir = gensym(tof_buf_temp_a); + + /* + inlet_new(&x->x_obj, &x->x_obj.ob_pd, + gensym("float"), gensym("set")); + + floatinlet_new(&x->x_obj, &x->inc); + */ + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + + + + return (void *)x; +} + +void path_setup(void) { + path_class = class_new(gensym("path"), + (t_newmethod)path_new, + (t_method)path_free, sizeof(t_path), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang(path_class, path_bang); + class_addanything(path_class,path_anything); + + //class_addmethod(path_class, + // (t_method)path_append, gensym("append"), + // A_GIMME, 0); + + //class_addfloat (path_class, path_float); + /*class_addmethod(path_class, + (t_method)path_set, gensym("set"), + A_DEFFLOAT, 0); +*/ + //class_addlist (path_class, path_list); + +} diff --git a/src/streamMinMax.c b/src/streamMinMax.c new file mode 100644 index 0000000..c2fb438 --- /dev/null +++ b/src/streamMinMax.c @@ -0,0 +1,107 @@ +#include "m_pd.h" + +static t_class *streamMinMax_class; + +typedef struct _streamMinMax { + t_object x_obj; + + t_float min; + t_float max; + t_int reset; + //t_outlet *f_out, *b_out; + t_outlet* outlet1; + t_outlet* outlet2; +} t_streamMinMax; + +void streamMinMax_float(t_streamMinMax *x, t_float f) +{ + + if ( x->reset) { + x->min = f; + x->max = f; + x->reset = 0; + } else { + if (f < x->min) x->min = f; + if (f > x->max) x->max = f; + } + + outlet_float(x->outlet1, x->min); + outlet_float(x->outlet2, x->max); +} + +void streamMinMax_bang(t_streamMinMax *x) +{ + //x->i_count = x->i_down; + x->reset = 1; + +} + +void streamMinMax_list(t_streamMinMax *x,t_symbol *s, int argc, t_atom *argv) +{ + + if (argc >= 2) { + float a = atom_getfloat(argv+1); + float b = atom_getfloat(argv); + if (a > b ) { + x->max=a; + x->min=b; + } else { + x->max=b; + x->min=a; + } + x->reset = 0; + } + +} + +static void streamMinMax_free(t_streamMinMax *x) +{ + + +} + +void *streamMinMax_new(t_symbol *s, int argc, t_atom *argv) +{ + t_streamMinMax *x = (t_streamMinMax *)pd_new(streamMinMax_class); + + x->reset = 1; + + streamMinMax_list(x,&s_list,argc,argv); + + + + //inlet_new(&x->x_obj, &x->x_obj.ob_pd, + // gensym("list"), gensym("bound")); + + //floatinlet_new(&x->x_obj, &x->step); + + x->outlet1 = outlet_new(&x->x_obj, &s_float); + x->outlet2 = outlet_new(&x->x_obj, &s_float); + //x->b_out = outlet_new(&x->x_obj, &s_bang); + + return (void *)x; +} + +void streamMinMax_setup(void) { + streamMinMax_class = class_new(gensym("streamMinMax"), + (t_newmethod)streamMinMax_new, + (t_method)streamMinMax_free, sizeof(t_streamMinMax), + CLASS_DEFAULT, + A_GIMME, 0); + + class_addbang (streamMinMax_class, streamMinMax_bang); + class_addfloat (streamMinMax_class, streamMinMax_float); + class_addlist (streamMinMax_class, streamMinMax_list); + /* + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_reset, gensym("reset"), 0); + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_set, gensym("set"), + A_DEFFLOAT, 0); + class_addmethod(streamMinMax_class, + (t_method)streamMinMax_bound, gensym("bound"), + A_DEFFLOAT, A_DEFFLOAT, 0); + + class_sethelpsymbol(streamMinMax_class, gensym("help-streamMinMax")); + */ +} diff --git a/src/wrapper.c b/src/wrapper.c new file mode 100644 index 0000000..8d0ec5e --- /dev/null +++ b/src/wrapper.c @@ -0,0 +1,81 @@ +#include "m_pd.h" +#include <math.h> + +static t_class *wrapper_class; + +typedef struct _wrapper { + t_object x_obj; + + t_float min; + t_float max; + //t_int iterating; + t_outlet* outlet1; + //t_outlet* outlet2; +} t_wrapper; + +/* +void wrapper_bang(t_wrapper *x) +{ + //x->i_count = x->i_down; + x->iterating = 0; + +} +*/ + +void wrapper_float(t_wrapper *x, t_float f) +{ + + t_float value = fmod(f - x->min ,x->max - x->min); + if ( value < 0 ) value = value + x->max; + else value = value + x->min; + + outlet_float(x->outlet1, value); + + +} + + + +static void wrapper_free(t_wrapper *x) +{ + + +} + +void *wrapper_new(t_symbol *s, int argc, t_atom *argv) +{ + t_wrapper *x = (t_wrapper *)pd_new(wrapper_class); + + + if ( argc >= 2) { + x->min = atom_getfloat(argv); + x->max = atom_getfloat(argv+1); + } else if ( argc == 1) { + x->min = 0; + x->max = atom_getfloat(argv); + } else { + x->min = 0; + x->max = 1; + } + + floatinlet_new(&x->x_obj, &x->min); + floatinlet_new(&x->x_obj, &x->max); + x->outlet1 = outlet_new(&x->x_obj, &s_float); + + + + return (void *)x; +} + +void wrapper_setup(void) { + wrapper_class = class_new(gensym("wrapper"), + (t_newmethod)wrapper_new, + (t_method)wrapper_free, sizeof(t_wrapper), + CLASS_DEFAULT, + A_GIMME, 0); + + //class_addbang (wrapper_class, wrapper_bang); + class_addfloat (wrapper_class, wrapper_float); + //class_addlist (wrapper_class, wrapper_list); + +} |