aboutsummaryrefslogtreecommitdiff
path: root/src/0x2e.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/0x2e.c')
-rw-r--r--src/0x2e.c77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/0x2e.c b/src/0x2e.c
index d138ed7..7dc06c9 100644
--- a/src/0x2e.c
+++ b/src/0x2e.c
@@ -1,4 +1,4 @@
-/*
+/*
* [.]: scala multiplication
*
* (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
@@ -7,12 +7,12 @@
* 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, see <http://www.gnu.org/licenses/>.
*/
@@ -23,8 +23,7 @@
static t_class *scalmul_class;
static t_class *scalmul_scal_class;
-typedef struct _scalmul
-{
+typedef struct _scalmul {
t_object x_obj;
t_int n1, n2;
@@ -35,7 +34,8 @@ typedef struct _scalmul
} t_scalmul;
-static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc, t_atom *argv)
+static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc,
+ t_atom *argv)
{
t_float *fp;
if (x->n2 != argc) {
@@ -44,30 +44,35 @@ static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc, t_atom *ar
x->buf2=(t_float *)getbytes(sizeof(t_float)*x->n2);
};
fp = x->buf2;
- while(argc--)*fp++=atom_getfloat(argv++);
+ while(argc--) {
+ *fp++=atom_getfloat(argv++);
+ }
}
-static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *argv)
+static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc,
+ t_atom *argv)
{
t_float *fp;
t_atom *ap;
int n;
- if (argc){
+ if (argc) {
if (x->n1 != argc) {
freebytes(x->buf1, x->n1 * sizeof(t_float));
x->n1 = argc;
x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1);
};
fp = x->buf1;
- while(argc--)*fp++=atom_getfloat(argv++);
+ while(argc--) {
+ *fp++=atom_getfloat(argv++);
+ }
}
- if (x->n1*x->n2==1){
+ if (x->n1*x->n2==1) {
outlet_float(x->x_obj.ob_outlet, *x->buf1**x->buf2);
return;
}
- if (x->n1==1){
+ if (x->n1==1) {
t_atom *a;
int i = x->n2;
t_float f = *x->buf1;
@@ -75,11 +80,11 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg
n = x->n2;
ap = (t_atom *)getbytes(sizeof(t_atom)*n);
a = ap;
- while(i--){
+ while(i--) {
SETFLOAT(a, *fp++*f);
a++;
}
- } else if (x->n2==1){
+ } else if (x->n2==1) {
t_float f = *x->buf2;
t_atom *a;
int i = x->n1;
@@ -87,7 +92,7 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg
ap = (t_atom *)getbytes(sizeof(t_atom)*n);
a = ap;
fp = x->buf1;
- while(i--){
+ while(i--) {
SETFLOAT(a, *fp++*f);
a++;
}
@@ -97,14 +102,16 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg
t_float *fp2=x->buf2;
fp = x->buf1;
n = x->n1;
- if (x->n1!=x->n2){
+ if (x->n1!=x->n2) {
post("scalar multiplication: truncating vectors to the same length");
- if (x->n2<x->n1)n=x->n2;
+ if (x->n2<x->n1) {
+ n=x->n2;
+ }
}
ap = (t_atom *)getbytes(sizeof(t_atom)*n);
a = ap;
i=n;
- while(i--){
+ while(i--) {
SETFLOAT(a, *fp++**fp2++);
a++;
}
@@ -121,10 +128,12 @@ static void scalmul_free(t_scalmul *x)
static void *scalmul_new(t_symbol* UNUSED(s), int argc, t_atom *argv)
{
t_scalmul *x;
- if (argc-1){
+ if (argc-1) {
x = (t_scalmul *)pd_new(scalmul_class);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
- } else x = (t_scalmul *)pd_new(scalmul_scal_class);
+ } else {
+ x = (t_scalmul *)pd_new(scalmul_scal_class);
+ }
outlet_new(&x->x_obj, 0);
@@ -132,14 +141,17 @@ static void *scalmul_new(t_symbol* UNUSED(s), int argc, t_atom *argv)
x->buf1 =(t_float*)getbytes(sizeof(t_float));
*x->buf1=0;
- if (argc)scalmul_lst2(x, gensym("list"), argc, argv);
- else {
+ if (argc) {
+ scalmul_lst2(x, gensym("list"), argc, argv);
+ } else {
x->n2 =1;
x->buf2 =(t_float*)getbytes(sizeof(t_float));
*x->buf2=0;
}
- if (argc==1)floatinlet_new(&x->x_obj, x->buf2);
+ if (argc==1) {
+ floatinlet_new(&x->x_obj, x->buf2);
+ }
return (x);
}
@@ -151,16 +163,19 @@ static void scalmul_help(t_scalmul*x)
void setup_0x2e(void)
{
- scalmul_class = class_new(gensym("."), (t_newmethod)scalmul_new,
- (t_method)scalmul_free, sizeof(t_scalmul), 0, A_GIMME, 0);
+ scalmul_class = class_new(gensym("."), (t_newmethod)scalmul_new,
+ (t_method)scalmul_free, sizeof(t_scalmul), 0, A_GIMME, 0);
class_addlist(scalmul_class, scalmul_lst);
- class_addmethod (scalmul_class, (t_method)scalmul_lst2, gensym(""), A_GIMME, 0);
- class_addmethod(scalmul_class, (t_method)scalmul_help, gensym("help"), A_NULL);
+ class_addmethod (scalmul_class, (t_method)scalmul_lst2, gensym(""),
+ A_GIMME, 0);
+ class_addmethod(scalmul_class, (t_method)scalmul_help, gensym("help"),
+ A_NULL);
- scalmul_scal_class = class_new(gensym("."), 0, (t_method)scalmul_free,
- sizeof(t_scalmul), 0, 0);
+ scalmul_scal_class = class_new(gensym("."), 0, (t_method)scalmul_free,
+ sizeof(t_scalmul), 0, 0);
class_addlist(scalmul_scal_class, scalmul_lst);
- class_addmethod(scalmul_scal_class, (t_method)scalmul_help, gensym("help"), A_NULL);
+ class_addmethod(scalmul_scal_class, (t_method)scalmul_help, gensym("help"),
+ A_NULL);
class_sethelpsymbol(scalmul_class, gensym("scalarmult"));
class_sethelpsymbol(scalmul_scal_class, gensym("scalarmult"));
@@ -170,6 +185,6 @@ void setup_0x2e(void)
#ifndef ZEXY_LIBRARY
void setup(void)
{
- setup_0x2e();
+ setup_0x2e();
}
#endif