summaryrefslogtreecommitdiff
path: root/libs/surfaces/mackie/mackie_midi_builder.h
blob: b5fc9f73c95b7feada8b7b936be7fd5f00282261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
	Copyright (C) 2006,2007 John Anderson

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef mackie_midi_builder_h
#define mackie_midi_builder_h

#include "midi_byte_array.h"
#include "types.h"
#include "controls.h"

namespace Mackie
{

class SurfacePort;

/**
	This knows how to build midi messages given a control and
	a state.
*/
class MackieMidiBuilder
{
public:
	/**
		The first byte of a midi message from the surface
		will contain one of these, sometimes bitmasked
		with the control id
	*/
	enum midi_types {
		midi_fader_id = Control::type_fader
		, midi_button_id = Control::type_button
		, midi_pot_id = Control::type_pot
	};

	/**
		The LED rings have these modes.
	*/
	enum midi_pot_mode {
		midi_pot_mode_dot = 0
		, midi_pot_mode_boost_cut = 1
		, midi_pot_mode_wrap = 2
		, midi_pot_mode_spread = 3
	};

	MidiByteArray build_led_ring( const Pot & pot, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot );
	MidiByteArray build_led_ring( const LedRing & led_ring, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot );

  	MidiByteArray build_led( const Led & led, LedState ls );
  	MidiByteArray build_led( const Button & button, LedState ls );
	
	MidiByteArray build_fader( const Fader & fader, float pos );
	
	/// return bytes that will reset all controls to their zero positions
	/// And blank the display for the strip. Pass SurfacePort so we know which sysex header to use.
	MidiByteArray zero_strip( SurfacePort &, const Strip & strip );
	
	// provide bytes to zero the given control
	MidiByteArray zero_control( const Control & control );
	
	// display the first 2 chars of the msg in the 2 char display
	// . is appended to the previous character, so A.B. would
	// be two characters
	MidiByteArray two_char_display( const std::string & msg, const std::string & dots = "  " );
	MidiByteArray two_char_display( unsigned int value, const std::string & dots = "  " );
	
	/**
		Timecode display. Only the difference between timecode and last_timecode will
		be encoded, to save midi bandwidth. If they're the same, an empty array will
		be returned
	*/
	MidiByteArray timecode_display( SurfacePort &, const std::string & timecode, const std::string & last_timecode = "" );
	
	/**
		for displaying characters on the strip LCD
		pass SurfacePort so we know which sysex header to use
	*/
	MidiByteArray strip_display( SurfacePort &, const Strip & strip, unsigned int line_number, const std::string & line );
	
	/// blank the strip LCD, ie write all spaces. Pass SurfacePort so we know which sysex header to use.
	MidiByteArray strip_display_blank( SurfacePort &, const Strip & strip, unsigned int line_number );
	
	/// for generating all strip names. Pass SurfacePort so we know which sysex header to use.
	MidiByteArray all_strips_display( SurfacePort &, std::vector<std::string> & lines1, std::vector<std::string> & lines2 );
	
protected:
	static MIDI::byte calculate_pot_value( midi_pot_mode mode, const ControlState & );
};

}

#endif