aboutsummaryrefslogtreecommitdiff
path: root/xvalue/xvalue.c
blob: 4f16f062a5f0a0b6578829a274502fdf0719ddda (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
77
/* extended (settable) value object
   Copyright (c) 2004 Tim Blechmann
   a huge part of the code is broken out of the code of the value object.

 * Copyright (c) 1997-1999 Miller Puckette.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#include "m_pd.h"


/* -------------------- xvalue ----------------------------- */

static t_class *xvalue_class;

static t_class *vcommon_class; 

typedef struct vcommon
{
    t_pd c_pd;
    int c_refcount;
    t_float c_f;
} t_vcommon;


typedef struct _xvalue
{
    t_object x_obj;
    t_symbol *x_sym;
    t_float *x_floatstar;
} t_xvalue;

static void *xvalue_new(t_symbol *s)
{
    t_xvalue *x = (t_xvalue *)pd_new(xvalue_class);
    x->x_sym = s;
    x->x_floatstar = value_get(s);
    outlet_new(&x->x_obj, &s_float);
    return (x);
}

static void xvalue_bang(t_xvalue *x)
{
    outlet_float(x->x_obj.ob_outlet, *x->x_floatstar);
}

static void xvalue_float(t_xvalue *x, t_float f)
{
    *x->x_floatstar = f;
}

static void xvalue_ff(t_xvalue *x)
{
    value_release(x->x_sym);
}

static void xvalue_set(t_xvalue *x, t_symbol *s)
{
    x->x_sym = s;
    x->x_floatstar = value_get(s);
}

void xvalue_setup(void)
{
    xvalue_class = class_new(gensym("xvalue"), (t_newmethod)xvalue_new,
    	(t_method)xvalue_ff,
    	sizeof(t_xvalue), 0, A_DEFSYM, 0);
    class_addcreator((t_newmethod)xvalue_new, gensym("xv"), A_DEFSYM, 0);
    class_addbang(xvalue_class, xvalue_bang);
    class_addfloat(xvalue_class, xvalue_float);
    class_addmethod(xvalue_class, (t_method) xvalue_set, gensym("set"), 
		    A_SYMBOL, 0);
    vcommon_class = class_new(gensym("xvalue"), 0, 0,
			      sizeof(t_vcommon), CLASS_PD, 0);
}