Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/track/beats.h

Go to the documentation of this file.
00001 #ifndef BEATS_H
00002 #define BEATS_H
00003 
00004 #include <QString>
00005 #include <QList>
00006 #include <QByteArray>
00007 #include <QSharedPointer>
00008 
00009 class Beats;
00010 typedef QSharedPointer<Beats> BeatsPointer;
00011 
00012 // QList's are attractive because they pre-allocate an internal buffer that is
00013 // not free'd after a clear(). The downside is that they do not necessarily
00014 // store adjecent items in adjacent memory locations.
00015 typedef QList<double> BeatList;
00016 
00017 // Beats is a pure abstract base class for BPM and beat management classes. It
00018 // provides a specification of all methods a beat-manager class must provide, as
00019 // well as a capability model for representing optional features.
00020 class Beats {
00021   public:
00022     Beats() { }
00023     virtual ~Beats() { }
00024 
00025     enum Capabilities {
00026         BEATSCAP_NONE          = 0x0000,
00027         BEATSCAP_ADDREMOVE     = 0x0001,
00028         BEATSCAP_TRANSLATE     = 0x0002,
00029         BEATSCAP_SCALE         = 0x0004,
00030         BEATSCAP_MOVEBEAT      = 0x0008
00031     };
00032     typedef int CapabilitiesFlags; // Allows us to do ORing
00033 
00034     virtual Beats::CapabilitiesFlags getCapabilities() const = 0;
00035 
00036     // Serialization
00037     virtual QByteArray* toByteArray() const = 0;
00038 
00039     // A string representing the version of the beat-processing code that
00040     // produced this Beats instance. Used by BeatsFactory for associating a
00041     // given serialization with the version that produced it.
00042     virtual QString getVersion() const = 0;
00043 
00045     // Beat calculations
00047 
00048     // Starting from sample dSamples, return the sample of the next beat in the
00049     // track, or -1 if none exists. If dSamples refers to the location of a
00050     // beat, dSamples is returned.
00051     virtual double findNextBeat(double dSamples) const = 0;
00052 
00053     // Starting from sample dSamples, return the sample of the previous beat in
00054     // the track, or -1 if none exists. If dSamples refers to the location of
00055     // beat, dSamples is returned.
00056     virtual double findPrevBeat(double dSamples) const = 0;
00057 
00058     // Starting from sample dSamples, return the sample of the closest beat in
00059     // the track, or -1 if none exists.
00060     virtual double findClosestBeat(double dSamples) const = 0;
00061 
00062     // Find the Nth beat from sample dSamples. Works with both positive and
00063     // negative values of n. Calling findNthBeat with n=0 is invalid. Calling
00064     // findNthBeat with n=1 or n=-1 is equivalent to calling findNextBeat and
00065     // findPrevBeat, respectively. If dSamples refers to the location of a beat,
00066     // then dSamples is returned. If no beat can be found, returns -1.<
00067     virtual double findNthBeat(double dSamples, int n) const = 0;
00068 
00069     // Adds to pBeatsList the position in samples of every beat occuring between
00070     // startPosition and endPosition
00071     virtual void findBeats(double startSample, double stopSample, BeatList* pBeatsList) const = 0;
00072 
00073     // Return whether or not a sample lies between startPosition and endPosition
00074     virtual bool hasBeatInRange(double startSample, double stopSample) const = 0;
00075 
00076     // Return the average BPM over the entire track if the BPM is
00077     // valid, otherwise returns -1
00078     virtual double getBpm() const = 0;
00079 
00080     // Return the average BPM over the range from startSample to endSample,
00081     // specified in samples if the BPM is valid, otherwise returns -1
00082     virtual double getBpmRange(double startSample, double stopSample) const = 0;
00083 
00085     // Beat mutations
00087 
00088     // Add a beat at location dBeatSample. Beats instance must have the
00089     // capability BEATSCAP_ADDREMOVE.
00090     virtual void addBeat(double dBeatSample) = 0;
00091 
00092     // Remove a beat at location dBeatSample. Beats instance must have the
00093     // capability BEATSCAP_ADDREMOVE.
00094     virtual void removeBeat(double dBeatSample) = 0;
00095 
00096     // Translate all beats in the song by dNumSamples samples. Beats that lie
00097     // before the start of the track or after the end of the track are not
00098     // removed. Beats instance must have the capability BEATSCAP_TRANSLATE.
00099     virtual void translate(double dNumSamples) = 0;
00100 
00101     // Scale the position of every beat in the song by dScalePercentage. Beats
00102     // class must have the capability BEATSCAP_SCALE.
00103     virtual void scale(double dScalePercentage) = 0;
00104 };
00105 
00106 #endif /* BEATS_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines