summaryrefslogtreecommitdiffstats
path: root/src/track/beats.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/track/beats.h')
-rw-r--r--src/track/beats.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/track/beats.h b/src/track/beats.h
index 54afb8fb98..085edcb52a 100644
--- a/src/track/beats.h
+++ b/src/track/beats.h
@@ -15,7 +15,7 @@
namespace mixxx {
class Beats;
-typedef std::shared_ptr<Beats> BeatsPointer;
+typedef std::shared_ptr<const Beats> BeatsPointer;
class BeatIterator {
public:
@@ -27,10 +27,17 @@ class BeatIterator {
/// Beats is the base class for BPM and beat management classes. It provides a
/// specification of all methods a beat-manager class must provide, as well as
/// a capability model for representing optional features.
-class Beats {
+///
+/// All instances of this class are supposed to be managed by std::shared_ptr!
+class Beats : private std::enable_shared_from_this<Beats> {
public:
virtual ~Beats() = default;
+ BeatsPointer clonePointer() const {
+ // All instances are immutable and can be shared safely
+ return shared_from_this();
+ }
+
static mixxx::BeatsPointer fromByteArray(
mixxx::audio::SampleRate sampleRate,
const QString& beatsVersion,
@@ -166,10 +173,21 @@ class Beats {
virtual BeatsPointer scale(BpmScale scale) const = 0;
/// Adjust the beats so the global average BPM matches `bpm`.
- virtual BeatsPointer setBpm(mixxx::Bpm bpm) = 0;
+ virtual BeatsPointer setBpm(mixxx::Bpm bpm) const = 0;
protected:
+ /// Type tag for making public constructors of derived classes inaccessible.
+ ///
+ /// The constructors must be public for using std::make_shared().
+ struct MakeSharedTag {};
+
+ Beats() = default;
+
virtual bool isValid() const = 0;
+
+ private:
+ Beats(const Beats&) = delete;
+ Beats(Beats&&) = delete;
};
} // namespace mixxx