MCP: some debug tracing for meters
[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 #include "controls.h"
24
25 namespace Mackie
26 {
27
28 class SurfacePort;
29 class Button;
30 class Meter;
31 class Fader;
32 class Jog;
33 class Pot;
34 class Led;
35 class LedRing;
36
37 /**
38         This knows how to build midi messages given a control and
39         a state.
40 */
41 class MackieMidiBuilder
42 {
43 public:
44         /**
45                 The first byte of a midi message from the surface
46                 will contain one of these, sometimes bitmasked
47                 with the control id
48         */
49         enum midi_types {
50                 midi_fader_id = Control::type_fader
51                 , midi_button_id = Control::type_button
52                 , midi_pot_id = Control::type_pot
53         };
54
55         /**
56                 The LED rings have these modes.
57         */
58         enum midi_pot_mode {
59                 midi_pot_mode_dot = 0
60                 , midi_pot_mode_boost_cut = 1
61                 , midi_pot_mode_wrap = 2
62                 , midi_pot_mode_spread = 3
63         };
64
65         MidiByteArray build_led_ring( const Pot & pot, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot );
66         MidiByteArray build_led_ring( const LedRing & led_ring, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot );
67
68         MidiByteArray build_led( const Led & led, LedState ls );
69         MidiByteArray build_led( const Button & button, LedState ls );
70         
71         MidiByteArray build_fader( const Fader & fader, float pos );
72
73         /// return bytes that will reset all controls to their zero positions
74         /// And blank the display for the strip. Pass SurfacePort so we know which sysex header to use.
75         MidiByteArray zero_strip( SurfacePort &, const Strip & strip );
76         
77         // provide bytes to zero the given control
78         MidiByteArray zero_control( const Control & control );
79         
80         // display the first 2 chars of the msg in the 2 char display
81         // . is appended to the previous character, so A.B. would
82         // be two characters
83         MidiByteArray two_char_display( const std::string & msg, const std::string & dots = "  " );
84         MidiByteArray two_char_display( unsigned int value, const std::string & dots = "  " );
85         
86         /**
87                 Timecode display. Only the difference between timecode and last_timecode will
88                 be encoded, to save midi bandwidth. If they're the same, an empty array will
89                 be returned
90         */
91         MidiByteArray timecode_display( SurfacePort &, const std::string & timecode, const std::string & last_timecode = "" );
92         
93         /**
94                 for displaying characters on the strip LCD
95                 pass SurfacePort so we know which sysex header to use
96         */
97         MidiByteArray strip_display( SurfacePort &, const Strip & strip, unsigned int line_number, const std::string & line );
98         
99         /// blank the strip LCD, ie write all spaces. Pass SurfacePort so we know which sysex header to use.
100         MidiByteArray strip_display_blank( SurfacePort &, const Strip & strip, unsigned int line_number );
101         
102         /// for generating all strip names. Pass SurfacePort so we know which sysex header to use.
103         MidiByteArray all_strips_display( SurfacePort &, std::vector<std::string> & lines1, std::vector<std::string> & lines2 );
104         
105 protected:
106         static MIDI::byte calculate_pot_value( midi_pot_mode mode, const ControlState & );
107 };
108
109 }
110
111 #endif