Skeleton for NI Maschine2 Surface
[ardour.git] / libs / surfaces / maschine2 / interface.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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, or (at your option)
7  * 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 Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #include <stdexcept>
20
21 #include "pbd/error.h"
22 #include "ardour/rc_configuration.h"
23 #include "control_protocol/control_protocol.h"
24 #include "maschine2.h"
25
26 using namespace ARDOUR;
27 using namespace PBD;
28 using namespace ArdourSurface;
29
30 static ControlProtocol*
31 new_maschine2 (ControlProtocolDescriptor*, Session* s)
32 {
33         Maschine2* m2 = 0;
34
35         try {
36                 m2 = new Maschine2 (*s);
37         }
38         catch (std::exception & e) {
39                 PBD::error << "Failed to instantiate Maschine2: " << e.what() << endmsg;
40                 delete m2;
41                 m2 = 0;
42         }
43
44         m2->set_active (true);
45         return m2;
46 }
47
48 static void
49 delete_maschine2 (ControlProtocolDescriptor*, ControlProtocol* cp)
50 {
51         delete cp;
52 }
53
54 static bool
55 probe_maschine2 (ControlProtocolDescriptor*)
56 {
57         return true;
58 }
59
60 static void*
61 maschine2_request_buffer_factory (uint32_t num_requests)
62 {
63         return Maschine2::request_factory (num_requests);
64 }
65
66 static ControlProtocolDescriptor maschine2_descriptor = {
67         /*name :              */   "NI Maschine2",
68         /*id :                */   "uri://ardour.org/surfaces/maschine2:0",
69         /*ptr :               */   0,
70         /*module :            */   0,
71         /*mandatory :         */   0,
72         /*supports_feedback : */   false,
73         /*probe :             */   probe_maschine2,
74         /*initialize :        */   new_maschine2,
75         /*destroy :           */   delete_maschine2,
76         /*request_buffer_factory */ maschine2_request_buffer_factory
77 };
78
79 extern "C" ARDOURSURFACE_API ControlProtocolDescriptor* protocol_descriptor () { return &maschine2_descriptor; }