<commit_before>#ifndef AL_ALLOSPHEREAPP_HPP
#define AL_ALLOSPHEREAPP_HPP


#include "alloutil/al_OmniStereoGraphicsRenderer.hpp"
#include "allocore/io/al_App.hpp"
#include "allocore/io/al_AudioIO.hpp"
#include "allocore/graphics/al_Font.hpp"
#include "Cuttlebone/Cuttlebone.hpp"

#include <iostream>

#if !defined(ALLOSPHERE_BUILD_SIMULATOR) && !defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER) && !defined(ALLOSPHERE_BUILD_AUDIO_RENDERER)
#define ALLOSPHERE_BUILD_GRAPHICS_RENDERER
#endif

#if (defined(ALLOSPHERE_BUILD_SIMULATOR) && defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER)) || \
	(defined(ALLOSPHERE_BUILD_SIMULATOR) && defined(ALLOSPHERE_BUILD_AUDIO_RENDERER)) || \
	(defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER) && defined(ALLOSPHERE_BUILD_AUDIO_RENDERER))
#error More than one application type defined
#endif

#ifndef ALLOAPP_PACKET_SIZE
#define PACKET_SIZE 1400
#else
#define PACKET_SIZE ALLOAPP_PACKET_SIZE
#endif

// The network ports used to communicate state from the simulator to the
// renderers
#define ALLOAPP_GRAPHICS_PORT 63059
#define ALLOAPP_AUDIO_PORT 63060

namespace al {

class DummyState {};

// Audio Renderers ----------------------------------------

/// Base class for audio renderer (no state)
/// You should only inherit from this class if you don't need to receive state from the
/// simulator. You will usually want to inherit from AudioRendererBase.
class AudioRendererBaseNoState {
public:
	AudioRendererBaseNoState(int framesPerBuf=128, double framesPerSec=44100.0,
	                         int outChans = 2, int inChans = 0 ) :
	    io(framesPerBuf, framesPerSec, AudioRendererBaseNoState::AppAudioCB,
	       this, outChans, inChans)
	{
	}

	~AudioRendererBaseNoState();

	virtual void initAudio();

	virtual void onSound(AudioIOData & io) {}


protected:
	AudioIO io;
private:

	static inline void AppAudioCB(AudioIOData& io) {
		AudioRendererBaseNoState& app = io.user<AudioRendererBaseNoState>();
		io.frame(0);
		app.onSound(io);
	}
};

/// Base class for audio renderer
/// You should inherit from this class if you want to receive state from the
/// simulator. Otherwise, you can inherit from AudioRendererBaseNoState.
/// The state will be updated by a "simulator" or compute node that should
/// inherit from SimulatorBase.
template<typename AudioState = DummyState, unsigned PORT = ALLOAPP_AUDIO_PORT>
class AudioRendererBase : public AudioRendererBaseNoState {
public:
	AudioRendererBase(int framesPerBuf=64, double framesPerSec=44100.0,
	                  int outChans = 2, int inChans = 0 ) :
	    AudioRendererBaseNoState(framesPerBuf, framesPerSec,
	                             outChans, inChans)
	{
		mTaker.start();
	}

	virtual void initAudio() override { AudioRendererBaseNoState::initAudio(); }

	///
	/// \brief Audio callback function
	/// \param io Audio IO data
	/// All real-time audio read/write operations will take place within this
	/// function accessing the buffers and information provided by the io object.
	virtual void onSound(AudioIOData & io) override {}

	///
	/// \brief updateAudioState reads the state buffer and updates current state
	/// \return true if a new state was received
	///
	bool updateAudioState() {
		bool newState = false;
		while (mTaker.get(mState) > 0) { newState = true;} // Pop all states in queue
		return newState;
	}

	///
	/// \brief popAudioState pops a single state from the state buffer and updates
	/// the current state
	/// \return Returns the number of states still pending in the buffer
	///
	int popAudioState() {
		return mTaker.get(mState);
	}

