Jack2 1.9.8
|
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 __JackGraphManager__ 00022 #define __JackGraphManager__ 00023 00024 #include "JackShmMem.h" 00025 #include "JackPort.h" 00026 #include "JackConstants.h" 00027 #include "JackConnectionManager.h" 00028 #include "JackAtomicState.h" 00029 #include "JackPlatformPlug.h" 00030 #include "JackSystemDeps.h" 00031 00032 namespace Jack 00033 { 00034 00039 PRE_PACKED_STRUCTURE 00040 class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectionManager> 00041 { 00042 00043 private: 00044 00045 unsigned int fPortMax; 00046 JackClientTiming fClientTiming[CLIENT_NUM]; 00047 JackPort fPortArray[0]; // The actual size depends of port_max, it will be dynamically computed and allocated using "placement" new 00048 00049 void AssertPort(jack_port_id_t port_index); 00050 jack_port_id_t AllocatePortAux(int refnum, const char* port_name, const char* port_type, JackPortFlags flags); 00051 void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index); 00052 void GetPortsAux(const char** matching_ports, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); 00053 jack_default_audio_sample_t* GetBuffer(jack_port_id_t port_index); 00054 void* GetBufferAux(JackConnectionManager* manager, jack_port_id_t port_index, jack_nframes_t frames); 00055 jack_nframes_t ComputeTotalLatencyAux(jack_port_id_t port_index, jack_port_id_t src_port_index, JackConnectionManager* manager, int hop_count); 00056 void RecalculateLatencyAux(jack_port_id_t port_index, jack_latency_callback_mode_t mode); 00057 00058 public: 00059 00060 JackGraphManager(int port_max); 00061 ~JackGraphManager() 00062 {} 00063 00064 void SetBufferSize(jack_nframes_t buffer_size); 00065 00066 // Ports management 00067 jack_port_id_t AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size); 00068 int ReleasePort(int refnum, jack_port_id_t port_index); 00069 void GetInputPorts(int refnum, jack_int_t* res); 00070 void GetOutputPorts(int refnum, jack_int_t* res); 00071 void RemoveAllPorts(int refnum); 00072 void DisconnectAllPorts(int refnum); 00073 00074 JackPort* GetPort(jack_port_id_t index); 00075 jack_port_id_t GetPort(const char* name); 00076 00077 int ComputeTotalLatency(jack_port_id_t port_index); 00078 int ComputeTotalLatencies(); 00079 void RecalculateLatency(jack_port_id_t port_index, jack_latency_callback_mode_t mode); 00080 00081 int RequestMonitor(jack_port_id_t port_index, bool onoff); 00082 00083 // Connections management 00084 int Connect(jack_port_id_t src_index, jack_port_id_t dst_index); 00085 int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index); 00086 int IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst); 00087 00088 // RT, client 00089 int GetConnectionsNum(jack_port_id_t port_index) 00090 { 00091 JackConnectionManager* manager = ReadCurrentState(); 00092 return manager->Connections(port_index); 00093 } 00094 00095 const char** GetConnections(jack_port_id_t port_index); 00096 void GetConnections(jack_port_id_t port_index, jack_int_t* connections); // TODO 00097 const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); 00098 00099 int GetTwoPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index); 00100 int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst); 00101 00102 void DisconnectAllInput(jack_port_id_t port_index); 00103 void DisconnectAllOutput(jack_port_id_t port_index); 00104 int DisconnectAll(jack_port_id_t port_index); 00105 00106 bool IsDirectConnection(int ref1, int ref2); 00107 void DirectConnect(int ref1, int ref2); 00108 void DirectDisconnect(int ref1, int ref2); 00109 00110 void Activate(int refnum); 00111 void Deactivate(int refnum); 00112 00113 int GetInputRefNum(jack_port_id_t port_index); 00114 int GetOutputRefNum(jack_port_id_t port_index); 00115 00116 // Buffer management 00117 void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames); 00118 00119 // Activation management 00120 void RunCurrentGraph(); 00121 bool RunNextGraph(); 00122 bool IsFinishedGraph(); 00123 00124 void InitRefNum(int refnum); 00125 int ResumeRefNum(JackClientControl* control, JackSynchro* table); 00126 int SuspendRefNum(JackClientControl* control, JackSynchro* table, long usecs); 00127 void TopologicalSort(std::vector<jack_int_t>& sorted); 00128 00129 JackClientTiming* GetClientTiming(int refnum) 00130 { 00131 return &fClientTiming[refnum]; 00132 } 00133 00134 void Save(JackConnectionManager* dst); 00135 void Restore(JackConnectionManager* src); 00136 00137 static JackGraphManager* Allocate(int port_max); 00138 static void Destroy(JackGraphManager* manager); 00139 00140 } POST_PACKED_STRUCTURE; 00141 00142 00143 } // end of namespace 00144 00145 #endif 00146