Fix merge regression: use TempoLines class instead of same built in to editor.
[ardour.git] / libs / ardour / parameter.cc
1 /*
2     Copyright (C) 2008 Paul Davis 
3     Written by Dave Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <ardour/parameter.h>
21
22 using namespace ARDOUR;
23         
24
25 /** Construct an Parameter from a string returned from Parameter::to_string
26  * (AutomationList automation-id property)
27  */
28 Parameter::Parameter(const std::string& str)
29         : Evoral::Parameter (NullAutomation, 0)
30 {
31         if (str == "gain") {
32                 _type = GainAutomation;
33         } else if (str == "solo") {
34                 _type = SoloAutomation;
35         } else if (str == "mute") {
36                 _type = MuteAutomation;
37         } else if (str == "fadein") {
38                 _type = FadeInAutomation;
39         } else if (str == "fadeout") {
40                 _type = FadeOutAutomation;
41         } else if (str == "envelope") {
42                 _type = EnvelopeAutomation;
43         } else if (str == "pan") {
44                 _type = PanAutomation;
45         } else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
46                 _type = PanAutomation;
47                 _id = atoi(str.c_str()+4);
48         } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
49                 _type = PluginAutomation;
50                 _id = atoi(str.c_str()+10);
51         } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
52                 _type = MidiCCAutomation;
53                 uint32_t channel = 0;
54                 sscanf(str.c_str(), "midicc-%d-%d", &channel, &_id);
55                 assert(channel < 16);
56                 _channel = channel;
57         } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
58                 _type = MidiPgmChangeAutomation;
59                 uint32_t channel = 0;
60                 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
61                 assert(channel < 16);
62                 _id = 0;
63                 _channel = channel;
64         } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
65                 _type = MidiPitchBenderAutomation;
66                 uint32_t channel = 0;
67                 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
68                 assert(channel < 16);
69                 _id = 0;
70                 _channel = channel;
71         } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") {
72                 _type = MidiChannelPressureAutomation;
73                 uint32_t channel = 0;
74                 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
75                 assert(channel < 16);
76                 _id = 0;
77                 _channel = channel;
78         } else {
79                 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
80         }
81
82         init_metadata((AutomationType)_type); // set min/max/normal
83 }
84
85
86 /** Unique string representation, suitable as an XML property value.
87  * e.g. <AutomationList automation-id="whatthisreturns">
88  */
89 std::string
90 Parameter::symbol() const
91 {
92         if (_type == GainAutomation) {
93                 return "gain";
94         } else if (_type == PanAutomation) {
95                 return string_compose("pan-%1", _id);
96         } else if (_type == SoloAutomation) {
97                 return "solo";
98         } else if (_type == MuteAutomation) {
99                 return "mute";
100         } else if (_type == FadeInAutomation) {
101                 return "fadein";
102         } else if (_type == FadeOutAutomation) {
103                 return "fadeout";
104         } else if (_type == EnvelopeAutomation) {
105                 return "envelope";
106         } else if (_type == PluginAutomation) {
107                 return string_compose("parameter-%1", _id);
108         } else if (_type == MidiCCAutomation) {
109                 return string_compose("midicc-%1-%2", int(_channel), _id);
110         } else if (_type == MidiPgmChangeAutomation) {
111                 return string_compose("midi-pgm-change-%1", int(_channel));
112         } else if (_type == MidiPitchBenderAutomation) {
113                 return string_compose("midi-pitch-bender-%1", int(_channel));
114         } else if (_type == MidiChannelPressureAutomation) {
115                 return string_compose("midi-channel-pressure-%1", int(_channel));
116         } else {
117                 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
118                 return "";
119         }
120 }
121