Reduce overhead of multi-type-ness (last Summer's SoC):
[ardour.git] / libs / ardour / automation_control.cc
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
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
21 #include <iostream>
22 #include <ardour/automation_control.h>
23 #include <ardour/session.h>
24 #include <ardour/automatable.h>
25
26 using namespace std;
27 using namespace ARDOUR;
28 using namespace PBD;
29
30
31 AutomationControl::AutomationControl(Session& session, boost::shared_ptr<AutomationList> list, string name)
32         : Controllable((name == "unnamed controllable") ? list->param_id().to_string() : name)
33         , _session(session)
34         , _list(list)
35         , _user_value(list->default_value())
36 {
37         cerr << "Created AutomationControl " << name << "(" << list->param_id().to_string() << ")" << endl;
38 }
39
40
41 /** Get the currently effective value (ie the one that corresponds to current output)
42  */
43 float
44 AutomationControl::get_value() const
45 {
46         if (_list->automation_playback())
47                 return _list->eval(_session.transport_frame());
48         else
49                 return _user_value;
50 }
51
52
53 void
54 AutomationControl::set_value(float value)
55 {
56         _user_value = value;
57         
58         if (_session.transport_stopped() && _list->automation_write())
59                 _list->add(_session.transport_frame(), value);
60
61         Changed(); /* EMIT SIGNAL */
62 }
63
64
65 /** Get the latest user-set value, which may not equal get_value() when automation
66  * is playing back, etc.
67  *
68  * Automation write/touch works by periodically sampling this value and adding it
69  * to the AutomationList.
70  */
71 float
72 AutomationControl::user_value() const
73 {
74         return _user_value;
75 }
76         
77
78 void
79 AutomationControl::set_list(boost::shared_ptr<ARDOUR::AutomationList> list)
80 {
81         _list = list;
82         _user_value = list->default_value();
83         Changed();  /* EMIT SIGNAL */
84 }
85