bool OscReceiver::setup(unsigned int port)
{

    if(m_serverThread)
    {
        LOG_WARN << "OscReceiver: Cannot set port while thread is running" << std::endl;
        return false;
    }

	std::stringstream stream;
	stream << port;
    m_serverThread = lo_server_thread_new(stream.str().c_str(), &errorCB);    
    if(!m_serverThread)
    	{
    		LOG_ERROR << "OscReceiver: Could not create server" << std::endl;
    		return false;
    	}
    	
    lo_server_thread_add_method(m_serverThread, NULL, NULL, &messageCB, this);

	return true;
}
예제 #2
0
int init_osc(int osc_port) {
  char tmp[8];
  if (osc_port < 0) return(1);
  if (osc_server) return (1);
  uint32_t port = (osc_port>100 && osc_port< 60000)?osc_port:8998;

  snprintf(tmp, sizeof(tmp), "%d", port);
  if(!silent)
    fprintf(stderr, "OSC trying port: %i\n",port);
  osc_server = lo_server_thread_new (tmp, oscb_error);

  if (!osc_server) {
    if(!silent) fprintf(stderr, "OSC start failed.");
    return(1);
  }

  if(!silent) {
    char *urlstr;
    urlstr = lo_server_thread_get_url (osc_server);
    fprintf(stderr, "OSC server name: %s\n",urlstr);
    free (urlstr);
  }

  lo_server_thread_add_method(osc_server, "/boverdrive/bias",      "f", &oscb_p_bias     , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/feedback",  "f", &oscb_p_feedback , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/sagtobias", "f", &oscb_p_sagtobias, NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/postfeed",  "f", &oscb_p_postfeed , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/globfeed",  "f", &oscb_p_globfeed , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/gainin",    "f", &oscb_p_gainin   , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/gainout",   "f", &oscb_p_gainout  , NULL);
  lo_server_thread_add_method(osc_server, "/boverdrive/quit",      "",  &oscb_quit       , NULL);

  lo_server_thread_start(osc_server);
  if(!silent) fprintf(stderr, "OSC server started on port %i\n",port);
  return (0);
}
예제 #3
0
파일: again.cpp 프로젝트: fohl/audioprj
//------------------------------------------------------------------------
tresult PLUGIN_API AGain::notify (IMessage* message)
{
	if (!message)
		return kInvalidArgument;

	if (!strcmp (message->getMessageID (), "setPort"))
	{
		TChar port[256] = {0};
		if (message->getAttributes ()->getString ("port", port, sizeof (port) / sizeof (char16)) == kResultOk)
		{
			char path[256];
			String tmp2 (port);
			tmp2.copyTo8 (path, 0, 255);

			if(server) {
				lo_method tmp = lo_server_thread_add_method(server,path,NULL,lo_method_handler,this);
			}

			return kResultOk;
		}
	}

	return AudioEffect::notify (message);
}
예제 #4
0
int init_osc( char * ip, char *outport, char * port ){
     /* create liblo addres */
    t = lo_address_new(ip, outport); // change later to use other host

    lo_server_thread st = lo_server_thread_new(port, error);

    lo_server_thread_add_method(st, "/joystick/open", "i", joy_open_handler, NULL);
    lo_server_thread_add_method(st, "/joystick/info", "i", joy_info_handler, NULL);
    lo_server_thread_add_method(st, "/joystick/close", "i", joy_close_handler, NULL);

    lo_server_thread_add_method(st, "/sdl2osc/info", "", info_handler, NULL);
    lo_server_thread_add_method(st, "/sdl2osc/quit", "", quit_handler, NULL);
    lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);

    lo_server_thread_start(st);
 
    lo_server s = lo_server_thread_get_server( st );

    lo_send_from( t, s, LO_TT_IMMEDIATE, "/sdl2osc/started", "" ); 
}
예제 #5
0
파일: OSCserver.hpp 프로젝트: AMMD/Ghislame
void add_method(const char *path, lo_server_thread st){
		lo_server_thread_add_method(st, path, NULL, button_handler, NULL);
};
예제 #6
0
파일: OSCserver.hpp 프로젝트: AMMD/Ghislame
	void add_method_wrapper(const char *path){
//		lo_server_thread_stop(server);
		lo_server_thread_add_method(server, path, NULL, button_handler, NULL);
//		add_method(path, server);
//		lo_server_thread_start(server);
	};
