2 * Copyright (C) 2018 Paul Davis (paul@linuxaudiosystems.com)
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, or (at your option)
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 Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __ardour_transport_master_manager_h__
20 #define __ardour_transport_master_manager_h__
24 #include <boost/noncopyable.hpp>
26 #include "ardour/transport_master.h"
27 #include "ardour/types.h"
31 class UI_TransportMaster;
33 class LIBARDOUR_API TransportMasterManager : public boost::noncopyable
36 ~TransportMasterManager ();
38 int set_default_configuration ();
40 static TransportMasterManager& instance();
41 /* this method is not thread-safe and is intended to be used only
42 * very early in application-lifetime to check if the TMM has
43 * been created yet. Do not use in other code.
45 static bool exists() { return _instance != 0; }
47 typedef std::list<boost::shared_ptr<TransportMaster> > TransportMasters;
49 int add (SyncSource type, std::string const & name, bool removeable = true);
50 int remove (std::string const & name);
53 PBD::Signal1<void,boost::shared_ptr<TransportMaster> > Added;
54 PBD::Signal1<void,boost::shared_ptr<TransportMaster> > Removed; // null argument means "clear"
56 double pre_process_transport_masters (pframes_t, samplepos_t session_transport_position);
58 double get_current_speed_in_process_context() const { return _master_speed; }
59 samplepos_t get_current_position_in_process_context() const { return _master_position; }
61 boost::shared_ptr<TransportMaster> current() const { return _current_master; }
62 int set_current (boost::shared_ptr<TransportMaster>);
63 int set_current (SyncSource);
64 int set_current (std::string const &);
66 PBD::Signal2<void,boost::shared_ptr<TransportMaster>, boost::shared_ptr<TransportMaster> > CurrentChanged;
68 int set_state (XMLNode const &, int);
71 void set_session (Session*);
72 Session* session() const { return _session; }
74 bool master_invalid_this_cycle() const { return _master_invalid_this_cycle; }
76 boost::shared_ptr<TransportMaster> master_by_type (SyncSource src) const;
77 boost::shared_ptr<TransportMaster> master_by_name (std::string const &) const;
79 TransportMasters const & transport_masters() const { return _transport_masters; }
81 static const std::string state_node_name;
84 TransportMasterManager();
86 TransportMasters _transport_masters;
87 mutable Glib::Threads::RWLock lock;
89 samplepos_t _master_position;
90 boost::shared_ptr<TransportMaster> _current_master;
93 bool _master_invalid_this_cycle;
95 // a DLL to chase the transport master
97 int transport_dll_initstate;
98 double t0; /// time at the beginning of ???
99 double t1; /// calculated end of the ???
100 double e2; /// second order loop error
101 double bandwidth; /// DLL filter bandwidth
102 double b, c, omega; /// DLL filter coefficients
104 void init_transport_master_dll (double speed, samplepos_t pos);
105 int master_dll_initstate;
107 static TransportMasterManager* _instance;
109 int add_locked (boost::shared_ptr<TransportMaster>);
110 double compute_matching_master_speed (pframes_t nframes, samplepos_t, bool& locate_required);
111 int set_current_locked (boost::shared_ptr<TransportMaster>);
113 PBD::ScopedConnection config_connection;
114 void parameter_changed (std::string const & what);
117 } // namespace ARDOUR
119 #endif /* __ardour_transport_master_manager_h__ */