summaryrefslogtreecommitdiff
path: root/common/JackGraphManager.h
blob: dd8af9d87f5f1d9fe2f1afe36ff4682b03959728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2006 Grame  

This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackGraphManager__
#define __JackGraphManager__

#include "JackShmMem.h"
#include "JackPort.h"
#include "JackConstants.h"
#include "JackConnectionManager.h"
#include "JackAtomicState.h"

namespace Jack
{

/*!
\brief Graph manager: contains the connection manager and the port array.
*/

class JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectionManager>
{

    private:

        JackPort fPortArray[PORT_NUM];   
		JackClientTiming fClientTiming[CLIENT_NUM];

        jack_port_id_t AllocatePortAux(int refnum, const char* port_name, JackPortFlags flags);
        void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index);
        const char** GetPortsAux(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
        float* GetBuffer(jack_port_id_t port_index);
        void* GetBufferAux(JackConnectionManager* manager, jack_port_id_t port_index, jack_nframes_t frames);
        jack_nframes_t GetTotalLatencyAux(jack_port_id_t port_index, jack_port_id_t src_port_index, JackConnectionManager* manager, int hop_count);

    public:

        JackGraphManager()
        {}
        virtual ~JackGraphManager()
        {}

        // Ports management
        jack_port_id_t AllocatePort(int refnum, const char* port_name, JackPortFlags flags);  
		int ReleasePort(int refnum, jack_port_id_t port_index); 
	    void RemoveAllPorts(int refnum); 
        void DisconnectAllPorts(int refnum); 
	
        JackPort* GetPort(jack_port_id_t index); 
        jack_port_id_t GetPort(const char* name); 
        jack_nframes_t GetTotalLatency(jack_port_id_t port_index); 
        int RequestMonitor(jack_port_id_t port_index, bool onoff); 

        // Connections management
        int Connect(jack_port_id_t src_index, jack_port_id_t dst_index);  
        int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index); 
        int GetConnectionsNum(jack_port_id_t port_index); 

        int ConnectedTo(jack_port_id_t port_src, const char* port_name); 
        const char** GetConnections(jack_port_id_t port_index); 
        const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);

        int CheckPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index); 
        int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst); 
        int CheckPort(jack_port_id_t port_index); 

        void DisconnectAllInput(jack_port_id_t port_index); 
        void DisconnectAllOutput(jack_port_id_t port_index); 
        int DisconnectAll(jack_port_id_t port_index); 

        bool IsDirectConnection(int ref1, int ref2); 
        void DirectConnect(int ref1, int ref2); 
        void DirectDisconnect(int ref1, int ref2); 
	
		void Activate(int refnum);
		void Deactivate(int refnum);

        int GetInputRefNum(jack_port_id_t port_index); 
        int GetOutputRefNum(jack_port_id_t port_index); 

        // Buffer management
        void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames); 

        // Activation management
        void RunCurrentGraph();  
        bool RunNextGraph();  
        bool IsFinishedGraph();  

		void InitRefNum(int refnum); 
        int ResumeRefNum(JackClientControl* control, JackSynchro** table);  
        int SuspendRefNum(JackClientControl* control, JackSynchro** table, long usecs); 
		
		JackClientTiming* GetClientTiming(int refnum);
		
        void Save(JackConnectionManager* dst);
        void Restore(JackConnectionManager* src);

};


} // end of namespace

#endif