예제 #7
0
파일: OSC.c 프로젝트: johan718/csound
static int OSC_list_init(CSOUND *csound, OSCLISTEN *p)
{
    //void  *x;
    int   i, n;

    OSC_GLOBALS *pp = (OSC_GLOBALS*)
                        csound->QueryGlobalVariable(csound, "_OSC_globals");
    if (UNLIKELY(pp == NULL))
      return csound->InitError(csound, Str("OSC not running"));
    /* find port */
    n = (int) *(p->ihandle);
    if (UNLIKELY(n < 0 || n >= pp->nPorts))
      return csound->InitError(csound, Str("invalid handle"));
    p->port = &(pp->ports[n]);
    p->saved_path = (char*) csound->Malloc(csound,
                                           strlen((char*) p->dest->data) + 1);
    strcpy(p->saved_path, (char*) p->dest->data);
    /* check for a valid argument list */
    n = csound->GetInputArgCnt(p) - 3;
    if (UNLIKELY(n < 1 || n > 28))
      return csound->InitError(csound, Str("invalid number of arguments"));
    if (UNLIKELY((int) strlen((char*) p->type->data) != n))
      return csound->InitError(csound,
                               "argument list inconsistent with format string");
    strcpy(p->saved_types, (char*) p->type->data);
    for (i = 0; i < n; i++) {
      const char *s;
      s = csound->GetInputArgName(p, i + 3);
      if (s[0] == 'g')
        s++;
      switch (p->saved_types[i]) {
        //#ifdef SOMEFINEDAY
      case 'G':
      case 'A':
      case 'a':
      case 'S':
        p->saved_types[i] = 'b';
        break;
        //#endif
      case 'c':
      case 'd':
      case 'f':
      case 'h':
      case 'i':
        if (UNLIKELY(*s != 'k'))
          return csound->InitError(csound, Str("argument list inconsistent "
                                               "with format string"));
        break;
      case 's':
        if (UNLIKELY(*s != 'S'))
          return csound->InitError(csound, Str("argument list inconsistent "
                                               "with format string"));
        break;
      default:
        return csound->InitError(csound, Str("invalid type"));
      }
    }
    csound->LockMutex(p->port->mutex_);
    p->nxt = p->port->oplst;
    p->port->oplst = (void*) p;
    csound->UnlockMutex(p->port->mutex_);
    (void) lo_server_thread_add_method(p->port->thread,
                                       p->saved_path, p->saved_types,
                                       OSC_handler, p->port);
    csound->RegisterDeinitCallback(csound, p,
                                   (int (*)(CSOUND *, void *)) OSC_listdeinit);
    return OK;
}
예제 #8
0
void OscReceiver::addHandler(const char *path, const char *types, lo_method_handler handler, void *userData)
{
    lo_server_thread_add_method(server_, path, types, handler, userData);
}
예제 #9
0
int main()
{
    lo_blob btest = lo_blob_new(sizeof(testdata), testdata);
    lo_server_thread st, sta, stb;
    lo_server s = lo_server_new(NULL, error);
    lo_bundle b;
    lo_message m1, m2;
    char *server_url, *path, *protocol, *host, *port;
    const char *host2, *port2;
    lo_address a;
    uint8_t midi_data[4] = {0xff, 0xf7, 0xAA, 0x00};
    union end_test32 et32;
    union end_test64 et64;
    lo_timetag tt = {0x1, 0x80000000}, sched;
    int count;
    int proto;
    char cmd[256];

    test_deserialise();

    sta = lo_server_thread_new("7591", error);
    stb = lo_server_thread_new("7591", rep_error);
    if (stb) {
	fprintf(stderr, "FAILED: create bad server thread object!\n");
	exit(1);
    }
    lo_server_thread_free(sta);

    /* leak check */
    st = lo_server_thread_new(NULL, error);
    lo_server_thread_start(st);
#ifdef WIN32
    Sleep(4);
#else
    usleep(4000);
#endif
    lo_server_thread_stop(st);
    lo_server_thread_free(st);
    st = lo_server_thread_new(NULL, error);
    lo_server_thread_start(st);
    lo_server_thread_stop(st);
    lo_server_thread_free(st);
    st = lo_server_thread_new(NULL, error);
    lo_server_thread_free(st);
    st = lo_server_thread_new(NULL, error);
    lo_server_thread_free(st);
    st = lo_server_thread_new(NULL, error);

    a = lo_address_new_from_url("osc://localhost/");
    TEST(a != NULL);
    lo_address_free(a);

    a = lo_address_new_from_url("osc.://localhost/");
    TEST(a == NULL);


    atexit(exitcheck);

    printf("type tests\n");
    TEST(sizeof(float) == sizeof(int32_t));
    TEST(sizeof(double) == sizeof(int64_t));

    et32.i = 0x23242526U;
    et32.i = lo_htoo32(et32.i);
    if (et32.c[0] != 0x23 || et32.c[1] != 0x24 || et32.c[2] != 0x25 ||
	et32.c[3] != 0x26) {
	fprintf(stderr, "failed 32bit endian conversion test\n");
	fprintf(stderr, "0x23242526 -> %X\n", et32.i);
	exit(1);
    } else {
	printf("passed 32bit endian conversion test\n");
    }

    et64.i = 0x232425262728292AULL;
    et64.i = lo_htoo64(et64.i);
    if (et64.c[0] != 0x23 || et64.c[1] != 0x24 || et64.c[2] != 0x25 ||
	et64.c[3] != 0x26 || et64.c[4] != 0x27 || et64.c[5] != 0x28 ||
	et64.c[6] != 0x29 || et64.c[7] != 0x2A) {
	fprintf(stderr, "failed 64bit endian conversion\n");
	fprintf(stderr, "0x232425262728292A -> %llX\n", (long long unsigned int)et64.i);
	exit(1);
    } else {
	printf("passed 64bit endian conversion\n");
    }
    printf("\n");

    /* OSC URL tests */
    path = lo_url_get_path("osc.udp://localhost:9999/a/path/is/here");
    if (strcmp(path, "/a/path/is/here")) {
	printf("failed lo_url_get_path() test1\n");
	printf("'%s' != '/a/path/is/here'\n", path);
	exit(1);
    } else {
	printf("passed lo_url_get_path() test1\n");
    }
    free(path);

    protocol = lo_url_get_protocol("osc.udp://localhost:9999/a/path/is/here");
    if (strcmp(protocol, "udp")) {
	printf("failed lo_url_get_protocol() test1\n");
	printf("'%s' != 'udp'\n", protocol);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol() test1\n");
    }
    free(protocol);

    protocol = lo_url_get_protocol("osc.tcp://localhost:9999/a/path/is/here");
    if (strcmp(protocol, "tcp")) {
	printf("failed lo_url_get_protocol() test2\n");
	printf("'%s' != 'tcp'\n", protocol);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol() test2\n");
    }
    free(protocol);
    
    protocol = lo_url_get_protocol("osc.udp://[::ffff:localhost]:9999/a/path/is/here");
    if (strcmp(protocol, "udp")) {
	printf("failed lo_url_get_protocol() test1 (IPv6)\n");
	printf("'%s' != 'udp'\n", protocol);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol() test1 (IPv6)\n");
    }
    free(protocol);

    proto = lo_url_get_protocol_id("osc.udp://localhost:9999/a/path/is/here");
    if (proto != LO_UDP) {
	printf("failed lo_url_get_protocol_id() test1\n");
	printf("'%d' != LO_UDP\n", proto);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol_id() test1\n");
    }

    proto = lo_url_get_protocol_id("osc.tcp://localhost:9999/a/path/is/here");
    if (proto != LO_TCP) {
	printf("failed lo_url_get_protocol_id() test2\n");
	printf("'%d' != LO_TCP\n", proto);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol_id() test2\n");
    }
    
    proto = lo_url_get_protocol_id("osc.invalid://localhost:9999/a/path/is/here");
    if (proto != -1) {
	printf("failed lo_url_get_protocol_id() test3\n");
	printf("'%d' != -1\n", proto);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol_id() test3\n");
    }
    
    proto = lo_url_get_protocol_id("osc.udp://[::ffff:localhost]:9999/a/path/is/here");
    if (proto != LO_UDP) {
	printf("failed lo_url_get_protocol_id() test1 (IPv6)\n");
	printf("'%d' != LO_UDP\n", proto);
	exit(1);
    } else {
	printf("passed lo_url_get_protocol_id() test1 (IPv6)\n");
    }

    host = lo_url_get_hostname("osc.udp://foo.example.com:9999/a/path/is/here");
    if (strcmp(host, "foo.example.com")) {
	printf("failed lo_url_get_hostname() test1\n");
	printf("'%s' != 'foo.example.com'\n", host);
	exit(1);
    } else {
	printf("passed lo_url_get_hostname() test1\n");
    }
    free(host);

    host = lo_url_get_hostname("osc.udp://[0000::::0001]:9999/a/path/is/here");
    if (strcmp(host, "0000::::0001")) {
	printf("failed lo_url_get_hostname() test2 (IPv6)\n");
	printf("'%s' != '0000::::0001'\n", host);
	exit(1);
    } else {
	printf("passed lo_url_get_hostname() test2 (IPv6)\n");
    }
    free(host);

    port = lo_url_get_port("osc.udp://localhost:9999/a/path/is/here");
    if (strcmp(port, "9999")) {
	printf("failed lo_url_get_port() test1\n");
	printf("'%s' != '9999'\n", port);
	exit(1);
    } else {
	printf("passed lo_url_get_port() test1\n");
    }
    free(port);
    
    port = lo_url_get_port("osc.udp://[::ffff:127.0.0.1]:9999/a/path/is/here");
    if (strcmp(port, "9999")) {
	printf("failed lo_url_get_port() test1 (IPv6)\n");
	printf("'%s' != '9999'\n", port);
	exit(1);
    } else {
	printf("passed lo_url_get_port() test1 (IPv6)\n");
    }
    free(port);
    printf("\n");
    
    
    
    
    
    a = lo_address_new_from_url("osc.tcp://foo.example.com:9999/");
    host2 = lo_address_get_hostname(a);
    if (strcmp(host2, "foo.example.com")) {
	printf("failed lo_address_get_hostname() test\n");
	printf("'%s' != 'foo.example.com'\n", host2);
	exit(1);
    } else {
	printf("passed lo_address_get_hostname() test\n");
    }

    port2 = lo_address_get_port(a);
    if (strcmp(port2, "9999")) {
	printf("failed lo_address_get_port() test\n");
	printf("'%s' != '9999'\n", port2);
	exit(1);
    } else {
	printf("passed lo_address_get_port() test\n");
    }

    proto = lo_address_get_protocol(a);
    if (proto != LO_TCP) {
	printf("failed lo_address_get_protocol() test\n");
	printf("'%d' != '%d'\n", proto, LO_TCP);
	exit(1);
    } else {
	printf("passed lo_address_get_protocol() test\n");
    }

    server_url = lo_address_get_url(a);
    if (strcmp(server_url, "osc.tcp://foo.example.com:9999/")) {
	printf("failed lo_address_get_url() test\n");
	printf("'%s' != '%s'\n", server_url, "osc.tcp://foo.example.com:9999/");
	exit(1);
    } else {
	printf("passed lo_address_get_url() test\n");
    }
    free(server_url);
    lo_address_free( a );
    printf("\n");
    

    /* Test blod sizes */
    if (lo_blob_datasize(btest) != 5 || lo_blobsize(btest) != 12) {
	printf("blob is %d (%d) bytes long, should be 5 (12)\n",
               lo_blob_datasize(btest), lo_blobsize(btest));
	lo_arg_pp(LO_BLOB, btest);
	printf(" <- blob\n");
	exit(1);
    }
    
    
    
    /* Server method handler tests */
    server_url = lo_server_thread_get_url(st);
    a = lo_address_new_from_url(server_url);
    printf("Server URL: %s\n", server_url);
    free(server_url);

    /* add method that will match the path /foo/bar, with two numbers, coerced
     * to float and int */

    lo_server_thread_add_method(st, "/foo/bar", "fi", foo_handler, lo_server_thread_get_server(st));

    lo_server_thread_add_method(st, "/reply", "s", reply_handler, NULL);

    lo_server_thread_add_method(st, "/lotsofformats", "fisbmhtdSccTFNI",
				lots_handler, NULL);

    lo_server_thread_add_method(st, "/coerce", "dfhiSs",
				coerce_handler, NULL);

    lo_server_thread_add_method(st, "/bundle", NULL,
				bundle_handler, NULL);
    lo_server_thread_add_method(st, "/timestamp", NULL,
				timestamp_handler, NULL);
    lo_server_thread_add_method(st, "/jitter", "ti",
				jitter_handler, NULL);

    lo_server_thread_add_method(st, "/pattern/foo", NULL,
				pattern_handler, "foo");
    lo_server_thread_add_method(st, "/pattern/bar", NULL,
				pattern_handler, "bar");
    lo_server_thread_add_method(st, "/pattern/baz", NULL,
				pattern_handler, "baz");

    lo_server_thread_add_method(st, "/subtest", "i",
				subtest_handler, st);

    lo_server_thread_add_method(st, "/subtest-reply", "i",
				subtest_reply_handler, NULL);

    /* add method that will match any path and args */
    lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);

    /* add method that will match the path /quit with no args */
    lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL);

    /* check that the thread restarts */
    lo_server_thread_start(st);
    lo_server_thread_stop(st);
    lo_server_thread_start(st);

    if (lo_send(a, "/foo/bar", "ff", 0.12345678f, 23.0f) == -1) {
	printf("OSC error A %d: %s\n", lo_address_errno(a), lo_address_errstr(a));
	exit(1);
    }

    if (lo_send(a, "/foo/bar", "ff", 0.12345678f, 23.0f) == -1) {
	printf("OSC error B %d: %s\n", lo_address_errno(a), lo_address_errstr(a));
	exit(1);
    }

    test_validation(a);
    test_multicast(st);

    lo_send(a, "/", "i", 242);
    lo_send(a, "/pattern/", "i", 243);

