Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
20 
21 #include <string>
22 
24 #include "ardour/types.h"
25 
26 namespace ARDOUR {
27 
28 class UI_TransportMaster;
29 
31 {
32  public:
35  TransportMasterManager& operator= (const TransportMasterManager&) = delete;
37 
39  void restart ();
40  void engine_stopped ();
41 
43  static void destroy();
44  /* this method is not thread-safe and is intended to be used only
45  * very early in application-lifetime to check if the TMM has
46  * been created yet. Do not use in other code.
47  */
48  static bool exists() { return _instance != 0; }
49 
50  typedef std::list<std::shared_ptr<TransportMaster> > TransportMasters;
51 
52  int add (SyncSource type, std::string const & name, bool removeable = true);
53  int remove (std::string const & name);
54  void clear (bool emit = true);
55 
56  PBD::Signal<void(std::shared_ptr<TransportMaster> )> Added;
57  PBD::Signal<void(std::shared_ptr<TransportMaster> )> Removed; // null argument means "clear"
58 
59  double pre_process_transport_masters (pframes_t, samplepos_t session_transport_position);
60 
61  double get_current_speed_in_process_context() const { return _master_speed; }
62  samplepos_t get_current_position_in_process_context() const { return _master_position; }
63 
64  std::shared_ptr<TransportMaster> current() const { return _current_master; }
65  int set_current (std::shared_ptr<TransportMaster>);
67  int set_current (std::string const &);
68 
69  PBD::Signal<void(std::shared_ptr<TransportMaster>, std::shared_ptr<TransportMaster> )> CurrentChanged;
70 
71  int set_state (XMLNode const &, int);
72  XMLNode& get_state() const;
73 
75  Session* session() const { return _session; }
76 
77  bool master_invalid_this_cycle() const { return _master_invalid_this_cycle; }
78 
79  std::shared_ptr<TransportMaster> master_by_type (SyncSource src) const;
80  std::shared_ptr<TransportMaster> master_by_name (std::string const &) const;
81  std::shared_ptr<TransportMaster> master_by_port (std::shared_ptr<Port> const &p) const;
82 
83  TransportMasters const & transport_masters() const { return _transport_masters; }
84 
85  static const std::string state_node_name;
86 
89  void reinit (double speed, samplepos_t pos);
90 
91  private:
93 
95  mutable Glib::Threads::RWLock lock;
96  double _master_speed;
98 
99  std::shared_ptr<TransportMaster> _current_master;
101 
104 
105  /* a DLL to chase the transport master, calculate playback speed
106  * by matching Ardour's current playhead position against
107  * the position of the transport-master */
108  double t0; // PH position at the beginning of this cycle
109  double t1; // expected PH position if next cycle
110  double e2; // second order loop error
111  double bandwidth; // DLL filter bandwidth
112  double b, c, omega; // DLL filter coefficients
113 
114  void init_transport_master_dll (double speed, samplepos_t pos);
115  int master_dll_initstate; // play-direction -1, +1, or 0: not initialized
116 
118 
119  /* original TC format in case the slave changed it */
120  std::optional<Timecode::TimecodeFormat> _session_tc_format;
123 
124  int add_locked (std::shared_ptr<TransportMaster>);
125  double compute_matching_master_speed (pframes_t nframes, samplepos_t, bool& locate_required);
126  int set_current_locked (std::shared_ptr<TransportMaster>);
127 
129  void parameter_changed (std::string const & what);
130 };
131 
132 } // namespace ARDOUR
133 
int set_current(std::shared_ptr< TransportMaster >)
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)
PBD::Signal< void(std::shared_ptr< TransportMaster >)> Removed
double compute_matching_master_speed(pframes_t nframes, samplepos_t, bool &locate_required)
PBD::Signal< void(std::shared_ptr< TransportMaster >, std::shared_ptr< TransportMaster >)> CurrentChanged
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
PBD::Signal< void(std::shared_ptr< TransportMaster >)> Added
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 >)
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
TransportMasterManager(const TransportMasterManager &)=delete
int add(SyncSource type, std::string const &name, bool removeable=true)
std::optional< Timecode::TimecodeFormat > _session_tc_format
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