Update NTK.
[nondaw.git] / session-manager / src / send_osc.C
blob609ce707dd8cdc751217c6209652bf6c5dc05ab4
2 /*******************************************************************************/
3 /* Copyright (C) 2010 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 // #include <lo/lo.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <OSC/Endpoint.H>
24 #include <ctype.h>
25 #include <string.h>
26 #include <time.h>
27 #include <unistd.h>
29 static bool got_response = false;
31 /************************/
32 /* OSC Message Handlers */
33 /************************/
35 static int osc_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message, void * )
37 //    OSCDMSG();
39     printf( "%s : ", path );
41     for ( int i = 0; i < argc; ++i )
42     {
43         switch ( types[i] )
44         {
45             case 's':
46                 printf( "\"%s\" ", &argv[i]->s );
47                 break;
48             case 'f':
49                 printf( "%f ", argv[i]->f );
50                 break;
51             case 'i':
52                 printf( "%i ", argv[i]->i );
53                 break;
54         }
55     }
57     printf( "\n" );
59     got_response = true;
61     return 0;
66 int main(int argc, char *argv[])
68     OSC::Endpoint s;
70     s.init( LO_UDP );
72     s.add_method( NULL, NULL, osc_reply, 0, "");
74     std::list<OSC::OSC_Value> args;
76     for ( int i = 3; i < argc; ++i )
77     {
78         const char *s = argv[i];
80         if ( strspn( s, "+-0123456789" ) == strlen( s ) )
81         {
82             args.push_back( OSC::OSC_Int( atol( s ) ) );
83         }
84         else if ( strspn( s, ".+-0123456789" ) == strlen( s ) )
85             args.push_back( OSC::OSC_Float( atof( s ) ) );
86         else
87         {
88             args.push_back( OSC::OSC_String( s ) );
89         }
90     }
92     lo_address t = lo_address_new_from_url( argv[1] );
94     fprintf( stderr, "Sending to %s\n", argv[1] );
96     s.send( t, argv[2], args );
98     printf( "Waiting for reply...\n" );
100     while ( ! got_response )
101          s.wait( 1000 * 30 );
103     return 0;