aboutsummaryrefslogtreecommitdiff
path: root/src/mtx_resize.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-21 14:33:31 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-21 14:33:31 +0000
commit10b474fba485e9a93157c7fa534bb66e7bcc6fde (patch)
tree73e9e02738ea62179a1722b37ef49a9e91cfcbad /src/mtx_resize.c
This commit was generated by cvs2svn to compensate for changes in r2637,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/iem/iemmatrix/; revision=2638
Diffstat (limited to 'src/mtx_resize.c')
-rw-r--r--src/mtx_resize.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/mtx_resize.c b/src/mtx_resize.c
new file mode 100644
index 0000000..edc2e17
--- /dev/null
+++ b/src/mtx_resize.c
@@ -0,0 +1,103 @@
+/*
+ * iemmatrix
+ *
+ * objects for manipulating simple matrices
+ * mostly refering to matlab/octave matrix functions
+ *
+ * (c) IOhannes m zmlnig, forum::fr::umlute
+ *
+ * IEM, Graz
+ *
+ * this code is published under the LGPL
+ *
+ */
+#include "iemmatrix.h"
+
+/* mtx_resize */
+
+static t_class *mtx_resize_class;
+static void mtx_resize_list2(t_matrix *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int r, c;
+ if (argc<1)return;
+ if (argc>2)error("mtx_resize : only rows & cols are needed, skipping the rest");
+ if (argc==1)r=c=atom_getfloat(argv++);
+ else{
+ r=atom_getfloat(argv++);
+ c=atom_getfloat(argv++);
+ }
+
+ if (r<0)r=0;
+ if (c<0)c=0;
+
+ x->current_row = r;
+ x->current_col = c;
+}
+
+static void mtx_resize_matrix(t_matrix *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int row=atom_getfloat(argv);
+ int col=atom_getfloat(argv+1);
+ int r = x->current_row, c = x->current_col;
+ int R=0, ROW, COL;
+
+ if (argc<2){ post("mtx_add: crippled matrix"); return; }
+ if ((col<1)||(row<1)) { post("mtx_add: invalid dimensions"); return; }
+ if (col*row>argc-2){ post("sparse matrix not yet supported : use \"mtx_check\""); return; }
+
+ if (!r)r=row;
+ if (!c)c=col;
+
+ if (r==row && c==col) { // no need to change
+ outlet_anything(x->x_obj.ob_outlet, gensym("matrix"), argc, argv);
+ return;
+ }
+
+ x->atombuffer=(t_atom *)getbytes((c*r+2)*sizeof(t_atom));
+ setdimen(x, r, c);
+ matrix_set(x, 0);
+
+ ROW=(r<row)?r:row;
+ COL=(c<col)?c:col;
+ R=ROW;
+ while(R--)memcpy(x->atombuffer+2+(ROW-R-1)*c, argv+2+(ROW-R-1)*col, COL*sizeof(t_atom));
+
+ matrix_bang(x);
+
+ freebytes(x->atombuffer, (c*r+2)*sizeof(t_atom));
+}
+
+static void *mtx_resize_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_matrix *x = (t_matrix *)pd_new(mtx_resize_class);
+ int c=0, r=0;
+
+ if(argc){
+ if(argc-1){
+ r=atom_getfloat(argv);
+ c=atom_getfloat(argv+1);
+ } else r=c=atom_getfloat(argv);
+ if(c<0)c=0;
+ if(r<0)r=0;
+ }
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym(""));
+ outlet_new(&x->x_obj, 0);
+ x->current_row = r;
+ x->current_col = c;
+ x->row = x->col= 0;
+ x->atombuffer = 0;
+
+ return (x);
+}
+void mtx_resize_setup(void)
+{
+ mtx_resize_class = class_new(gensym("mtx_resize"), (t_newmethod)mtx_resize_new,
+ 0, sizeof(t_matrix), 0, A_GIMME, 0);
+ class_addmethod (mtx_resize_class, (t_method)mtx_resize_matrix, gensym("matrix"), A_GIMME, 0);
+ class_addmethod (mtx_resize_class, (t_method)mtx_resize_list2, gensym(""), A_GIMME, 0);
+ class_sethelpsymbol(mtx_resize_class, gensym("iemmatrix/mtx_size"));
+}
+void iemtx_resize_setup(void){
+ mtx_resize_setup();
+}
+