aboutsummaryrefslogtreecommitdiff
path: root/src/iemlib2/iem_send.c
blob: 67c508f954af25c402ecdacb3dcd5c66a556397d (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.

iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */

#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif

#include "m_pd.h"
#include "iemlib.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* -------------------- iem_send ------------------------------ */
/* ------- like millers s, but with setable send label -------- */

struct _iem_send_proxy;

static t_class *iem_send_class;
static t_class *iem_send_proxy_class;

typedef struct _iem_send
{
  t_object                x_obj;
  struct _iem_send_proxy  *x_proxy_inlet;
  t_symbol                *x_send_label_sym;
} t_iem_send;

typedef struct _iem_send_proxy
{
  t_object    p_obj;
  t_iem_send  *p_owner;
} t_iem_send_proxy;

static void iem_send_bang(t_iem_send *x)
{
	if(x->x_send_label_sym)
    if(x->x_send_label_sym->s_thing)
      pd_bang(x->x_send_label_sym->s_thing);
}

static void iem_send_float(t_iem_send *x, t_float f)
{
	if(x->x_send_label_sym)
    if(x->x_send_label_sym->s_thing)
      pd_float(x->x_send_label_sym->s_thing, f);
}

static void iem_send_symbol(t_iem_send *x, t_symbol *s)
{
	if(x->x_send_label_sym)
    if(x->x_send_label_sym->s_thing)
      pd_symbol(x->x_send_label_sym->s_thing, s);
}

static void iem_send_pointer(t_iem_send *x, t_gpointer *gp)
{
	if(x->x_send_label_sym)
    if(x->x_send_label_sym->s_thing)
      pd_pointer(x->x_send_label_sym->s_thing, gp);
}

static void iem_send_list(t_iem_send *x, t_symbol *s, int argc, t_atom *argv)
{
	if(x->x_send_label_sym)
    if(x->x_send_label_sym->s_thing)
      pd_list(x->x_send_label_sym->s_thing, s, argc, argv);
}

static void iem_send_anything(t_iem_send *x, t_symbol *s, int argc, t_atom *argv)
{
	if(x->x_send_label_sym)
	  if(x->x_send_label_sym->s_thing)
      typedmess(x->x_send_label_sym->s_thing, s, argc, argv);
}

/* begin of proxy methods (anything inlets) */

static void iem_send_proxy_clear(t_iem_send_proxy *p, t_symbol *s, int ac, t_atom *av)
{
  t_iem_send *x = p->p_owner;

  x->x_send_label_sym = 0;
}

static void iem_send_proxy_set(t_iem_send_proxy *p, t_symbol *s, int ac, t_atom *av)
{
  t_iem_send *x = p->p_owner;

	if(ac > 0)
  {
    if(IS_A_SYMBOL(av,0))
      x->x_send_label_sym = atom_getsymbol(av);
    else if(IS_A_FLOAT(av,0))
    {
      char str[32];
      
      sprintf(str, "%g", atom_getfloat(av));
      x->x_send_label_sym = gensym(str);
    }
  }
}

/* end of proxy methods (anything inlets) */

static void iem_send_free(t_iem_send *x)
{
  if(x->x_proxy_inlet)
    pd_free((t_pd *)x->x_proxy_inlet);
}

static void *iem_send_new(t_symbol *s, int ac, t_atom *av)
{
  t_iem_send *x = (t_iem_send *)pd_new(iem_send_class);
	t_iem_send_proxy *p = (t_iem_send_proxy *)pd_new(iem_send_proxy_class);

  x->x_proxy_inlet = p;
  p->p_owner = x;
  
  if(ac > 0)
  {
    if(IS_A_SYMBOL(av,0))
    {
      x->x_send_label_sym = atom_getsymbol(av);
    }
    else if(IS_A_FLOAT(av,0))
    {
      char str[32];
      
      sprintf(str, "%g", atom_getfloat(av));
      x->x_send_label_sym = gensym(str);
    }
    else
      x->x_send_label_sym = 0;
  }
  else
    x->x_send_label_sym = 0;
	inlet_new((t_object *)x, (t_pd *)p, 0, 0);
  return (x);
}

void iem_send_setup(void)
{
  iem_send_class = class_new(gensym("iem_send"), (t_newmethod)iem_send_new, (t_method)iem_send_free,
    sizeof(t_iem_send), 0, A_GIMME, 0);
  class_addcreator((t_newmethod)iem_send_new, gensym("iem_s"), A_GIMME, 0);
  class_addbang(iem_send_class, iem_send_bang);
  class_addfloat(iem_send_class, iem_send_float);
  class_addsymbol(iem_send_class, iem_send_symbol);
  class_addpointer(iem_send_class, iem_send_pointer);
  class_addlist(iem_send_class, iem_send_list);
  class_addanything(iem_send_class, iem_send_anything);
  class_sethelpsymbol(iem_send_class, gensym("iemhelp/help-iem_send"));

	iem_send_proxy_class = class_new(gensym("_iem_send_proxy"),
    0, 0, sizeof(t_iem_send_proxy), CLASS_PD | CLASS_NOINLET, 0);
  class_addmethod(iem_send_proxy_class, (t_method)iem_send_proxy_clear, gensym("clear"), A_GIMME, 0);
  class_addmethod(iem_send_proxy_class, (t_method)iem_send_proxy_set, gensym("set"), A_GIMME, 0);
}