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<> {
51 LocateTransportDisposition ltd;
64 , for_loop_end (false)
67 assert (t != StopTransport);
70 Event (EventType t, bool ab, bool cl)
77 , for_loop_end (false)
80 assert (t == StopTransport);
82 Event (EventType t, samplepos_t pos, LocateTransportDisposition l, bool fl, bool lp, bool f4c)
95 void* operator new (size_t);
96 void operator delete (void *ptr, size_t /*size*/);
98 static void init_pool ();
105 TransportFSM (TransportAPI& tapi);
112 /* should we do anything here? this method is modelled on the
113 boost::msm design, but its not clear that we ever need to
114 do anything like this.
131 std::string current_state () const;
134 MotionState _motion_state;
135 ButlerState _butler_state;
139 /* transition actions */
141 void schedule_butler_for_transport_work () const;
142 void start_playback ();
143 void stop_playback (Event const &);
144 void start_locate_after_declick () const;
145 void locate_for_loop (Event const &);
146 void roll_after_locate () const;
147 void start_locate_while_stopped (Event const &) const;
148 void interrupt_locate (Event const &) const;
149 void start_declick_for_locate (Event const &);
153 bool should_roll_after_locate () const;
154 bool should_not_roll_after_locate () const { return !should_roll_after_locate (); }
157 bool locating () const { return _motion_state == WaitingForLocate; }
158 bool rolling () const { return _motion_state == Rolling; }
159 bool stopped () const { return _motion_state == Stopped; }
160 bool stopping () const { return _motion_state == DeclickToStop; }
161 bool waiting_for_butler() const { return _butler_state == WaitingForButler; }
162 bool declick_in_progress() const { return _motion_state == DeclickToLocate || _motion_state == DeclickToStop; }
164 void enqueue (Event* ev);
168 void transition (MotionState ms);
169 void transition (ButlerState bs);
171 void process_events ();
172 bool process_event (Event&, bool was_deferred, bool& deferred);
177 typedef boost::intrusive::list<Event> EventList;
178 EventList queued_events;
179 EventList deferred_events;
181 mutable boost::optional<bool> current_roll_after_locate_status;
183 void defer (Event& ev);
184 void bad_transition (Event const &);
185 void set_roll_after (bool) const;
186 bool compute_should_roll (LocateTransportDisposition) const;
189 } /* end namespace ARDOUR */