substantial overhaul of MCU code - no more separate thread, just connect to signals...
[ardour.git] / libs / surfaces / mackie / types.h
1 /*
2         Copyright (C) 2006,2007 John Anderson
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
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #ifndef mackie_types_h
19 #define mackie_types_h
20
21 #include <iostream>
22
23 namespace Mackie
24 {
25
26 /**
27         This started off as an enum, but it got really annoying
28         typing ? on : off
29 */
30 class LedState
31 {
32 public:
33         enum state_t { none, off, flashing, on };
34         LedState()  : _state( none ) {}
35         LedState( bool yn ): _state( yn ? on : off ) {}
36         LedState( state_t state ): _state( state ) {}
37
38         bool operator == ( const LedState & other ) const
39         {
40                 return state() == other.state();
41         }
42         
43         bool operator != ( const LedState & other ) const
44         {
45                 return state() != other.state();
46         }
47         
48         state_t state() const { return _state; }
49         
50 private:
51         state_t _state;
52 };
53
54 extern LedState on;
55 extern LedState off;
56 extern LedState flashing;
57 extern LedState none;
58
59 enum ButtonState { neither = -1, release = 0, press = 1 };
60
61 /**
62         Contains the state for a control, with some convenience
63         constructors
64 */
65 struct ControlState
66 {
67         ControlState(): pos(0.0), sign(0), delta(0.0), ticks(0), led_state(off), button_state(neither) {}
68         
69         ControlState( LedState ls ): pos(0.0), delta(0.0), led_state(ls), button_state(neither) {}
70         
71         // Note that this sets both pos and delta to the flt value
72         ControlState( LedState ls, float flt ): pos(flt), delta(flt), ticks(0), led_state(ls), button_state(neither) {}
73         ControlState( float flt ): pos(flt), delta(flt), ticks(0), led_state(none), button_state(neither) {}
74         ControlState( float flt, unsigned int tcks ): pos(flt), delta(flt), ticks(tcks), led_state(none), button_state(neither) {}
75         ControlState( ButtonState bs ): pos(0.0), delta(0.0), ticks(0), led_state(none), button_state(bs) {}
76         
77         /// For faders. Between 0 and 1.
78         float pos;
79                 
80         /// For pots. Sign. Either -1 or 1;
81         int sign;
82
83         /// For pots. Signed value of total movement. Between 0 and 1
84         float delta;
85                 
86         /// For pots. Unsigned number of ticks. Usually between 1 and 16.
87         unsigned int ticks;
88                 
89         LedState led_state;
90         ButtonState button_state;
91 };
92
93 std::ostream & operator << ( std::ostream &, const ControlState & );
94
95 class Control;
96 class Fader;
97 class Button;
98 class Strip;
99 class Group;
100 class Pot;
101 class Led;
102 class LedRing;
103
104 }
105
106 #endif