don't attempt MIDI playback if there are no MIDI buffers provided for processing
[ardour.git] / libs / evoral / src / Control.cpp
1 /* This file is part of Evoral.
2  * Copyright (C) 2008 David Robillard <http://drobilla.net>
3  * Copyright (C) 2000-2008 Paul Davis
4  *
5  * Evoral is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or (at your option) any later
8  * version.
9  *
10  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 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  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include <iostream>
20
21 #include "evoral/Control.hpp"
22 #include "evoral/ControlList.hpp"
23 #include "evoral/ParameterDescriptor.hpp"
24 #include "evoral/TypeMap.hpp"
25
26 namespace Evoral {
27
28 Control::Control(const Parameter&               parameter,
29                  const ParameterDescriptor&     desc,
30                  boost::shared_ptr<ControlList> list)
31         : _parameter(parameter)
32         , _user_value(desc.normal)
33 {
34         set_list (list);
35 }
36
37
38 /** Get the currently effective value (ie the one that corresponds to current output)
39  */
40 double
41 Control::get_double (bool from_list, double frame) const
42 {
43         if (from_list) {
44                 return _list->eval(frame);
45         } else {
46                 return _user_value;
47         }
48 }
49
50
51 void
52 Control::set_double (double value, double frame, bool to_list)
53 {
54         _user_value = value;
55
56         /* if we're in a write pass, the automation watcher will determine the
57            values and add them to the list, so we we don't need to bother.
58         */
59
60         if (to_list && (!_list->in_write_pass() || _list->descriptor().toggled)) {
61                 _list->add (frame, value, false);
62         }
63 }
64
65
66 void
67 Control::set_list(boost::shared_ptr<ControlList> list)
68 {
69         _list_marked_dirty_connection.disconnect ();
70
71         _list = list;
72
73         if (_list) {
74                 _list->Dirty.connect_same_thread (_list_marked_dirty_connection, boost::bind (&Control::list_marked_dirty, this));
75         }
76 }
77
78 void
79 Control::list_marked_dirty ()
80 {
81         ListMarkedDirty (); /* EMIT SIGNAL */
82 }
83
84 } // namespace Evoral
85