#ifndef _MSC_VER  /* MS compiler refuses to compile this case */
    lo_send(a, "/bar", "ff", 0.12345678f, 1.0/0.0);
#endif
    lo_send(a, "/lotsofformats", "fisbmhtdSccTFNI", 0.12345678f, 123, "123",
	    btest, midi_data, 0x0123456789abcdefULL, tt, 0.9999, "sym",
	    'X', 'Y');
    lo_send(a, "/coerce", "fdihsS", 0.1f, 0.2, 123, 124LL, "aaa", "bbb");
    lo_send(a, "/coerce", "ffffss", 0.1f, 0.2f, 123.0, 124.0, "aaa", "bbb");
    lo_send(a, "/coerce", "ddddSS", 0.1, 0.2, 123.0, 124.0, "aaa", "bbb");
    lo_send(a, "/a/b/c/d", "sfsff", "one", 0.12345678f, "three",
	    -0.00000023001f, 1.0);
    lo_send(a, "/a/b/c/d", "b", btest);

    TEST(test_varargs(a, "/lotsofformats", "fisbmhtdSccTFNI", 0.12345678f, 123,
                      "123", btest, midi_data, 0x0123456789abcdefULL, tt,
                      0.9999, "sym", 'X', 'Y', LO_ARGS_END) == 0);

#ifdef __GNUC__
    // Note: Lack of support for variable-argument macros in non-GCC compilers
    //       does not allow us to test for these conditions.

    // too many args
    TEST(test_varargs(a, "/lotsofformats", "f", 0.12345678f, 123,
                      "123", btest, midi_data, 0x0123456789abcdefULL, tt,
                      0.9999, "sym", 'X', 'Y', LO_ARGS_END) != 0);
    // too many types
    TEST(test_varargs(a, "/lotsofformats", "fisbmhtdSccTFNI", 0.12345678f, 123,
                      "123", btest, midi_data, 0x0123456789abcdefULL, tt, 0.5,
                      LO_ARGS_END) != 0);
#endif

    // test lo_message_add
    m1 = lo_message_new();
    TEST(lo_message_add(m1, "fisbmhtdSccTFNI", 0.12345678f, 123, "123",
                        btest, midi_data, 0x0123456789abcdefULL, tt, 0.9999, "sym",
                        'X', 'Y') == 0);
    lo_send_message(a, "/lotsofformats", m1);
    lo_message_free(m1);
 
    lo_blob_free(btest);

    lo_send(a, "/pattern/*", "s", "a");
    lo_send(a, "/pattern/ba[rz]", "s", "b");

    server_url = lo_server_thread_get_url(st);
    sprintf(cmd, "." PATHDELIM "subtest %s &", server_url);
    if (system(cmd) != 0) {
	fprintf(stderr, "Cannot execute subtest command\n");
	exit(1);
    }
    system(cmd);
    free(server_url);

#ifdef WIN32
    Sleep(2000);
#else
    sleep(2);
