1 #ifndef _ardour_transport_fsm_h_
2 #define _ardour_transport_fsm_h_
7 #include <boost/intrusive/list.hpp>
8 #include <boost/optional.hpp>
14 #include "pbd/demangle.h"
15 #include "pbd/stacktrace.h"
17 #include "ardour/debug.h"
18 #include "ardour/types.h"
27 /* All code related to this object is expected to be run synchronously
28 * and single-threaded from the process callback. It can be re-entrant
29 * if handling one transport state change queues another state change,
30 * but that is handled explicitly (see the @param processing member and
45 struct Event : public boost::intrusive::list_base_hook<> {
48 bool abort; /* for stop */
49 bool with_roll; /* for locate */
52 bool clear_state; /* for stop */
53 bool with_flush; /* for locate */
65 , for_loop_end (false)
68 Event (EventType t, bool ab, bool cl)
73 assert (t == StopTransport);
75 Event (EventType t, samplepos_t pos, bool r, bool fl, bool lp, bool f4c)
86 void* operator new (size_t);
87 void operator delete (void *ptr, size_t /*size*/);
89 static void init_pool ();
96 TransportFSM (TransportAPI& tapi);
103 /* should we do anything here? this method is modelled on the
104 boost::msm design, but its not clear that we ever need to
105 do anything like this.
122 std::string current_state () const;
125 MotionState _motion_state;
126 ButlerState _butler_state;
130 /* transition actions */
132 void schedule_butler_for_transport_work () const;
133 void start_playback ();
134 void stop_playback ();
135 void start_locate_after_declick () const;
136 void locate_for_loop (Event const &);
137 void roll_after_locate () const;
138 void start_locate_while_stopped (Event const &) const;
139 void interrupt_locate (Event const &) const;
140 void start_declick_for_locate (Event const &);
144 bool should_roll_after_locate () const;
145 bool should_not_roll_after_locate () const { return !should_roll_after_locate (); }
148 bool locating () const { return _motion_state == WaitingForLocate; }
149 bool rolling () const { return _motion_state == Rolling; }
150 bool stopped () const { return _motion_state == Stopped; }
151 bool waiting_for_butler() const { return _butler_state == WaitingForButler; }
152 bool declick_in_progress() const { return _motion_state == DeclickToLocate || _motion_state == DeclickToStop; }
154 void enqueue (Event* ev);
158 void transition (MotionState ms);
159 void transition (ButlerState bs);
161 void process_events ();
162 bool process_event (Event&, bool was_deferred, bool& deferred);
168 typedef boost::intrusive::list<Event> EventList;
169 EventList queued_events;
170 EventList deferred_events;
172 mutable boost::optional<bool> current_roll_after_locate_status;
174 void defer (Event& ev);
175 void bad_transition (Event const &);
176 void set_roll_after (bool) const;
179 } /* end namespace ARDOUR */