Ardour  8.12
transport_master_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Paul Davis <paul@linuxaudiosystems.com>
3  *
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.
8  *
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.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __ardour_transport_master_manager_h__
20 #define __ardour_transport_master_manager_h__
21 
22 #include <string>
23 
24 #include <boost/noncopyable.hpp>
25 
27 #include "ardour/types.h"
28 
29 namespace ARDOUR {
30 
31 class UI_TransportMaster;
32 
33 class LIBARDOUR_API TransportMasterManager : public boost::noncopyable
34 {
35  public:
38 
40  void restart ();
41  void engine_stopped ();
42 
44  static void destroy();
45  /* this method is not thread-safe and is intended to be used only
46  * very early in application-lifetime to check if the TMM has
47  * been created yet. Do not use in other code.
48  */
49  static bool exists() { return _instance != 0; }
50 
51  typedef std::list<std::shared_ptr<TransportMaster> > TransportMasters;
52 
53  int add (SyncSource type, std::string const & name, bool removeable = true);
54  int remove (std::string const & name);
55  void clear (bool emit = true);
56 
57  PBD::Signal1<void,std::shared_ptr<TransportMaster> > Added;
58  PBD::Signal1<void,std::shared_ptr<TransportMaster> > Removed; // null argument means "clear"
59 
60  double pre_process_transport_masters (pframes_t, samplepos_t session_transport_position);
61 
62  double get_current_speed_in_process_context() const { return _master_speed; }
63  samplepos_t get_current_position_in_process_context() const { return _master_position; }
64 
65  std::shared_ptr<TransportMaster> current() const { return _current_master; }
66  int set_current (std::shared_ptr<TransportMaster>);
68  int set_current (std::string const &);
69 
70  PBD::Signal2<void,std::shared_ptr<TransportMaster>, std::shared_ptr<TransportMaster> > CurrentChanged;
71 
72  int set_state (XMLNode const &, int);
73  XMLNode& get_state() const;
74 
76  Session* session() const { return _session; }
77 
78  bool master_invalid_this_cycle() const { return _master_invalid_this_cycle; }
79 
80  std::shared_ptr<TransportMaster> master_by_type (SyncSource src) const;
81  std::shared_ptr<TransportMaster> master_by_name (std::string const &) const;
82  std::shared_ptr<TransportMaster> master_by_port (std::shared_ptr<Port> const &p) const;
83 
84  TransportMasters const & transport_masters() const { return _transport_masters; }
85 
86  static const std::string state_node_name;
87 
90  void reinit (double speed, samplepos_t pos);
91 
92  private:
94 
96  mutable Glib::Threads::RWLock lock;
97  double _master_speed;
99 
100  std::shared_ptr<TransportMaster> _current_master;
102 
105 
106  /* a DLL to chase the transport master, calculate playback speed
107  * by matching Ardour's current playhead position against
108  * the position of the transport-master */
109  double t0; // PH position at the beginning of this cycle
110  double t1; // expected PH position if next cycle
111  double e2; // second order loop error
112  double bandwidth; // DLL filter bandwidth
113  double b, c, omega; // DLL filter coefficients
114 
115  void init_transport_master_dll (double speed, samplepos_t pos);
116  int master_dll_initstate; // play-direction -1, +1, or 0: not initialized
117 
119 
120  /* original TC format in case the slave changed it */
121  boost::optional<Timecode::TimecodeFormat> _session_tc_format;
124 
125  int add_locked (std::shared_ptr<TransportMaster>);
126  double compute_matching_master_speed (pframes_t nframes, samplepos_t, bool& locate_required);
127  int set_current_locked (std::shared_ptr<TransportMaster>);
128 
130  void parameter_changed (std::string const & what);
131 };
132 
133 } // namespace ARDOUR
134 
135 #endif /* __ardour_transport_master_manager_h__ */
int set_current(std::shared_ptr< TransportMaster >)
boost::optional< Timecode::TimecodeFormat > _session_tc_format
void init_transport_master_dll(double speed, samplepos_t pos)
int remove(std::string const &name)
std::shared_ptr< TransportMaster > master_by_name(std::string const &) const
double pre_process_transport_masters(pframes_t, samplepos_t session_transport_position)
double compute_matching_master_speed(pframes_t nframes, samplepos_t, bool &locate_required)
PBD::Signal1< void, std::shared_ptr< TransportMaster > > Added
int set_current(std::string const &)
std::shared_ptr< TransportMaster > master_by_type(SyncSource src) const
static TransportMasterManager & create()
void reinit(double speed, samplepos_t pos)
std::shared_ptr< TransportMaster > master_by_port(std::shared_ptr< Port > const &p) const
int add_locked(std::shared_ptr< TransportMaster >)
void clear(bool emit=true)
void parameter_changed(std::string const &what)
static TransportMasterManager * _instance
int set_current_locked(std::shared_ptr< TransportMaster >)
PBD::Signal2< void, std::shared_ptr< TransportMaster >, std::shared_ptr< TransportMaster > > CurrentChanged
PBD::Signal1< void, std::shared_ptr< TransportMaster > > Removed
static TransportMasterManager & instance()
int set_state(XMLNode const &, int)
TransportMasters const & transport_masters() const
samplepos_t get_current_position_in_process_context() const
std::list< std::shared_ptr< TransportMaster > > TransportMasters
std::shared_ptr< TransportMaster > current() const
int add(SyncSource type, std::string const &name, bool removeable=true)
std::shared_ptr< TransportMaster > _current_master
static const std::string state_node_name
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplepos_t samplepos_t