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