	///
	/// \brief state a reference to the shared state
	/// \return
	///
	AudioState &audioState() { return mState;}

private:
	cuttlebone::Taker<AudioState, 1400, PORT> mTaker;
	AudioState mState;
};


//Simulator

template<typename State = DummyState, typename AudioState = DummyState,
         unsigned GRAPHICSPORT = ALLOAPP_GRAPHICS_PORT,
         unsigned AUDIOPORT = ALLOAPP_AUDIO_PORT>
class SimulatorBase : public App {
public:
	explicit SimulatorBase(const Window::Dim& dims = Window::Dim(320, 240),
	                          const std::string title="",
	                          double fps=60,
	                          Window::DisplayMode mode = Window::DEFAULT_BUF,
	                          int flags=0) :
	    mDims(dims), mTitle(title), mFps(fps), mMode(mode), mFlags(flags)
	{
		mMakerGraphics.start();
		mMakerAudio.start();
	}

	virtual void initWindow();

	///
	/// \brief Override the onDraw to provide a GUI for the simulator
	///
	virtual void onDraw(Graphics &g, const Viewpoint &v) override;

	///
	/// \brief onAnimate contains the computation for the state
	/// \param dt the time delta since last call to onAnimate()
	///
	virtual void onAnimate(double dt) override{}

	///
	/// \brief Send the state to the graphics renderers
	///
	void sendState() { mMakerGraphics.set(mState);}

	///
	/// \brief Send the state to the audio renderers
	///
	void sendAudioState() { mMakerAudio.set(mAudioState);}

	///
	/// \brief state a reference to the shared state
	/// \return<commit_msg>Added constructor parameter to set broadcastIP for SimulatorBase in AlloSphereApp<commit_after>#ifndef AL_ALLOSPHEREAPP_HPP
#define AL_ALLOSPHEREAPP_HPP


#include "alloutil/al_OmniStereoGraphicsRenderer.hpp"
#include "allocore/io/al_App.hpp"
#include "allocore/io/al_AudioIO.hpp"
#include "allocore/graphics/al_Font.hpp"
#include "Cuttlebone/Cuttlebone.hpp"

#include <iostream>

#if !defined(ALLOSPHERE_BUILD_SIMULATOR) && !defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER) && !defined(ALLOSPHERE_BUILD_AUDIO_RENDERER)
#define ALLOSPHERE_BUILD_GRAPHICS_RENDERER
#endif

#if (defined(ALLOSPHERE_BUILD_SIMULATOR) && defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER)) || \
	(defined(ALLOSPHERE_BUILD_SIMULATOR) && defined(ALLOSPHERE_BUILD_AUDIO_RENDERER)) || \
	(defined(ALLOSPHERE_BUILD_GRAPHICS_RENDERER) && defined(ALLOSPHERE_BUILD_AUDIO_RENDERER))
#error More than one application type defined
#endif

#ifndef ALLOAPP_PACKET_SIZE
#define PACKET_SIZE 1400
#else
#define PACKET_SIZE ALLOAPP_PACKET_SIZE
#endif

// The network ports used to communicate state from the simulator to the
// renderers
#define ALLOAPP_GRAPHICS_PORT 63059
#define ALLOAPP_AUDIO_PORT 63060

namespace al {

class DummyState {};

// Audio Renderers ----------------------------------------

/// Base class for audio renderer (no state)
/// You should only inherit from this class if you don't need to receive state from the
/// simulator. You will usually want to inherit from AudioRendererBase.
class AudioRendererBaseNoState {
public:
	AudioRendererBaseNoState(int framesPerBuf=128, double framesPerSec=44100.0,
	                         int outChans = 2, int inChans = 0 ) :
	    io(framesPerBuf, framesPerSec, AudioRendererBaseNoState::AppAudioCB,
	       this, outChans, inChans)
	{
	}

	~AudioRendererBaseNoState();

