Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Messager.h

00001 /***************************************************/
00033 /***************************************************/
00034 
00035 #ifndef STK_MESSAGER_H
00036 #define STK_MESSAGER_H
00037 
00038 #include "Stk.h"
00039 #include "Skini.h"
00040 #include <queue>
00041 
00042 const int DEFAULT_QUEUE_LIMIT = 200;
00043 
00044 #if defined(__STK_REALTIME__)
00045 
00046 #include "Mutex.h"
00047 #include "Thread.h"
00048 #include "TcpServer.h"
00049 #include "RtMidi.h"
00050 
00051 extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
00052 
00053 extern "C" THREAD_RETURN THREAD_TYPE socketHandler(void * ptr);
00054 
00055 #endif // __STK_REALTIME__
00056 
00057 class Messager : public Stk
00058 {
00059  public:
00060 
00061   // This structure is used to share data among the various realtime
00062   // messager threads.  It must be public.
00063   struct MessagerData {
00064     Skini skini;
00065     std::queue<Skini::Message> queue;
00066     unsigned int queueLimit;
00067     int sources;
00068 
00069 #if defined(__STK_REALTIME__)
00070     Mutex mutex;
00071     RtMidiIn *midi;
00072     TcpServer *socket;
00073     std::vector<int> fd;
00074     fd_set mask;
00075 #endif
00076 
00077     // Default constructor.
00078     MessagerData()
00079       :queueLimit(0), sources(0) {}
00080   };
00081 
00083   Messager();
00084 
00086   ~Messager();
00087 
00089 
00095   void popMessage( Skini::Message& message );
00096 
00098   void pushMessage( Skini::Message& message );
00099 
00101 
00109   bool setScoreFile( const char* filename );
00110 
00111 #if defined(__STK_REALTIME__)
00112 
00113 
00122   bool startStdInput();
00123 
00125 
00136   bool startSocketInput( int port=2001 );
00137 
00139 
00151   bool startMidiInput( int port=0 );
00152 
00153 #endif
00154 
00155  protected:
00156 
00157   MessagerData data_;
00158 
00159 #if defined(__STK_REALTIME__)
00160   Thread stdinThread_;
00161   Thread socketThread_;
00162 #endif
00163 
00164 };
00165 
00166 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2007 Perry R. Cook and Gary P. Scavone. All Rights Reserved.