Faderport8 control surface support
[ardour.git] / libs / surfaces / faderport8 / fp8_strip.h
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) 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
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef _ardour_surfaces_fp8strip_h_
20 #define _ardour_surfaces_fp8strip_h_
21
22 #include <stdint.h>
23 #include <boost/shared_ptr.hpp>
24
25 #include "pbd/signals.h"
26
27 #include "fp8_base.h"
28 #include "fp8_button.h"
29
30 namespace ARDOUR {
31         class Stripable;
32         class AutomationControl;
33         class PeakMeter;
34         class ReadOnlyControl;
35 }
36
37 namespace ArdourSurface {
38
39 class FP8Strip
40 {
41 public:
42         FP8Strip (FP8Base& b, uint8_t id);
43         ~FP8Strip ();
44
45         FP8ButtonInterface& solo_button () { return _solo; }
46         FP8ButtonInterface& mute_button () { return _mute; }
47         FP8ButtonInterface& selrec_button () { return _selrec; }
48         FP8ButtonInterface& recarm_button () { return *_selrec.button_shift(); }
49         FP8ButtonInterface& select_button () { return *_selrec.button(); }
50
51         bool midi_touch (bool t);
52         bool midi_fader (float val);
53
54         void initialize (); // call only when connected, sends midi
55
56         void set_select_cb (boost::function<void ()>&);
57
58         enum DisplayMode {
59                 Stripables,
60                 PluginSelect, // no clock display
61                 PluginParam, // param value
62         };
63
64         void set_periodic_display_mode (DisplayMode m) {
65                 _displaymode = m;
66         }
67
68         // convenience function to call all set_XXX_controllable
69         void set_stripable (boost::shared_ptr<ARDOUR::Stripable>, bool panmode);
70         void set_text_line (uint8_t, std::string const&);
71
72         enum CtrlMask {
73                 CTRL_FADER  = 0x001,
74                 CTRL_MUTE   = 0x002,
75                 CTRL_SOLO   = 0x004,
76                 CTRL_REC    = 0x004,
77                 CTRL_PAN    = 0x008,
78                 CTRL_SELECT = 0x010,
79                 CTRL_TEXT1  = 0x100,
80                 CTRL_TEXT2  = 0x200,
81                 CTRL_TEXT3  = 0x400,
82                 CTRL_TEXT4  = 0x800,
83
84                 CTRL_TEXT   = 0xf00,
85                 CTRL_ALL    = 0xfff,
86         };
87
88         void unset_controllables (int which = CTRL_ALL);
89
90         void set_fader_controllable (boost::shared_ptr<ARDOUR::AutomationControl>);
91         void set_mute_controllable  (boost::shared_ptr<ARDOUR::AutomationControl>);
92         void set_solo_controllable  (boost::shared_ptr<ARDOUR::AutomationControl>);
93         void set_rec_controllable   (boost::shared_ptr<ARDOUR::AutomationControl>);
94         void set_pan_controllable   (boost::shared_ptr<ARDOUR::AutomationControl>);
95
96 private:
97         FP8Base&  _base;
98         uint8_t   _id;
99         FP8MomentaryButton _solo;
100         FP8MomentaryButton _mute;
101         FP8ARMSensitiveButton _selrec;
102
103         bool _touching;
104
105         PBD::ScopedConnection _base_connection; // periodic
106         PBD::ScopedConnectionList _button_connections;
107
108         boost::shared_ptr<ARDOUR::Stripable> _stripable;
109
110         boost::shared_ptr<ARDOUR::AutomationControl> _fader_ctrl;
111         boost::shared_ptr<ARDOUR::AutomationControl> _mute_ctrl;
112         boost::shared_ptr<ARDOUR::AutomationControl> _solo_ctrl;
113         boost::shared_ptr<ARDOUR::AutomationControl> _rec_ctrl;
114         boost::shared_ptr<ARDOUR::AutomationControl> _pan_ctrl;
115
116         PBD::ScopedConnection _fader_connection;
117         PBD::ScopedConnection _mute_connection;
118         PBD::ScopedConnection _solo_connection;
119         PBD::ScopedConnection _rec_connection;
120         PBD::ScopedConnection _pan_connection;
121
122         boost::shared_ptr<ARDOUR::PeakMeter> _peak_meter;
123         boost::shared_ptr<ARDOUR::ReadOnlyControl> _redux_ctrl;
124         boost::function<void ()> _select_plugin_functor;
125
126         /* notifications, update view */
127         void notify_fader_changed ();
128         void notify_solo_changed ();
129         void notify_mute_changed ();
130         void notify_rec_changed ();
131         void notify_pan_changed ();
132
133         /* actions, update model */
134         void set_mute (bool);
135         void set_solo (bool);
136         void set_select ();
137         void set_recarm ();
138
139         /* periodic poll, update view */
140         void periodic_update_fader ();
141         void periodic_update_meter ();
142         void periodic_update_timecode ();
143         void periodic ();
144
145         /* cache */
146         unsigned short _last_fader;
147         uint8_t _last_meter;
148         uint8_t _last_redux;
149         uint8_t _last_panpos;
150
151         /* display */
152         void set_strip_mode (uint8_t, bool clear = false);
153         void set_bar_mode (uint8_t);
154
155         uint8_t _strip_mode;
156         uint8_t _bar_mode;
157         DisplayMode _displaymode;
158         std::string _last_line[4];
159 };
160
161 } /* namespace */
162 #endif /* _ardour_surfaces_fp8strip_h_ */