+void MidiClockTicker::transport_state_changed()
+{
+ if (_session->exporting()) {
+ /* no midi clock during export, for now */
+ return;
+ }
+
+ float speed = _session->transport_speed();
+ framepos_t position = _session->transport_frame();
+
+ DEBUG_TRACE (PBD::DEBUG::MidiClock,
+ string_compose ("Transport state change, speed: %1 position: %2 play loop: %3\n", speed, position, _session->get_play_loop())
+ );
+
+ if (speed == 1.0f) {
+ _last_tick = position;
+
+ if (!Config->get_send_midi_clock())
+ return;
+
+ if (_session->get_play_loop()) {
+ assert(_session->locations()->auto_loop_location());
+ if (position == _session->locations()->auto_loop_location()->start()) {
+ send_start_event(0);
+ } else {
+ send_continue_event(0);
+ }
+ } else if (position == 0) {
+ send_start_event(0);
+ } else {
+ send_continue_event(0);
+ }
+
+ send_midi_clock_event(0);
+
+ } else if (speed == 0.0f) {
+ if (!Config->get_send_midi_clock())
+ return;
+
+ send_stop_event(0);
+ }
+
+ tick(position, *((Timecode::BBT_Time *) 0), *((Timecode::Time *)0));
+}
+
+void MidiClockTicker::position_changed (framepos_t position)
+{
+ DEBUG_TRACE (PBD::DEBUG::MidiClock, string_compose ("Position change: %1\n", position));
+
+ _last_tick = position;
+}
+
+void MidiClockTicker::transport_looped()
+{
+ Location* loop_location = _session->locations()->auto_loop_location();
+ assert(loop_location);
+
+ DEBUG_TRACE (PBD::DEBUG::MidiClock,
+ string_compose ("Transport looped, position: %1, loop start: %2, loop end: %3, play loop: %4\n",
+ _session->transport_frame(), loop_location->start(), loop_location->end(), _session->get_play_loop())
+ );
+
+ // adjust _last_tick, so that the next MIDI clock message is sent
+ // in due time (and the tick interval is still constant)
+ framecnt_t elapsed_since_last_tick = loop_location->end() - _last_tick;
+ _last_tick = loop_location->start() - elapsed_since_last_tick;
+}
+
+void MidiClockTicker::tick (const framepos_t& transport_frames, const Timecode::BBT_Time& /*transport_bbt*/, const Timecode::Time& /*transport_smpt*/)
+{
+ if (!Config->get_send_midi_clock() || _session == 0 || _session->transport_speed() != 1.0f || _midi_port == 0)