#endif
    TEST(reply_count == 3);
    TEST(pattern_count == 5);
    TEST(subtest_count == 2);
    TEST(subtest_reply_count == 22);
    printf("\n");

    {
        lo_timetag t = {10,0xFFFFFFFC};
        b = lo_bundle_new(t);
    }
    m1 = lo_message_new();
    lo_message_add_string(m1, "abcdefghijklmnopqrstuvwxyz");
    lo_message_add_string(m1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    lo_bundle_add_message(b, "/bundle", m1);
    lo_send_bundle(a, b);

    /* This should be safe for multiple copies of the same message. */
    lo_bundle_free_messages(b);

    {
        lo_timetag t = {1,2};
        b = lo_bundle_new(t);
    }
    m1 = lo_message_new();
    lo_message_add_int32(m1, 23);
    lo_message_add_string(m1, "23");
    lo_bundle_add_message(b, "/bundle", m1);
    m2 = lo_message_new();
    lo_message_add_string(m2, "24");
    lo_message_add_int32(m2, 24);
    lo_bundle_add_message(b, "/bundle", m2);
    lo_bundle_add_message(b, "/bundle", m1);

/* 
    lo_send_bundle(a, b);
    if (a->errnum) {
	printf("error %d: %s\n", a->errnum, a->errstr);
	exit(1);
    }
*/
    TEST(lo_send_bundle(a, b) == 88);

    /* Test freeing out-of-order copies of messages in a bundle. */
    lo_bundle_free_messages(b);

    {
        lo_timetag t = {10,0xFFFFFFFE};
        b = lo_bundle_new(t);
    }
    m1 = lo_message_new();
    lo_message_add_string(m1, "abcdefghijklmnopqrstuvwxyz");
    lo_message_add_string(m1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    lo_bundle_add_message(b, "/bundle", m1);
    lo_send_bundle(a, b);
    lo_message_free(m1);
    lo_bundle_free(b);

    lo_timetag_now(&sched);

    sched.sec += 5;
    b = lo_bundle_new(sched);
    m1 = lo_message_new();
    lo_message_add_string(m1, "future");
    lo_message_add_string(m1, "time");
    lo_message_add_string(m1, "test");
    lo_bundle_add_message(b, "/bundle", m1);

    lo_send_bundle(a, b);
    lo_message_free(m1);
    lo_bundle_free(b);

    lo_send_timestamped(a, sched, "/bundle", "s", "lo_send_timestamped() test");

    /* test bundle timestamp ends up in message struct (and doesn't end up in
       unbundled messages) */
    lo_timetag_now(&sched);    
    lo_send_timestamped(a, sched, "/timestamp", "it", 1, sched);
    lo_send(a, "/timestamp", "it", 0, sched);

#define JITTER_ITS 25
    /* jitter tests */
    {
	lo_timetag stamps[JITTER_ITS];
	lo_timetag now;
	int i;

	for (i=0; i<JITTER_ITS; i++) {
	    lo_timetag_now(&now);
	    stamps[i] = now;
	    stamps[i].sec += 1;
	    stamps[i].frac = rand();
	    lo_send_timestamped(a, stamps[i], "/jitter", "ti", stamps[i], i);
	}
    }

#ifdef WIN32
    Sleep(2000);
#else
    sleep(2);
#endif

    lo_address_free(a);

    TEST(lo_server_thread_events_pending(st));

    while (lo_server_thread_events_pending(st)) {
	printf("pending events, wait...\n");
#ifdef WIN32
	fflush(stdout);
	Sleep(1000);
#else
	sleep(1);
#endif
    }
    
    TEST(bundle_count == 7);
    printf("\n");

    printf("bundle timing jitter results:\n"
	   "max jitter = %fs\n"
	   "avg jitter = %fs\n"
           "min jitter = %fs\n\n",
           jitter_max, jitter_total/(float)jitter_count, jitter_min);

    server_url = lo_server_get_url(s);

    lo_server_add_method(s, NULL, NULL, generic_handler, NULL);
    a = lo_address_new_from_url(server_url);
    TEST(lo_server_recv_noblock(s, 0) == 0);
    printf("Testing noblock API on %s\n", server_url);
    lo_send(a, "/non-block-test", "f", 23.0);

    count = 0;
    while (!lo_server_recv_noblock(s, 10) && count++ < 1000) { }
    if (count >= 1000) {
	printf("lo_server_recv_noblock() test failed\n");

	exit(1);
    }

    /* Delete methods */
    lo_server_thread_del_method(st, "/coerce", "dfhiSs");
    lo_server_del_method(s, NULL, NULL);

    lo_address_free(a);
    lo_server_free(s);
    free(server_url);

#ifndef WIN32
    { /* UNIX domain tests */
	lo_address ua;
	lo_server us;
	char *addr;

	unlink("/tmp/testlo.osc");
	us = lo_server_new_with_proto("/tmp/testlo.osc", LO_UNIX, error);
	ua = lo_address_new_from_url("osc.unix:///tmp/testlo.osc");
	TEST(lo_server_get_protocol(us) == LO_UNIX);
	TEST(lo_send(ua, "/unix", "f", 23.0) == 16);
	TEST(lo_server_recv(us) == 16);
	addr = lo_server_get_url(us);
	TEST(!strcmp("osc.unix:////tmp/testlo.osc", addr));
	free(addr);
	lo_address_free(ua);
	ua = lo_address_new_with_proto(LO_UNIX, NULL, "/tmp/testlo.osc");
	TEST(lo_send(ua, "/unix", "f", 23.0) == 16);
	TEST(lo_server_recv(us) == 16);
	lo_server_free(us);
	lo_address_free(ua);
    }
#endif

    { /* TCP tests */
	lo_address ta;
	lo_server ts;
	char *addr;

	ts = lo_server_new_with_proto(NULL, LO_TCP, error);
	addr = lo_server_get_url(ts);
	ta = lo_address_new_from_url(addr);
	if (lo_address_errno(ta)) {
	    printf("err: %s\n", lo_address_errstr(ta));
	    exit(1);
	}
	TEST(lo_server_get_protocol(ts) == LO_TCP);
	TEST(lo_send(ta, "/tcp", "f", 23.0) == 16);
	TEST(lo_send(ta, "/tcp", "f", 23.0) == 16);
	TEST(lo_server_recv(ts) == 16);
	TEST(lo_server_recv(ts) == 16);
	free(addr);
	lo_server_free(ts);
	lo_address_free(ta);
    }

    server_url = lo_server_thread_get_url(st);
    a = lo_address_new_from_url(server_url);
    /* exit */
    lo_send(a, "/quit", NULL);
    lo_address_free(a);

    while (!done) {
#ifdef WIN32
    Sleep(1);
#else
	usleep(1000);
#endif
    }

    lo_server_thread_free(st);
    free(server_url);


    return 0;
}
예제 #10
0
파일: lurkcast.c 프로젝트: yaxu/screencast
gint
main (gint   argc,
      gchar *argv[])
{
  GstElement *pipeline, 
    *xsrc,
    *xcap,
    *videorate,
    //*videoscale,
    *scalecap,
    *flt, *ffmpegconv, *oggmux, *out, 
    *theoraenc, *vidqueue,
    *audiosource, *audiorate, *audioflt, *audioconv, *audioenc, *audioqueue
    ;

  GMainLoop *loop;

  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);

  pipeline = gst_pipeline_new ("pipeline");

  //video bit
  xsrc = gst_element_factory_make("ximagesrc", "xsrc");
  xcap = gst_element_factory_make ("capsfilter", "xcap");
  videorate = gst_element_factory_make ("videorate", "videorate");
  

  //videoscale = gst_element_factory_make ("videoscale", "videoscale");
  irc = gst_element_factory_make ("textoverlay", "irc");
  scalecap = gst_element_factory_make ("capsfilter", "scalecap");

  ffmpegconv = gst_element_factory_make ("ffmpegcolorspace", "conv");
  flt = gst_element_factory_make ("capsfilter", "flt");
  theoraenc = gst_element_factory_make ("theoraenc", "theoraenc");
  vidqueue = gst_element_factory_make ("queue", "vidqueue");

  //audio bit
  audiosource = gst_element_factory_make ("jackaudiosrc", "audiosrc");
  audiorate = gst_element_factory_make("audiorate", "audiorate");
  audioflt = gst_element_factory_make ("capsfilter", "audioflt");
  audioconv = gst_element_factory_make ("audioconvert", "audioconv");
  audioenc = gst_element_factory_make ("vorbisenc", "audioenc");
  audioqueue = gst_element_factory_make ("queue", "audioqueue");
  
  //multiplexing and sending bit
  oggmux = gst_element_factory_make ("oggmux", "mux");
#ifdef FILE
  out = gst_element_factory_make ("filesink", "filesink");
#else
  out = gst_element_factory_make ("shout2send", "shout");
#endif
  //configure

  g_object_set(G_OBJECT (audiosource),
               "connect", 0,
               "name", "lurkcast",
               NULL);
  
  g_object_set (G_OBJECT (xsrc),
		"use-damage", FALSE,
                "startx", 1,
                "starty", 31,
		"endx", 640,
		"endy", 510,
		NULL);

  g_object_set (G_OBJECT (xcap), "caps",
  		gst_caps_new_simple ("video/x-raw-rgb",
				     "framerate", GST_TYPE_FRACTION, 10, 1,
				     NULL), NULL);

  g_object_set (G_OBJECT (flt), "caps",
  		gst_caps_new_simple ("video/x-raw-yuv",
				     "framerate", GST_TYPE_FRACTION, 8, 1,
				     "width", G_TYPE_INT, 640,
				     "height", G_TYPE_INT, 480,
				     NULL), NULL);
  
  g_object_set (G_OBJECT (scalecap), "caps",
  		gst_caps_new_simple ("video/x-raw-yuv",
				     "width", G_TYPE_INT, 640,
				     "height", G_TYPE_INT, 480,
				     NULL), NULL);

  /*
  GValue val;
  memset(&val, 0, sizeof(val));
  
  GValueArray *arr; // for channel position layout
  arr = g_value_array_new(CHANNELS);
  
  g_value_init(&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
  
  for (int i = 0; i < CHANNELS; i++) {
    g_value_set_enum(&val, GST_AUDIO_CHANNEL_POSITION_NONE);
    g_value_array_append(arr, &val);
    g_value_reset(&val);
  }

  g_value_unset(&val);

  */

  g_object_set (G_OBJECT (audioflt), "caps",
  		gst_caps_new_simple ("audio/x-raw-float",
				     "rate", G_TYPE_INT, 44100,
				     "channels", G_TYPE_INT, CHANNELS,
				     "depth", G_TYPE_INT, 16,
				     //"channel-positions", arr,
				     NULL), NULL);
#ifdef FILE
  g_object_set (G_OBJECT (out),
		"location", FILE,
		NULL);
#else
  printf("sending..\n");
  g_object_set (G_OBJECT (out),
		"ip", "lurk.org",
		"password", "***",
		"mount", "/lurk.ogg",
		NULL);
#endif

  g_object_set (G_OBJECT (theoraenc),
		"quality", 30,
		NULL);

  g_object_set (G_OBJECT (audioenc),
		"quality", 0.3,
		NULL);

  // add and link together
  gst_bin_add_many (GST_BIN (pipeline), 
		    xsrc, 
                    xcap,
                    videorate,
		    //videoscale,
		    scalecap,
		    irc,
		    ffmpegconv, 
                    //flt, 
                    theoraenc, 
		    vidqueue, oggmux, out, 
		    audiosource, audiorate, audioflt, audioconv, audioenc, 
		    audioqueue,
		    NULL);
  gst_element_link_many (
			 xsrc, 
                         xcap,
			 ffmpegconv, 
                         videorate,
                         irc,
                         //videoscale,
                         //flt,
                         theoraenc, 
			 vidqueue, oggmux, out, 
			 NULL);
   
  gst_element_link_many (audiosource, audiorate, audioflt, audioconv, audioenc, 
    			 audioqueue, oggmux,
                         NULL);
   

  /* play */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  lo_server_thread osc = osc = lo_server_thread_new("7777", error);
  lo_server_thread_add_method(osc, "/text/irc", "s", irc_handler, NULL);
  lo_server_thread_start(osc);

  g_main_loop_run (loop);
   
  /* clean up */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (GST_OBJECT (pipeline));
   
  return 0;
}
예제 #11
0
	void buttonClicked (Button *button)
	{
		if (button == mReceive)
		{
			lo_server_thread_free(mServer);
			mServer = NULL;
			
			if (mReceive->getToggleState())
			{
				String p = mReceivePort->getText();
				mServer = lo_server_thread_new(p.toRawUTF8(), osc_err_handler);
				if (!mServer)
				{
					fprintf(stderr, "lo_server_thread_new failed (port in use ?)\n");
					mReceive->setToggleState(false, dontSendNotification);
					mReceivePort->setEnabled(true);
				}
				else
				{
					lo_server_thread_add_method(mServer, NULL, NULL, osc_method_handler, this);
					lo_server_thread_start(mServer);
					mReceivePort->setEnabled(false);
				}
			}
			else
			{
				mReceivePort->setEnabled(true);
			}
			
			mFilter->setOscReceiveEnabled(mReceive->getToggleState());
		}
		else if (button == mSend)
		{
			lo_address_free(mAddress);
			mAddress = NULL;
			
			if (mSend->getToggleState())
			{
				String i = mSendIp->getText();
				String p = mSendPort->getText();
				mAddress = lo_address_new(i.toRawUTF8(), p.toRawUTF8());
				if (!mAddress)
				{
					fprintf(stderr, "lo_address_new failed (port in use ?)\n");
					mSend->setToggleState(false, dontSendNotification);
					mSendIp->setEnabled(true);
					mSendPort->setEnabled(true);
				}
				else
				{
					//fprintf(stderr, "osc to %s %s\n", i.toRawUTF8(), p.toRawUTF8());
					mSourceXY = FPoint(-1, -1);
					mSource = -1;
					
					mSendIp->setEnabled(false);
					mSendPort->setEnabled(false);
				}
			}
			else
			{
				mSendIp->setEnabled(true);
				mSendPort->setEnabled(true);
			}
			
			mFilter->setOscSendEnabled(mSend->getToggleState());
		}
		else
		{
            JUCE_COMPILER_WARNING("debug on this")
			printf("unknown button clicked...\n");
		}
	}
