/*
- Copyright (C) 1999-2003 Paul Davis
+ Copyright (C) 1999-2009 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#include <cmath>
#include <glibmm/thread.h>
#include <pbd/pthread_utils.h>
#include <pbd/memento_command.h>
+#include <pbd/stacktrace.h>
#include <midi++/mmc.h>
#include <midi++/port.h>
if (!(_state_of_the_state & (InitialConnecting|Deletion))) {
Event* ev = new Event (Event::InputConfigurationChange, Event::Add, Event::Immediate, 0, 0.0);
queue_event (ev);
- }
+ }
}
void
ev = new Event (Event::SetLoop, Event::Add, Event::Immediate, 0, 0.0, yn);
queue_event (ev);
-
+
if (!yn && Config->get_seamless_loop() && transport_rolling()) {
// request an immediate locate to refresh the diskstreams
// after disabling looping
waiting_for_sync_offset = true;
}
- transport_sub_state = (Config->get_auto_return() ? AutoReturning : 0);
+ transport_sub_state = ((Config->get_slave_source() == None && Config->get_auto_return()) ? AutoReturning : 0);
}
void
}
if (post_transport_work & PostTransportReverse) {
-
-
+
clear_clicks();
cumulative_rf_motion = 0;
reset_rf_scale (0);
update_latency_compensation (true, abort);
}
- if (Config->get_auto_return() || (post_transport_work & PostTransportLocate) || synced_to_jack()) {
+ if ((Config->get_slave_source() == None && Config->get_auto_return()) ||
+ (post_transport_work & PostTransportLocate) ||
+ (_requested_return_frame >= 0) ||
+ synced_to_jack()) {
if (pending_locate_flush) {
flush_all_redirects ();
}
+
+ if (((Config->get_slave_source() == None && Config->get_auto_return()) ||
+ synced_to_jack() ||
+ _requested_return_frame >= 0) &&
+ !(post_transport_work & PostTransportLocate)) {
- if ((Config->get_auto_return() || synced_to_jack()) && !(post_transport_work & PostTransportLocate)) {
+ /* no explicit locate queued */
- _transport_frame = last_stop_frame;
+ bool do_locate = false;
- if (synced_to_jack()) {
+ if (_requested_return_frame >= 0) {
+ _transport_frame = _requested_return_frame;
+ _requested_return_frame = -1;
+ do_locate = true;
+ } else {
+ if (play_loop && !synced_to_jack()) {
+ Location *location = _locations.auto_loop_location();
+
+ if (location != 0) {
+ _transport_frame = location->start();
+ do_locate = true;
+ } else {
+ _transport_frame = last_stop_frame;
+ }
+ } else {
+ _transport_frame = last_stop_frame;
+ }
+ _requested_return_frame = -1;
+ }
+
+ if (synced_to_jack() && !play_loop) {
+ do_locate = true;
+ }
+
+ if (do_locate) {
+ // cerr << "non-realtimestop: transport locate to " << _transport_frame << endl;
_engine.transport_locate (_transport_frame);
}
}
}
#endif
- last_stop_frame = _transport_frame;
+ if (_requested_return_frame < 0) {
+ last_stop_frame = _transport_frame;
+ } else {
+ last_stop_frame = _requested_return_frame;
+ _requested_return_frame = -1;
+ }
+
+ have_looped = false;
- send_full_time_code ();
+ send_full_time_code ();
deliver_mmc (MIDI::MachineControl::cmdStop, 0);
deliver_mmc (MIDI::MachineControl::cmdLocate, _transport_frame);
/* XXX its a little odd that we're doing this here
when realtime_stop(), which has already executed,
will have done this.
+ JLC - so let's not because it seems unnecessary and breaks loop record
*/
-
+#if 0
if (!Config->get_latched_record_enable()) {
g_atomic_int_set (&_record_status, Disabled);
} else {
g_atomic_int_set (&_record_status, Enabled);
}
RecordStateChanged (); /* emit signal */
+#endif
}
if ((post_transport_work & PostTransportLocate) && get_record_enabled()) {
if (post_transport_work & PostTransportStop) {
_play_range = false;
-
- /* do not turn off autoloop on stop */
-
+ play_loop = false;
}
- PositionChanged (_transport_frame); /* EMIT SIGNAL */
+ nframes_t tf = _transport_frame;
+
+ PositionChanged (tf); /* EMIT SIGNAL */
TransportStateChange (); /* EMIT SIGNAL */
/* and start it up again if relevant */
{
/* Called from event-handling context */
- if ((actively_recording() && yn) || _locations.auto_loop_location() == 0) {
+ Location *loc;
+
+ if ((actively_recording() && yn) || (loc = _locations.auto_loop_location()) == 0) {
return;
}
if ((play_loop = yn)) {
- Location *loc;
-
- if ((loc = _locations.auto_loop_location()) != 0) {
+ if (loc) {
if (Config->get_seamless_loop()) {
// set all diskstreams to use internal looping
}
}
- /* stick in the loop event */
+ /* put the loop event into the event list */
Event* event = new Event (Event::AutoLoop, Event::Replace, loc->end(), loc->start(), 0.0f);
merge_event (event);
- /* locate to start of loop and roll if current pos is outside of the loop range */
- if (_transport_frame < loc->start() || _transport_frame > loc->end()) {
- event = new Event (Event::LocateRoll, Event::Add, Event::Immediate, loc->start(), 0, !synced_to_jack());
- merge_event (event);
- }
- else {
- // locate to current position (+ 1 to force reload)
- event = new Event (Event::LocateRoll, Event::Add, Event::Immediate, _transport_frame + 1, 0, !synced_to_jack());
- merge_event (event);
- }
+ /* locate to start of loop and roll */
+ event = new Event (Event::LocateRoll, Event::Add, Event::Immediate, loc->start(), 0, !synced_to_jack());
+ merge_event (event);
}
-
} else {
clear_events (Event::AutoLoop);
}
}
+int
+Session::micro_locate (nframes_t distance)
+{
+ boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
+
+ for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+ if (!(*i)->can_internal_playback_seek (distance)) {
+ return -1;
+ }
+ }
+
+ for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+ (*i)->internal_playback_seek (distance);
+ }
+
+ _transport_frame += distance;
+ return 0;
+}
+
void
Session::locate (nframes_t target_frame, bool with_roll, bool with_flush, bool with_loop)
{
- if (actively_recording()) {
+ if (actively_recording() && !with_loop) {
return;
}
}
}
- if (transport_rolling() && !Config->get_auto_play() && !with_roll && !(synced_to_jack() && play_loop)) {
+ if (transport_rolling() && (!auto_play_legal || !Config->get_auto_play()) && !with_roll && !(synced_to_jack() && play_loop)) {
realtime_stop (false);
}
if ( !with_loop || loop_changing) {
-
+
post_transport_work = PostTransportWork (post_transport_work | PostTransportLocate);
if (with_roll) {
} else {
- cerr << "butler not requested\n";
-
/* this is functionally what clear_clicks() does but with a tentative lock */
Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK);
// cancel looping directly, this is called from event handling context
set_play_loop (false);
}
+ else if (al && _transport_frame == al->start()) {
+ if (with_loop) {
+ // this is only necessary for seamless looping
+
+ boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
+
+ for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+ if ((*i)->record_enabled ()) {
+ // tell it we've looped, so it can deal with the record state
+ (*i)->transport_looped(_transport_frame);
+ }
+ }
+ }
+ have_looped = true;
+ TransportLooped(); // EMIT SIGNAL
+ }
}
loop_changing = false;
+
+ _send_smpte_update = true;
}
void
before the last stop, then we have to do extra work.
*/
- if ((_transport_speed && speed * _transport_speed < 0.0f) || (_last_transport_speed * speed < 0.0f)) {
+ if ((_transport_speed && speed * _transport_speed < 0.0f) || (_last_transport_speed * speed < 0.0f) || (_last_transport_speed == 0.0f && speed < 0.0f)) {
post_transport_work = PostTransportWork (post_transport_work | PostTransportReverse);
+ last_stop_frame = _transport_frame;
}
_last_transport_speed = _transport_speed;
Session::start_transport ()
{
_last_roll_location = _transport_frame;
+ have_looped = false;
/* if record status is Enabled, move it to Recording. if its
already Recording, move it to Disabled.
break;
case Recording:
- disable_record (false);
+ if (!play_loop) {
+ disable_record (false);
+ }
break;
default:
break;
}
- if (!synced_to_jack() || _exporting) {
- actually_start_transport ();
- } else {
- waiting_to_start = true;
- }
-}
-
-void
-Session::actually_start_transport ()
-{
- waiting_to_start = false;
-
transport_sub_state |= PendingDeclickIn;
_transport_speed = 1.0;
if (post_transport_work & PostTransportLocate) {
- if ((Config->get_auto_play() && !_exporting) || (post_transport_work & PostTransportRoll)) {
+ if (((Config->get_slave_source() == None && (auto_play_legal && Config->get_auto_play())) && !_exporting) || (post_transport_work & PostTransportRoll)) {
start_transport ();
} else {
}
void
-Session::set_slave_source (SlaveSource src)
+Session::set_slave_source (SlaveSource src, bool stop_the_transport)
{
bool reverse = false;
bool non_rt_required = false;
switch (src) {
case None:
- stop_transport ();
+ if (stop_the_transport) {
+ stop_transport ();
+ }
break;
case MTC:
merge_event (ev);
}
+void
+Session::request_roll_at_and_return (nframes_t start, nframes_t return_to)
+{
+ Event *ev = new Event (Event::LocateRollLocate, Event::Add, Event::Immediate, return_to, 1.0);
+ ev->target2_frame = start;
+ queue_event (ev);
+}
+
void
Session::request_bounded_roll (nframes_t start, nframes_t end)
{
request_stop ();
- Event *ev = new Event (Event::StopOnce, Event::Replace, Event::Immediate, end, 0.0);
+ Event *ev = new Event (Event::StopOnce, Event::Replace, end, Event::Immediate, 0.0);
queue_event (ev);
request_locate (start, true);
}
g_atomic_int_set (&butler_should_do_transport_work, 0);
post_transport_work = PostTransportWork (0);
stop_butler ();
-
+
realtime_stop (false);
non_realtime_stop (false, 0, ignored);
transport_sub_state = 0;
+ if (synced_to_jack()) {
+ /* transport is already stopped, hence the second argument */
+ set_slave_source (None, false);
+ }
+
TransportStateChange (); /* EMIT SIGNAL */
}
void
Session::xrun_recovery ()
{
- if (Config->get_stop_recording_on_xrun() && actively_recording()) {
+ Xrun (transport_frame()); //EMIT SIGNAL
- HaltOnXrun (); /* EMIT SIGNAL */
+ if (Config->get_stop_recording_on_xrun() && actively_recording()) {
/* it didn't actually halt, but we need
to handle things in the same way.
_worst_track_latency = 0;
+#undef DEBUG_LATENCY
+#ifdef DEBUG_LATENCY
+ cerr << "\n---------------------------------\nUPDATE LATENCY\n";
+#endif
+
boost::shared_ptr<RouteList> r = routes.reader ();
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
}
}
+#ifdef DEBUG_LATENCY
+ cerr << "\tworst was " << _worst_track_latency << endl;
+#endif
+
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
(*i)->set_latency_delay (_worst_track_latency);
}
{
update_latency_compensation (false, false);
}
+
+void
+Session::allow_auto_play (bool yn)
+{
+ auto_play_legal = yn;
+}
+
+void
+Session::reset_jack_connection (jack_client_t* jack)
+{
+ JACK_Slave* js;
+
+ if (_slave && ((js = dynamic_cast<JACK_Slave*> (_slave)) != 0)) {
+ js->reset_client (jack);
+ }
+}