4 #include "../../pdbox.h"
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <netinet/tcp.h>
16 static t_class
*ipod_class
= 0;
25 static t_int x_fd
= -1;
29 static void ipod_connect(void)
34 error("ipod_connect: already connected");
42 struct sockaddr_in server
;
46 char hostname
[] = "127.0.0.1";
50 error("ipod_connect: already connected");
55 sockfd
= socket(AF_INET
, SOCK_DGRAM
, 0);
59 sys_sockerror("socket");
63 /* connect socket using hostname provided in command line */
65 server
.sin_family
= AF_INET
;
66 hp
= gethostbyname(hostname
);
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
);
82 post("connected %s %d",hostname
,portno
);
89 static void ipod_bang(t_ipod
*x
)
91 static char sendme
[200];
93 snprintf(sendme
, sizeof(sendme
), "%s bang;\n", x
->x_what
->s_name
);
94 SEND_FROM_CORE(sendme
);
96 sprintf(sendme
,"%s bang;\n",x
->x_what
->s_name
);
97 send(x_fd
,sendme
,strlen(sendme
),0);
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];
109 ftoan(f
, f_buf
, sizeof(f_buf
)-1);
110 strcpy(sendme
, x
->x_what
->s_name
);
112 strcat(sendme
, f_buf
);
114 SEND_FROM_CORE(sendme
);
116 sprintf(sendme
,"%s %f;\n",x
->x_what
->s_name
,f
);
117 send(x_fd
,sendme
,strlen(sendme
),0);
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
);
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
);
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();
154 pd_bind(&ipod
->x_obj
.ob_pd
,s
);