Merged with trunk R1612.
[ardour.git] / libs / ardour / ardour / tempo.h
index 2f04f603e78be13a8a2836209490259c238e82aa..5e3e93e48b8595ac6f2be64b2435d16a9f59d343 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __ardour_tempo_h__
 #include <string>
 #include <vector>
 #include <cmath>
-#include <pthread.h>
-#include <pbd/lockmonitor.h>
+#include <glibmm/thread.h>
+
 #include <pbd/undo.h>
+#include <pbd/stateful.h> 
+#include <pbd/statefuldestructible.h> 
+
 #include <sigc++/signal.h>
 
 #include <ardour/ardour.h>
-#include <ardour/stateful.h>
-#include <ardour/state_manager.h>
 
 class XMLNode;
 
@@ -55,7 +55,7 @@ class Tempo {
        }
 
        double beats_per_minute () const { return _beats_per_minute; }
-       double frames_per_beat (jack_nframes_t sr) const {
+       double frames_per_beat (nframes_t sr) const {
                return  ((60.0 * sr) / _beats_per_minute);
        }
 
@@ -83,7 +83,7 @@ class Meter {
        double beats_per_bar () const { return _beats_per_bar; }
        double note_divisor() const { return _note_type; }
        
-       double frames_per_bar (const Tempo&, jack_nframes_t sr) const;
+       double frames_per_bar (const Tempo&, nframes_t sr) const;
 
   protected:
 
@@ -110,12 +110,12 @@ class MetricSection {
        virtual ~MetricSection() {}
 
        const BBT_Time& start() const { return _start; }
-       const jack_nframes_t frame() const { return _frame; }
+       const nframes_t frame() const { return _frame; }
 
        void set_movable (bool yn) { _movable = yn; }
        bool movable() const { return _movable; }
 
-       virtual void set_frame (jack_nframes_t f) {
+       virtual void set_frame (nframes_t f) {
                _frame = f;
        };
 
@@ -132,7 +132,7 @@ class MetricSection {
 
   private:
        BBT_Time       _start;
-       jack_nframes_t _frame;
+       nframes_t _frame;
        bool           _movable;
 };
 
@@ -160,20 +160,11 @@ class TempoSection : public MetricSection, public Tempo {
 
 typedef list<MetricSection*> Metrics;
 
-class TempoMapState : public StateManager::State {
-  public:
-       TempoMapState (std::string why) 
-               : StateManager::State (why) {
-               metrics = new Metrics;
-       }
-
-       Metrics *metrics;
-};
-
-class TempoMap : public Stateful, public StateManager {
+class TempoMap : public PBD::StatefulDestructible
+{
   public:
 
-       TempoMap (jack_nframes_t frame_rate);
+       TempoMap (nframes_t frame_rate);
        ~TempoMap();
 
        /* measure-based stuff */
@@ -185,34 +176,34 @@ class TempoMap : public Stateful, public StateManager {
 
        struct BBTPoint {
            BBTPointType type;
-           jack_nframes_t frame;
+           nframes_t frame;
            const Meter* meter;
            const Tempo* tempo;
            uint32_t bar;
            uint32_t beat;
            
-           BBTPoint (const Meter& m, const Tempo& t, jack_nframes_t f, BBTPointType ty, uint32_t b, uint32_t e) 
+           BBTPoint (const Meter& m, const Tempo& t, nframes_t f, BBTPointType ty, uint32_t b, uint32_t e) 
                    : type (ty), frame (f), meter (&m), tempo (&t), bar (b), beat (e) {}
        };
 
        typedef vector<BBTPoint> BBTPointList;
        
        template<class T> void apply_with_metrics (T& obj, void (T::*method)(const Metrics&)) {
-               LockMonitor lm (lock, __LINE__, __FILE__);
+               Glib::RWLock::ReaderLock lm (lock);
                (obj.*method)(*metrics);
        }
 
-       BBTPointList *get_points (jack_nframes_t start, jack_nframes_t end) const;
+       BBTPointList *get_points (nframes_t start, nframes_t end) const;
 
-       void           bbt_time (jack_nframes_t when, BBT_Time&) const;
-       jack_nframes_t frame_time (const BBT_Time&) const;
-       jack_nframes_t bbt_duration_at (jack_nframes_t, const BBT_Time&, int dir) const;
+       void           bbt_time (nframes_t when, BBT_Time&) const;
+       nframes_t frame_time (const BBT_Time&) const;
+       nframes_t bbt_duration_at (nframes_t, const BBT_Time&, int dir) const;
 
        static const Tempo& default_tempo() { return _default_tempo; }
        static const Meter& default_meter() { return _default_meter; }
 
-       const Tempo& tempo_at (jack_nframes_t);
-       const Meter& meter_at (jack_nframes_t);
+       const Tempo& tempo_at (nframes_t);
+       const Meter& meter_at (nframes_t);
 
        void add_tempo(const Tempo&, BBT_Time where);
        void add_meter(const Meter&, BBT_Time where);
@@ -227,15 +218,15 @@ class TempoMap : public Stateful, public StateManager {
        void replace_meter (MeterSection& existing, const Meter& replacement);
 
 
-       jack_nframes_t round_to_bar  (jack_nframes_t frame, int dir);
+       nframes_t round_to_bar  (nframes_t frame, int dir);
 
-       jack_nframes_t round_to_beat (jack_nframes_t frame, int dir);
+       nframes_t round_to_beat (nframes_t frame, int dir);
 
-       jack_nframes_t round_to_beat_subdivision (jack_nframes_t fr, int sub_num);
+       nframes_t round_to_beat_subdivision (nframes_t fr, int sub_num);
 
-       jack_nframes_t round_to_tick (jack_nframes_t frame, int dir);
+       nframes_t round_to_tick (nframes_t frame, int dir);
 
-       void set_length (jack_nframes_t frames);
+       void set_length (nframes_t frames);
 
        XMLNode& get_state (void);
        int set_state (const XMLNode&);
@@ -243,8 +234,6 @@ class TempoMap : public Stateful, public StateManager {
        void dump (std::ostream&) const;
        void clear ();
 
-       UndoAction get_memento() const;
-
        /* this is a helper class that we use to be able to keep
           track of which meter *AND* tempo are in effect at
           a given point in time.
@@ -256,66 +245,58 @@ class TempoMap : public Stateful, public StateManager {
                
                void set_tempo (const Tempo& t)    { _tempo = &t; }
                void set_meter (const Meter& m)    { _meter = &m; }
-               void set_frame (jack_nframes_t f)  { _frame = f; }
+               void set_frame (nframes_t f)  { _frame = f; }
                void set_start (const BBT_Time& t) { _start = t; }
                
                const Meter&    meter() const { return *_meter; }
                const Tempo&    tempo() const { return *_tempo; }
-               jack_nframes_t  frame() const { return _frame; }
+               nframes_t  frame() const { return _frame; }
                const BBT_Time& start() const { return _start; }
                
          private:
                const Meter*   _meter;
                const Tempo*   _tempo;
-               jack_nframes_t _frame;
+               nframes_t _frame;
                BBT_Time       _start;
                
        };
 
        Metric metric_at (BBT_Time bbt) const;
-       Metric metric_at (jack_nframes_t) const;
-        void bbt_time_with_metric (jack_nframes_t, BBT_Time&, const Metric&) const;
+       Metric metric_at (nframes_t) const;
+        void bbt_time_with_metric (nframes_t, BBT_Time&, const Metric&) const;
+
+       sigc::signal<void,ARDOUR::Change> StateChanged;
 
   private:
        static Tempo    _default_tempo;
        static Meter    _default_meter;
 
        Metrics            *metrics;
-       jack_nframes_t     _frame_rate;
-       jack_nframes_t      last_bbt_when;
+       nframes_t     _frame_rate;
+       nframes_t      last_bbt_when;
        bool                last_bbt_valid;
        BBT_Time            last_bbt;
-       mutable PBD::Lock   lock;
+       mutable Glib::RWLock    lock;
        
        void timestamp_metrics ();
 
 
-       jack_nframes_t round_to_type (jack_nframes_t fr, int dir, BBTPointType);
+       nframes_t round_to_type (nframes_t fr, int dir, BBTPointType);
 
-       jack_nframes_t frame_time_unlocked (const BBT_Time&) const;
+       nframes_t frame_time_unlocked (const BBT_Time&) const;
 
-       void bbt_time_unlocked (jack_nframes_t, BBT_Time&) const;
+       void bbt_time_unlocked (nframes_t, BBT_Time&) const;
 
-       jack_nframes_t bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, int dir) const;
+       nframes_t bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, int dir) const;
 
        const MeterSection& first_meter() const;
        const TempoSection& first_tempo() const;
 
-       jack_nframes_t count_frames_between (const BBT_Time&, const BBT_Time&) const;
-       jack_nframes_t count_frames_between_metrics (const Meter&, const Tempo&, const BBT_Time&, const BBT_Time&) const;
+       nframes_t count_frames_between (const BBT_Time&, const BBT_Time&) const;
+       nframes_t count_frames_between_metrics (const Meter&, const Tempo&, const BBT_Time&, const BBT_Time&) const;
 
        int move_metric_section (MetricSection&, const BBT_Time& to);
        void do_insert (MetricSection* section);
-
-       Change  restore_state (StateManager::State&);
-       StateManager::State* state_factory (std::string why) const;
-
-       bool        in_set_state;
-
-       /* override state_manager::save_state so we can check in_set_state */
-
-       void save_state (std::string why);
-
 };
 
 }; /* namespace ARDOUR */