~CarlaNSM()
    {
        CARLA_SAFE_ASSERT(fReadyActionOpen);
        CARLA_SAFE_ASSERT(fReadyActionSave);

        if (fServerThread != nullptr)
        {
            lo_server_thread_stop(fServerThread);
            lo_server_thread_free(fServerThread);
            fServerThread = nullptr;
            fServer = nullptr;
        }

        if (fServerURL != nullptr)
        {
            std::free(fServerURL);
            fServerURL = nullptr;
        }

        if (fReplyAddress != nullptr)
        {
            lo_address_free(fReplyAddress);
            fReplyAddress = nullptr;
        }
    }
Exemple #2
0
void OSCPlugin::openInput(quint32 input)
{
    if (input >= OSC_INPUTS)
        return;

    qDebug() << Q_FUNC_INFO << "Input " << input << " port: " << m_ports[input];

	/** Cleanup a previous server instance if started */
    if (m_serv_threads[input] != NULL)
    {
        lo_server_thread_stop(m_serv_threads[input]);
        lo_server_thread_free(m_serv_threads[input]);
        m_serv_threads[input] = NULL;
    }
    /* start a new server on the defined port */
    QByteArray p_bytes  = m_ports[input].toLatin1();
    const char *c_port = p_bytes.data();

    m_serv_threads[input] = lo_server_thread_new(c_port, errorCallback);

    if (m_serv_threads[input] != NULL)
	{
		/* add method that will match any path and args */
        lo_server_thread_add_method(m_serv_threads[input], NULL, NULL, messageCallback, &m_callbackInfo[input]);

        lo_server_thread_start(m_serv_threads[input]);
	}
}
Exemple #3
0
int osc_server( int port)
{
	char sport[8];

	if( !port)
	{
		printf("[OSC SERVER] No valid port\n");
		return 0;
	}
	else
	{
		snprintf( sport, 8, "%d", port);
		printf("[OSC SERVER] Init server at %d\n", port);
	}

	lo_server_thread st = lo_server_thread_new( sport, osc_error);

	lo_server_thread_add_method(st, NULL, NULL, osc_handler_generic, NULL);
	lo_server_thread_add_method(st, "/a/b/c", "fff", osc_handler_vector, NULL);
	lo_server_thread_add_method(st, "/quit", "", osc_handler_quit, NULL);
	lo_server_thread_add_method(st, "/int", "i", osc_handler_int, NULL);
	lo_server_thread_add_method(st, "/quad", "iffff", osc_handler_quad, NULL);

	lo_server_thread_start(st);

	while ( !osc_server_done)
	{
		usleep(1000);
	}

	lo_server_thread_free(st);

	return 0;
}
Exemple #4
0
//ctrl+c etc
static void signal_handler(int sig)
{
	shutdown_in_progress=1;
	process_enabled=0;

	fprintf(stderr,"\nterminate signal %d received.\n",sig);

	if(close_on_incomp==0)
	{
		fprintf(stderr,"telling sender to pause.\n");

		//lo_address loa = lo_address_new(sender_host,sender_port);
		lo_address loa = lo_address_new_with_proto(lo_proto, sender_host,sender_port);

		lo_message msg=lo_message_new();
		lo_send_message (loa, "/pause", msg);
		lo_message_free(msg);
	}

	usleep(1000);

	fprintf(stderr,"cleaning up...");

	lo_server_thread_free(lo_st);
	rb_free(rb);
	rb_free(rb_helper);

	fprintf(stderr,"done.\n");
	
	fflush(stderr);

	exit(0);
}
Exemple #5
0
void shutdown_osc(void) {
  if (!osc_server) return;
  lo_server_thread_stop(osc_server);
  lo_server_thread_free(osc_server);
  if(!silent) fprintf(stderr, "OSC server shut down.\n");
  osc_server=NULL;
}
int main()
{
    /* start a new server on port 7770 */
    lo_server_thread st = lo_server_thread_new("7770", error);

    /* 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 /foo/bar, with two numbers, coerced
     * to float and int */
    lo_server_thread_add_method(st, "/foo/bar", "fi", foo_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);

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

    lo_server_thread_free(st);

    return 0;
}
Exemple #7
0
/* Main */
int main (int argc, const char * argv[])
{    
    // Port number for incoming OSC messages
    char *portNumber = {'\0'};
    
    /* Parse input options */
    int opt;
    
    while ((opt = getopt(argc, (char * const*)argv, "p:h")) != -1)
    {
        printf("opt = %d\n", opt);
        switch(opt)
        {
            case 'p':
                portNumber = optarg;
                break;

            case 'h':
            default:
                print_usage(basename((char *)argv[0]));
                break;
        }
    }
    
    // If we haven't specified a port...
    if (&portNumber[0] == '\0') portNumber = DEFAULT_PORT_NUMBER;
    printf("Initializing liblo using port number %s\n", portNumber);
    
    /* start a new server on specified port */
    lo_server_thread st = lo_server_thread_new(portNumber, error);
    
    /* add method that will match any path and args */
    lo_server_thread_add_method(st, NULL, NULL, handleOSC, NULL);
    
    /* start the thread and get the initial time */
    lo_server_thread_start(st);
    gettimeofday(&tv_init, NULL);
    
    /* Main run loop */
    char input[80];
    bool shouldStop = false;
    
    printf("Enter 'q' to quit\n");
    
    while (shouldStop == false) {
        
        // Grab an input line
        scanf("%s", input);
        
        // Check for quit command, else continue
        if (input[0] == 'q')
            shouldStop = true;
    }
    
    printf("cleaning up...\n");
    
    lo_server_thread_free(st);
    
    return 0;
}
Exemple #8
0
int main(int argc,char *argv[]) {
	srand(time(NULL));

	int quit = 0;
	int seed = rand() % 255;

	lo_address client = lo_address_new("localhost","9999");
	lo_server_thread server = lo_server_thread_new("9998",err_callback);
	lo_server_thread_add_method(server,"/client/quit","",quit_callback,(void*)&quit);
	lo_server_thread_add_method(server,NULL,NULL,all_callback,NULL);

	printf("starting osc server at %s with seed %d\n",lo_server_thread_get_url(server),seed);
	lo_server_thread_start(server);

	int k = 0;
	while (!quit) {
		if (lo_send(client,"/client/test","ii",seed,k++) < 0) fprintf(stderr,"osc client error: %s\n",lo_address_errstr(client));
		sleep(1);
	}

	printf("stopping osc server\n");
	lo_server_thread_stop(server);

	lo_server_thread_free(server);
	lo_address_free(client);
	return 0;
}
Exemple #9
0
void Gear_OscInput::stopOscServer()
{
	if (!_loServerThread)
		return;
	
	lo_server_thread_free(_loServerThread);
	_loServerThread=NULL;
}
Exemple #10
0
void finish_osc( lo_server_thread st )
{
	if (verbose) printf( "Stopping OSC server thread.\n");

	lo_server_thread_stop( st );
	lo_server_thread_free( st );
	
}
Exemple #11
0
bool OscToShmdata::stop() {
  shm_.reset(nullptr);
  if (nullptr != osc_thread_) {
    lo_server_thread_free(osc_thread_);
    osc_thread_ = nullptr;
    return true;
  }
  return false;
}
void	veejay_free_osc_server( void *dosc )
{
	osc_recv_t *s = (osc_recv_t*) dosc;
	lo_server_thread_stop( s->st );
	lo_server_thread_free( s->st );
	free(s->url);
//	vevo_port_free( s->events );
	free(s);
	s = NULL;
}
Exemple #13
0
//------------------------------------------------------------------------
tresult PLUGIN_API AGain::terminate  ()
{
	if(server) 
	{
		lo_server_thread_free(server);
	}

	// nothing to do here yet...except calling our parent terminate
	return AudioEffect::terminate ();
}
Exemple #14
0
    Client::~Client()
    {
        if(_st)
            stop();

        if(_st)
            lo_server_thread_free(_st);
        else
            lo_server_free(_server);
    }
