aboutsummaryrefslogtreecommitdiff
path: root/iemlib2/src/iem_symtoalist.c
blob: eda8f8c3a794d2a69bb564be7aa9b8ac96c5f6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.

iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2008 */


#include "m_pd.h"
#include "iemlib.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>


/* ------------------------ iem_symtoalist --------------------- */
/* --------- converts a symbol to a ASCII list of floats ------- */

static t_class *iem_symtoalist_class;

typedef struct _iem_symtoalist
{
  t_object x_obj;
  char     x_string[MAXPDSTRING];
  t_atom   x_av[MAXPDSTRING];
} t_iem_symtoalist;

static void iem_symtoalist_symbol(t_iem_symtoalist *x, t_symbol *s)
{
  char *string=s->s_name;
  unsigned char uc;
  t_int i, n=strlen(string);
  
  for(i=0; i<n; i++)
  {
    uc = (unsigned char)string[i];
    SETFLOAT(x->x_av+i, (t_float)uc);
  }
  outlet_list(x->x_obj.ob_outlet, &s_list, n, x->x_av);
}

static void iem_symtoalist_float(t_iem_symtoalist *x, t_floatarg f)
{
  char string[40];
  unsigned char uc;
  t_int i, n;
  
  sprintf(string, "%g", f);
  n=strlen(string);
  for(i=0; i<n; i++)
  {
    uc = (unsigned char)string[i];
    SETFLOAT(x->x_av+i, (t_float)uc);
  }
  outlet_list(x->x_obj.ob_outlet, &s_list, n, x->x_av);
}

static void iem_symtoalist_free(t_iem_symtoalist *x)
{
}

static void *iem_symtoalist_new(void)
{
  t_iem_symtoalist *x = (t_iem_symtoalist *)pd_new(iem_symtoalist_class);
  
  x->x_string[0] = 0;
  SETFLOAT(x->x_av, 0.0);
  outlet_new(&x->x_obj, &s_list);
  return (x);
}

void iem_symtoalist_setup(void)
{
  iem_symtoalist_class = class_new(gensym("iem_symtoalist"), (t_newmethod)iem_symtoalist_new,
    0, sizeof(t_iem_symtoalist), 0, 0);
  class_addsymbol(iem_symtoalist_class, iem_symtoalist_symbol);
  class_addfloat(iem_symtoalist_class, iem_symtoalist_float);
}