Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
20 
21 #include "pbd/signals.h"
22 #include "pbd/stateful.h"
23 
24 #include "temporal/types.h"
25 
26 namespace Temporal {
27 
29  public:
30  explicit TimeDomainProvider () : have_domain (false), parent (nullptr) {}
31  explicit TimeDomainProvider (TimeDomain td) : have_domain (true), domain (td), parent (nullptr) {}
32  TimeDomainProvider (TimeDomain td, TimeDomainProvider const & p) : have_domain (true), domain (td), parent (&p) { listen(); }
33 
34  /* Copy constructor - note how a constructor that only set the parent would have the same signature. */
35  TimeDomainProvider (TimeDomainProvider const & other) : have_domain (other.have_domain), domain (other.domain), parent (other.parent) { listen(); }
36 
37  /* The extra bool argument is just to differentiate this from the copy constructor above */
38  TimeDomainProvider (TimeDomainProvider const & parnt, bool) : have_domain (false), parent (&parnt) { listen(); }
39 
40  virtual ~TimeDomainProvider() {}
41 
42  /* replicates part of Stateful API but we do not want inheritance */
43 
44  XMLNode& get_state () const;
45  int set_state (const XMLNode&, int version);
46 
48  if (this != &other) {
50  have_domain = other.have_domain;
51  domain = other.domain;
52  parent = other.parent;
53  listen ();
54  }
55  return *this;
56  }
57 
58  TimeDomain time_domain() const { if (have_domain) return domain; if (parent) return parent->time_domain(); return AudioTime; }
59 
60  bool has_own_time_domain() const { return have_domain; }
61  void clear_time_domain () { have_domain = false; TimeDomainChanged(); /* EMIT SIGNAL */ }
62  void set_time_domain (TimeDomain td) { have_domain = true; domain = td; time_domain_changed(); TimeDomainChanged(); /* EMIT SIGNAL */}
63 
64  TimeDomainProvider const * time_domain_parent() const { return parent; }
65  bool has_time_domain_parent() const { return (bool) parent; }
66  void clear_time_domain_parent () { parent = nullptr; TimeDomainChanged (); /* EMIT SIGNAL */ }
69  TimeDomain old_domain = time_domain();
70  parent = &p;
71  have_domain = false;
72  TimeDomain new_domain = time_domain ();
73  if (old_domain != new_domain) {
75  }
76  }
77 
78  mutable PBD::Signal<void()> TimeDomainChanged;
79 
80  virtual void time_domain_changed() {
81  /* Forward a time domain change to children */
83  }
84 
85  protected:
86  void listen () {
87  if (parent) {
88  parent->TimeDomainChanged.connect_same_thread (parent_connection, std::bind (&TimeDomainProvider::time_domain_changed, this));
89  }
90  }
91 
92  private:
97 };
98 
99 }
100 
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::Signal< 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