changes from torben for processor/plugin count determination and other fixes; rework...
[ardour.git] / libs / ardour / ardour / parameter.h
1 /*
2     Copyright (C) 2007 Paul Davis 
3     Author: Dave Robillard
4     
5     This program is free software; you can redistribute it and/or modify it
6     under the terms of the GNU General Public License as published by the Free
7     Software Foundation; either version 2 of the License, or (at your option)
8     any later version.
9     
10     This program is distributed in the hope that it will be useful, but WITHOUT
11     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13     for more details.
14     
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_parameter_h__
21 #define __ardour_parameter_h__
22
23 #include <string>
24 #include <pbd/compose.h>
25 #include <pbd/error.h>
26 #include <ardour/types.h>
27 #include <evoral/Parameter.hpp>
28 #include <evoral/MIDIParameters.hpp>
29
30 namespace ARDOUR {
31
32 /** ID of an automatable parameter.
33  *
34  * A given automatable object has a number of automatable parameters.  This is
35  * the unique ID for those parameters.  Anything automatable (AutomationList,
36  * Curve) must have unique Parameter ID with respect to it's Automatable parent.
37  *
38  * These are fast to compare, but passing a (const) reference around is
39  * probably more efficient than copying because the Parameter contains
40  * metadata not used for comparison.
41  *
42  * See evoral/Parameter.hpp for precise definition.
43  */
44 class Parameter : public Evoral::Parameter
45 {
46 public:
47         Parameter(AutomationType type = NullAutomation, uint32_t id=0, uint8_t channel=0)
48                 : Evoral::Parameter((uint32_t)type, id, channel)
49         {
50                 init_metadata(type);
51         }
52         
53         Parameter(const Evoral::Parameter& copy)
54                 : Evoral::Parameter(copy)
55         {
56         }
57         
58         static void init_metadata(AutomationType type) {
59                 double min    = 0.0f;
60                 double max    = 1.0f;
61                 double normal = 0.0f;
62                 switch(type) {
63                 case NullAutomation:
64                 case GainAutomation:
65                         max = 2.0f;
66                         normal = 1.0f;
67                         break;
68                 case PanAutomation:
69                         normal = 0.5f;
70                         break;
71                 case PluginAutomation:
72                 case SoloAutomation:
73                 case MuteAutomation:
74                 case FadeInAutomation:
75                 case FadeOutAutomation:
76                 case EnvelopeAutomation:
77                         max = 2.0f;
78                         normal = 1.0f;
79                         break;
80                 case MidiCCAutomation:
81                 case MidiPgmChangeAutomation:
82                 case MidiChannelPressureAutomation:
83                         Evoral::MIDI::controller_range(min, max, normal); break;
84                 case MidiPitchBenderAutomation:
85                         Evoral::MIDI::bender_range(min, max, normal); break;
86                 }
87                 set_range(type, min, max, normal);
88         }
89         
90         Parameter(const std::string& str);
91
92         inline AutomationType type() const { return (AutomationType)_type; }
93
94         std::string symbol() const;
95
96         inline bool is_integer() const {
97                 return (_type >= MidiCCAutomation && _type <= MidiChannelPressureAutomation);
98         }
99
100         inline operator Parameter() { return (Parameter)*this; }
101 };
102
103
104 } // namespace ARDOUR
105
106 #endif // __ardour_parameter_h__
107