aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reference/cxc.split.pd58
-rw-r--r--split.c101
2 files changed, 104 insertions, 55 deletions
diff --git a/reference/cxc.split.pd b/reference/cxc.split.pd
index 823173b..a9719e0 100644
--- a/reference/cxc.split.pd
+++ b/reference/cxc.split.pd
@@ -1,46 +1,28 @@
-#N canvas 0 0 576 343 10;
-#X msg 142 36 62.116.43.90;
-#X obj 143 212 print;
+#N canvas 790 499 576 343 10;
#X obj 145 157 cxc.split .;
#X msg 243 100 set x;
-#X msg 300 100 set zwejdgb;
#X msg 176 99 set .;
-#X obj 384 260 print;
-#X obj 373 214 route bla;
-#X obj 268 232 pack f f f f;
-#X msg 266 148 bang;
-#X msg 268 194 2;
-#X msg 298 195 22;
-#X msg 320 193 3;
-#X msg 346 194 43;
-#X obj 267 171 t b b b b;
#X obj 111 277 unpack f f f f;
#X floatatom 111 307 5 0 0 0 - - -;
#X floatatom 153 307 5 0 0 0 - - -;
#X floatatom 194 307 5 0 0 0 - - -;
#X floatatom 233 307 5 0 0 0 - - -;
-#X msg 390 168 list 62 118 57 46;
-#X msg 278 28 bli.1.vlo.2.3.444;
-#X connect 0 0 2 0;
-#X connect 2 0 1 0;
-#X connect 2 0 15 0;
-#X connect 3 0 2 0;
-#X connect 4 0 2 0;
-#X connect 5 0 2 0;
-#X connect 7 1 6 0;
-#X connect 8 0 6 0;
-#X connect 9 0 14 0;
-#X connect 10 0 8 0;
-#X connect 11 0 8 1;
-#X connect 12 0 8 2;
-#X connect 13 0 8 3;
-#X connect 14 0 10 0;
-#X connect 14 1 11 0;
-#X connect 14 2 12 0;
-#X connect 14 3 13 0;
-#X connect 15 0 16 0;
-#X connect 15 1 17 0;
-#X connect 15 2 18 0;
-#X connect 15 3 19 0;
-#X connect 20 0 7 0;
-#X connect 21 0 2 0;
+#X msg 30 42 bli.5.bla.8.90;
+#X msg 29 14 62.116.7.89;
+#X msg 278 70 set /;
+#X msg 162 15 /home/someone/pd/test/patches/bla.pd;
+#X msg 300 100 set azwejdgb;
+#X obj 165 183 print;
+#X connect 0 0 3 0;
+#X connect 0 0 13 0;
+#X connect 1 0 0 0;
+#X connect 2 0 0 0;
+#X connect 3 0 4 0;
+#X connect 3 1 5 0;
+#X connect 3 2 6 0;
+#X connect 3 3 7 0;
+#X connect 8 0 0 0;
+#X connect 9 0 0 0;
+#X connect 10 0 0 0;
+#X connect 11 0 0 0;
+#X connect 12 0 0 0;
diff --git a/split.c b/split.c
index 69b2ce0..e3d57a1 100644
--- a/split.c
+++ b/split.c
@@ -1,4 +1,6 @@
#include <m_pd.h>
+#include <string.h>
+#include <math.h>
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
@@ -28,6 +30,51 @@ void split_symbol(t_split *x, t_symbol *s)
split_anything(x, s, 0, a);
}
+
+// move these to generic location later on
+int split_string_isnum(char* s)
+{
+ // int isnum = 1;
+ char tc;
+ while((tc = *s++) != '\0') {
+ // tc= s;
+ switch(tc) {
+ case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
+ // post("yo numba: %c", tc);
+ break;
+ default:
+ return 0;
+ break;
+ }
+ }
+ return 1;
+}
+
+float split_string2float(char* s)
+{
+ // check for '.' ...
+ int isnum = 1, cnt = strlen(s) - 1;
+ char tc;
+ int iret = 0, itmp = 0;
+ double factor = 10.;
+ float fret;
+ while((tc = *s++) != '\0') {
+ // tc= s;
+ switch(tc) {
+ case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
+ itmp = (int)pow(factor, (double)cnt);
+ // post("tempchar: %c, iret: %d, itmp: %d", tc, iret, itmp);
+ iret = iret + ((tc - 48) * itmp);
+ // post("tempchar: %c, iret: %d, cnt: %d", tc, iret, cnt);
+ break;
+ default:
+ break;
+ }
+ cnt--;
+ }
+ return (float)iret;
+}
+
void split_anything(t_split *x,t_symbol* s,t_int argc,t_atom* argv)
{
int i = argc; int j;
@@ -35,35 +82,55 @@ void split_anything(t_split *x,t_symbol* s,t_int argc,t_atom* argv)
t_atom a_out[256];
int c_out = 0;
t_atom* a = a_out;
- char u[MAXPDSTRING]; char v[MAXPDSTRING];
+ // char *str;
+ char u[MAXPDSTRING];
+ char v[MAXPDSTRING];
+ // char *v;
u[0] = '\0';
v[0] = '\0';
int isnum = 1;
+ float tf;
for(j=0; j<strlen(s->s_name); j++) {
u[0] = s->s_name[j];
if(u[0] == x->x_splitter->s_name[0]) {
- // post("found split: %d", v);
- post("found split: %d", (int)v);
-/* if(isnum) */
-/* SETFLOAT(a, (int)v); */
-/* else */
- SETSYMBOL(a, gensym(v));
- a++; c_out++;
- // reset stuff
- v[0] = '\0';
- isnum = 1;
+ if(v[0] != '\0') {
+ // check if string is digits only
+ if(split_string_isnum(v)) {
+ split_string2float(v);
+ tf = split_string2float(v);
+ SETFLOAT(a, tf);
+ // tf = 0.0;
+ }
+ else {
+ SETSYMBOL(a, gensym(v));
+ }
+ a++; c_out++;
+ // reset stuff
+ v[0] = '\0';
+ isnum = 1;
+ } // v[0] != '\0'
} else {
- if(!(48 <= u[0] <= 57)) {
- isnum = 0;
- }
+/* if(!(48 <= u[0] <= 57)) { */
+/* isnum = 0; */
+/* } */
strncat(v, u, 1);
- }
+ } // char matches splitter
+ }
+
+ // have to do this again here, damn.
+ if(split_string_isnum(v)) {
+ split_string2float(v);
+ tf = split_string2float(v);
+ SETFLOAT(a, tf);
+ tf = 0.0;
+ }
+ else {
+ SETSYMBOL(a, gensym(v));
}
- // post("found split: %s", v);
- SETSYMBOL(a, gensym(v));
a++, c_out++;
+
/* #if 1 */
/* // post("sym: %s",s->s_name); */
/* SETSYMBOL(a,s); */