Skeleton for NI Maschine2 Surface
[ardour.git] / libs / surfaces / maschine2 / maschine2.h
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 #ifndef _ardour_surfaces_maschine2_h_
20 #define _ardour_surfaces_maschine2_h_
21
22 #ifdef PLATFORM_WINDOWS
23 #include <windows.h>
24 #endif
25
26 #include <hidapi.h>
27
28 #define ABSTRACT_UI_EXPORTS
29 #include "pbd/abstract_ui.h"
30 #include "ardour/types.h"
31 #include "ardour/port.h"
32 #include "control_protocol/control_protocol.h"
33
34 namespace MIDI {
35         class Port;
36 }
37
38 namespace ArdourSurface {
39
40 class M2Contols;
41 class M2Device;
42 class Maschine2Canvas;
43 class Maschine2Layout;
44
45 class Maschine2Exception : public std::exception
46 {
47         public:
48                 Maschine2Exception (const std::string& msg) : _msg (msg) { }
49                 virtual ~Maschine2Exception () throw () {}
50                 const char* what () const throw () { return _msg.c_str (); }
51         private:
52                 std::string _msg;
53 };
54
55 struct Maschine2Request : public BaseUI::BaseRequestObject {
56   public:
57         Maschine2Request () {}
58         ~Maschine2Request () {}
59 };
60
61 class Maschine2: public ARDOUR::ControlProtocol, public AbstractUI<Maschine2Request>
62 {
63         public:
64                 Maschine2 (ARDOUR::Session&);
65                 ~Maschine2 ();
66
67                 static void* request_factory (uint32_t);
68
69 #if 0
70                 bool has_editor () const { return false; }
71                 void* get_gui () const;
72                 void  tear_down_gui ();
73 #endif
74
75                 int set_active (bool yn);
76                 XMLNode& get_state ();
77                 int set_state (const XMLNode & node, int version);
78
79                 Maschine2Canvas* canvas () const { return _canvas; }
80                 Maschine2Layout* current_layout() const;
81
82                 typedef enum {
83                         Mikro,
84                         Maschine,
85                         Studio
86                 } Maschine2Type;
87
88         private:
89                 void do_request (Maschine2Request*);
90
91                 int start ();
92                 int stop ();
93
94                 void thread_init ();
95                 void run_event_loop ();
96                 void stop_event_loop ();
97
98                 sigc::connection read_connection;
99                 sigc::connection write_connection;
100
101                 bool dev_write ();
102                 bool dev_read ();
103
104                 hid_device* _handle;
105                 M2Device* _hw;
106                 M2Contols* _ctrl;
107                 Maschine2Canvas* _canvas;
108
109                 Maschine2Type _maschine_type;
110
111                 PBD::ScopedConnectionList session_connections;
112                 PBD::ScopedConnectionList button_connections;
113
114                 void connect_signals ();
115                 void stripable_selection_changed () {}
116
117
118                 /* Master Mode */
119                 enum MasterMode {
120                         MST_NONE,
121                         MST_VOLUME,
122                         MST_TEMPO
123                 } _master_state;
124
125                 void handle_master_change (enum MasterMode);
126                 void notify_master_change ();
127
128                 /* PAD Port */
129                 boost::shared_ptr<ARDOUR::Port> _midi_out;
130                 MIDI::Port* _output_port;
131
132                 /* callbacks */
133                 void notify_record_state_changed ();
134                 void notify_transport_state_changed ();
135                 void notify_loop_state_changed ();
136                 void notify_parameter_changed (std::string);
137                 void notify_snap_change ();
138                 void notify_session_dirty_changed ();
139                 void notify_history_changed ();
140
141                 void button_play ();
142                 void button_record ();
143                 void button_loop ();
144                 void button_metronom ();
145                 void button_rewind ();
146
147                 void button_action (const std::string&, const std::string&);
148
149                 void button_snap_released ();
150                 void button_snap_pressed ();
151                 void button_snap_changed (bool);
152
153                 void encoder_master (int);
154                 void button_encoder ();
155
156                 void pad_event (unsigned int, float, bool);
157                 void pad_change (unsigned int, float);
158 };
159
160 } /* namespace */
161 #endif /* _ardour_surfaces_maschine2_h_*/