aboutsummaryrefslogtreecommitdiff
path: root/hex2dec.c
blob: 11768382d62f6f6189eef7380f7d810fd40e3d1b (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
#include "m_pd.h"
#include <math.h>

#include <string.h>
#include <stdio.h>

/* ----------------------- hex2dec --------------------- */

static t_class *hex2dec_class;

typedef struct _hex2dec
{
    t_object x_obj;
    t_symbol *x_format;
} t_hex2dec;

static void *hex2dec_new(t_symbol *s)
{
    t_hex2dec *x = (t_hex2dec *)pd_new(hex2dec_class);
    if (!s->s_name) s = gensym("file.%d");
    outlet_new(&x->x_obj, &s_symbol);
    x->x_format = s;
    return (x);
}

static void hex2dec_float(t_hex2dec *x, t_floatarg f)
{
    char buf[MAXPDSTRING];
    sprintf(buf, x->x_format->s_name, (int)f);
    outlet_symbol(x->x_obj.ob_outlet, gensym(buf));
}

static void hex2dec_symbol(t_hex2dec *x, t_symbol *s)
{
    char buf[MAXPDSTRING];
    sprintf(buf, x->x_format->s_name, s->s_name);
    outlet_symbol(x->x_obj.ob_outlet, gensym(buf));
}

static void hex2dec_setup(void)
{
    hex2dec_class = class_new(gensym("hex2dec"),
    (t_newmethod)hex2dec_new, 0,
    	sizeof(t_hex2dec), 0, A_DEFSYM, 0);
    class_addfloat(hex2dec_class, hex2dec_float);
    class_addsymbol(hex2dec_class, hex2dec_symbol);
}