aboutsummaryrefslogtreecommitdiff
path: root/cyclone/hammer/xbendout.c
blob: faa401ef92e4324151b2c8e744f28928c7feec49 (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
/* Copyright (c) 2002-2003 krzYszcz and others.
 * 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"

typedef struct _xbendout
{
    t_object  x_ob;
    t_float   x_channel;
    int       x_value;
} t_xbendout;

static t_class *xbendout_class;

static void xbendout_dooutput(t_xbendout *x)
{
    int value = x->x_value;
    int channel = (int)x->x_channel;  /* CHECKME */
    if (value >= 0 &&  /* CHECKME */
	value <= 16383 &&  /* CHECKME */
	channel > 0)  /* CHECKME */
    {
	outlet_float(((t_object *)x)->ob_outlet, 224 + ((channel-1) & 0x0F));
	outlet_float(((t_object *)x)->ob_outlet, value & 0x7F);
	outlet_float(((t_object *)x)->ob_outlet, value >> 7);
    }
}

static void xbendout_float(t_xbendout *x, t_float f)
{
    x->x_value = (int)f;  /* CHECKME */
    xbendout_dooutput(x);
}

static void *xbendout_new(t_floatarg f)
{
    t_xbendout *x = (t_xbendout *)pd_new(xbendout_class);
    floatinlet_new((t_object *)x, &x->x_channel);
    outlet_new((t_object *)x, &s_float);
    x->x_channel = ((int)f > 0 ? f : 1);  /* CHECKME */
    x->x_value = 8192;  /* CHECKME if not -1 */
    return (x);
}

void xbendout_setup(void)
{
    xbendout_class = class_new(gensym("xbendout"), 
			       (t_newmethod)xbendout_new, 0,
			       sizeof(t_xbendout), 0,
			       A_DEFFLOAT, 0);
    class_addbang(xbendout_class, xbendout_dooutput);
    class_addfloat(xbendout_class, xbendout_float);
}