aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abs/mtx_linspace.pd43
-rw-r--r--abs/mtx_logspace.pd27
-rw-r--r--doc/mtx_colon-help.pd52
-rw-r--r--src/mtx_colon.c64
4 files changed, 168 insertions, 18 deletions
diff --git a/abs/mtx_linspace.pd b/abs/mtx_linspace.pd
new file mode 100644
index 0000000..1ad6947
--- /dev/null
+++ b/abs/mtx_linspace.pd
@@ -0,0 +1,43 @@
+#N canvas 661 125 619 626 10;
+#X obj 88 95 inlet;
+#X obj 88 370 outlet;
+#X text 85 50 linspace creates a linear scale between the start and
+end point with N points;
+#X text 239 128 arg1: startval;
+#X text 236 144 arg2: stopval;
+#X text 232 159 arg3: N;
+#X obj 188 168 - 1;
+#X obj 140 251 /;
+#X obj 140 231 pack f f;
+#X obj 88 292 mtx_* 0;
+#X obj 88 230 f;
+#X obj 126 188 f;
+#X obj 126 208 -;
+#X msg 88 249 0 \$1;
+#X obj 88 270 mtx_:;
+#X obj 88 167 t b b f;
+#X obj 88 313 mtx_+ \$1;
+#X obj 88 126 pack \$1 \$2 \$3;
+#X obj 88 147 unpack f f f;
+#X text 169 92 inlet is a 3 argument list;
+#X text 201 112 optional creation arguments:;
+#X connect 0 0 17 0;
+#X connect 6 0 8 1;
+#X connect 6 0 10 1;
+#X connect 7 0 9 1;
+#X connect 8 0 7 0;
+#X connect 9 0 16 0;
+#X connect 10 0 13 0;
+#X connect 11 0 12 0;
+#X connect 12 0 8 0;
+#X connect 13 0 14 0;
+#X connect 14 0 9 0;
+#X connect 15 0 10 0;
+#X connect 15 1 11 0;
+#X connect 15 2 12 1;
+#X connect 15 2 16 1;
+#X connect 16 0 1 0;
+#X connect 17 0 18 0;
+#X connect 18 0 15 0;
+#X connect 18 1 11 1;
+#X connect 18 2 6 0;
diff --git a/abs/mtx_logspace.pd b/abs/mtx_logspace.pd
new file mode 100644
index 0000000..ea85532
--- /dev/null
+++ b/abs/mtx_logspace.pd
@@ -0,0 +1,27 @@
+#N canvas 0 0 657 300 10;
+#X obj 147 50 inlet;
+#X obj 146 219 outlet;
+#X obj 147 104 unpack f f f;
+#X obj 148 128 log;
+#X obj 183 128 log;
+#X obj 149 151 pack f f f;
+#X obj 148 172 mtx_linspace;
+#X obj 147 194 mtx_exp;
+#X text 125 1 logspace creates a logarithmical scale between start
+and end point with N points;
+#X obj 147 80 pack \$1 \$2 \$3;
+#X text 385 104 arg1: startval;
+#X text 382 120 arg2: stopval;
+#X text 378 135 arg3: N;
+#X text 315 68 inlet is a 3 argument list;
+#X text 347 88 optional creation arguments:;
+#X connect 0 0 9 0;
+#X connect 2 0 3 0;
+#X connect 2 1 4 0;
+#X connect 2 2 5 2;
+#X connect 3 0 5 0;
+#X connect 4 0 5 1;
+#X connect 5 0 6 0;
+#X connect 6 0 7 0;
+#X connect 7 0 1 0;
+#X connect 9 0 2 0;
diff --git a/doc/mtx_colon-help.pd b/doc/mtx_colon-help.pd
new file mode 100644
index 0000000..f123acf
--- /dev/null
+++ b/doc/mtx_colon-help.pd
@@ -0,0 +1,52 @@
+#N canvas 419 109 670 565 10;
+#X text 458 17 updated for;
+#X obj 546 17 iemmatrix 0.2;
+#X obj 595 43 matrix;
+#X text 465 42 see also help for;
+#X msg 12 124 bang;
+#X text 90 15 [mtx_colon];
+#X text 47 34 colon operator: reading as row-vector / creating ascending
+number arrays;
+#X text 153 122 1 sequences;
+#X obj 12 277 mtx_print mtx_colon-sequence;
+#X obj 313 275 mtx_print mtx_colon-readout;
+#X obj 313 186 t a a;
+#X obj 432 231 mtx_print orig;
+#X obj 313 240 mtx_:;
+#X msg 85 141 bang;
+#X obj 12 233 mtx_:;
+#X msg 85 161 0 3;
+#X msg 12 145 2 1.5 7;
+#X text 422 120 2 linear read-out;
+#X text 8 60 you can create sequences (matrix vectors) with start-
+\, stop- and increment values. similar to octave you can also read
+out matrices linearly as vectors.;
+#X obj 301 411 mtx_print orig;
+#X obj 257 499 mtx_:;
+#X obj 257 434 mtx_transpose;
+#X obj 257 411 t a a;
+#X obj 257 456 mtx_repmat 1 3;
+#X obj 257 520 mtx_print sample-hold;
+#X msg 313 141 matrix 2 2 1 3 2 4;
+#X msg 257 358 matrix 1 4 1 2 3 4;
+#X obj 342 498 mtx_print repeated-orig;
+#X obj 257 477 t a a;
+#X text 251 324 this is e.g. useful when repeating values via sample+hold
+;
+#X connect 4 0 16 0;
+#X connect 10 0 12 0;
+#X connect 10 1 11 0;
+#X connect 12 0 9 0;
+#X connect 13 0 15 0;
+#X connect 14 0 8 0;
+#X connect 15 0 14 0;
+#X connect 16 0 14 0;
+#X connect 20 0 24 0;
+#X connect 21 0 23 0;
+#X connect 22 0 21 0;
+#X connect 22 1 19 0;
+#X connect 23 0 28 0;
+#X connect 25 0 10 0;
+#X connect 26 0 22 0;
+#X connect 28 0 20 0;
+#X connect 28 1 27 0;
diff --git a/src/mtx_colon.c b/src/mtx_colon.c
index 642eb4f..4e36630 100644
--- a/src/mtx_colon.c
+++ b/src/mtx_colon.c
@@ -16,15 +16,12 @@
#include "iemmatrix.h"
static t_class *mtx_colon_class;
-static t_symbol *col_sym;
-static t_symbol *col_sym2;
typedef struct _MTXColon_ MTXColon;
struct _MTXColon_
{
t_object x_obj;
int size;
- t_symbol *colon_mode;
t_atom *list_out;
t_outlet *list_outlet;
@@ -36,11 +33,6 @@ static void deleteMTXColon (MTXColon *mtx_colon_obj)
freebytes (mtx_colon_obj->list_out, sizeof(t_atom)*(mtx_colon_obj->size+2));
}
-static void mTXSetColonMode (MTXColon *mtx_colon_obj, t_symbol *c_mode)
-{
- mtx_colon_obj->colon_mode = c_mode;
-}
-
static void *newMTXColon (t_symbol *s, int argc, t_atom *argv)
{
MTXColon *mtx_colon_obj = (MTXColon *) pd_new (mtx_colon_class);
@@ -93,15 +85,8 @@ static void mTXColonList (MTXColon *mtx_colon_obj, t_symbol *s,
}
mtx_colon_obj->list_out = list_out;
- if ((mtx_colon_obj->colon_mode == col_sym)||
- (mtx_colon_obj->colon_mode == col_sym2)) {
- SETFLOAT (&list_out[1],1.0f);
- SETFLOAT (&list_out[0],(t_float)size);
- }
- else {
- SETFLOAT (&list_out[0],1.0f);
- SETFLOAT (&list_out[1],(t_float)size);
- }
+ SETFLOAT (&list_out[0],1.0f);
+ SETFLOAT (&list_out[1],(t_float)size);
list_out += 2;
for (;size--;list_out++,startval+=step)
SETFLOAT(list_out,startval);
@@ -110,6 +95,49 @@ static void mTXColonList (MTXColon *mtx_colon_obj, t_symbol *s,
}
}
+static void mTXColonMtx (MTXColon *mtx_colon_obj, t_symbol *s,
+ int argc, t_atom *argv)
+{
+ int rows = atom_getint (argv++);
+ int columns = atom_getint (argv++);
+ int size = rows * columns;
+ int list_size = argc - 2;
+ t_atom *list_ptr = argv;
+ t_atom *list_out = mtx_colon_obj->list_out;
+
+ if (!size) {
+ post("mtx_colon: invalid matrix dimensions");
+ return;
+ }
+ else if (list_size<size) {
+ post("mtx_colon: sparse matrix not yet supported: use \"mtx_check\"");
+ return;
+ }
+ else if (!list_out) {
+ list_out = (t_atom*) getbytes (sizeof (t_atom) * (size+2));
+ }
+ else if (size != mtx_colon_obj->size)
+ {
+ list_out = (t_atom*) resizebytes (list_out,
+ sizeof (t_atom) * (mtx_colon_obj->size+2),
+ sizeof (t_atom) * (size+2));
+ }
+ mtx_colon_obj->list_out = list_out;
+ mtx_colon_obj->size = size;
+
+ list_out+=2;
+ while (size--)
+ *list_out++ = *list_ptr++;
+
+ list_out = mtx_colon_obj->list_out;
+ size = mtx_colon_obj->size;
+
+ SETSYMBOL(list_out, gensym("matrix"));
+ SETFLOAT(list_out, 1);
+ SETFLOAT(&list_out[1], size);
+ mTXColonBang (mtx_colon_obj);
+}
+
void mtx_colon_setup (void)
{
mtx_colon_class = class_new
@@ -119,7 +147,7 @@ void mtx_colon_setup (void)
sizeof (MTXColon),
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_colon_class, (t_method) mTXColonBang);
- class_addmethod (mtx_colon_class, (t_method) mTXSetColonMode, gensym("mode"), A_SYMBOL, 0);
+ class_addmethod (mtx_colon_class, (t_method) mTXColonMtx, gensym("matrix"), A_GIMME, 0);
class_addlist (mtx_colon_class, (t_method) mTXColonList);
class_addcreator ((t_newmethod) newMTXColon, gensym("mtx_:"), A_GIMME, 0);