Mercurial > hg > beaglert
changeset 129:cce58e6ec2a2 scope-refactoring
Added ifdefs USE_JUCE to NetworkSend. Juce part not added yet
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 24 Aug 2015 20:53:26 +0100 |
parents | 2696a7f00053 |
children | da1c61aa97ea |
files | core/NetworkSend.cpp include/NetworkSend.h |
diffstat | 2 files changed, 57 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/core/NetworkSend.cpp Mon Aug 24 18:55:19 2015 +0100 +++ b/core/NetworkSend.cpp Mon Aug 24 20:53:26 2015 +0100 @@ -1,30 +1,30 @@ -//scope.cpp #include <NetworkSend.h> -#define BUILD_FOR_UDPRECEIVE_PLUGIN -#define NETWORK_AUDIO_BUFFER_SIZE 302 - +#ifdef USE_JUCE +#else //initialize the static members of NetworkSend bool NetworkSend::staticConstructed=false; std::vector<NetworkSend*> NetworkSend::objAddrs(0); AuxiliaryTask NetworkSend::sendDataTask=NULL; -void transmitAudio(){ +void sendData(){ NetworkSend::sendAllData(); } - +void NetworkSend::staticConstructor(){ + if(staticConstructed==true) + return; + staticConstructed=true; + sendDataTask = BeagleRT_createAuxiliaryTask(::sendData, 95, "sendDataTask"); //TODO: allow variable priority +} void NetworkSend::sendAllData(){ for(unsigned int n=0; n<NetworkSend::objAddrs.size(); n++){ NetworkSend::objAddrs[n]->sendData(); } } - -void NetworkSend::staticConstructor(){ - if(staticConstructed==true) - return; - staticConstructed=true; - sendDataTask = BeagleRT_createAuxiliaryTask(transmitAudio, 95, "sendDataTask"); //TODO: allow variable priority -}; +int NetworkSend::getNumInstances(){ + return objAddrs.size(); +} +#endif /* USE_JUCE */ NetworkSend::NetworkSend() { @@ -44,9 +44,10 @@ } } -void NetworkSend::setup(float aSampleRate){ +void NetworkSend::setup(float aSampleRate){//TODO: remove this method setup(aSampleRate, 0, 9999, "192.168.7.1");//channelNumber=0 } + void NetworkSend::setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer){ staticConstructor(); //FIXME: ideally this should be in the constructor, but this is not currently possible //because of limitations in BeagleRT_createAuxiliaryTask() @@ -112,10 +113,8 @@ } } -int NetworkSend::getNumInstances(){ - return objAddrs.size(); -}; - +#ifdef USE_JUCE +#else Scope::Scope(int aNumChannels): channels(aNumChannels) {}; @@ -154,3 +153,4 @@ void Scope::sendData(){ NetworkSend::sendAllData(); } +#endif
--- a/include/NetworkSend.h Mon Aug 24 18:55:19 2015 +0100 +++ b/include/NetworkSend.h Mon Aug 24 20:53:26 2015 +0100 @@ -2,11 +2,14 @@ #ifndef SCOPE_H_ #define SCOPE_H_ +#ifdef USE_JUCE +#else #include <BeagleRT.h> #include <rtdk.h> #include <cmath> #include <UdpClient.h> #include <vector> +#endif /* USE_JUCE */ #define NETWORK_AUDIO_BUFFER_SIZE 302 @@ -20,30 +23,45 @@ static const int headerLength=2; }; +#ifdef USE_JUCE +class NetworkSend: public Thread { +#else class NetworkSend { - int sampleCount; - float sampleRate; +#endif /* USE_JUCE */ + int sampleCount; + float sampleRate; +#ifdef USE_JUCE + DatagramSocket udpClient; +#else UdpClient udpClient; static bool staticConstructed; - static void staticConstructor(); - static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) - static std::vector<NetworkSend *> objAddrs; - public: - NetworkBuffer channel; - NetworkSend(); - ~NetworkSend(); - void setup(float aSampleRate); - void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); - void sendData(); - void log(float value); - void setPort(int aPort); - void setServer(const char* aServer); - void setChannelNumber(int aChannelNumber); - int getChannelNumber(); - static int getNumInstances(); - static void sendAllData(); + static void staticConstructor(); + static AuxiliaryTask sendDataTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) + static std::vector<NetworkSend *> objAddrs; +#endif /* USE_JUCE */ + public: + NetworkBuffer channel; + NetworkSend(); + ~NetworkSend(); + void setup(float aSampleRate); + void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); + void sendData(); + void log(float value); + void setPort(int aPort); + void setServer(const char* aServer); + void setChannelNumber(int aChannelNumber); + int getChannelNumber(); +#ifdef USE_JUCE + void run(); +#else + static int getNumInstances(); + static void sendAllData(); + static void run(); +#endif /* USE_JUCE */ }; +#ifdef USE_JUCE +#else /** * An array of NetworkSend objects with some default parameters * @@ -64,4 +82,6 @@ void setPort(int channel, int port); int getNumChannels(); }; +#endif /* USE_JUCE */ + #endif /* SCOPE_H */