gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
JackClient.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef JACKCLIENT_H_
18 #define JACKCLIENT_H_
19 
20 #include "JackBase.H"
21 
29 
56 class JackClient : virtual public JackBase {
64  static int processAudioStatic(jack_nframes_t nframes, void *arg) {
65  return reinterpret_cast<JackClient*>(arg)->processAudio(nframes);
66  }
67 
75  static int bufferSizeChangeStatic(jack_nframes_t nframes, void *arg) {
76  return reinterpret_cast<JackClient*>(arg)->bufferSizeChange(nframes);
77  }
78 
79 protected:
84  virtual int processAudio(jack_nframes_t nframes)=0;
85 
90  virtual int bufferSizeChange(jack_nframes_t nframes){
91  cout<<"JackClient::bufferSizeChangeStatic : New buffer size = "<<nframes<<endl;
92  return 0;
93  }
94 
95 public:
98  JackClient(void) : JackBase() {}
99 
103  JackClient(string clientName_) : JackBase(clientName_) {}
104 
106  virtual ~JackClient() {
107  disconnect(); // if the client is running, then stop the client and disconnect from the server
108  }
109 
115  virtual int connect(string clientName_) {
116  return JackBase::connect(clientName_);
117  }
118 
125  virtual int connect(const string &clientName_, const string &serverName) {
126  JackBase::connect(clientName_, serverName); // get the jack client connected
127 
128  if (0 != jack_set_process_callback(client, processAudioStatic, this))
130 
131  if (0 != jack_set_buffer_size_callback(client, bufferSizeChangeStatic, this))
133 
134  return NO_ERROR;
135  }
136 
140  virtual int getBlockSize() {
141  return jack_get_buffer_size (client);
142  }
143 
144 
148  int setBlockSize(int size) {
149  int res=jack_set_buffer_size(client,size);
150  if (res!=0)
152  return NO_ERROR;
153  }
154 
159  virtual int startClient() {
160  /* Tell the JACK server that we are ready to roll. Our
161  * process() callback will start running now. */
162 
163  return jack_activate(client);
164  }
165 
173  virtual int startClient(int inCnt, int outCnt, bool doConnect=true) {
174 
175  if (startClient())
177 
178 
179  if (doConnect) {
180  vector<jack_port_t *> inPorts, outPorts; // find the physical ports and auto connect
181  int inCntLocal=getPortListAndCount((JackPortFlags)(JackPortIsPhysical|JackPortIsOutput), &inPorts, NULL, NULL);
182  if (inCntLocal==0)
184  if (inCnt<inCntLocal)
185  inCntLocal=inCnt;
186  for (int i=0; i<inCntLocal; i++)
187  if (jack_connect(client, jack_port_name(inPorts[i]), jack_port_name(inputPorts[i])))
188  cerr<<"cannot connect input port "<<i<<endl;
189 
190  int outCntLocal=getPortListAndCount((JackPortFlags)(JackPortIsPhysical|JackPortIsInput), &outPorts, NULL, NULL);
191  if (outCntLocal==0)
193  if (outCnt<outCntLocal)
194  outCntLocal=outCnt;
195  for (int i=0; i<outCntLocal; i++)
196  if (jack_connect(client, jack_port_name(outputPorts[i]), jack_port_name(outPorts[i])))
197  cerr<<"cannot connect output port "<<i<<endl;
198  }
199  return 0;
200  }
201 };
202 #endif // JACKCLIENT_H_
size(signal)
virtual int disconnect(void)
Definition: JackBase.H:254
virtual int getBlockSize()
Definition: JackClient.H:140
virtual int connect(string clientName_)
Definition: JackBase.H:369
int getPortListAndCount(JackPortFlags flags, vector< jack_port_t *> *ports, const char *portNamePattern, const char *typeNamePattern)
Definition: JackBase.H:159
virtual int evaluateError(int errorNum)
Definition: Debug.H:132
#define JACK_HAS_NO_CAPTURE_PORTS_ERROR
The server has no capture ports.
Definition: JackBase.H:40
virtual int connect(const string &clientName_, const string &serverName)
Definition: JackClient.H:125
virtual ~JackClient()
Destructor.
Definition: JackClient.H:106
#define JACK_SET_CALLBACK_ERROR
The Client failed to register its callback with the server.
Definition: JackBase.H:36
virtual int startClient()
Definition: JackClient.H:159
int setBlockSize(int size)
Definition: JackClient.H:148
#define NO_ERROR
There is no error.
Definition: Debug.H:33
static int processAudioStatic(jack_nframes_t nframes, void *arg)
Definition: JackClient.H:64
#define JACK_SET_BUFFER_SIZE_ERROR
Couldn&#39;t set the buffer size.
Definition: JackBase.H:43
virtual int startClient(int inCnt, int outCnt, bool doConnect=true)
Definition: JackClient.H:173
#define JACK_SET_BUFFSIZE_CALLBACK_ERROR
Couldn&#39;t set the buffer size callback.
Definition: JackBase.H:44
JackClient(string clientName_)
Definition: JackClient.H:103
static int bufferSizeChangeStatic(jack_nframes_t nframes, void *arg)
Definition: JackClient.H:75
virtual int connect(string clientName_)
Definition: JackClient.H:115
virtual int processAudio(jack_nframes_t nframes)=0
jack_client_t * client
The jack client.
Definition: JackBase.H:108
#define JACK_HAS_NO_PLAYBACK_PORTS_ERROR
The server has no playback.
Definition: JackBase.H:41
JackClient(void)
Definition: JackClient.H:98
vector< jack_port_t * > inputPorts
The input ports.
Definition: JackBase.H:118
#define JACK_ACTIVATE_ERROR
Couldn&#39;t activate the client with the server.
Definition: JackBase.H:39
vector< jack_port_t * > outputPorts
The output ports.
Definition: JackBase.H:119
virtual int bufferSizeChange(jack_nframes_t nframes)
Definition: JackClient.H:90
gtkIOStream: /tmp/gtkiostream/include/JackClient.H Source File
GTK+ IOStream  Beta