summaryrefslogtreecommitdiff
path: root/libs/surfaces/mackie/controls.cc
blob: aa7112a7ecb44db2020ff0f0ea53e9124bb0be5f (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 /*
	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.
*/

#include <iostream>
#include <iomanip>
#include <sstream>

#include "ardour/automation_control.h"
#include "pbd/enumwriter.h"

#include "controls.h"
#include "types.h"
#include "surface.h"
#include "control_group.h"
#include "button.h"
#include "led.h"
#include "pot.h"
#include "fader.h"
#include "jog.h"
#include "meter.h"


using namespace std;
using namespace ArdourSurface;
using namespace Mackie;

using ARDOUR::AutomationControl;

void Group::add (Control& control)
{
	_controls.push_back (&control);
}

Control::Control (int id, std::string name, Group & group)
	: _id (id)
	, _name (name)
	, _group (group)
	, _in_use (false)
{
}

/** @return true if the control is in use, or false otherwise.
    Buttons are `in use' when they are held down.
    Faders with touch support are `in use' when they are being touched.
    Pots, or faders without touch support, are `in use' from the first move
    event until a timeout after the last move event.
*/
bool
Control::in_use () const
{
	return _in_use;
}

void
Control::set_in_use (bool in_use)
{
	_in_use = in_use;
}

void
Control::set_control (boost::shared_ptr<AutomationControl> ac)
{
	normal_ac = ac;
}

void
Control::set_value (float val, PBD::Controllable::GroupControlDisposition group_override)
{
	if (normal_ac) {
		normal_ac->set_value (normal_ac->interface_to_internal (val), group_override);
	}
}

float
Control::get_value ()
{
	if (!normal_ac) {
		return 0.0f;
	}
	return normal_ac->internal_to_interface (normal_ac->get_value());
}

void
Control::start_touch (double when)
{
	if (normal_ac) {
		return normal_ac->start_touch (when);
	}
}

void
Control::stop_touch (bool mark, double when)
{
	if (normal_ac) {
		return normal_ac->stop_touch (mark, when);
	}
}

ostream & operator <<  (ostream & os, const ArdourSurface::Mackie::Control & control)
{
	os << typeid (control).name();
	os << " { ";
	os << "name: " << control.name();
	os << ", ";
	os << "id: " << "0x" << setw(2) << setfill('0') << hex << control.id() << setfill(' ');
	os << ", ";
	os << "group: " << control.group().name();
	os << " }";

	return os;
}