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) 2013 Paul Davis
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.
*/
#include <boost/scoped_ptr.hpp>
#include <jack/session.h>
#include "pbd/epa.h"
#include "ardour/jack_connection.h"
#define GET_PRIVATE_JACK_POINTER(j) jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return; }
#define GET_PRIVATE_JACK_POINTER_RET(j,r) jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return r; }
using namespace ARDOUR;
using namespace PBD;
static void jack_halted_callback (void* arg)
{
JackConnection* jc = static_cast<JackConnection*> (arg);
jc->halted_callback ();
}
static void jack_halted_info_callback (jack_status_t code, const char* reason, void* arg)
{
JackConnection* jc = static_cast<JackConnection*> (arg);
jc->halted_info_callback (code, reason);
}
JackConnection::JackConnection (const std::string& arg1, const std::string& arg2)
: _jack (0)
, client_name (arg1)
, session_uuid (arg2)
{
}
JackConnection::~JackConnection ()
{
close ();
}
int
JackConnection::open ()
{
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
jack_status_t status;
close ();
/* revert all environment settings back to whatever they were when ardour started
*/
if (global_epa) {
current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
global_epa->restore ();
}
if ((_jack = jack_client_open (client_name.c_str(), JackSessionID, &status, session_uuid.c_str())) == 0) {
return -1;
}
if (status & JackNameNotUnique) {
client_name = jack_get_client_name (_jack);
}
/* attach halted handler */
if (jack_on_info_shutdown) {
jack_on_info_shutdown (_jack, jack_halted_info_callback, this);
} else {
jack_on_shutdown (_jack, jack_halted_callback, this);
}
return 0;
}
int
JackConnection::close ()
{
GET_PRIVATE_JACK_POINTER_RET (_jack, -1);
if (_priv_jack) {
return jack_client_close (_priv_jack);
}
return 0;
}
void
JackConnection::halted_callback ()
{
_jack = 0;
Disconnected ("");
}
void
JackConnection::halted_info_callback (jack_status_t /*status*/, const char* reason)
{
_jack = 0;
Disconnected (reason);
}
|