Ardour  8.7-14-g57a6773833
domain_provider.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2023 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
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 
19 #ifndef __temporal_domain_provider_h__
20 #define __temporal_domain_provider_h__
21 
22 #include "pbd/signals.h"
23 #include "pbd/stateful.h"
24 
25 #include "temporal/types.h"
26 
27 namespace Temporal {
28 
30  public:
31  explicit TimeDomainProvider () : have_domain (false), parent (nullptr) {}
32  explicit TimeDomainProvider (TimeDomain td) : have_domain (true), domain (td), parent (nullptr) {}
33  TimeDomainProvider (TimeDomain td, TimeDomainProvider const & p) : have_domain (true), domain (td), parent (&p) { listen(); }
34 
35  /* Copy constructor - note how a constructor that only set the parent would have the same signature. */
36  TimeDomainProvider (TimeDomainProvider const & other) : have_domain (other.have_domain), domain (other.domain), parent (other.parent) { listen(); }
37 
38  /* The extra bool argument is just to differentiate this from the copy constructor above */
39  TimeDomainProvider (TimeDomainProvider const & parnt, bool) : have_domain (false), parent (&parnt) { listen(); }
40 
41  virtual ~TimeDomainProvider() {}
42 
43  /* replicates part of Stateful API but we do not want inheritance */
44 
45  XMLNode& get_state () const;
46  int set_state (const XMLNode&, int version);
47 
49  if (this != &other) {
51  have_domain = other.have_domain;
52  domain = other.domain;
53  parent = other.parent;
54  listen ();
55  }
56  return *this;
57  }
58 
59  TimeDomain time_domain() const { if (have_domain) return domain; if (parent) return parent->time_domain(); return AudioTime; }
60 
61  bool has_own_time_domain() const { return have_domain; }
62  void clear_time_domain () { have_domain = false; TimeDomainChanged(); /* EMIT SIGNAL */ }
63  void set_time_domain (TimeDomain td) { have_domain = true; domain = td; time_domain_changed(); TimeDomainChanged(); /* EMIT SIGNAL */}
64 
65  TimeDomainProvider const * time_domain_parent() const { return parent; }
66  bool has_time_domain_parent() const { return (bool) parent; }
67  void clear_time_domain_parent () { parent = nullptr; TimeDomainChanged (); /* EMIT SIGNAL */ }
70  TimeDomain old_domain = time_domain();
71  parent = &p;
72  have_domain = false;
73  TimeDomain new_domain = time_domain ();
74  if (old_domain != new_domain) {
76  }
77  }
78 
79  mutable PBD::Signal0<void> TimeDomainChanged;
80 
81  virtual void time_domain_changed() {
82  /* Forward a time domain change to children */
84  }
85 
86  protected:
87  void listen () {
88  if (parent) {
89  parent->TimeDomainChanged.connect_same_thread (parent_connection, boost::bind (&TimeDomainProvider::time_domain_changed, this));
90  }
91  }
92 
93  private:
98 };
99 
100 }
101 
102 #endif /* __temporal_domain_provider_h__ */
void set_time_domain_parent(TimeDomainProvider const &p)
virtual void time_domain_changed()
TimeDomain time_domain() const
int set_state(const XMLNode &, int version)
TimeDomainProvider const * parent
TimeDomainProvider const * time_domain_parent() const
void set_time_domain(TimeDomain td)
PBD::Signal0< void > TimeDomainChanged
TimeDomainProvider(TimeDomainProvider const &other)
TimeDomainProvider & operator=(TimeDomainProvider const &other)
TimeDomainProvider(TimeDomain td, TimeDomainProvider const &p)
XMLNode & get_state() const
TimeDomainProvider(TimeDomainProvider const &parnt, bool)
PBD::ScopedConnection parent_connection
Definition: xml++.h:114