Exemple #15
0
// Destructor.
synthv1_nsm::~synthv1_nsm (void)
{
#ifdef CONFIG_LIBLO
	if (m_thread) {
		lo_server_thread_stop(m_thread);
		lo_server_thread_free(m_thread);
	}
	if (m_address)
		lo_address_free(m_address);
#endif
}
Exemple #16
0
void osc_server_start( t_osc *osc)
{
	lo_server_thread_start( osc->thread);

	while ( !osc->done)
	{
		usleep(1000);
	}

	lo_server_thread_free( osc->thread);
}
Exemple #17
0
//if JACK was shut down or the connection was otherwise lost
//=========================================================
void jack_shutdown_handler (void *arg)
{
	io_quit("jack_shutdown");

//main udp osc server
	lo_server_thread_free(lo_st);
//check for tcp
//

	exit (0);
}
// Destructor.
qtractorNsmClient::~qtractorNsmClient (void)
{
#ifdef CONFIG_LIBLO
	if (m_thread) {
		lo_server_thread_stop(m_thread);
		lo_server_thread_free(m_thread);
	}
	if (m_address)
		lo_address_free(m_address);
#endif
}
Exemple #19
0
int main (int argc, char * argv[]) {
  lo_server_thread st;        // server to receive messages from
  lo_address addr;            // address to send messages to
  static struct filter ftr;   // stores data to be passed to handler
  int i, j;                   // index variables

  /* Set up the filter signature.  The signature helps us verify that things 
   * that we think are filters are actually filters. */
  srandom ((unsigned int) time (NULL));
  FILTER_SIGNATURE = random ();

  /* check for read port and write port */
  if (argc < 3)
    {
      printf ("- Missing Argument -\nUsage: oschand read_port write_port\n");
      exit (1);
    } // if

  /* start a new server and set up write port */
  st = lo_server_thread_new (argv[1], &error);
  addr = lo_address_new ("127.0.0.1", argv[2]);

  /* setup filter structure to be passed to joint handler */
  ftr.signature = FILTER_SIGNATURE;
  ftr.addr = addr;
  ftr.num_joints = argc - 3;
  ftr.joints = (char **) malloc (sizeof (char *) * ftr.num_joints);

  for (j = 0, i = 3; j < ftr.num_joints; j++, i++)
    ftr.joints[j] = argv[i];

  /* add method that will handle joints */
  lo_server_thread_add_method (st, "/joint", "sifff", joint_handler, &ftr);

  /* 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);

  /* wait for messages */
  while (!done)
    {
#ifdef WIN32
      Sleep (1);
#else
      usleep (1000);
#endif
    } // while

  lo_server_thread_free (st);
  lo_address_free (addr);

  return 0;
} // main
Exemple #20
0
/* RESET routine for cleaning up */
static int OSC_reset(CSOUND *csound, OSC_GLOBALS *p)
{
    int i;
    for (i = 0; i < p->nPorts; i++)
      if (p->ports[i].thread) {
        lo_server_thread_stop(p->ports[i].thread);
        lo_server_thread_free(p->ports[i].thread);
        csound->DestroyMutex(p->ports[i].mutex_);
      }
    csound->DestroyGlobalVariable(csound, "_OSC_globals");
    return OK;
}
Exemple #21
0
void OSCPlugin::closeInput(quint32 input)
{
    if (input >= OSC_INPUTS)
        return;

    if (m_serv_threads[input] != NULL)
    {
        lo_server_thread_stop(m_serv_threads[input]);
        lo_server_thread_free(m_serv_threads[input]);
        m_serv_threads[input] = NULL;
    }
}
Exemple #22
0
void OSCPlugin::closeOutput(quint32 output)
{
    if (output >= QLCIOPLUGINS_UNIVERSES)
        return;

    if (m_nodes[output].m_serv_thread != NULL)
    {
        lo_server_thread_stop(m_nodes[output].m_serv_thread);
        lo_server_thread_free(m_nodes[output].m_serv_thread);
        m_nodes[output].m_serv_thread = NULL;
    }
}
Exemple #23
0
static int OSC_deinit(CSOUND *csound, OSCINIT *p)
{
    int n = (int)*p->ihandle;
    OSC_GLOBALS *pp = alloc_globals(csound);
    OSC_PORT    *ports = pp->ports;
    csound->Message(csound, "handle=%d\n", n);
    csound->DestroyMutex(ports[n].mutex_);
    ports[n].mutex_ = NULL;
    lo_server_thread_stop(ports[n].thread);
    lo_server_thread_free(ports[n].thread);
    ports[n].thread =  NULL;
    csound->Message(csound, Str("OSC deinitiatised\n"));
    return OK;
}
Exemple #24
0
int main(int argc, char * argv[])
{
	if (argc < 2)
	{
		printf("- Missing Argument -\nUsage: osc2text port\n");
		exit(1);
	}

	char port[6];
	int ret;

	/* TODO: We could have some better port number checks here, rather than letting
	 * liblo handle it
	 */
	if ((ret = snprintf(port,6,"%s",argv[1])) < 0)
	{
		printf("- Invalid port -");
		exit(ret);
	}

    /* start a new server on port 7770 */
    lo_server_thread st = lo_server_thread_new(port, error);

    /* 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 /foo/bar, with two numbers, coerced
     * to float and int */
    lo_server_thread_add_method(st, "/foo/bar", "fi", foo_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);

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

    lo_server_thread_free(st);

    return 0;
}
Exemple #25
0
int main(int argc, char *argv[]) {
  // Catch signals
  signal(SIGINT, mh_sigint);
  signal(SIGTERM, mh_sigint);

  // Initialise LEDs
  if (matrix_init() < 0) return 1;

  // Set up OSC server
  const char *path;
  lo_server_thread st;
  int chmod_err = 0;

  if (argc > 1) {
    path = argv[1];
  } else {
    path = SOCKET_PATH;
  }

  unlink(path);
  st = lo_server_thread_new(path, mh_osc_error);
  chmod_err = chmod_socket(path);

  if (chmod_err != 0) {
    fprintf(stderr, "Error changing socket permissions\n");
    return 1;
  }

  // Set up OSC message handlers
  lo_server_thread_add_method(st, "/set", "iii", mh_osc_set, NULL);
  lo_server_thread_add_method(st, "/render", NULL, mh_osc_render, NULL);
  lo_server_thread_add_method(st, "/clear", NULL, mh_osc_clear, NULL);
  lo_server_thread_start(st);

  // Ready
  printf("Listening on socket: %s\n", path);

  while (1) {
    usleep(1000);
  }

  // Cleanup
  lo_server_thread_free(st);
  mh_cleanup();

  return 0;
}
Exemple #26
0
bool Ambix_rotator_zAudioProcessor::oscIn(bool arg)
{
	if (arg) {
        if (!osc_in) {

            st = lo_server_thread_new(osc_in_port.toUTF8(), error);
			if (st != NULL)
			{
				lo_server_thread_add_method(st, "/rotation", "fff", rotation_handler, this);
				lo_server_thread_add_method(st, "/head_pose", "fffffff", headpose_handler, this);

				int res = lo_server_thread_start(st);
				if (res == 0)
				{
					arg = true;
					osc_in = true;
					osc_error = "OSC: receiving on port ";
					osc_error += osc_in_port;
				}
            } else {
                osc_error = "OSC: ERROR port is not free";
                //osc_error.formatted("OSC: ERROR %s", lo_address_errstr());
                arg = false;
                osc_in = false;
            }
        } else {
            
            oscIn(false);
            oscIn(true);
        }
	} else { // turn off osc
        if (osc_in)
        {
			lo_server_thread_stop(st);

#ifndef _WIN32
            lo_server_thread_free(st); // this crashes in windows
#endif
            arg = false;
            osc_in = false;
            osc_error = "OSC: not receiving";
        }
	}
	return arg;
}
Exemple #27
0
int main(int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterActor     *stage;

  if (argc < 1)
    {
      g_error ("Usage: %s", argv[0]);
      return EXIT_FAILURE;
    }
  else
  {
    GError *error = NULL;
    GOptionContext *context;
  
    context = g_option_context_new (PROGRAM_DESC);
    g_option_context_add_main_entries (context, entries, NULL); //GETTEXT_PACKAGE);
    //g_option_context_add_group (context, gtk_get_option_group (TRUE));
    if (! g_option_context_parse (context, &argc, &argv, &error))
      {
        g_print ("option parsing failed: %s\n", error->message);
        return EXIT_FAILURE; // exit (1);
      }
  }

  if (option_version)
  {
    g_print("contextize version %s\n", PACKAGE_VERSION);
    return 0;
  }

  g_thread_init(NULL); // to load images asynchronously. must be called before clutter_init
  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    {
      g_error ("Failed to initialize clutter\n");
      return EXIT_FAILURE;
    }
  gst_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_actor_set_size(stage, STAGE_WIDTH, STAGE_HEIGHT);
  clutter_stage_set_color(CLUTTER_STAGE(stage), &black);
  clutter_stage_set_title(CLUTTER_STAGE(stage), STAGE_TITLE);

  /* Make a timeline */
  timeline = clutter_timeline_new (1000);
  g_object_set(timeline, "loop", TRUE, NULL);

  ClutterActor *texture_live = setup_camera_texture(stage);

  // create the layout
  ClutterLayoutManager *layout;
  ClutterActor *box;
  layout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_CENTER,
                                  CLUTTER_BIN_ALIGNMENT_CENTER);
  box = clutter_box_new(layout); /* then the container */
  clutter_actor_set_name(box, BOX_ACTOR);
  /* we can use the layout object to add actors */
  clutter_bin_layout_add(CLUTTER_BIN_LAYOUT(layout), texture_live,
                         CLUTTER_BIN_ALIGNMENT_FILL,
                         CLUTTER_BIN_ALIGNMENT_FILL);
  clutter_container_add_actor(CLUTTER_CONTAINER(stage), box);
  clutter_actor_set_size(box, STAGE_WIDTH, STAGE_HEIGHT);
  clutter_actor_show_all(box);

  g_signal_connect(G_OBJECT(stage), "fullscreen", G_CALLBACK(on_fullscreen), NULL);
  g_signal_connect(G_OBJECT(stage), "unfullscreen", G_CALLBACK(on_unfullscreen), NULL);
  g_signal_connect(G_OBJECT(stage), "key-press-event", G_CALLBACK(key_press_event), NULL);

  /* start the timeline */
  clutter_timeline_start (timeline);

  clutter_actor_show_all (stage);

  if (option_fullscreen)
      clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), TRUE);

  // OSC server
  lo_server_thread osc_server = NULL;
  if (option_osc_receive_port != 0)
  {
    gchar *osc_port_str = g_strdup_printf("%i", option_osc_receive_port);
    if (option_verbose)
      g_print("Listening on osc.udp://localhost:%s\n", osc_port_str);
    osc_server = lo_server_thread_new(osc_port_str, on_osc_error);
    g_free(osc_port_str);
  
    lo_server_thread_start(osc_server);
  }

  clutter_main();

  if (option_osc_receive_port != 0)
    lo_server_thread_free(osc_server);
  return EXIT_SUCCESS;
}
Exemple #28
0
MantaOSC::~MantaOSC()
{
   lo_server_thread_stop(OSCServerThread);
   lo_address_free(OSCAddress);
   lo_server_thread_free(OSCServerThread);
}
Exemple #29
0
void osc_stop()
{
    done = 1;
    lo_server_thread_free(st);
}
Exemple #30
0
void osc_free()
{
    lo_server_thread_free(st);
    free(osc);

}