fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / monitor_control.cc
1 /*
2     Copyright (C) 2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "ardour/monitor_control.h"
20
21 #include "pbd/i18n.h"
22
23 using namespace ARDOUR;
24 using namespace PBD;
25
26 MonitorControl::MonitorControl (Session& session, std::string const & name, Monitorable& m)
27         : SlavableAutomationControl (session, MonitoringAutomation, ParameterDescriptor (MonitoringAutomation),
28                                      boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(MonitoringAutomation))),
29                                      name)
30
31         , _monitorable (m)
32         , _monitoring (MonitorAuto)
33 {
34         _list->set_interpolation(Evoral::ControlList::Discrete);
35         /* monitoring changes must be synchronized by the process cycle */
36         set_flags (Controllable::Flag (flags() | Controllable::RealTime));
37 }
38
39 void
40 MonitorControl::actually_set_value (double val, Controllable::GroupControlDisposition gcd)
41 {
42         int v = (int) val;
43         switch (v) {
44         case MonitorAuto:
45         case MonitorInput:
46         case MonitorDisk:
47         case MonitorCue:
48                 break;
49         default:
50                 /* illegal value */
51                 return;
52         }
53
54         _monitoring = MonitorChoice (v);
55         AutomationControl::actually_set_value (val, gcd);
56 }
57
58 XMLNode&
59 MonitorControl::get_state ()
60 {
61         XMLNode& node (SlavableAutomationControl::get_state());
62         node.add_property (X_("monitoring"), enum_2_string (_monitoring));
63         return node;
64 }
65
66 int
67 MonitorControl::set_state (XMLNode const & node, int version)
68 {
69         SlavableAutomationControl::set_state (node, version);
70
71         const XMLProperty* prop;
72
73         if ((prop = node.property (X_("monitoring"))) != 0) {
74                 _monitoring = MonitorChoice (string_2_enum (prop->value(), _monitoring));
75         } else {
76                 _monitoring = MonitorAuto;
77         }
78
79         return 0;
80 }