Comment out excessive terminal output.
[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         : _type(NullAutomation)
30         , _id(0)
31         , _channel(0)
32 {
33         if (str == "gain") {
34                 _type = GainAutomation;
35         } else if (str == "solo") {
36                 _type = SoloAutomation;
37         } else if (str == "mute") {
38                 _type = MuteAutomation;
39         } else if (str == "fadein") {
40                 _type = FadeInAutomation;
41         } else if (str == "fadeout") {
42                 _type = FadeOutAutomation;
43         } else if (str == "envelope") {
44                 _type = EnvelopeAutomation;
45         } else if (str == "pan") {
46                 _type = PanAutomation;
47         } else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
48                 _type = PanAutomation;
49                 _id = atoi(str.c_str()+4);
50         } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
51                 _type = PluginAutomation;
52                 _id = atoi(str.c_str()+10);
53         } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
54                 _type = MidiCCAutomation;
55                 uint32_t channel = 0;
56                 sscanf(str.c_str(), "midicc-%d-%d", &channel, &_id);
57                 assert(channel < 16);
58                 _channel = channel;
59         } else {
60                 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
61         }
62 }
63
64
65 /** Unique string representation, suitable as an XML property value.
66  * e.g. <AutomationList automation-id="whatthisreturns">
67  */
68 std::string
69 Parameter::to_string() const
70 {
71         if (_type == GainAutomation) {
72                 return "gain";
73         } else if (_type == PanAutomation) {
74                 return string_compose("pan-%1", _id);
75         } else if (_type == SoloAutomation) {
76                 return "solo";
77         } else if (_type == MuteAutomation) {
78                 return "mute";
79         } else if (_type == FadeInAutomation) {
80                 return "fadein";
81         } else if (_type == FadeOutAutomation) {
82                 return "fadeout";
83         } else if (_type == EnvelopeAutomation) {
84                 return "envelope";
85         } else if (_type == PluginAutomation) {
86                 return string_compose("parameter-%1", _id);
87         } else if (_type == MidiCCAutomation) {
88                 return string_compose("midicc-%1-%2", int(_channel), _id);
89         } else if (_type == MidiPgmChangeAutomation) {
90                 return string_compose("midi-pgm-change-%1", int(_channel));
91         } else if (_type == MidiPitchBenderAutomation) {
92                 return string_compose("midi-pitch-bender-%1", int(_channel));
93         } else if (_type == MidiChannelAftertouchAutomation) {
94                 return string_compose("midi-channel-aftertouch-%1", int(_channel));
95         } else {
96                 PBD::warning << "Uninitialized Parameter to_string() called." << endmsg;
97                 return "";
98         }
99 }
100