improved/new DEBUG_TRACE output
[ardour.git] / libs / evoral / Control.cc
1 /*
2  * Copyright (C) 2008-2016 David Robillard <d@drobilla.net>
3  * Copyright (C) 2010-2014 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <iostream>
23
24 #include "evoral/Control.h"
25 #include "evoral/ControlList.h"
26 #include "evoral/ParameterDescriptor.h"
27 #include "evoral/TypeMap.h"
28
29 namespace Evoral {
30
31 Control::Control(const Parameter&               parameter,
32                  const ParameterDescriptor&     desc,
33                  boost::shared_ptr<ControlList> list)
34         : _parameter(parameter)
35         , _user_value(desc.normal)
36 {
37         set_list (list);
38 }
39
40
41 /** Get the currently effective value (ie the one that corresponds to current output)
42  */
43 double
44 Control::get_double (bool from_list, double frame) const
45 {
46         if (from_list) {
47                 return _list->eval(frame);
48         } else {
49                 return _user_value;
50         }
51 }
52
53
54 void
55 Control::set_double (double value, double frame, bool to_list)
56 {
57         _user_value = value;
58
59         /* if we're in a write pass, the automation watcher will determine the
60            values and add them to the list, so we we don't need to bother.
61         */
62
63         if (to_list && (!_list->in_write_pass() || _list->descriptor().toggled)) {
64                 _list->add (frame, value, false);
65         }
66 }
67
68
69 void
70 Control::set_list(boost::shared_ptr<ControlList> list)
71 {
72         _list_marked_dirty_connection.disconnect ();
73
74         _list = list;
75
76         if (_list) {
77                 _list->Dirty.connect_same_thread (_list_marked_dirty_connection, boost::bind (&Control::list_marked_dirty, this));
78         }
79 }
80
81 void
82 Control::list_marked_dirty ()
83 {
84         ListMarkedDirty (); /* EMIT SIGNAL */
85 }
86
87 } // namespace Evoral
88