aboutsummaryrefslogtreecommitdiff
path: root/iemlib2/src/iem_alisttosym.c
blob: c9a4484928ea41edbc7c4f2959f96d258e867ce4 (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
/* 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"


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

static t_class *iem_alisttosym_class;

typedef struct _iem_alisttosym
{
  t_object x_obj;
  char     x_string[MAXPDSTRING];
} t_iem_alisttosym;

static void iem_alisttosym_list(t_iem_alisttosym *x, t_symbol *s, int ac, t_atom *av)
{
  t_int i=0, j=0, k=0;
  unsigned char uc=0;
  
  if(ac > 0)
  {
    for(i=0, j=0; i<ac; i++)
    {
      if(IS_A_FLOAT(av, i))
      {
        k = atom_getintarg(i, ac, av);
        if((k >= 0) && (k <= 255))
        {
          uc = (unsigned char)k;
          x->x_string[j++] = (char)uc;
        }
      }
      if(j >= (MAXPDSTRING - 2))
        break;
    }
  }
  x->x_string[j] = 0;
  outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_string));
}

static void iem_alisttosym_free(t_iem_alisttosym *x)
{
}

static void *iem_alisttosym_new(void)
{
  t_iem_alisttosym *x = (t_iem_alisttosym *)pd_new(iem_alisttosym_class);
  
  x->x_string[0] = 0;
  outlet_new(&x->x_obj, &s_symbol);
  return (x);
}

void iem_alisttosym_setup(void)
{
  iem_alisttosym_class = class_new(gensym("iem_alisttosym"), (t_newmethod)iem_alisttosym_new,
    0, sizeof(t_iem_alisttosym), 0, 0);
  class_addlist(iem_alisttosym_class, iem_alisttosym_list);
}