summaryrefslogtreecommitdiff
path: root/libs/surfaces/us2400/button.cc
blob: 5e577a6c0b83c2bac8af55361aa824387040e202 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
	Copyright (C) 2006,2007 John Anderson
	Copyright (C) 2012 Paul Davis
	Copyright (C) 2017 Ben Loftis

	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 <glib.h>

#include "ardour/ardour.h"

#include "button.h"
#include "surface.h"
#include "control_group.h"

using namespace ArdourSurface;
using namespace US2400;

Control*
Button::factory (Surface& surface, Button::ID bid, int id, const std::string& name, Group& group)
{
	Button* b = new Button (surface, bid, id, name, group);
	/* store button with the device-specific ID */
	surface.buttons[id] = b;
	surface.controls.push_back (b);
	group.add (*b);
	return b;
}

void
Button::pressed ()
{
	press_time = ARDOUR::get_microseconds ();
}

void
Button::released ()
{
	press_time = 0;
}

int32_t
Button::long_press_count ()
{
	if (press_time == 0) {
		return -1; /* button is not pressed */
	}

	const ARDOUR::microseconds_t delta = ARDOUR::get_microseconds () - press_time;

	if (delta < 500000) {
		return 0;
	} else if (delta < 1000000) {
		return 1;
	}

	return 2;
}
int
Button::name_to_id (const std::string& name)
{
	if (!g_ascii_strcasecmp (name.c_str(), "Send")) { return Send; }
	if (!g_ascii_strcasecmp (name.c_str(), "Pan")) { return Pan; }
	if (!g_ascii_strcasecmp (name.c_str(), "Bank Left")) { return Left; }
	if (!g_ascii_strcasecmp (name.c_str(), "Bank Right")) { return Right; }
	if (!g_ascii_strcasecmp (name.c_str(), "Flip")) { return Flip; }
	if (!g_ascii_strcasecmp (name.c_str(), "Mstr Select")) { return MstrSelect; }
	if (!g_ascii_strcasecmp (name.c_str(), "F1")) { return F1; }
	if (!g_ascii_strcasecmp (name.c_str(), "F2")) { return F2; }
	if (!g_ascii_strcasecmp (name.c_str(), "F3")) { return F3; }
	if (!g_ascii_strcasecmp (name.c_str(), "F4")) { return F4; }
	if (!g_ascii_strcasecmp (name.c_str(), "F5")) { return F5; }
	if (!g_ascii_strcasecmp (name.c_str(), "F6")) { return F6; }
	if (!g_ascii_strcasecmp (name.c_str(), "Shift")) { return Shift; }
	if (!g_ascii_strcasecmp (name.c_str(), "Drop")) { return Drop; }
	if (!g_ascii_strcasecmp (name.c_str(), "Clear Solo")) { return ClearSolo; }
	if (!g_ascii_strcasecmp (name.c_str(), "Rewind")) { return Rewind; }
	if (!g_ascii_strcasecmp (name.c_str(), "Ffwd")) { return Ffwd; }
	if (!g_ascii_strcasecmp (name.c_str(), "Stop")) { return Stop; }
	if (!g_ascii_strcasecmp (name.c_str(), "Play")) { return Play; }
	if (!g_ascii_strcasecmp (name.c_str(), "Record")) { return Record; }
	if (!g_ascii_strcasecmp (name.c_str(), "Scrub")) { return Scrub; }

		/* Strip buttons */

	if (!g_ascii_strcasecmp (name.c_str(), "Solo")) { return Solo; }
	if (!g_ascii_strcasecmp (name.c_str(), "Mute")) { return Mute; }
	if (!g_ascii_strcasecmp (name.c_str(), "Select")) { return Select; }
	if (!g_ascii_strcasecmp (name.c_str(), "Fader Touch")) { return FaderTouch; }

	/* Master Fader button */

	if (!g_ascii_strcasecmp (name.c_str(), "Master Fader Touch")) { return MasterFaderTouch; }

	return -1;
}

std::string
Button::id_to_name (Button::ID id)
{
	if (id == Send) { return "Send"; }
	if (id == Pan) { return "Pan"; }
	if (id == Left) { return "Bank Left"; }
	if (id == Right) { return "Bank Right"; }
	if (id == Flip) { return "Flip"; }
	if (id == MstrSelect) { return "Mstr Select"; }
	if (id == F1) { return "F1"; }
	if (id == F2) { return "F2"; }
	if (id == F3) { return "F3"; }
	if (id == F4) { return "F4"; }
	if (id == F5) { return "F5"; }
	if (id == F6) { return "F6"; }
	if (id == Shift) { return "Shift"; }
	if (id == Drop) { return "Drop"; }
	if (id == ClearSolo) { return "Clear Solo"; }
	if (id == Rewind) { return "Rewind"; }
	if (id == Ffwd) { return "FFwd"; }
	if (id == Stop) { return "Stop"; }
	if (id == Play) { return "Play"; }
	if (id == Record) { return "Record"; }
	if (id == Scrub) { return "Scrub"; }

	if (id == Solo) { return "Solo"; }
	if (id == Mute) { return "Mute"; }
	if (id == Select) { return "Select"; }
	if (id == FaderTouch) { return "Fader Touch"; }

	if (id == MasterFaderTouch) { return "Master Fader Touch"; }

	return "???";
}