1 /*
2  * Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
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 of the License, or
7  * (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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __us2400_controls_h__
20 #define __us2400_controls_h__
21 
22 #include <map>
23 #include <vector>
24 #include <string>
25 #include <stdint.h>
26 
27 #include <boost/smart_ptr.hpp>
28 
29 #include "pbd/controllable.h"
30 #include "pbd/signals.h"
31 
32 #include "us2400_control_exception.h"
33 #include "midi_byte_array.h"
34 
35 namespace ARDOUR {
36 	class AutomationControl;
37 }
38 
39 namespace ArdourSurface {
40 
41 namespace US2400 {
42 
43 class Strip;
44 class Group;
45 class Surface;
46 
47 class Control {
48 public:
49 	Control (int id, std::string name, Group& group);
~Control()50 	virtual ~Control() {}
51 
id()52 	int id() const { return _id; }
name()53 	const std::string & name() const  { return _name; }
group()54 	Group & group() const { return _group; }
55 
56 	bool in_use () const;
57 	void set_in_use (bool);
58 
59 	// Keep track of the timeout so it can be updated with more incoming events
60 	sigc::connection in_use_connection;
61 
62 	virtual MidiByteArray zero() = 0;
63 
64 	/** If we are doing an in_use timeout for a fader without touch, this
65 	 *  is its touch button control; otherwise 0.
66 	 */
67 	Control* in_use_touch_control;
68 
control()69 	boost::shared_ptr<ARDOUR::AutomationControl> control () const { return normal_ac; }
70 	virtual void set_control (boost::shared_ptr<ARDOUR::AutomationControl>);
reset_control()71 	virtual void reset_control () { normal_ac.reset(); }
72 
73 	virtual void mark_dirty() = 0;
74 
75 	float get_value ();
76 	void set_value (float val, PBD::Controllable::GroupControlDisposition gcd = PBD::Controllable::UseGroup);
77 
78 	virtual void start_touch (double when);
79 	virtual void stop_touch (double when);
80 
81   protected:
82 	boost::shared_ptr<ARDOUR::AutomationControl> normal_ac;
83 
84   private:
85 	int _id; /* possibly device-dependent ID */
86 	std::string _name;
87 	Group& _group;
88 	bool _in_use;
89 };
90 
91 }
92 }
93 
94 std::ostream & operator <<  (std::ostream & os, const ArdourSurface::US2400::Control & control);
95 
96 #endif /* __us2400_controls_h__ */
97