Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 218016
Collapse All | Expand All

(-)alsa-patch-bay-1.0.0-orig/src/driver/jack/jack-addr.cpp (-1 / +2 lines)
Lines 10-16 Link Here
10
 */
10
 */
11
#include <iostream>
11
#include <iostream>
12
12
#include <cstring>
13
#include <cstdlib>
13
#include "jack-addr.h"
14
#include "jack-addr.h"
14
namespace APB {
15
namespace APB {
(-)alsa-patch-bay-1.0.0-orig/src/driver/jack/jack-addr.cpp~ (+99 lines)
Line 0 Link Here
1
/*
2
 * ALSA Patch Bay
3
 *
4
 * Copyright (C) 2002 Robert Ham (node@users.sourceforge.net)
5
 *
6
 * You have permission to use this file under the GNU General
7
 * Public License, version 2 or later.  See the file COPYING
8
 * for the full text.
9
 *
10
 */
11
12
#include <iostream>
13
14
#include "jack-addr.h"
15
16
namespace APB {
17
namespace Jack {
18
19
Addr:: Addr (const std::string &portName, Driver * driver)
20
: _portName (portName),
21
  _driver (driver)
22
{
23
}
24
25
Addr:: Addr (const Addr& addr)
26
: _portName (addr._portName),
27
  _driver (addr._driver)
28
{
29
}
30
31
Addr:: ~Addr ()
32
{
33
}
34
35
std::string
36
Addr:: client () const
37
{
38
  char * client;
39
  char * ptr;
40
41
  client = strdup (_portName.c_str());
42
43
  ptr = strchr (client, ':');
44
  if (ptr)
45
    *ptr = '\0';
46
47
48
  std::string clients (client);
49
  free (client);
50
51
  return clients;
52
}
53
54
std::string
55
Addr:: port () const
56
{
57
  char * ptr;
58
59
  ptr = strchr (_portName.c_str(), ':');
60
  ptr++;
61
62
  std::string ports (ptr);
63
64
  return ports;
65
}
66
67
const char *
68
Addr:: portName () const
69
{
70
  return _portName.c_str ();
71
}
72
73
bool
74
Addr:: equals (const APB::Addr * addr) const
75
{
76
  const Addr * a = (const Addr *) addr;
77
78
  return _portName == a->_portName;
79
}
80
81
bool
82
Addr:: clientEquals (const APB::Addr * addr) const
83
{
84
  const Addr * a = (const Addr *) addr;
85
86
  return client() == a->client();
87
}
88
89
std::string
90
Addr:: getName () const
91
{
92
  return _portName;
93
}
94
95
} /* namespace Jack */
96
} /* namespace APB */
97
98
/* EOF */
99
(-)alsa-patch-bay-1.0.0-orig/src/driver/jack/jack-driver.cpp (-1 / +2 lines)
Lines 18-24 Link Here
18
#include "misc.h"
18
#include "misc.h"
19
#include "plugin.h"
19
#include "plugin.h"
20
#include "ui.h"
20
#include "ui.h"
21
21
#include <cstdlib>
22
#include <cstring>
22
namespace APB {
23
namespace APB {
23
namespace Jack {
24
namespace Jack {
(-)alsa-patch-bay-1.0.0-orig/src/driver/jack/jack-driver.cpp~ (+330 lines)
Line 0 Link Here
1
/*
2
 * ALSA Patch Bay
3
 *
4
 * Copyright (C) 2002 Robert Ham (node@users.sourceforge.net)
5
 *
6
 * You have permission to use this file under the GNU General
7
 * Public License, version 2 or later.  See the file COPYING
8
 * for the full text.
9
 *
10
 */
11
12
#include <unistd.h>
13
#include <stdio.h>
14
#include <errno.h>
15
16
#include "jack-driver.h"
17
#include "jack-addr.h"
18
#include "misc.h"
19
#include "plugin.h"
20
#include "ui.h"
21
22
#include <cstring>
23
namespace APB {
24
namespace Jack {
25
26
static int
27
jackGraphOrderCallback (void * data)
28
{
29
  char refresh = 1;
30
  ssize_t err;
31
  int refreshWriteFile = *(int *)data;
32
33
  err = write (refreshWriteFile, &refresh, sizeof (refresh));
34
  if (err == -1)
35
    {
36
      std::cerr << "error writing to refresh pipe: "
37
                << strerror (errno)
38
                << std::endl;
39
      return 1;
40
    }
41
42
  return 0;
43
}
44
45
Driver:: Driver (const std::string& title, int * argc, char *** argv)
46
{
47
  char * client_name;
48
  char * ptr;
49
50
  client_name = strdup (title.c_str ());
51
  ptr = client_name;
52
  while ( (ptr = strchr (ptr, ' ')) )
53
    *ptr = '_';
54
55
  _jackClient = jack_client_new (client_name);
56
  if (!_jackClient)
57
    {
58
      std::cerr << __FUNCTION__
59
                << ": could not connect to jackd"
60
                << std::endl;
61
      abort ();
62
    }
63
64
  free (client_name);
65
66
  jack_set_graph_order_callback (_jackClient, &jackGraphOrderCallback, &_refreshWriteFile);
67
68
  jack_activate (_jackClient);
69
}
70
71
Driver:: ~Driver ()
72
{
73
  jack_deactivate (_jackClient);
74
75
  jack_client_close (_jackClient);
76
}
77
78
std::string
79
Driver:: findClientName (const APB::Addr * addr) const
80
{
81
  const Addr * a = (const Addr *) addr;
82
83
  return std::string (a->client ());
84
}
85
86
std::string
87
Driver:: findPortName (const APB::Addr * addr) const
88
{
89
  const Addr * a = (const Addr *) addr;
90
91
  return std::string (a->port ());
92
}
93
94
const std::list<APB::Addr *>&
95
Driver:: getReadPorts ()
96
{
97
  return _readPorts;
98
}
99
100
const std::list<APB::Addr *>&
101
Driver:: getWritePorts ()
102
{
103
  return _writePorts;
104
}
105
106
const std::list<const APB::Subscription *>&
107
Driver:: getSubscriptions ()
108
{
109
  static std::list<const APB::Subscription *> subs;
110
111
  subs.clear ();
112
  for (std::list<APB::Subscription *>::iterator i = _subscriptions.begin ();
113
       i != _subscriptions.end();
114
       ++i)
115
    {
116
      if ((*i)->from () == 0)
117
        std::cerr << DEBUG_STRING << "null from()" << std::endl;
118
      if ((*i)->to () == 0)
119
        std::cerr << DEBUG_STRING << "null to()" << std::endl;
120
      subs.push_back (*i);
121
    }
122
123
  return subs;
124
}
125
126
void
127
Driver:: refreshPorts ()
128
{
129
  refreshPortList (_readPorts, JackPortIsOutput);
130
  refreshPortList (_writePorts, JackPortIsInput);
131
  refreshSubscriptions ();
132
}
133
134
void
135
Driver:: refreshPortList (std::list<APB::Addr *>& portList, enum JackPortFlags flags)
136
{
137
  for (std::list<APB::Addr *>::iterator ad = portList.begin();
138
       ad != portList.end ();
139
       ++ad)
140
    {
141
/*      delete *ad; */
142
    }
143
  portList.clear ();
144
145
  const char ** jack_ports = jack_get_ports (_jackClient, NULL, NULL, flags);
146
147
  if (!jack_ports)
148
    return;
149
150
  Addr * addr;
151
  for (unsigned long i = 0; jack_ports[i]; ++i)
152
    {
153
      addr = new Addr (std::string (jack_ports[i]), this);
154
155
      portList.push_back (addr);
156
    }
157
158
  free (jack_ports);
159
}
160
161
Addr *
162
Driver:: findWritePort (const char * portName)
163
{
164
  Addr * addr;
165
  std::string port_name (portName);
166
  for (std::list<APB::Addr *>::const_iterator writeAddrIter = _writePorts.begin ();
167
       writeAddrIter != _writePorts.end ();
168
       writeAddrIter++)
169
    {
170
      addr = (Addr *) *writeAddrIter;
171
172
      if (port_name == addr->getName ())
173
        return addr;
174
    }
175
176
  return 0;
177
}
178
179
void
180
Driver:: refreshSubscriptions ()
181
{
182
  for (std::list<APB::Subscription *>::iterator s = _subscriptions.begin ();
183
       s != _subscriptions.end ();
184
       ++s)
185
    {
186
      delete *s;
187
    }
188
  _subscriptions.clear ();
189
190
  jack_port_t * port;
191
  Addr * addr;
192
  const char ** connections;
193
194
  for (std::list<APB::Addr *>::const_iterator readAddrIter = _readPorts.begin ();
195
       readAddrIter != _readPorts.end ();
196
       ++readAddrIter)
197
    {
198
      addr = (Addr *) *readAddrIter;
199
      port = jack_port_by_name (_jackClient, addr->portName ());
200
201
      if (!port)
202
        {
203
          std::cerr << __FUNCTION__
204
                    << ": could not find port '"
205
                    << addr->portName ()
206
                    << "'"
207
                    << std::endl;
208
          continue;
209
        }
210
211
      connections = jack_port_get_all_connections (_jackClient, port);
212
213
      if (!connections)
214
        continue;
215
216
      for (unsigned long i = 0; connections[i]; ++i)
217
        {
218
          Addr * waddr = findWritePort (connections[i]);
219
220
          if (!waddr)
221
            continue;
222
223
          Subscription * sub = new Subscription (addr, waddr);
224
          _subscriptions.push_back (sub);
225
        }
226
227
      free (connections);
228
    }
229
}
230
231
void
232
Driver:: subscribePorts (const APB::Addr * readAddr, const APB::Addr * writeAddr)
233
{
234
  Addr * raddr = (Addr *) readAddr;
235
  Addr * waddr = (Addr *) writeAddr;
236
237
  int err = jack_connect (_jackClient, raddr->portName (), waddr->portName ());
238
239
  if (err)
240
    {
241
      throw Exception ("Jack server could not connect ports");
242
    }
243
244
  _ui->log (std::string ("Subscribed ports '") + raddr->portName () + "' and '"
245
                                               + waddr->portName () + "'");
246
}
247
248
void
249
Driver:: subscribeClients (const APB::Addr * readAddr, const APB::Addr * writeAddr)
250
{
251
  Addr * raddr;
252
  Addr * waddr = NULL;
253
  std::string rclient (((const Addr *)readAddr)->client ());
254
  std::string wclient (((const Addr *)writeAddr)->client ());
255
256
  unsigned long rcount = 0;
257
  for (std::list<APB::Addr *>::iterator riter = _readPorts.begin ();
258
       riter != _readPorts.end ();
259
       ++riter)
260
    {
261
      raddr = (Addr *) *riter;
262
      if (raddr->client() == rclient)
263
        {
264
          unsigned long wcount = 0;
265
          std::list<APB::Addr *>::iterator witer;
266
          for (witer = _writePorts.begin ();
267
               witer != _writePorts.end ();
268
               ++witer)
269
            {
270
              waddr = (Addr *) *witer;
271
              if (waddr->client() == wclient)
272
                {
273
                  if (wcount == rcount)
274
                    break;
275
276
                  ++wcount;
277
                }
278
            }
279
280
          if (witer == _writePorts.end () || wcount != rcount)
281
            continue;
282
283
          subscribePorts (raddr, waddr);
284
285
          rcount++;
286
        }
287
    }
288
}
289
290
void
291
Driver:: removeSubscription (const Subscription * sub)
292
{
293
  Addr * raddr = (Addr *) sub->from ();
294
  Addr * waddr = (Addr *) sub->to ();
295
296
  int err = jack_disconnect (_jackClient, raddr->portName (), waddr->portName ());
297
298
  if (err)
299
    {
300
      throw Exception ("Jack server could not disconnect ports");
301
    }
302
303
  _ui->log (std::string ("Removed subscription ") + sub->getName ());
304
}
305
306
} /* namespace Jack */
307
308
class JackPlugin : public DriverPlugin
309
{
310
  public:
311
    virtual Driver *   getDriver       (const std::string& title, int * argc, char *** argv);
312
};
313
314
315
Driver *
316
JackPlugin:: getDriver (const std::string& title, int * argc, char *** argv)
317
{
318
  return new Jack::Driver (title, argc, argv);
319
}
320
321
} /* namespace APB */
322
323
APB::DriverPlugin *
324
getDriverPlugin ()
325
{
326
  return new APB::JackPlugin ();
327
}
328
329
/* EOF */
330
(-)alsa-patch-bay-1.0.0-orig/src/driver.cpp (-1 / +1 lines)
Lines 15-21 Link Here
15
#include <errno.h>
15
#include <errno.h>
16
#include <string.h>
16
#include <string.h>
17
#include <fcntl.h>
17
#include <fcntl.h>
18
18
#include <cstdlib>
19
#include "driver.h"
19
#include "driver.h"
20
namespace APB {
20
namespace APB {
(-)alsa-patch-bay-1.0.0-orig/src/driver.cpp~ (+83 lines)
Line 0 Link Here
1
/*
2
 * ALSA Patch Bay
3
 *
4
 * Copyright (C) 2002 Robert Ham (node@users.sourceforge.net)
5
 *
6
 * You have permission to use this file under the GNU General
7
 * Public License, version 2 or later.  See the file COPYING
8
 * for the full text.
9
 *
10
 */
11
12
#include <iostream>
13
14
#include <unistd.h>
15
#include <errno.h>
16
#include <string.h>
17
#include <fcntl.h>
18
19
#include "driver.h"
20
21
namespace APB {
22
23
Driver:: Driver ()
24
  : _ui (0),
25
    _jfd (true)
26
{
27
  int err;
28
  int files[2];
29
30
  err = pipe (files);
31
  if (err)
32
    {
33
      std::cerr << "error creating pipe, exiting: " << strerror (errno) << std::endl;
34
      exit (1);
35
    }
36
37
  _refreshReadFile = files[0];
38
  _refreshWriteFile = files[1];
39
40
  /* set the read file to not block */
41
  err = fcntl (_refreshReadFile, F_SETFL, O_NONBLOCK);
42
  if (err)
43
    {
44
      std::cerr << "error setting read end of pipe to non-blocking mode, exiting: " << strerror (errno) << std::endl;
45
      exit (1);
46
    }
47
}
48
49
void
50
Driver:: setJFD (bool jfd)
51
{
52
  _jfd = jfd;
53
}
54
55
void
56
Driver:: setUI (UI * ui)
57
{
58
  _ui = ui;
59
}
60
61
int
62
Driver:: getRefreshReadFile ()
63
{
64
  return _refreshReadFile;
65
}
66
67
#ifdef HAVE_LADCCA
68
void
69
Driver:: setCCAClient (cca_client_t * client)
70
{
71
  _ccaClient = client;
72
}
73
74
cca_client_t *
75
Driver:: getCCAClient ()
76
{
77
  return _ccaClient;
78
}
79
#endif /* HAVE_LADCCA */
80
81
82
83
} /* namespace APB */
(-)alsa-patch-bay-1.0.0-orig/src/misc.cpp (-1 / +1 lines)
Lines 10-16 Link Here
10
 */
10
 */
11
#include <sstream>
11
#include <sstream>
12
12
#include <cstdlib>
13
#include "misc.h"
13
#include "misc.h"
14
namespace APB {
14
namespace APB {
(-)alsa-patch-bay-1.0.0-orig/src/misc.cpp~ (+40 lines)
Line 0 Link Here
1
/*
2
 * ALSA Patch Bay
3
 *
4
 * Copyright (C) 2002 Robert Ham (node@users.sourceforge.net)
5
 *
6
 * You have permission to use this file under the GNU General
7
 * Public License, version 2 or later.  See the file COPYING
8
 * for the full text.
9
 *
10
 */
11
12
#include <sstream>
13
14
#include "misc.h"
15
16
namespace APB {
17
18
Exception:: Exception (const std::string& d, int e)
19
: desc (d),
20
  err (e)
21
{
22
}
23
24
std::string int2string (int i) {
25
  static std::string str;
26
27
  std::ostringstream ss;
28
29
  ss << i;
30
31
  str = ss.str();
32
33
  return str;
34
}
35
36
int randomNumber (double lower, double upper) {
37
  return (int) ((lower-1)+(int) ((upper+1)*rand()/(RAND_MAX+1.0)));
38
}
39
40
} /* namespace APB */
(-)alsa-patch-bay-1.0.0-orig/src/plugins.cpp (-1 / +1 lines)
Lines 14-20 Link Here
14
#include <dirent.h>
14
#include <dirent.h>
15
#include <errno.h>
15
#include <errno.h>
16
#include <string.h>
16
#include <string.h>
17
17
#include <cstdlib>
18
#include <iostream>
18
#include <iostream>
19
#include <list>
19
#include <list>
20
#include <string>
20
#include <string>
(-)alsa-patch-bay-1.0.0-orig/src/plugins.cpp~ (+220 lines)
Line 0 Link Here
1
/*
2
 * ALSA Patch Bay
3
 *
4
 * Copyright (C) 2002 Robert Ham (node@users.sourceforge.net)
5
 *
6
 * You have permission to use this file under the GNU General
7
 * Public License, version 2 or later.  See the file COPYING
8
 * for the full text.
9
 *
10
 */
11
12
#include <dlfcn.h>
13
#include <sys/types.h>
14
#include <dirent.h>
15
#include <errno.h>
16
#include <string.h>
17
18
#include <iostream>
19
#include <list>
20
#include <string>
21
22
#include "plugin.h"
23
#include "plugins.h"
24
25
namespace APB {
26
27
static void * uiPluginHandle;
28
static void * driverPluginHandle;
29
30
PluginSet *
31
getPluginSet ()
32
{
33
  static PluginSet plugs;
34
  return &plugs;
35
}
36
37
UIPlugin *
38
openUIPlugin (std::string pluginName)
39
{
40
  std::string fqn;
41
  void * dlhandle;
42
  GetUIPluginFunc getUIPlugin;
43
  UIPlugin * plugin;
44
  const char * error;
45
46
  fqn = std::string (PKGLIBDIR) + "/ui/" + pluginName + ".so";
47
48
  dlhandle = dlopen (fqn.c_str(), RTLD_LAZY|RTLD_GLOBAL);
49
50
  if (!dlhandle)
51
    {
52
      std::cerr << __FUNCTION__
53
                << ": could not open ui plugin '"
54
                << fqn
55
                << "': "
56
                << dlerror ()
57
                << std::endl;
58
      exit (1);
59
    }
60
61
  dlerror();
62
63
  /* gcc 3.x */
64
  getUIPlugin = (GetUIPluginFunc) dlsym (dlhandle, "_Z11getUIPluginv");
65
  error = dlerror ();
66
  if (error)
67
    {
68
      /* gcc 2.95.x */
69
      getUIPlugin = (GetUIPluginFunc) dlsym (dlhandle, "getUIPlugin__Fv");
70
      error = dlerror ();
71
      if (error)
72
        {
73
          std::cerr << __FUNCTION__
74
                    << ": could not find getUIPlugin function in plugin '"
75
                    << fqn
76
                    << "': "
77
                    << error
78
                    << std::endl;
79
          dlclose (dlhandle);
80
          exit (1);
81
        }
82
    }
83
84
  plugin = getUIPlugin ();
85
86
  uiPluginHandle = dlhandle;
87
88
  return plugin;
89
}
90
91
DriverPlugin *
92
openDriverPlugin (std::string pluginName)
93
{
94
  std::string fqn;
95
  void * dlhandle;
96
  GetDriverPluginFunc getDriverPlugin;
97
  DriverPlugin * plugin;
98
  const char * error;
99
100
  fqn = std::string (PKGLIBDIR) + "/driver/" + pluginName + ".so";
101
102
  dlhandle = dlopen (fqn.c_str(), RTLD_LAZY|RTLD_GLOBAL);
103
104
  if (!dlhandle)
105
    {
106
      std::cerr << __FUNCTION__
107
                << ": could not open driver plugin '"
108
                << fqn
109
                << "': "
110
                << dlerror ()
111
                << std::endl;
112
      exit (1);
113
    }
114
115
  dlerror();
116
117
  getDriverPlugin = (GetDriverPluginFunc) dlsym (dlhandle, "_Z15getDriverPluginv");
118
  error = dlerror ();
119
  if (error)
120
    {
121
      getDriverPlugin = (GetDriverPluginFunc) dlsym (dlhandle, "getDriverPlugin__Fv");
122
      error = dlerror ();
123
      if (error)
124
        {
125
          std::cerr << __FUNCTION__
126
                    << ": could not find getDriverPlugin function in plugin '"
127
                    << fqn
128
                    << "': "
129
                    << error
130
                    << std::endl;
131
          dlclose (dlhandle);
132
          exit (1);
133
        }
134
    }
135
136
  plugin = getDriverPlugin ();
137
138
  driverPluginHandle = dlhandle;
139
140
  return plugin;
141
}
142
143
void
144
readDir (std::string dirname, std::list<std::string>& plugins)
145
{
146
  struct dirent * dir_entry;
147
  DIR * dir;
148
  char * plugin, * ptr;
149
150
  dir = opendir (dirname.c_str());
151
152
  if (!dir)
153
    {
154
      std::cerr << __FUNCTION__
155
                << ": could not open plugin directory '"
156
                << dirname
157
                << "': "
158
                << strerror (errno)
159
                << std::endl;
160
      exit (1);
161
    }
162
163
  while ( (dir_entry = readdir (dir)) )
164
    {
165
      plugin = strdup (dir_entry->d_name);
166
      dirname = plugin;
167
      if (dirname == "." || dirname == "..")
168
        continue;
169
170
      ptr = strrchr (plugin, '.');
171
      if (!ptr) {
172
        free (plugin);
173
        continue;
174
      }
175
      *ptr = '\0';
176
      plugins.push_back (plugin);
177
      free (plugin);
178
    }
179
}
180
181
void
182
initPlugins ()
183
{
184
  std::string dir;
185
186
  dir = std::string (PKGLIBDIR) + "/driver";
187
  readDir (dir, getPluginSet()->driverPlugins);
188
189
  dir = std::string (PKGLIBDIR) + "/ui";
190
  readDir (dir, getPluginSet()->uiPlugins);
191
192
193
  if (getPluginSet()->driverPlugins.size () == 0)
194
    {
195
      std::cerr << __FUNCTION__
196
                << ": no driver plugins"
197
                << std::endl;
198
      exit (1);
199
    }
200
201
  if (getPluginSet()->uiPlugins.size () == 0)
202
    {
203
      std::cerr << __FUNCTION__
204
                << ": no ui plugins"
205
                << std::endl;
206
      exit (1);
207
    }
208
}
209
210
void
211
closePlugins ()
212
{
213
}
214
215
} /* namespace APB */
216
217
218
/* EOF */
219
220

Return to bug 218016