Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / m_fixed.c
blob51294425e0dadfcbc7f2b86d278c3870590270f1
2 #ifdef ROCKBOX
3 #include "plugin.h"
4 #include "../../pdbox.h"
5 #else /* ROCKBOX */
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <netinet/tcp.h>
9 #include <netdb.h>
10 #include <stdio.h>
11 #endif /* ROCKBOX */
13 #include "m_pd.h"
14 #include "m_imp.h"
16 static t_class *ipod_class = 0;
18 typedef struct _ipod
20 t_object x_obj;
21 t_symbol* x_what;
22 } t_ipod;
24 static t_ipod* ipod;
25 static t_int x_fd = -1;
29 static void ipod_connect(void)
31 #ifdef ROCKBOX
32 if (x_fd >= 0)
34 error("ipod_connect: already connected");
35 return;
37 else
39 x_fd++;
41 #else /* ROCKBOX */
42 struct sockaddr_in server;
43 struct hostent *hp;
44 int sockfd;
45 int portno = 3334;
46 char hostname[] = "127.0.0.1";
47 int intarg;
48 if (x_fd >= 0)
50 error("ipod_connect: already connected");
51 return;
54 /* create a socket */
55 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
57 if (sockfd < 0)
59 sys_sockerror("socket");
60 return;
63 /* connect socket using hostname provided in command line */
65 server.sin_family = AF_INET;
66 hp = gethostbyname(hostname);
67 if (hp == 0)
69 post("bad host?\n");
70 return;
73 memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
75 server.sin_port = htons((u_short)portno);
76 if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
78 sys_sockerror("connecting stream socket");
79 sys_closesocket(sockfd);
80 return;
82 post("connected %s %d",hostname,portno);
83 x_fd = sockfd;
84 #endif /* ROCKBOX */
89 static void ipod_bang(t_ipod *x)
91 static char sendme[200];
92 #ifdef ROCKBOX
93 snprintf(sendme, sizeof(sendme), "%s bang;\n", x->x_what->s_name);
94 SEND_FROM_CORE(sendme);
95 #else /* ROCKBOX */
96 sprintf(sendme,"%s bang;\n",x->x_what->s_name);
97 send(x_fd,sendme,strlen(sendme),0);
98 #endif /*ROCKBOX */
100 // if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing);
103 static void ipod_float(t_ipod *x, t_float f)
105 static char sendme[200];
106 #ifdef ROCKBOX
107 char f_buf[32];
109 ftoan(f, f_buf, sizeof(f_buf)-1);
110 strcpy(sendme, x->x_what->s_name);
111 strcat(sendme, " ");
112 strcat(sendme, f_buf);
114 SEND_FROM_CORE(sendme);
115 #else /* ROCKBOX */
116 sprintf(sendme,"%s %f;\n",x->x_what->s_name,f);
117 send(x_fd,sendme,strlen(sendme),0);
118 #endif /* ROCKBOX */
120 // post("forwarding float %s",x->x_what->s_name);
121 // if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f);
124 static void *ipod_new(t_symbol* what)
126 t_ipod *x = (t_ipod *)pd_new(ipod_class);
127 post("new ipod %s",what->s_name);
128 x->x_what = what;
129 return (x);
132 static void ipod_setup(void)
134 ipod_class = class_new(gensym("ipod"), (t_newmethod)ipod_new, 0,
135 sizeof(t_ipod), 0, A_DEFSYM, 0);
136 class_addbang(ipod_class, ipod_bang);
137 class_addfloat(ipod_class, ipod_float);
138 ipod_connect();
141 void pd_checkgui(t_pd *x, t_symbol *s)
143 if (!strncmp(s->s_name,"pod_",4))
144 if (!strcmp((*x)->c_name->s_name,"gatom") ||
145 !strcmp((*x)->c_name->s_name,"vsl") ||
146 !strcmp((*x)->c_name->s_name,"hsl") ||
147 !strcmp((*x)->c_name->s_name,"bng") ||
148 !strcmp((*x)->c_name->s_name,"vradio") ||
149 !strcmp((*x)->c_name->s_name,"hradio")) {
151 post("binding %s to %s",s->s_name,(*x)->c_name->s_name);
152 if (!ipod_class) ipod_setup();
153 ipod = ipod_new(s);
154 pd_bind(&ipod->x_obj.ob_pd,s);