view include/OSCServer.h @ 377:a430a16d2c02 prerelease

Updated scripts so that the Bela folder on the bbb is ~/Bela. Note: BeagleRT_startup.sh is still the same (because the reference to it needs to be changed in /etc/init.d/ ....
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 11 Jun 2016 01:54:43 +0100
parents e4392164b458
children faa5f58c71af
line wrap: on
line source
/***** OSCServer.h *****/
#ifndef __OSCServer_H_INCLUDED__
#define __OSCServer_H_INCLUDED__ 

#include <UdpServer.h>
#include <oscpkt.hh>
#include <Bela.h>
#include <queue>

#define UDP_RECIEVE_TIMEOUT_MS 20
#define UDP_RECIEVE_MAX_LENGTH 16384

class OSCServer{
    public:
        OSCServer();

        // must be called once during setup
        void setup(int port);
        
        // returns true if messages are queued
        // audio-thread safe
        bool messageWaiting();
        
        // removes and returns the oldest message from the queue
        // audio-thread safe, but don't call unless messageWaiting() returns true
        oscpkt::Message popMessage();
        
        // if there are OSC messages waiting, decode and queue them
        // not audio-thread safe!
        void recieveMessageNow(int timeout);
        
    private:
        int port;
        UdpServer socket;

        AuxiliaryTask OSCRecieveTask;
        
        void createAuxTasks();
        void messageCheck();
        
        static void checkMessages(void*);
        
        int inBuffer[UDP_RECIEVE_MAX_LENGTH];
        std::queue<oscpkt::Message> inQueue;
        oscpkt::Message poppedMessage;
        oscpkt::PacketReader pr;
};


#endif