Merged with trunk R1612.
[ardour.git] / libs / surfaces / mackie / mackie_midi_builder.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_midi_builder_h
19 #define mackie_midi_builder_h
20
21 #include "midi_byte_array.h"
22 #include "types.h"
23
24 namespace Mackie
25 {
26
27 /**
28         This knows how to build midi messages given a control and
29         a state.
30 */
31 class MackieMidiBuilder
32 {
33 public:
34         /**
35                 The first byte of a midi message from the surface
36                 will contain one of these, sometimes bitmasked
37                 with the control id
38         */
39         enum midi_types {
40                 midi_fader_id = 0xe0
41                 , midi_button_id = 0x90
42                 , midi_pot_id = 0xb0
43         };
44
45         /**
46                 The LED rings have these modes.
47         */
48         enum midi_pot_mode {
49                 midi_pot_mode_dot = 0
50                 , midi_pot_mode_boost_cut = 1
51                 , midi_pot_mode_wrap = 2
52                 , midi_pot_mode_spread = 3
53         };
54
55         MidiByteArray build_led_ring( const Pot & pot, const ControlState & );
56         MidiByteArray build_led_ring( const LedRing & led_ring, const ControlState & );
57
58         MidiByteArray build_led( const Led & led, LedState ls );
59         MidiByteArray build_led( const Button & button, LedState ls );
60         
61         MidiByteArray build_fader( const Fader & fader, float pos );
62         
63         /// return bytes that will reset all controls to their zero positions
64         MidiByteArray zero_strip( const Strip & strip );
65         
66         // provide bytes to zero the given control
67         MidiByteArray zero_control( const Control & control );
68         
69         // display the first 2 chars of the msg in the 2 char display
70         // . is appended to the previous character, so A.B. would
71         // be two characters
72         MidiByteArray two_char_display( const std::string & msg, const std::string & dots = "  " );
73         MidiByteArray two_char_display( unsigned int value, const std::string & dots = "  " );
74         
75 protected:
76         static MIDI::byte calculate_pot_value( midi_pot_mode mode, const ControlState & );
77 };
78
79 }
80
81 #endif