FP8: unhardcode IDs and strip-count
[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 #include "pbd/controllable.h"
27
28 #include "fp8_base.h"
29 #include "fp8_button.h"
30
31 #define N_STRIPS 8
32
33 namespace ARDOUR {
34         class Stripable;
35         class AutomationControl;
36         class PeakMeter;
37         class ReadOnlyControl;
38 }
39
40 namespace ArdourSurface {
41
42 class FP8Strip
43 {
44 public:
45         FP8Strip (FP8Base& b, uint8_t id);
46         ~FP8Strip ();
47
48         enum CtrlElement {
49                 BtnSolo,
50                 BtnMute,
51                 BtnSelect,
52                 Fader,
53                 Meter,
54                 Redux,
55                 BarVal,
56                 BarMode
57         };
58
59         static uint8_t midi_ctrl_id (CtrlElement type, uint8_t id);
60
61         FP8ButtonInterface& solo_button () { return _solo; }
62         FP8ButtonInterface& mute_button () { return _mute; }
63         FP8ButtonInterface& selrec_button () { return _selrec; }
64         FP8ButtonInterface& recarm_button () { return *_selrec.button_shift(); }
65         FP8ButtonInterface& select_button () { return *_selrec.button(); }
66
67         bool midi_touch (bool t);
68         bool midi_fader (float val);
69
70         void initialize (); // call only when connected, sends midi
71
72         void set_select_cb (boost::function<void ()>&);
73
74         enum DisplayMode {
75                 Stripables,
76                 PluginSelect, // no clock display
77                 PluginParam, // param value
78                 SendDisplay, // param value + select-bar
79         };
80
81         void set_periodic_display_mode (DisplayMode m);
82
83         // convenience function to call all set_XXX_controllable
84         void set_stripable (boost::shared_ptr<ARDOUR::Stripable>, bool panmode);
85         void set_text_line (uint8_t, std::string const&, bool inv = false);
86
87         enum CtrlMask {
88                 CTRL_FADER  = 0x001,
89                 CTRL_MUTE   = 0x002,
90                 CTRL_SOLO   = 0x004,
91                 CTRL_REC    = 0x004,
92                 CTRL_PAN    = 0x008,
93                 CTRL_SELECT = 0x010,
94                 CTRL_TEXT0  = 0x100,
95                 CTRL_TEXT1  = 0x200,
96                 CTRL_TEXT2  = 0x400,
97                 CTRL_TEXT3  = 0x800,
98
99                 CTRL_TEXT01 = 0x300,
100                 CTRL_TEXT   = 0xf00,
101                 CTRL_ALL    = 0xfff,
102         };
103
104         void unset_controllables (int which = CTRL_ALL);
105
106         void set_fader_controllable  (boost::shared_ptr<ARDOUR::AutomationControl>);
107         void set_mute_controllable   (boost::shared_ptr<ARDOUR::AutomationControl>);
108         void set_solo_controllable   (boost::shared_ptr<ARDOUR::AutomationControl>);
109         void set_rec_controllable    (boost::shared_ptr<ARDOUR::AutomationControl>);
110         void set_pan_controllable    (boost::shared_ptr<ARDOUR::AutomationControl>);
111         void set_select_controllable (boost::shared_ptr<ARDOUR::AutomationControl>);
112
113 private:
114         FP8Base&  _base;
115         uint8_t   _id;
116         FP8MomentaryButton _solo;
117         FP8MomentaryButton _mute;
118         FP8ARMSensitiveButton _selrec;
119
120         bool _touching;
121
122         PBD::ScopedConnection _base_connection; // periodic
123         PBD::ScopedConnectionList _button_connections;
124
125         std::string _stripable_name;
126
127         boost::shared_ptr<ARDOUR::AutomationControl> _fader_ctrl;
128         boost::shared_ptr<ARDOUR::AutomationControl> _mute_ctrl;
129         boost::shared_ptr<ARDOUR::AutomationControl> _solo_ctrl;
130         boost::shared_ptr<ARDOUR::AutomationControl> _rec_ctrl;
131         boost::shared_ptr<ARDOUR::AutomationControl> _pan_ctrl;
132         boost::shared_ptr<ARDOUR::AutomationControl> _x_select_ctrl;
133
134         PBD::ScopedConnection _fader_connection;
135         PBD::ScopedConnection _mute_connection;
136         PBD::ScopedConnection _solo_connection;
137         PBD::ScopedConnection _rec_connection;
138         PBD::ScopedConnection _pan_connection;
139         PBD::ScopedConnection _x_select_connection;
140
141         boost::shared_ptr<ARDOUR::PeakMeter> _peak_meter;
142         boost::shared_ptr<ARDOUR::ReadOnlyControl> _redux_ctrl;
143
144         void set_x_select_controllable (boost::shared_ptr<ARDOUR::AutomationControl>);
145         boost::function<void ()> _select_plugin_functor;
146
147         void drop_automation_controls ();
148
149         PBD::Controllable::GroupControlDisposition group_mode () const;
150
151         /* notifications, update view */
152         void notify_fader_changed ();
153         void notify_solo_changed ();
154         void notify_mute_changed ();
155         void notify_rec_changed ();
156         void notify_pan_changed ();
157         void notify_x_select_changed ();
158
159         /* actions, update model */
160         void set_mute (bool);
161         void set_solo (bool);
162         void set_select ();
163         void set_recarm ();
164
165         /* periodic poll, update view */
166         void set_strip_name ();
167         void periodic_update_fader ();
168         void periodic_update_meter ();
169         void periodic_update_timecode (uint32_t);
170         void periodic ();
171
172         /* cache */
173         unsigned short _last_fader;
174         uint8_t _last_meter;
175         uint8_t _last_redux;
176         uint8_t _last_barpos;
177
178         /* display */
179         void set_strip_mode (uint8_t, bool clear = false);
180         void set_bar_mode (uint8_t, bool force = false);
181
182         uint8_t _strip_mode;
183         uint8_t _bar_mode;
184         DisplayMode _displaymode;
185         std::string _last_line[4];
186 };
187
188 } /* namespace */
189 #endif /* _ardour_surfaces_fp8strip_h_ */