FP8: add mode to reset gain to unity
[ardour.git] / libs / surfaces / faderport8 / faderport8_interface.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2015 Paul Davis
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <pbd/failed_constructor.h>
21
22 #include "control_protocol/control_protocol.h"
23 #include "faderport8.h"
24
25 using namespace ARDOUR;
26 using namespace ArdourSurface;
27
28 static ControlProtocol*
29 new_faderport8_midi_protocol (ControlProtocolDescriptor* /*descriptor*/, Session* s)
30 {
31         FaderPort8* fp;
32
33         try {
34                 fp =  new FaderPort8 (*s);
35         } catch (failed_constructor& err) {
36                 return 0;
37         }
38
39         if (fp->set_active (true)) {
40                 delete fp;
41                 return 0;
42         }
43
44         return fp;
45 }
46
47 static void
48 delete_faderport8_midi_protocol (ControlProtocolDescriptor* /*descriptor*/, ControlProtocol* cp)
49 {
50         delete cp;
51 }
52
53 static bool
54 probe_faderport8_midi_protocol (ControlProtocolDescriptor* /*descriptor*/)
55 {
56         return FaderPort8::probe ();
57 }
58
59 static void*
60 faderport8_request_buffer_factory (uint32_t num_requests)
61 {
62         return FaderPort8::request_factory (num_requests);
63 }
64
65 static ControlProtocolDescriptor faderport8_midi_descriptor = {
66         /*name :              */    "PreSonus FaderPort8",
67         /*id :                */    "uri://ardour.org/surfaces/faderport8:0",
68         /*ptr :               */    0,
69         /*module :            */    0,
70         /*mandatory :         */    0,
71         /*supports_feedback : */    true,
72         /*probe :             */    probe_faderport8_midi_protocol,
73         /*initialize :        */    new_faderport8_midi_protocol,
74         /*destroy :           */    delete_faderport8_midi_protocol,
75         /*request_buffer_factory */ faderport8_request_buffer_factory
76 };
77
78 extern "C" ARDOURSURFACE_API
79 ControlProtocolDescriptor* protocol_descriptor () {
80         return &faderport8_midi_descriptor;
81 }