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