summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/parameter.h
blob: dbcccd811f3d7189b2367649fc2deb2f502e5239 (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
/*
    Copyright (C) 2007 Paul Davis 
    Author: Dave Robillard
    
    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 __ardour_parameter_h__
#define __ardour_parameter_h__

#include <string>
#include <pbd/compose.h>
#include <pbd/error.h>
#include <ardour/types.h>
#include <evoral/Parameter.hpp>
#include <evoral/MIDIParameters.hpp>

namespace ARDOUR {

/** ID of an automatable parameter.
 *
 * A given automatable object has a number of automatable parameters.  This is
 * the unique ID for those parameters.  Anything automatable (AutomationList,
 * Curve) must have unique Parameter ID with respect to it's Automatable parent.
 *
 * These are fast to compare, but passing a (const) reference around is
 * probably more efficient than copying because the Parameter contains
 * metadata not used for comparison.
 *
 * See evoral/Parameter.hpp for precise definition.
 */
class Parameter : public Evoral::Parameter
{
public:
	Parameter(AutomationType type = NullAutomation, uint32_t id=0, uint8_t channel=0)
		: Evoral::Parameter((uint32_t)type, id, channel)
	{
		init(type);
	}
	
	Parameter(AutomationType type, double min, double max, double normal)
		: Evoral::Parameter((uint32_t)type, 0, 0, min, max, normal)
	{}
	
	Parameter(const Evoral::Parameter& copy)
		: Evoral::Parameter(copy)
	{
		init((AutomationType)_type);
	}
	
	void init(AutomationType type) {
		_normal = 0.0f;
		switch(type) {
		case NullAutomation:
		case GainAutomation:
			_min = 0.0f;
			_max = 2.0f;
			_normal = 1.0f;
			break;
		case PanAutomation:
			_min = 0.0f;
			_max = 1.0f;
			_normal = 0.5f;
		case PluginAutomation:
		case SoloAutomation:
		case MuteAutomation:
		case FadeInAutomation:
		case FadeOutAutomation:
		case EnvelopeAutomation:
			_min = 0.0f;
			_max = 2.0f;
			_normal = 1.0f;
		case MidiCCAutomation:
			Evoral::MIDI::ContinuousController::set_range(*this); break;
		case MidiPgmChangeAutomation:
			Evoral::MIDI::ProgramChange::set_range(*this); break;
		case MidiPitchBenderAutomation:
			Evoral::MIDI::PitchBender::set_range(*this); break;
		case MidiChannelAftertouchAutomation:
			Evoral::MIDI::ChannelAftertouch::set_range(*this); break;
		}
	}
	
	Parameter(const std::string& str);

	inline AutomationType type() const { return (AutomationType)_type; }

	std::string symbol() const;

	inline bool is_integer() const {
		return (_type >= MidiCCAutomation && _type <= MidiChannelAftertouchAutomation);
	}

	inline operator Parameter() { return (Parameter)*this; }
};


} // namespace ARDOUR

#endif // __ardour_parameter_h__