aboutsummaryrefslogtreecommitdiff
path: root/cyclone/hammer/active.c
blob: 9d10f80de736445d35de6c56c3376db63c8b7a88 (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
/* 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 <stdio.h>
#include "m_pd.h"
#include "hammer/gui.h"

typedef struct _active
{
    t_object   x_ob;
    t_symbol  *x_cvname;
    int        x_on;
} t_active;

static t_class *active_class;

static void active_dofocus(t_active *x, t_symbol *s, t_floatarg f)
{
    if ((int)f)
    {
	int on = (s == x->x_cvname);
	if (on != x->x_on)
	    outlet_float(((t_object *)x)->ob_outlet, x->x_on = on);
    }
    else if (x->x_on && s == x->x_cvname)
	outlet_float(((t_object *)x)->ob_outlet, x->x_on = 0);
}

static void active_free(t_active *x)
{
    hammergui_unbindfocus((t_pd *)x);
}

static void *active_new(void)
{
    t_active *x = (t_active *)pd_new(active_class);
    char buf[32];
    sprintf(buf, ".x%x.c", (int)canvas_getcurrent());
    x->x_cvname = gensym(buf);
    x->x_on = 0;
    outlet_new((t_object *)x, &s_float);
    hammergui_bindfocus((t_pd *)x);
    return (x);
}

void active_setup(void)
{
    active_class = class_new(gensym("active"),
			     (t_newmethod)active_new,
			     (t_method)active_free,
			     sizeof(t_active), CLASS_NOINLET, 0);
    class_addmethod(active_class, (t_method)active_dofocus,
		    gensym("_focus"), A_SYMBOL, A_FLOAT, 0);
}