Пример #1
0
int main(int argc, char *argv[])
{
	int port;

	if (argc < 2) {
		printf("Usage: %s port\n", argv[0]);
		return -1;
	}

	port = atoi(argv[1]);

	listen_thread(port);

	return 0;
}
// ------------------------------------------------------------------------------
//   Listen Thread
// ------------------------------------------------------------------------------
void
Autopilot_Interface::
start_listen_thread(void)
{
	if ( not listening_status == false )
	{
		fprintf(stderr,"listen thread already running\n");
		return;
	}

	else
	{
		// write_thread();
		listen_thread();
		return;
	}

}
Пример #3
0
int main(int argc, char* argv[])
{
    if(argc < 2){
        ADDRESS = "localhost";
    }else{
    	std::string line = argv[1];
    	
    	int colon_pos = line.find(":");
    	if(colon_pos != std::string::npos){
    		ADDRESS = line.substr(0, colon_pos);
    		PORT = std::stoi(line.substr(colon_pos + 1, std::string::npos));
    	}else{
    		ADDRESS = line;
    	}
    }
    std::cout << ADDRESS << std::endl;
    std::cout << PORT << std::endl;
    
    //start ros thread
    XInitThreads();
    std::thread ros_thread(ros_stuff);
    
    //Initialize OSC stuff
    UdpTransmitSocket transmit_socket( IpEndpointName( ADDRESS.c_str(), PORT ) );
    
    listener = new LRPacketListener();
    //listener->registerStringCallback(nothing);
    listener->registerTransportCallback(sync);
    listener->registerPlaybackCallback(playbackChanged);
    listener->registerClipUpdateCallback(loadClip);
    receive_socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ), listener);
    
    //Set up threads
    std::thread listen_thread(listen);

	//interupt quits
    signal(SIGINT, [](int signum){std::cout << "okay" << std::endl; quit = true; receive_socket->Break(); receive_socket->AsynchronousBreak();});
    
    //conductor
    listener->registerTransportCallback(update_baton);
    
    //SFML
    sf::Font font;
	if (!font.loadFromFile("Ubuntu-R.ttf"))
	{
		std::cout << "where's the font?" << std::endl;
	}
	play_shape.rotate(90);
	play_shape.setPosition(700, 10);
	play_shape.setFillColor(sf::Color::Green);
	stop_shape.setPosition(700, 10);
	stop_shape.setFillColor(sf::Color::Red);
	
	for(int i = 0; i < 50; i++){
		
		sf::CircleShape baton(8, 20);
		sf::Color color(255, i*255/50, 0, 51*(i-50)*(i-50)/500);
		baton.setFillColor(color);
		baton.setPosition(400, 300);
		baton_trail.push_back(baton);
	}

	// select the font
	transport_text.setFont(font); // font is a sf::Font
	time_text.setFont(font);
	offset_text.setFont(font);
	debug_text.setFont(font);
	transport_text.setCharacterSize(24); // in pixels, not points!
	time_text.setCharacterSize(24);
	offset_text.setCharacterSize(24);
	debug_text.setCharacterSize(24);
	transport_text.setColor(sf::Color::White);
	time_text.setColor(sf::Color::White);
	offset_text.setColor(sf::Color::White);
	debug_text.setColor(sf::Color::White);
	transport_text.setPosition(10, 10);
	time_text.setPosition(10, 40);
	offset_text.setPosition(10, 70);
	debug_text.setPosition(400, 70);

	// set the string to display
	transport_text.setString("Hello world");
	time_text.setString("waiting...");
	offset_text.setString("no offset");

    //sfml window
    sf::ContextSettings settings;
	settings.antialiasingLevel = 8;
    sf::RenderWindow window(sf::VideoMode(800, 600), "Terpsichore", sf::Style::Default, settings);
    window.setVerticalSyncEnabled(true);
    
        
    //request initial information
    send("/terpsichore", (int)1, transmit_socket);
    
    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed){
                window.close();
                quit = true;
                receive_socket->Break(); 
                receive_socket->AsynchronousBreak();
            }
        }
        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        
        // draw the notes of the currently playing clips
        double y = 100.0;
        double scale = 50.0;
        for(std::map<int, Clip*>::iterator clip_it = listener->clips.begin(); clip_it != listener->clips.end(); clip_it++){
        	
        	Clip* c = clip_it->second;
        	for(std::multimap<Position, Note>::iterator note_it = c->notes.begin(); note_it != c->notes.end(); note_it++){
        		Position p = note_it->first;
        		Note n = note_it->second;
        		double x = p.toFloat(listener->transport.timeSignature) * scale + 10;
        		double w = n.duration * scale;
        		double h = n.pitch;
        		
        		sf::RectangleShape noteRect(sf::Vector2f(w, h));
        		noteRect.setFillColor(sf::Color::Blue);
        		noteRect.setOutlineThickness(2);
        		noteRect.setOutlineColor(sf::Color::Cyan);
        		noteRect.setPosition(x, y);
        		window.draw(noteRect); 
        	}
        	y += 80;
        	debug_text.setString(std::to_string(y));
        }
        
        
        // window.draw(...);
        transport_text.setString(transport_string);
        time_text.setString(time_string);
        window.draw(time_text);
        offset_text.setString(offset_string);
        window.draw(offset_text);
        window.draw(debug_text);

		if(playing){
			window.draw(play_shape);
		}else{
			window.draw(stop_shape);
		}
        //draw the baton point;
        for(int i = baton_trail.size() - 1; i >= 0; i--){
	        window.draw(baton_trail.at(i));
        }

        window.draw(transport_text);
        // end the current frame
        window.display();
    }
    
    
    //stopping threads
    std::cout << "attempting to join\n";
    listen_thread.join();
    ros_thread.join();
    
    delete receive_socket;
    delete listener;

    return 0;
}