Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / surfaces / mackie / interface.cc
1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009 David Robillard <d@drobilla.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <stdexcept>
23
24 #include "pbd/error.h"
25
26 #include "ardour/rc_configuration.h"
27
28 #include "control_protocol/control_protocol.h"
29 #include "mackie_control_protocol.h"
30
31 using namespace ARDOUR;
32 using namespace PBD;
33 using namespace std;
34 using namespace ArdourSurface;
35 using namespace Mackie;
36
37 static ControlProtocol*
38 new_mackie_protocol (ControlProtocolDescriptor*, Session* s)
39 {
40         MackieControlProtocol* mcp = 0;
41
42         try {
43                 mcp = new MackieControlProtocol (*s);
44                 /* do not set active here - wait for set_state() */
45         }
46         catch (exception & e) {
47                 error << "Error instantiating MackieControlProtocol: " << e.what() << endmsg;
48                 delete mcp;
49                 mcp = 0;
50         }
51
52         return mcp;
53 }
54
55 static void
56 delete_mackie_protocol (ControlProtocolDescriptor*, ControlProtocol* cp)
57 {
58         try
59         {
60                 delete cp;
61         }
62         catch ( exception & e )
63         {
64                 cout << "Exception caught trying to destroy MackieControlProtocol: " << e.what() << endl;
65         }
66 }
67
68 /**
69         This is called on startup to check whether the lib should be loaded.
70
71         So anything that can be changed in the UI should not be used here to
72         prevent loading of the lib.
73 */
74 static bool
75 probe_mackie_protocol (ControlProtocolDescriptor*)
76 {
77         return MackieControlProtocol::probe();
78 }
79
80 static void*
81 mackie_request_buffer_factory (uint32_t num_requests)
82 {
83         return MackieControlProtocol::request_factory (num_requests);
84 }
85
86 // Field names commented out by JE - 06-01-2010
87 static ControlProtocolDescriptor mackie_descriptor = {
88         /*name :              */   "Mackie",
89         /*id :                */   "uri://ardour.org/surfaces/mackie:0",
90         /*ptr :               */   0,
91         /*module :            */   0,
92         /*mandatory :         */   0,
93         // actually, the surface does support feedback, but all this
94         // flag does is show a submenu on the UI, which is useless for the mackie
95         // because feedback is always on. In any case, who'd want to use the
96         // mcu without the motorised sliders doing their thing?
97         /*supports_feedback : */   false,
98         /*probe :             */   probe_mackie_protocol,
99         /*initialize :        */   new_mackie_protocol,
100         /*destroy :           */   delete_mackie_protocol,
101         /*request_buffer_factory */ mackie_request_buffer_factory
102 };
103
104 extern "C" ARDOURSURFACE_API ControlProtocolDescriptor* protocol_descriptor () { return &mackie_descriptor; }