+ DSP primitives: fix a rather stupid bug in clamping functions
[calf.git] / src / osctlserv.cpp
blobdda8befebf1dfa0043b7212337bd05f9a1f79e8d
1 /* Calf DSP Library
2 * Open Sound Control UDP server support
4 * Copyright (C) 2007-2009 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include <calf/osctl.h>
23 #include <calf/osctlserv.h>
24 #include <assert.h>
25 #include <arpa/inet.h>
26 #include <sys/socket.h>
27 #include <stdlib.h>
28 #include <sstream>
30 using namespace osctl;
31 using namespace std;
33 void osc_server::parse_message(const char *buffer, int len)
35 osctl::string_buffer buf(string(buffer, len));
36 osc_strstream str(buf);
37 string address, type_tag;
38 str >> address;
39 str >> type_tag;
40 // cout << "Address " << address << " type tag " << type_tag << endl << flush;
41 if (!address.empty() && address[0] == '/'
42 &&!type_tag.empty() && type_tag[0] == ',')
44 sink->receive_osc_message(address, type_tag.substr(1), str);
48 void osc_server::on_bind()
50 ioch = g_io_channel_unix_new(socket);
51 srcid = g_io_add_watch(ioch, G_IO_IN, on_data, this);
54 gboolean osc_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
56 osc_server *self = (osc_server *)obj;
57 char buf[16384];
58 int len = recv(self->socket, buf, 16384, 0);
59 if (len > 0)
61 if (buf[0] == '/')
63 self->parse_message(buf, len);
65 if (buf[0] == '#')
67 // XXXKF bundles are not supported yet
70 return TRUE;
73 osc_server::~osc_server()
75 if (ioch)
76 g_source_remove(srcid);