예제 #12
0
파일: oscrec.c 프로젝트: ViktorNova/oscfile
int
main (int argc, char **argv)
{
	lo_server_thread serv = NULL;
	FILE *file = NULL;

	int c;
	while ( (c = getopt (argc, argv, "i:o:")) != -1)
		switch (c)
		{
			case 'i':
			{
				int proto = lo_url_get_protocol_id (optarg);
				if (proto == -1)
					fprintf (stderr, "protocol not supported\n");
				char *port = lo_url_get_port (optarg);
				serv = lo_server_thread_new_with_proto (port, proto, _error);
				free (port);
				break;
			}
			case 'o':
			{
				if (!strcmp (optarg, "-"))
					file = stdout;
				else
					file = fopen (optarg, "wb");
				break;
			}
			case '?':
				if ( (optopt == 'i') || (optopt == 'o') )
					fprintf (stderr, "Option `-%c' requires an argument.\n", optopt);
				else if (isprint (optopt))
					fprintf (stderr, "Unknown option `-%c'.\n", optopt);
				else
					fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
				return 1;
			default:
				return (1);
		}
		
	if (!serv || !file)
	{
		fprintf (stderr, "usage: %s -i PROTOCOL://HOST:PORT -o FILE|-\n\n", argv[0]);
		return (1);
	}

	lo_server *_serv = lo_server_thread_get_server (serv);
	lo_server_add_bundle_handlers (_serv, _bundle_start_handler, _bundle_end_handler, file);
	lo_server_enable_queue (_serv, 0, 1);
	lo_server_thread_add_method (serv, NULL, NULL, _msg_handler, file);
	lo_server_thread_start (serv);

	signal (SIGHUP, _quit);
	signal (SIGQUIT, _quit);
	signal (SIGTERM, _quit);
	signal (SIGINT, _quit);

	while (!done)
		nanosleep (&_10mu, NULL);

	fprintf (stderr, "cleaning up\n");

	lo_server_thread_stop (serv);
	lo_server_thread_free (serv);

	if (file != stdout)
		fclose (file);
	
	return 0;
}
예제 #13
0
static int	servit_new_event(
		void *userdata,
		void *osc_space,
		void *instance,
		const char *base,
		const char *key,
		const char *fmt,
		const char **args,
		const char *descr,
		vevo_event_f *func,
		int extra_token,
		void *ptemplate,
	        lo_method_handler method )
{
	veejay_t *info = (veejay_t*) userdata;
	osc_recv_t *s = (osc_recv_t*) info->osc_server;
	void *p = (void*) vevo_port_new( VEVO_ANONYMOUS_PORT );
	int error;
	
	if( func )
	{
		error = vevo_property_set( p, "func", VEVO_ATOM_TYPE_VOIDPTR,1,&func );
	}

	if( fmt == NULL )
		error = vevo_property_set( p, "format", VEVO_ATOM_TYPE_STRING,0,NULL );
	else
		error = vevo_property_set( p, "format", VEVO_ATOM_TYPE_STRING,1, &fmt );

	if( descr == NULL )
		error = vevo_property_set(p, "description",VEVO_ATOM_TYPE_STRING,0, NULL );
	else
		error = vevo_property_set(p, "description", VEVO_ATOM_TYPE_STRING,1, &descr );
	
	if( ptemplate )
	{
		error = vevo_property_set( p, "parent", VEVO_ATOM_TYPE_VOIDPTR,1,&ptemplate );
	}
	
/*	if( extra_token >= 0)
	{
		error = vevo_property_set(p, "ref", VEVO_ATOM_TYPE_INT,1, &extra_token );
	}*/
	
	if( args )
	{
		int i;
		for( i = 0;i < 4; i ++ )
		{
			if(args[i])
			{
				char index[10];
				sprintf(index,"help_%d",i);
				error = vevo_property_set( p, index, VEVO_ATOM_TYPE_STRING,1,&(args[i]) );
			}
		}
	}

	plugin_data_t *pd = (plugin_data_t*) vj_malloc(sizeof(plugin_data_t));
	pd->seq = extra_token;
	pd->caller = userdata;
	pd->instance = instance;
	error = vevo_property_set( p,
				"userdata",
				VEVO_ATOM_TYPE_VOIDPTR,
				1,
				&pd );

	char *tmp_path = NULL;
	if( base)
		tmp_path = osc_create_path( base, key );     
	else
		tmp_path = strdup(key);

	char *my_path  = veejay_valid_osc_name( tmp_path );
	
	error = vevo_property_set( osc_space,
				   my_path,
				   VEVO_ATOM_TYPE_PORTPTR,
				   1,
				   &p );

	lo_server_thread_add_method(
				s->st,
				my_path,
				fmt,
				method,
				(void*) pd );

	free(my_path);
	free(tmp_path);
	
	return VEVO_NO_ERROR;
}
예제 #14
0
파일: mjosc.c 프로젝트: egasimus/madjack
lo_server_thread init_osc( char *port )
{
	lo_server_thread st = NULL;
	lo_server serv = NULL;
	
	// Create new server
	st = lo_server_thread_new( port, osc_error_handler );
	if (!st) return NULL;
	
	// Add the methods
	serv = lo_server_thread_get_server( st );
	lo_server_thread_add_method( st, "/deck/play", "", play_handler, serv);
	lo_server_thread_add_method( st, "/deck/pause", "", pause_handler, serv);
	lo_server_thread_add_method( st, "/deck/stop", "", stop_handler, serv);
	lo_server_thread_add_method( st, "/deck/cue", "", cue_handler, serv);
	lo_server_thread_add_method( st, "/deck/cue", "f", cue_handler, serv);
	lo_server_thread_add_method( st, "/deck/eject", "", eject_handler, serv);
	lo_server_thread_add_method( st, "/deck/load", "s", load_handler, serv);
	lo_server_thread_add_method( st, "/deck/get_state", "", state_handler, serv);
	lo_server_thread_add_method( st, "/deck/get_duration", "", duration_handler, serv);
	lo_server_thread_add_method( st, "/deck/get_position", "", position_handler, serv);
	lo_server_thread_add_method( st, "/deck/get_filepath", "", filepath_handler, serv);
	lo_server_thread_add_method( st, "/get_error", "", get_error_handler, serv);
	lo_server_thread_add_method( st, "/get_version", "", get_version_handler, serv);
	lo_server_thread_add_method( st, "/ping", "", ping_handler, serv);

	// add method that will match any path and args
	lo_server_thread_add_method(st, NULL, NULL, wildcard_handler, serv);

	// Start the thread
	lo_server_thread_start(st);

	if (!quiet) {
		char *url = lo_server_thread_get_url( st );
		printf( "OSC server URL: %s\n", url );
		free(url);
	}
	
	return st;
}
ModuleManager::ModuleManager(Server *s, const char *osc) : Module(s,osc)
{
    lo_server_thread_add_method(st->st, "/ModuleManager/RequestML", "i", requestML, this);
    mPath[0] = '\0';
    mColor = -1;
}
예제 #16
0
int main(int argc, char *argv[])
{
    unsigned int i;
    int opt;
    int help = 0;
    int console = 0;
    char port_name[32];
    pthread_t dt;
#ifdef HAVE_LASH
    lash_args_t *lash_args = lash_extract_args(&argc, &argv);
     lash_event_t *event;
#endif

    auto_begin_threshold = db2lin(DEFAULT_AUTO_BEGIN_THRESHOLD);
    auto_end_threshold = db2lin(DEFAULT_AUTO_END_THRESHOLD);

    while ((opt = getopt(argc, argv, "hic:t:n:p:f:sab:e:T:")) != -1) {
	switch (opt) {
	case 'h':
	    help = 1;
	    break;
	case 'i':
	    console = 1;
	    break;
	case 'c':
	    num_ports = atoi(optarg);
	    DEBUG(1, "ports: %d\n", num_ports);
	    break;
	case 't':
	    buf_length = atoi(optarg);
	    DEBUG(1, "buffer: %ds\n", buf_length);
	    break;
	case 'n':
	    client_name = optarg;
	    DEBUG(1, "client name: %s\n", client_name);
	    break;
	case 'p':
	    prefix = optarg;
	    DEBUG(1, "prefix: %s\n", prefix);
	    break;
	case 'f':
	    format_name = optarg;
	    break;
	case 's':
	    safe_filename = 1;
	    break;
	case 'a':
	    auto_record = 1;
	    break;
	case 'b':
	    auto_begin_threshold = db2lin(atof(optarg));
	    break;
	case 'e':
	    auto_end_threshold = db2lin(atof(optarg));
	    break;
	case 'T':
	    auto_end_time = atoi(optarg);
	    break;
	default:
	    num_ports = 0;
	    break;
	}
    }

    if (optind != argc) {
	num_ports = argc - optind;
    }

    if (num_ports < 1 || num_ports > MAX_PORTS || help) {
	fprintf(stderr, "Usage %s: [-h] [-i] [-c channels] [-n jack-name]\n\t"
			"[-t buffer-length] [-p file prefix] [-f format]\n\t"
			"[-a] [-b begin-threshold] [-e end-threshold] [-T end-time]\n\t"
			"[port-name ...]\n\n", argv[0]);
	fprintf(stderr, "\t-h\tshow this help\n");
	fprintf(stderr, "\t-i\tinteractive mode (console instead of X11) also enabled\n\t\tif DISPLAY is unset\n");
	fprintf(stderr, "\t-c\tspecify number of recording channels\n");
	fprintf(stderr, "\t-n\tspecify the JACK name timemachine will use\n");
	fprintf(stderr, "\t-t\tspecify the pre-recording buffer length\n");
	fprintf(stderr, "\t-p\tspecify the saved file prefix, may include path\n");
	fprintf(stderr, "\t-s\tuse safer characters in filename (windows compatibility)\n");
	fprintf(stderr, "\t-f\tspecify the saved file format\n");
	fprintf(stderr, "\t-a\tenable automatic sound-triggered recording\n");
	fprintf(stderr, "\t-b\tspecify threshold above which automatic recording will begin\n");
	fprintf(stderr, "\t-e\tspecify threshold below which automatic recording will end\n");
	fprintf(stderr, "\t-T\tspecify silence length before automatic recording ends\n");
	fprintf(stderr, "\n");
	fprintf(stderr, "\tchannels must be in the range 1-8, default %d\n",
			DEFAULT_NUM_PORTS);
	fprintf(stderr, "\tjack-name, default \"%s\"\n", DEFAULT_CLIENT_NAME);
	fprintf(stderr, "\tfile-prefix, default \"%s\"\n", DEFAULT_PREFIX);
	fprintf(stderr, "\tbuffer-length, default %d secs\n", DEFAULT_BUF_LENGTH);
	fprintf(stderr, "\tformat, default '%s', options: wav, w64\n", DEFAULT_FORMAT);
	fprintf(stderr, "\tbegin-threshold, default %.1f dB\n", DEFAULT_AUTO_BEGIN_THRESHOLD);
	fprintf(stderr, "\tend-threshold, default %.1f dB\n", DEFAULT_AUTO_END_THRESHOLD);
	fprintf(stderr, "\tend-time, default %d secs\n", DEFAULT_AUTO_END_TIME);
	fprintf(stderr, "\n");
	fprintf(stderr, "specifying port names to connect to on the command line overrides -c\n\n");
	exit(1);
    }

    if (!strcasecmp(format_name, "wav")) {
	format_sf = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
    }
#ifdef HAVE_W64
    if (!strcasecmp(format_name, "w64")) {
	format_sf = SF_FORMAT_W64 | SF_FORMAT_FLOAT;
    }
#endif

    if (format_sf == 0) {
	fprintf(stderr, "Unknown format '%s'\n", format_name);
    }

    /* Register with jack */
    if ((client = jack_client_open(client_name, 0, NULL)) == 0) {
	DEBUG(0, "jack server not running?\n");
	exit(1);
    }
    DEBUG(1, "registering as %s\n", client_name);

    process_init(buf_length);

#ifdef HAVE_LASH
    lash_client = lash_init (lash_args, "TimeMachine",
                     0, /* would be LASH_Config_Data_Set etc. */
                     LASH_PROTOCOL (2,0));
    if (!lash_client) {
	DEBUG(1, "could not initialise LASH\n");
    }
    event = lash_event_new_with_type(LASH_Client_Name);
    lash_event_set_string(event, client_name);
    lash_send_event(lash_client, event);
#endif

    jack_set_process_callback(client, process, 0);

    if (jack_activate(client)) {
	DEBUG(0, "cannot activate JACK client");
	exit(1);
    }
#ifdef HAVE_LASH
    lash_jack_client_name(lash_client, client_name);
#endif

    /* Create the jack ports */
    for (i = 0; i < num_ports; i++) {
	jack_port_t *port;

	snprintf(port_name, 31, "in_%d", i + 1);
	ports[i] = jack_port_register(client, port_name,
				      JACK_DEFAULT_AUDIO_TYPE,
				      JackPortIsInput, 0);
	if (optind != argc) {
	    port = jack_port_by_name(client, argv[optind+i]);
	    if (port == NULL) {
		fprintf(stderr, "Can't find port '%s'\n", port_name);
		continue;
	    }
	    if (jack_connect(client, argv[optind+i], jack_port_name(ports[i]))) {
		fprintf(stderr, "Cannot connect port '%s' to '%s'\n",
			argv[optind+i], jack_port_name(ports[i]));
	    }
	}
    }

    /* Start the disk thread */
    pthread_create(&dt, NULL, (void *)&writer_thread, NULL);

#ifdef HAVE_LIBREADLINE
    if (console || !getenv("DISPLAY") || getenv("DISPLAY")[0] == '\0') {
#ifdef HAVE_LIBLO
      lo_server_thread st = lo_server_thread_new(OSC_PORT, NULL);
      if (st) {
	  lo_server_thread_add_method(st, "/start", "", osc_handler_nox, (void *)1);
	  lo_server_thread_add_method(st, "/stop", "", osc_handler_nox, (void *)0);
	  lo_server_thread_start(st);
	  printf("Listening for OSC requests on osc.udp://localhost:%s\n",
	    OSC_PORT);
      }
#endif

      int done = 0;
      while (!done) {
	char *line = readline("TimeMachine> ");
	if (!line) {
	  printf("EOF\n");
	  break;
	}
	if (line && *line) {
	  add_history(line);
	  if (strncmp(line, "q", 1) == 0) done = 1;
	  else if (strncmp(line, "start", 3) == 0) recording_start();
	  else if (strncmp(line, "stop", 3) == 0) recording_stop();
	  else if (strncmp(line, "help", 3) == 0) {
	    printf("Commands: start stop\n");
	  } else {
	    printf("Unknown command\n");
          }
	}
	free(line);
      }
    } else
#endif
    {
      gtk_init(&argc, &argv);

      add_pixmap_directory(PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
      add_pixmap_directory("pixmaps");
      add_pixmap_directory("../pixmaps");

      img_on = create_pixbuf("on.png");
      img_off = create_pixbuf("off.png");
      img_busy = create_pixbuf("busy.png");
      icon_on = create_pixbuf("on-icon.png");
      icon_off = create_pixbuf("off-icon.png");

      main_window = create_window(client_name);
      gtk_window_set_icon(GTK_WINDOW(main_window), icon_off);
      gtk_widget_show(main_window);

      bind_meters();
      g_timeout_add(100, meter_tick, NULL);

#ifdef HAVE_LIBLO
    lo_server_thread st = lo_server_thread_new(OSC_PORT, NULL);
    if (st) {
	lo_server_thread_add_method(st, "/start", "", osc_handler, (void *)1);
	lo_server_thread_add_method(st, "/stop", "", osc_handler, (void *)0);
	lo_server_thread_start(st);
	printf("Listening for OSC requests on osc.udp://localhost:%s\n",
	       OSC_PORT);
    }
#endif

#ifdef HAVE_LASH
      gtk_idle_add(idle_cb, lash_client);
#endif

      gtk_main();
    }

    cleanup();

    /* We can't ever get here, but it keeps gcc quiet */
    return 0;
}
예제 #17
0
void activate_OSCsensors() {
	curr_OSC_Node = 0 ;
	active_OSC_Nodes = TRUE ;
	struct X3D_OSC_Sensor *realnode ;
	char buf[32];
	int i ;
	/* what amount of storage */
	int fltCount;
	int intCount;
	int strCount;
	int blobCount;
	int midiCount;
	int otherCount;

	while (active_OSC_Nodes && curr_OSC_Node < num_OSC_Nodes) {
		realnode = (struct X3D_OSC_Sensor *) OSC_Nodes[curr_OSC_Node] ;
        if (checkNode(realnode,__FILE__,__LINE__)) {
		#if TRACK_OSC_MSG
		printf("activate_OSCsensors : %s,%d node=%p name=%s\n", __FILE__,__LINE__,realnode,realnode->description->strptr) ;
		#endif
		if (realnode->_status < 0) {
			printf("activate_OSCsensors : %s,%d Moving %s to ready.\n", __FILE__,__LINE__,realnode->description->strptr) ;
			realnode->_status = 0 ;
		} else if (realnode->_status == 0) {
			printf("activate_OSCsensors : %s,%d\n", __FILE__,__LINE__) ;
			printf("activate_OSCsensors : enabled=%d\n",	realnode->enabled) ;
			printf("activate_OSCsensors : gotEvents=%d\n",	realnode->gotEvents) ;
			printf("activate_OSCsensors : description=%s\n",realnode->description->strptr) ;
			printf("activate_OSCsensors : protocol=%s\n",	realnode->protocol->strptr) ;
			printf("activate_OSCsensors : port=%d\n",	realnode->port) ;
			printf("activate_OSCsensors : filter=%s\n",	realnode->filter->strptr) ;
			printf("activate_OSCsensors : handler=%s\n",	realnode->handler->strptr) ;
/*
11715                     if(allFields) {
11716                         spacer fprintf (fp,"\t_talkToNodes (MFNode):\n");
11717                         for (i=0; i<tmp->_talkToNodes.n; i++) { dump_scene(fp,level+1,tmp->_talkToNodes.p[i]); }
11718                     }
11719                     if(allFields) {
11720                         spacer fprintf (fp,"\t_status (SFInt32) \t%d\n",tmp->_status);
11721                     }
11722                     if(allFields) {
11723                         spacer fprintf (fp,"\t_floatInpFIFO (SFNode):\n"); dump_scene(fp,level+1,tmp->_floatInpFIFO);
11724                     }
11725                     if(allFields) {
11726                         spacer fprintf (fp,"\t_int32OutFIFO (SFNode):\n"); dump_scene(fp,level+1,tmp->_int32OutFIFO);
11727                     }
11728                         spacer fprintf (fp,"\ttalksTo (MFString): \n");
11729                         for (i=0; i<tmp->talksTo.n; i++) { spacer fprintf (fp,"                 %d: \t%s\n",i,tmp->talksTo.p[i]->strptr); }
*/
			printf("activate_OSCsensors : talksTo=[ ");
			for (i=0; i < realnode->talksTo.n; i++) {
				printf("\"%s\" ",realnode->talksTo.p[i]->strptr);
				/* This would be a good time to convert the name into an entry in _talkToNodes */
				struct X3D_Node * myNode;
				/* myNode = X3DParser_getNodeFromName(realnode->talksTo.p[i]->strptr); */
				myNode = parser_getNodeFromName(realnode->talksTo.p[i]->strptr);
				if (myNode != NULL) {
					printf("(%p) ",(void *)myNode);
				} else {
					printf("(..) ");
				}
			}
			printf("] (%d nodes) (Need to fix %s,%d)\n",realnode->talksTo.n , __FILE__,__LINE__);
			printf("activate_OSCsensors : listenfor=%s , expect %d parameters\n", realnode->listenfor->strptr , (int)strlen(realnode->listenfor->strptr)) ;
			printf("activate_OSCsensors : FIFOsize=%d\n",	realnode->FIFOsize) ;
			printf("activate_OSCsensors : _status=%d\n",	realnode->_status) ;

			if (realnode->FIFOsize > 0) {
				/* what amount of storage */
				utilOSCcounts(realnode->listenfor->strptr,&intCount,&fltCount,&strCount,&blobCount,&midiCount,&otherCount);
				intCount = realnode->FIFOsize * (intCount + midiCount); 
				fltCount = realnode->FIFOsize * fltCount;
				strCount = realnode->FIFOsize * (strCount + blobCount + otherCount); 
				printf("Allocate %d floats, %d ints for '%s'\n",fltCount,intCount,realnode->description->strptr);

				realnode->_int32InpFIFO = (void *) NewRingBuffer (intCount) ;
				realnode->_floatInpFIFO = (void *) NewRingBuffer (fltCount) ;
				realnode->_stringInpFIFO = (void *) NewRingBuffer (strCount) ;

			}

			/* start a new server on the required port */
			int foundCurrentPort = -1 ;
			for ( i=0 ; i < num_OSC_Nodes ; i++) {
				if(realnode->port == serverPort[i]) {
					foundCurrentPort=i;
					i = num_OSC_Nodes+1;
				}
			}
			if (foundCurrentPort < 0) {
				foundCurrentPort = serverCount ;
				serverPort[foundCurrentPort] = realnode->port ;
				serverCount++ ;

				sprintf (buf,"%d",realnode->port);

				if (strcmp("TCP",realnode->protocol->strptr)==0) {
					/* oscThread[foundCurrentPort] = lo_server_thread_new_with_proto(buf, LO_TCP, error); */
					oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
				} else if (strcmp("UNIX",realnode->protocol->strptr)==0) {
					/* oscThread[foundCurrentPort] = lo_server_thread_new_with_proto(buf, LO_UNIX, error); */
					oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
				} else {
					/* oscThread[foundCurrentPort] = lo_server_thread_new_with_proto(buf, LO_UDP, error); */
					oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
				}
				lo_server_thread_start(oscThread[foundCurrentPort]);
			}

			printf("%d servers; current server is running in slot %d on port %d\n",serverCount,foundCurrentPort,serverPort[foundCurrentPort]) ;

			/* add method (by looking up its name) that will in future use the required path */
			/* need to re-read the lo code to check that you can register the same callback twice (or more) with different paths) */
			/* See OSCcallbacks.c */
			int foundHandler = 0 ;
			for (i=0 ; i < OSCfuncCount ; i++) {
				printf("%d/%d : Check %s against %s\n",i,OSCfuncCount,realnode->handler->strptr,OSCfuncNames[i]);
				if (0 == strcmp(realnode->handler->strptr,OSCfuncNames[i])) {foundHandler = i;}
			}
			if (OSCcallbacks[foundHandler] != NULL) {
				printf("Going to hook '%s' to '%s' handler\n",realnode->description->strptr ,OSCfuncNames[foundHandler]) ;
				lo_server_thread_add_method(oscThread[foundCurrentPort], realnode->filter->strptr, realnode->listenfor->strptr,
					(OSCcallbacks[foundHandler]), realnode);
			}

			realnode->_status = 1 ;
			/* We only want one OSC node to become active in one slowtick */
			active_OSC_Nodes = FALSE ;
		} 
        } // end of checkNode conditional - JAS
            
		curr_OSC_Node++;
	}
}
예제 #18
0
파일: osc.c 프로젝트: cmeon/xwax-1.5-osc
int osc_start(struct deck *deck, struct library *library)
{
    osc_deck = deck;
    osc_library = library;
    
    address[0] = lo_address_new_from_url("osc.udp://0.0.0.0:7771/");
    address[1] = lo_address_new_from_url("osc.udp://0.0.0.0:7771/");
    
    
    /* start a new server on port 7770 */
    st = lo_server_thread_new("7770", error);
    
    lo_server_thread_add_method(st, "/xwax/load_track", "isss", load_track_handler, NULL);

    lo_server_thread_add_method(st, "/xwax/set_cue", "iif", set_cue_handler, NULL);

    lo_server_thread_add_method(st, "/xwax/punch_cue", "ii", punch_cue_handler, NULL);  

    lo_server_thread_add_method(st, "/xwax/get_status", "i", get_status_handler, NULL);
    
    lo_server_thread_add_method(st, "/xwax/recue", "i", recue_handler, NULL); 
  
    lo_server_thread_add_method(st, "/xwax/disconnect", "i", disconnect_handler, NULL);    
    
    lo_server_thread_add_method(st, "/xwax/reconnect", "i", reconnect_handler, NULL);    

    lo_server_thread_add_method(st, "/xwax/connect", "", connect_handler, NULL);

    lo_server_thread_add_method(st, "/xwax/pitch", "if", pitch_handler, NULL);

    lo_server_thread_add_method(st, "/xwax/position", "if", position_handler, NULL);
    
    /* add method that will match the path /quit with no args */
    lo_server_thread_add_method(st, "/quit", "", quit_handler, NULL);

    lo_server_thread_start(st);
    
    ///* Start a TCP server used for receiving PPM packets */
    //st_tcp = lo_server_thread_new_with_proto("7771", LO_TCP, error);
    //if (!st_tcp) {
        //printf("Could not create tcp server thread.\n");
        //exit(1);
    //}
    
    //lo_server s = lo_server_thread_get_server(st);   
    
    ///* add method that will match the path /foo/bar, with two numbers, coerced
     //* to float and int */
    
    //lo_server_thread_start(st_tcp);
    
    //printf("Listening on TCP port %s\n", "7771");

    return 0;
}
예제 #19
0
파일: osc.c 프로젝트: colinbouvry/minuit
void osc_method_add( t_osc *osc, const char *msg, const char *type, osc_method f)
{
	lo_server_thread_add_method( osc->thread, msg, type, *f, NULL);
}
예제 #20
0
파일: cldj.cpp 프로젝트: ryo-okabayashi/pa
int main(void) {

	srand(time(NULL));

	create_list(MUSIC_DIR);
	max_list = list.size();

	PaStreamParameters outputParameters;
	PaStream *stream;
	PaError e;

	signal(SIGINT, signal_catch);

	/*
	pthread_t thread;
	pthread_attr_t thread_attr;
	pthread_attr_init(&thread_attr);
	pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
	if(pthread_create(&thread, &thread_attr, thread1, NULL) != 0) {
		perror("pthrad create error");
	}
	pthread_join(thread, NULL);
	*/

	if (REC) rec.prepare();

	// OSC
	lo_server_thread server;
	server = lo_server_thread_new(OSC_PORT, NULL);
	lo_server_thread_add_method(server, "/1/fader1", "f", osc, NULL);
	lo_server_thread_add_method(server, "/1/fader2", "f", osc, NULL);
	lo_server_thread_add_method(server, "/1/toggle1", "i", osc, NULL);
	lo_server_thread_add_method(server, "/1/toggle2", "i", osc, NULL);
	lo_server_thread_add_method(server, "/1/toggle3", "i", osc, NULL);
	lo_server_thread_add_method(server, "/1/toggle4", "i", osc, NULL);
	lo_server_thread_start(server);

	// reset
	lo_send(address, "/1/fader1", "f", 0.0);
	lo_send(address, "/1/fader2", "f", 0.0);
	lo_send(address, "/1/rotary2", "f", 0.0);
	lo_send(address, "/1/rotary3", "f", 0.0);
	lo_send(address, "/1/rotary6", "f", 0.0);
	lo_send(address, "/1/toggle1", "i", 1);
	lo_send(address, "/1/toggle2", "i", 0);
	lo_send(address, "/1/toggle3", "i", 1);
	lo_send(address, "/1/toggle4", "i", 0);

	e = Pa_Initialize();
	err(e);

	// devices
	/*
	int numDevices = Pa_GetDeviceCount();
	const PaDeviceInfo *deviceInfo;
	for (int i = 0; i < numDevices; i++) {
		deviceInfo = Pa_GetDeviceInfo( i );
		const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
		cout << i << ": " << hostInfo->name << endl;
	}
	*/

	outputParameters.device = Pa_GetDefaultOutputDevice();
	if (outputParameters.device == paNoDevice) {
		cerr << "Error: No default output device." << endl;
		exit(0);
	}
	outputParameters.channelCount = 2;
	outputParameters.sampleFormat = paFloat32;
	outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
	outputParameters.hostApiSpecificStreamInfo = NULL;

	e = Pa_OpenStream(
			&stream,
			NULL,
			&outputParameters,
			SAMPLE_RATE,
			FRAMES_PER_BUFFER,
			paClipOff,
			paCallback,
			NULL );
	err(e);

	e = Pa_StartStream(stream);
	err(e);

	// input
	int c;
	while ((c = getchar())) {
		if (c == 'q') {
			break;
		}
	}

	//pthread_exit(NULL);

	e = Pa_StopStream(stream);
	err(e);

	e = Pa_CloseStream(stream);
	err(e);

	Pa_Terminate();

	return 0;
}
예제 #21
0
//================================================================
void registerOSCMessagePatterns(const char *port)
{
	/* osc server */
	//lo_st=lo_server_thread_new(port, error);
	lo_st=lo_server_thread_new_with_proto(port, lo_proto, osc_error_handler);

//AUDIO RELATED=========================================

/*
	/offer fiiiifh

	1) f: audio rx/tx format version
	2) i: sample rate
	3) i: bytes per sample
	4) i: period size
	5) i: channel count
	6) f: expected network data rate
	7) h: send / request counter
*/

	lo_server_thread_add_method(lo_st, "/offer", "fiiiifh", osc_offer_handler, NULL);

/*
	experimental

	/buffer ii

	1) i: target fill value for available periods in ringbuffer (multi channel)
	2) i: max. target buffer size in mc periods
	drop or add periods
	this will introduce a hearable click on drops
	or pause playback for rebuffering depending on the current buffer fill
*/

	lo_server_thread_add_method(lo_st, "/buffer", "ii", osc_buffer_handler, NULL);

/*
	/audio hhtib*

	1) h: message number
	2) h: xrun counter (sender side, as all the following meta data)
	3) t: timetag (seconds since Jan 1st 1900 in the UTC, fraction 1/2^32nds of a second)
	4) i: sampling rate
	5) b: blob of channel 1 (period size * bytes per sample) bytes long
	...
	...b: up to n channels
*/

	char typetag_string[1024];
	int v=0;
	for(v=0;v<1024;v++)
	{
		typetag_string[v]='\0';
	}

	//char *prefix="hhti";
	typetag_string[0]='h';
	typetag_string[1]='h';
	typetag_string[2]='t';
	typetag_string[3]='i';

	/////////////////
	int data_offset=4;

//the max possible channel count depends on JACK period size, SR, liblo version (fixmax), 16/32 bit, 100/1000 mbit/s network
/*
	//support 1-n blobs / channels per message
	lo_server_thread_add_method(lo_st, "/audio", "hhtib", audio_handler, NULL);
	lo_server_thread_add_method(lo_st, "/audio", "hhtibb", audio_handler, NULL);
..
*/
	v=0;
	for(v=0;v<max_channel_count;v++)
	{
		typetag_string[data_offset+v]='b';
		lo_server_thread_add_method(lo_st, "/audio", typetag_string, osc_audio_handler, NULL);
	}

//GUI I/O, CONTROL RELATED==============================

/*
	/quit
	close / release resources and shutdown program
*/
	lo_server_thread_add_method(lo_st, "/quit", "", osc_quit_handler, NULL);


}//end registerocsmessages