2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/compose.h"
24 #include "ardour/automation_control.h"
25 #include "ardour/automation_watch.h"
26 #include "ardour/debug.h"
27 #include "ardour/session.h"
29 using namespace ARDOUR;
34 AutomationWatch* AutomationWatch::_instance = 0;
37 AutomationWatch::instance ()
40 _instance = new AutomationWatch;
45 AutomationWatch::AutomationWatch ()
52 AutomationWatch::~AutomationWatch ()
60 Glib::Threads::Mutex::Lock lm (automation_watch_lock);
61 automation_watches.clear ();
65 AutomationWatch::add_automation_watch (boost::shared_ptr<AutomationControl> ac)
67 Glib::Threads::Mutex::Lock lm (automation_watch_lock);
68 DEBUG_TRACE (DEBUG::Automation, string_compose ("now watching control %1 for automation\n", ac->name()));
69 automation_watches.push_back (ac);
71 /* if an automation control is added here while the transport is
72 * rolling, make sure that it knows that there is a write pass going
73 * on, rather than waiting for the transport to start.
76 if (_session && _session->transport_rolling() && ac->alist()->automation_write()) {
77 DEBUG_TRACE (DEBUG::Automation, string_compose ("\ttransport is rolling @ %1, so enter write pass\n", _session->transport_speed()));
78 ac->list()->set_in_write_pass (true);
81 /* we can't store shared_ptr<Destructible> in connections because it
82 * creates reference cycles. we don't need to make the weak_ptr<>
83 * explicit here, but it helps to remind us what is going on.
86 boost::weak_ptr<AutomationControl> wac (ac);
87 ac->DropReferences.connect_same_thread (*this, boost::bind (&AutomationWatch::remove_weak_automation_watch, this, wac));
91 AutomationWatch::remove_weak_automation_watch (boost::weak_ptr<AutomationControl> wac)
93 boost::shared_ptr<AutomationControl> ac = wac.lock();
99 remove_automation_watch (ac);
103 AutomationWatch::remove_automation_watch (boost::shared_ptr<AutomationControl> ac)
105 Glib::Threads::Mutex::Lock lm (automation_watch_lock);
106 DEBUG_TRACE (DEBUG::Automation, string_compose ("remove control %1 from automation watch\n", ac->name()));
107 automation_watches.remove (ac);
108 ac->list()->set_in_write_pass (false);
112 AutomationWatch::timer ()
114 if (!_session || !_session->transport_rolling()) {
119 Glib::Threads::Mutex::Lock lm (automation_watch_lock);
121 framepos_t time = _session->audible_frame ();
123 for (AutomationWatches::iterator aw = automation_watches.begin(); aw != automation_watches.end(); ++aw) {
124 if ((*aw)->alist()->automation_write()) {
125 (*aw)->list()->add (time, (*aw)->user_double());
134 AutomationWatch::thread ()
136 while (_run_thread) {
137 usleep (100000); // Config->get_automation_interval() * 10);
143 AutomationWatch::set_session (Session* s)
145 transport_connection.disconnect ();
153 SessionHandlePtr::set_session (s);
157 _thread = Glib::Threads::Thread::create (boost::bind (&AutomationWatch::thread, this));
159 _session->TransportStateChange.connect_same_thread (transport_connection, boost::bind (&AutomationWatch::transport_state_change, this));
164 AutomationWatch::transport_state_change ()
170 bool rolling = _session->transport_rolling();
173 Glib::Threads::Mutex::Lock lm (automation_watch_lock);
175 for (AutomationWatches::iterator aw = automation_watches.begin(); aw != automation_watches.end(); ++aw) {
176 DEBUG_TRACE (DEBUG::Automation, string_compose ("%1: transport state changed, speed %2, in write pass ? %3 writing ? %4\n",
177 (*aw)->name(), _session->transport_speed(), rolling,
178 (*aw)->alist()->automation_write()));
179 if (rolling && (*aw)->alist()->automation_write()) {
180 (*aw)->list()->set_in_write_pass (true);
182 (*aw)->list()->set_in_write_pass (false);