don't ping JACK server 4 times to see if it is already up when ardour starts
[ardour.git] / libs / backends / jack / jack_api.cc
1 /*
2     Copyright (C) 2013 Paul Davis
3
4     This program 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     This program 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 should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "jack_connection.h"
21 #include "jack_audiobackend.h"
22
23 using namespace ARDOUR;
24
25 static boost::shared_ptr<JACKAudioBackend> backend;
26 static boost::shared_ptr<JackConnection> jack_connection;
27
28 static boost::shared_ptr<AudioBackend>
29 backend_factory (AudioEngine& ae)
30 {
31         if (!jack_connection) {
32                 return boost::shared_ptr<AudioBackend>();
33         }
34
35         if (!backend) {
36                 backend.reset (new JACKAudioBackend (ae, jack_connection));
37         }
38
39         return backend;
40 }
41
42 static int
43 instantiate (const std::string& arg1, const std::string& arg2)
44 {
45         try {
46                 jack_connection.reset (new JackConnection (arg1, arg2));
47         } catch (...) {
48                 return -1;
49         }
50
51         return 0;
52 }
53
54 static int 
55 deinstantiate ()
56 {
57         backend.reset ();
58         jack_connection.reset ();
59
60         return 0;
61 }
62
63 static bool
64 already_configured ()
65 {
66         return !JackConnection::in_control ();
67 }
68
69 static ARDOUR::AudioBackendInfo _descriptor = {
70         "JACK",
71         instantiate,
72         deinstantiate,
73         backend_factory,
74         already_configured,
75 };
76
77 extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor() { return &_descriptor; }
78