Dmitry Baikov jackmp-time patch: add jack_get_time, jack_time_to_frames, jack_frames_...
[jack2.git] / common / JackClient.h
blobd7e9fb83698213b88c48294fadd693391ee9b6cd
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2006 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __JackClient__
22 #define __JackClient__
24 #include "JackClientInterface.h"
25 #include "JackThread.h"
26 #include "JackConstants.h"
27 #include "JackSynchro.h"
28 #include "types.h"
29 #include "transport_types.h"
30 #include <list>
32 namespace Jack
35 class JackClientChannelInterface;
36 class JackGraphManager;
37 class JackServer;
38 class JackEngine;
39 class JackSynchro;
40 struct JackClientControl;
41 struct JackEngineControl;
42 class JackSyncInterface;
44 typedef void (*JackShutdownCallback)(void *arg);
46 /*!
47 \brief The base class for clients: share part of the implementation for JackInternalClient and JackLibClient.
50 class JackClient : public JackClientInterface, public JackRunnableInterface
53 protected:
55 JackProcessCallback fProcess;
56 JackGraphOrderCallback fGraphOrder;
57 JackXRunCallback fXrun;
58 JackShutdownCallback fShutdown;
59 JackThreadInitCallback fInit;
60 JackBufferSizeCallback fBufferSize;
61 JackFreewheelCallback fFreewheel;
62 JackPortRegistrationCallback fPortRegistration;
63 JackTimebaseCallback fTimebase;
64 JackSyncCallback fSync;
65 void* fProcessArg;
66 void* fGraphOrderArg;
67 void* fXrunArg;
68 void* fShutdownArg;
69 void* fInitArg;
70 void* fBufferSizeArg;
71 void* fFreewheelArg;
72 void* fPortRegistrationArg;
73 void* fTimebaseArg;
74 void* fSyncArg;
75 int fConditionnal;
77 JackThread* fThread; /*! Thread to execute the Process function */
78 JackClientChannelInterface* fChannel;
79 JackSynchro** fSynchroTable;
80 std::list<jack_port_id_t> fPortList;
82 int StartThread();
83 void SetupDriverSync(bool freewheel);
84 bool IsActive();
86 bool CallProcessCallback();
87 void CallSyncCallback();
88 void CallTimebaseCallback();
89 int RequestNewPos(jack_position_t* pos);
91 virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value);
93 public:
95 JackClient();
96 JackClient(JackSynchro** table);
97 virtual ~JackClient();
99 virtual int Open(const char* name) = 0;
100 virtual int Close();
102 virtual JackGraphManager* GetGraphManager() const = 0;
103 virtual JackEngineControl* GetEngineControl() const = 0;
105 // Notifications
106 virtual int ClientNotify(int refnum, const char* name, int notify, int sync, int value);
108 virtual int Activate();
109 virtual int Deactivate();
111 // Context
112 virtual int SetBufferSize(jack_nframes_t buffer_size);
113 virtual int SetFreeWheel(int onoff);
114 virtual void ShutDown();
115 virtual pthread_t GetThreadID();
117 // Port management
118 virtual int PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
119 virtual int PortUnRegister(jack_port_id_t port);
121 virtual int PortConnect(const char* src, const char* dst);
122 virtual int PortDisconnect(const char* src, const char* dst);
123 virtual int PortConnect(jack_port_id_t src, jack_port_id_t dst);
124 virtual int PortDisconnect(jack_port_id_t src);
126 virtual int PortIsMine(jack_port_id_t port_index);
128 // Transport
129 virtual int ReleaseTimebase();
130 virtual int SetSyncCallback(JackSyncCallback sync_callback, void* arg);
131 virtual int SetSyncTimeout(jack_time_t timeout);
132 virtual int SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg);
133 virtual int TransportLocate(jack_nframes_t frame);
134 virtual jack_transport_state_t TransportQuery(jack_position_t* pos);
135 virtual jack_nframes_t GetCurrentTransportFrame();
136 virtual int TransportReposition(jack_position_t* pos);
137 virtual void TransportStart();
138 virtual void TransportStop();
140 // Callbacks
141 virtual void OnShutdown(JackShutdownCallback callback, void *arg);
142 virtual int SetProcessCallback(JackProcessCallback callback, void* arg);
143 virtual int SetXRunCallback(JackXRunCallback callback, void* arg);
144 virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
145 virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
146 virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
147 virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
148 virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
150 // JackRunnableInterface interface
151 bool Init();
152 bool Execute();
155 // Each "side" server and client will implement this to get the shared graph manager, engine control and inter-process synchro table.
156 extern JackGraphManager* GetGraphManager();
157 extern JackEngineControl* GetEngineControl();
158 extern JackSynchro** GetSynchroTable();
160 } // end of namespace
162 #endif