Jack2 1.9.6

JackTransportEngine.h

00001 /*
00002 Copyright (C) 2001 Paul Davis
00003 Copyright (C) 2004-2008 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU Lesser General Public License as published by
00007 the Free Software Foundation; either version 2.1 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public License
00016 along with this program; if not, write to the Free Software 
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 
00019 */
00020 
00021 #ifndef __JackTransportEngine__
00022 #define __JackTransportEngine__
00023 
00024 #include "JackAtomicArrayState.h"
00025 #include "JackCompilerDeps.h"
00026 #include "types.h"
00027 
00028 namespace Jack
00029 {
00030 
00031 typedef enum {
00032     TransportCommandNone = 0,
00033     TransportCommandStart = 1,
00034     TransportCommandStop = 2,
00035 } transport_command_t;
00036 
00090 class JackClientInterface;
00091 
00092 class SERVER_EXPORT JackTransportEngine : public JackAtomicArrayState<jack_position_t>
00093 {
00094 
00095     private:
00096 
00097         jack_transport_state_t fTransportState;
00098         volatile transport_command_t fTransportCmd;
00099         transport_command_t fPreviousCmd;               /* previous transport_cmd */
00100         jack_time_t fSyncTimeout;
00101         int fSyncTimeLeft;
00102         int fTimeBaseMaster;
00103         bool fPendingPos;
00104         bool fNetworkSync;
00105         bool fConditionnal;
00106         SInt32 fWriteCounter;
00107 
00108         bool CheckAllRolling(JackClientInterface** table);
00109         void MakeAllStartingLocating(JackClientInterface** table);
00110         void MakeAllStopping(JackClientInterface** table);
00111         void MakeAllLocating(JackClientInterface** table);
00112         
00113         void SyncTimeout(jack_nframes_t frame_rate, jack_nframes_t buffer_size);
00114 
00115     public:
00116 
00117         JackTransportEngine();
00118 
00119         ~JackTransportEngine()
00120         {}
00121 
00122         void SetCommand(transport_command_t state)
00123         {
00124             fTransportCmd = state;
00125         }
00126 
00127         jack_transport_state_t GetState() const
00128         {
00129             return fTransportState;
00130         }
00131         
00132         void SetState(jack_transport_state_t state)
00133         {
00134             fTransportState = state;
00135         }
00136         
00137         /*
00138                 \brief 
00139         */
00140         int ResetTimebase(int refnum);
00141 
00142         /*
00143                 \brief 
00144         */
00145         int SetTimebaseMaster(int refnum, bool conditionnal);
00146         
00147         void GetTimebaseMaster(int& refnum, bool& conditionnal)
00148         {
00149             refnum = fTimeBaseMaster;
00150             conditionnal = fConditionnal;
00151         }
00152 
00153         /*
00154                 \brief 
00155         */
00156         void CycleBegin(jack_nframes_t frame_rate, jack_time_t time);
00157 
00158         /*
00159                 \brief 
00160         */
00161         void CycleEnd(JackClientInterface** table, jack_nframes_t frame_rate, jack_nframes_t buffer_size);
00162 
00163         /*
00164                 \brief 
00165         */
00166         void SetSyncTimeout(jack_time_t timeout)
00167         {
00168             fSyncTimeout = timeout;
00169         }
00170 
00171         void ReadCurrentPos(jack_position_t* pos);
00172 
00173         jack_unique_t GenerateUniqueID()
00174         {
00175             return (jack_unique_t)INC_ATOMIC(&fWriteCounter);
00176         }
00177         
00178         void RequestNewPos(jack_position_t* pos);
00179         
00180         jack_transport_state_t Query(jack_position_t* pos);
00181         
00182         jack_nframes_t GetCurrentFrame();
00183 
00184         static void CopyPosition(jack_position_t* from, jack_position_t* to);
00185         
00186         bool GetNetworkSync() const
00187         {
00188             return fNetworkSync;
00189         }
00190         
00191         void SetNetworkSync(bool sync)
00192         {
00193             fNetworkSync = sync;
00194         }
00195 
00196 } POST_PACKED_STRUCTURE;
00197 
00198 } // end of namespace
00199 
00200 #endif