summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/m_fixed.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_fixed.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/m_fixed.c252
1 files changed, 252 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_fixed.c b/apps/plugins/pdbox/PDa/src/m_fixed.c
new file mode 100644
index 0000000000..c91fa0512e
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/m_fixed.c
@@ -0,0 +1,252 @@
1
2#include <sys/socket.h>
3#include <netinet/in.h>
4#include <netinet/tcp.h>
5#include <netdb.h>
6#include <stdio.h>
7
8#include "m_pd.h"
9#include "m_imp.h"
10
11static t_class *ipod_class = 0;
12
13typedef struct _ipod
14{
15 t_object x_obj;
16 t_symbol* x_what;
17} t_ipod;
18
19static t_ipod* ipod;
20static t_int x_fd = -1;
21
22
23
24static void ipod_connect()
25{
26 struct sockaddr_in server;
27 struct hostent *hp;
28 int sockfd;
29 int portno = 3334;
30 char hostname[] = "127.0.0.1";
31 int intarg;
32 if (x_fd >= 0)
33 {
34 error("ipod_connect: already connected");
35 return;
36 }
37
38 /* create a socket */
39 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
40
41 if (sockfd < 0)
42 {
43 sys_sockerror("socket");
44 return;
45 }
46
47 /* connect socket using hostname provided in command line */
48
49 server.sin_family = AF_INET;
50 hp = gethostbyname(hostname);
51 if (hp == 0)
52 {
53 post("bad host?\n");
54 return;
55 }
56
57 memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
58
59 server.sin_port = htons((u_short)portno);
60 if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
61 {
62 sys_sockerror("connecting stream socket");
63 sys_closesocket(sockfd);
64 return;
65 }
66 post("connected %s %d",hostname,portno);
67 x_fd = sockfd;
68}
69
70
71
72static void ipod_bang(t_ipod *x)
73{
74 static char sendme[200];
75 sprintf(sendme,"%s bang;\n",x->x_what->s_name);
76 send(x_fd,sendme,strlen(sendme),0);
77
78// if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing);
79}
80
81static void ipod_float(t_ipod *x, t_float f)
82{
83 static char sendme[200];
84
85 sprintf(sendme,"%s %f;\n",x->x_what->s_name,f);
86 send(x_fd,sendme,strlen(sendme),0);
87
88// post("forwarding float %s",x->x_what->s_name);
89// if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f);
90}
91
92static void *ipod_new(t_symbol* what)
93{
94 t_ipod *x = (t_ipod *)pd_new(ipod_class);
95 post("new ipod %s",what->s_name);
96 x->x_what = what;
97 return (x);
98}
99
100static void ipod_setup(void)
101{
102 ipod_class = class_new(gensym("ipod"), (t_newmethod)ipod_new, 0,
103 sizeof(t_ipod), 0, A_DEFSYM, 0);
104 class_addbang(ipod_class, ipod_bang);
105 class_addfloat(ipod_class, ipod_float);
106 ipod_connect();
107}
108
109void pd_checkgui(t_pd *x, t_symbol *s)
110{
111 if (!strncmp(s->s_name,"pod_",4))
112 if (!strcmp((*x)->c_name->s_name,"gatom") ||
113 !strcmp((*x)->c_name->s_name,"vsl") ||
114 !strcmp((*x)->c_name->s_name,"hsl") ||
115 !strcmp((*x)->c_name->s_name,"bng") ||
116 !strcmp((*x)->c_name->s_name,"vradio") ||
117 !strcmp((*x)->c_name->s_name,"hradio")) {
118
119 post("binding %s to %s",s->s_name,(*x)->c_name->s_name);
120 if (!ipod_class) ipod_setup();
121 ipod = ipod_new(s);
122 pd_bind(&ipod->x_obj.ob_pd,s);
123 }
124}
125
126
127
128#include <sys/socket.h>
129#include <netinet/in.h>
130#include <netinet/tcp.h>
131#include <netdb.h>
132#include <stdio.h>
133
134#include "m_pd.h"
135#include "m_imp.h"
136
137static t_class *ipod_class = 0;
138
139typedef struct _ipod
140{
141 t_object x_obj;
142 t_symbol* x_what;
143} t_ipod;
144
145static t_ipod* ipod;
146static t_int x_fd = -1;
147
148
149
150static void ipod_connect()
151{
152 struct sockaddr_in server;
153 struct hostent *hp;
154 int sockfd;
155 int portno = 3334;
156 char hostname[] = "127.0.0.1";
157 int intarg;
158 if (x_fd >= 0)
159 {
160 error("ipod_connect: already connected");
161 return;
162 }
163
164 /* create a socket */
165 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
166
167 if (sockfd < 0)
168 {
169 sys_sockerror("socket");
170 return;
171 }
172
173 /* connect socket using hostname provided in command line */
174
175 server.sin_family = AF_INET;
176 hp = gethostbyname(hostname);
177 if (hp == 0)
178 {
179 post("bad host?\n");
180 return;
181 }
182
183 memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
184
185 server.sin_port = htons((u_short)portno);
186 if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
187 {
188 sys_sockerror("connecting stream socket");
189 sys_closesocket(sockfd);
190 return;
191 }
192 post("connected %s %d",hostname,portno);
193 x_fd = sockfd;
194}
195
196
197
198static void ipod_bang(t_ipod *x)
199{
200 static char sendme[200];
201 sprintf(sendme,"%s bang;\n",x->x_what->s_name);
202 send(x_fd,sendme,strlen(sendme),0);
203
204// if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing);
205}
206
207static void ipod_float(t_ipod *x, t_float f)
208{
209 static char sendme[200];
210
211 sprintf(sendme,"%s %f;\n",x->x_what->s_name,f);
212 send(x_fd,sendme,strlen(sendme),0);
213
214// post("forwarding float %s",x->x_what->s_name);
215// if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f);
216}
217
218static void *ipod_new(t_symbol* what)
219{
220 t_ipod *x = (t_ipod *)pd_new(ipod_class);
221 post("new ipod %s",what->s_name);
222 x->x_what = what;
223 return (x);
224}
225
226static void ipod_setup(void)
227{
228 ipod_class = class_new(gensym("ipod"), (t_newmethod)ipod_new, 0,
229 sizeof(t_ipod), 0, A_DEFSYM, 0);
230 class_addbang(ipod_class, ipod_bang);
231 class_addfloat(ipod_class, ipod_float);
232 ipod_connect();
233}
234
235void pd_checkgui(t_pd *x, t_symbol *s)
236{
237 if (!strncmp(s->s_name,"pod_",4))
238 if (!strcmp((*x)->c_name->s_name,"gatom") ||
239 !strcmp((*x)->c_name->s_name,"vsl") ||
240 !strcmp((*x)->c_name->s_name,"hsl") ||
241 !strcmp((*x)->c_name->s_name,"bng") ||
242 !strcmp((*x)->c_name->s_name,"vradio") ||
243 !strcmp((*x)->c_name->s_name,"hradio")) {
244
245 post("binding %s to %s",s->s_name,(*x)->c_name->s_name);
246 if (!ipod_class) ipod_setup();
247 ipod = ipod_new(s);
248 pd_bind(&ipod->x_obj.ob_pd,s);
249 }
250}
251
252