aboutsummaryrefslogtreecommitdiff
path: root/cyclone/hammer/next.c
blob: 3fe7d6eb718d40b8571146b638363861973a0c89 (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
/* 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"

//#define NEXT_USEEVENTNO

typedef struct _next
{
    t_object   x_ob;
#ifdef NEXT_USEEVENTNO
    int        x_lastevent;
#else
    double     x_lastevent;
#endif
    t_outlet  *x_out2;
} t_next;

static t_class *next_class;

/* CHECKME first call, CHECKME if the outlets are not swapped */
static void next_anything(t_next *x, t_symbol *s, int ac, t_atom *av)
{
#ifdef NEXT_USEEVENTNO
    int nextevent = sys_geteventno();
#else
    double nextevent = clock_getlogicaltime();
#endif
    if (x->x_lastevent == nextevent)
	outlet_bang(x->x_out2);
    else
    {
	x->x_lastevent = nextevent;
	outlet_bang(((t_object *)x)->ob_outlet);
    }
}

static void *next_new(void)
{
    t_next *x = (t_next *)pd_new(next_class);
    outlet_new((t_object *)x, &s_bang);
    x->x_out2 = outlet_new((t_object *)x, &s_bang);
#ifdef NEXT_USEEVENTNO
	x->x_lastevent = sys_geteventno();
#else
	x->x_lastevent = clock_getlogicaltime();
#endif
    return (x);
}

void next_setup(void)
{
    next_class = class_new(gensym("next"),
			   (t_newmethod)next_new, 0,
			   sizeof(t_next), 0, 0);
    class_addanything(next_class, next_anything);
}