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