	virtual void initAudio();

	virtual void onSound(AudioIOData & io) {}


protected:
	AudioIO io;
private:

	static inline void AppAudioCB(AudioIOData& io) {
		AudioRendererBaseNoState& app = io.user<AudioRendererBaseNoState>();
		io.frame(0);
		app.onSound(io);
	}
};

/// Base class for audio renderer
/// You should inherit from this class if you want to receive state from the
/// simulator. Otherwise, you can inherit from AudioRendererBaseNoState.
/// The state will be updated by a "simulator" or compute node that should
/// inherit from SimulatorBase.
template<typename AudioState = DummyState, unsigned PORT = ALLOAPP_AUDIO_PORT>
class AudioRendererBase : public AudioRendererBaseNoState {
public:
	AudioRendererBase(int framesPerBuf=64, double framesPerSec=44100.0,
	                  int outChans = 2, int inChans = 0 ) :
	    AudioRendererBaseNoState(framesPerBuf, framesPerSec,
	                             outChans, inChans)
	{
		mTaker.start();
	}

	virtual void initAudio() override { AudioRendererBaseNoState::initAudio(); }

	///
	/// \brief Audio callback function
	/// \param io Audio IO data
	/// All real-time audio read/write operations will take place within this
	/// function accessing the buffers and information provided by the io object.
	virtual void onSound(AudioIOData & io) override {}

	///
	/// \brief updateAudioState reads the state buffer and updates current state
	/// \return true if a new state was received
	///
	bool updateAudioState() {
		bool newState = false;
		while (mTaker.get(mState) > 0) { newState = true;} // Pop all states in queue
		return newState;
	}

	///
	/// \brief popAudioState pops a single state from the state buffer and updates
	/// the current state
	/// \return Returns the number of states still pending in the buffer
	///
	int popAudioState() {
		return mTaker.get(mState);
	}

	///
	/// \brief state a reference to the shared state
	/// \return
	///
	AudioState &audioState() { return mState;}

private:
	cuttlebone::Taker<AudioState, 1400, PORT> mTaker;
	AudioState mState;
};


//Simulator

template<typename State = DummyState, typename AudioState = DummyState,
         unsigned GRAPHICSPORT = ALLOAPP_GRAPHICS_PORT,
         unsigned AUDIOPORT = ALLOAPP_AUDIO_PORT>
class SimulatorBase : public App {
public:
	explicit SimulatorBase(const Window::Dim& dims = Window::Dim(320, 240),
	                       const std::string title="",
	                       double fps=60,
	                       Window::DisplayMode mode = Window::DEFAULT_BUF,
	                       int flags=0,
	                       const char *broadcastIP = "127.0.0.1") :
	    mDims(dims), mTitle(title), mFps(fps), mMode(mode), mFlags(flags),
	    mMakerAudio(broadcastIP),
	    mMakerGraphics(broadcastIP)
	{
		mMakerGraphics.start();
		mMakerAudio.start();
	}

	virtual void initWindow();

	///
	/// \brief Override the onDraw to provide a GUI for the simulator
	///
	virtual void onDraw(Graphics &g, const Viewpoint &v) override;

	///
	/// \brief onAnimate contains the computation for the state
	/// \param dt the time delta since last call to onAnimate()
	///
	virtual void onAnimate(double dt) override{}

	///
	/// \brief Send the state to the graphics renderers
	///
	void sendState() { mMakerGraphics.set(mState);}

	///
	/// \brief Send the state to the audio renderers
	///
	void sendAudioState() { mMakerAudio.set(mAudioState);}

	///
	/// \brief state a reference to the shared state
	/// \return
{'fraction_non_alphanumeric': 0.1068243505234587, 'fraction_numerical': 0.010275300504071345, 'mean_word_length': 3.4778645833333335, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6186279', 'n_tokens_mistral': 3375, 'n_tokens_neox': 3168, 'n_words': 926}