void
ARDOUR_UI::startup ()
{
- /* Once the UI is up and running, start the audio engine. Doing
- this before the UI is up and running can cause problems
- when not running with SCHED_FIFO, because the amount of
- CPU and disk work needed to get the UI started can interfere
- with the scheduling of the audio thread.
- */
-
- Glib::signal_idle().connect (mem_fun(*this, &ARDOUR_UI::start_engine));
+ // relax
}
void
break;
}
}
+
+ engine->stop (true);
Config->save_state();
quit ();
}
void session_add_midi_track ();
void set_engine (ARDOUR::AudioEngine&);
+ gint start_engine ();
gint exit_on_main_window_close (GdkEventAny *);
void queue_transport_change ();
void map_transport_state ();
int32_t do_engine_start ();
- gint start_engine ();
void engine_halted ();
void engine_stopped ();
return -1;
}
-
+ ui->start_engine ();
+
if (maybe_load_session ()) {
ui->run (text_receiver);
ui = 0;
bool will_reconnect_at_halt ();
void set_reconnect_at_halt (bool);
- int stop ();
+ int stop (bool forever = false);
int start ();
bool running() const { return _running; }
CONFIG_VARIABLE (AutoConnectOption, output_auto_connect, "output-auto-connect", AutoConnectOption (0))
CONFIG_VARIABLE (AutoConnectOption, input_auto_connect, "input-auto-connect", AutoConnectOption (0))
-#ifdef __APPLE__
-CONFIG_VARIABLE (std::string, auditioner_output_left, "auditioner-output-left", "coreaudio:Built-in Audio:in1")
-CONFIG_VARIABLE (std::string, auditioner_output_right, "auditioner-output-right", "coreaudio:Built-in Audio:in2")
-#else
-CONFIG_VARIABLE (std::string, auditioner_output_left, "auditioner-output-left", "alsa_pcm:playback_1")
-CONFIG_VARIABLE (std::string, auditioner_output_right, "auditioner-output-right", "alsa_pcm:playback_2")
-#endif
+CONFIG_VARIABLE (std::string, auditioner_output_left, "auditioner-output-left", "default")
+CONFIG_VARIABLE (std::string, auditioner_output_right, "auditioner-output-right", "default")
/* MIDI and MIDI related */
void hookup_io ();
void when_engine_running ();
- sigc::connection first_time_running;
void graph_reordered ();
string _current_snapshot_name;
bool butler_should_run;
mutable gint butler_should_do_transport_work;
int butler_request_pipe[2];
+
+ inline bool transport_work_requested() const { return g_atomic_int_get(&butler_should_do_transport_work); }
struct ButlerRequest {
enum Type {
void realtime_stop (bool abort);
void non_realtime_start_scrub ();
void non_realtime_set_speed ();
- void non_realtime_stop (bool abort);
- void non_realtime_overwrite ();
- void non_realtime_buffer_fill ();
+ void non_realtime_stop (bool abort, int entry_request_count, bool& finished);
+ void non_realtime_overwrite (int entry_request_count, bool& finished);
void butler_transport_work ();
void post_transport ();
void engine_halted ();
}
int
-AudioEngine::stop ()
+AudioEngine::stop (bool forever)
{
if (_running) {
_running = false;
- jack_deactivate (_jack);
+ if (forever) {
+ jack_client_t* foo = _jack;
+ _jack = 0;
+ jack_client_close (foo);
+ } else {
+ jack_deactivate (_jack);
+ }
Stopped(); /* EMIT SIGNAL */
}
AudioEngine::jack_timebase_callback (jack_transport_state_t state, nframes_t nframes,
jack_position_t* pos, int new_position)
{
- if (session && session->synced_to_jack()) {
+ if (_jack && session && session->synced_to_jack()) {
session->jack_timebase_callback (state, nframes, pos, new_position);
}
}
int
AudioEngine::jack_sync_callback (jack_transport_state_t state, jack_position_t* pos)
{
- if (session) {
+ if (_jack && session) {
return session->jack_sync_callback (state, pos);
} else {
return true;
int
AudioEngine::_xrun_callback (void *arg)
{
- static_cast<AudioEngine *>(arg)->Xrun (); /* EMIT SIGNAL */
+ AudioEngine* ae = static_cast<AudioEngine*> (arg);
+ if (ae->jack()) {
+ ae->Xrun (); /* EMIT SIGNAL */
+ }
return 0;
}
int
AudioEngine::_graph_order_callback (void *arg)
{
- static_cast<AudioEngine *>(arg)->GraphReordered (); /* EMIT SIGNAL */
+ AudioEngine* ae = static_cast<AudioEngine*> (arg);
+ if (ae->jack()) {
+ ae->GraphReordered (); /* EMIT SIGNAL */
+ }
return 0;
}
}
remove_all_ports ();
-
}
Port *
void
AudioEngine::halted (void *arg)
{
- AudioEngine *ae = reinterpret_cast<AudioEngine *> (arg);
+ AudioEngine* ae = static_cast<AudioEngine *> (arg);
ae->_running = false;
ae->_jack = 0;
#include <ardour/audio_diskstream.h>
#include <ardour/audioregion.h>
+#include <ardour/audioengine.h>
#include <ardour/route.h>
#include <ardour/session.h>
#include <ardour/auditioner.h>
{
string left = Config->get_auditioner_output_left();
string right = Config->get_auditioner_output_right();
+
+ if (left == "default") {
+ left = _session.engine().get_nth_physical_output (0);
+ }
+
+ if (right == "default") {
+ right = _session.engine().get_nth_physical_output (1);
+ }
if ((left.length() == 0) && (right.length() == 0)) {
+ warning << _("no outputs available for auditioner - manual connection required") << endmsg;
return;
}
void
Auditioner::output_changed (IOChange change, void* src)
{
+ string phys;
+
if (change & ConnectionsChanged) {
const char ** connections;
connections = output (0)->get_connections ();
if (connections) {
- Config->set_auditioner_output_left (connections[0]);
+ phys = _session.engine().get_nth_physical_output (0);
+ if (phys != connections[0]) {
+ Config->set_auditioner_output_left (connections[0]);
+ } else {
+ Config->set_auditioner_output_left ("default");
+ }
free (connections);
+ } else {
+ Config->set_auditioner_output_left ("");
}
connections = output (1)->get_connections ();
if (connections) {
- Config->set_auditioner_output_right (connections[0]);
+ phys = _session.engine().get_nth_physical_output (1);
+ if (phys != connections[0]) {
+ Config->set_auditioner_output_right (connections[0]);
+ } else {
+ Config->set_auditioner_output_right ("default");
+ }
free (connections);
+ } else {
+ Config->set_auditioner_output_right ("");
}
}
}
plgone_connection = _playlist->GoingAway.connect (bind (mem_fun (*this, &Diskstream::playlist_deleted), boost::weak_ptr<Playlist>(_playlist)));
}
- if (!overwrite_queued) {
+ /* don't do this if we've already asked for it *or* if we are setting up
+ the diskstream for the very first time - the input changed handling will
+ take care of the buffer refill.
+ */
+
+ if (!overwrite_queued && !(_session.state_of_the_state() & Session::CannotSave)) {
_session.request_overwrite_buffer (this);
overwrite_queued = true;
}
/* we don't want to run execute this again */
- first_time_running.disconnect ();
-
set_block_size (_engine.frames_per_cycle());
set_frame_rate (_engine.frame_rate());
// XXX HOW TO ALERT UI TO THIS ? DO WE NEED TO?
}
- if (auditioner == 0) {
-
- /* we delay creating the auditioner till now because
- it makes its own connections to ports named
- in the ARDOUR_RC config file. the engine has
- to be running for this to work.
- */
-
- try {
- auditioner.reset (new Auditioner (*this));
- }
-
- catch (failed_constructor& err) {
- warning << _("cannot create Auditioner: no auditioning of regions possible") << endmsg;
- }
- }
-
/* Create a set of Connection objects that map
to the physical outputs currently available
*/
*/
_state_of_the_state = StateOfTheState (_state_of_the_state | InitialConnecting);
+ cerr << "InitialConnecting set\n";
+
+ if (auditioner == 0) {
+
+ /* we delay creating the auditioner till now because
+ it makes its own connections to ports.
+ the engine has to be running for this to work.
+ */
+
+ try {
+ auditioner.reset (new Auditioner (*this));
+ }
+
+ catch (failed_constructor& err) {
+ warning << _("cannot create Auditioner: no auditioning of regions possible") << endmsg;
+ }
+ }
/* Tell all IO objects to create their ports */
IOConnectionsComplete (); /* EMIT SIGNAL */
_state_of_the_state = StateOfTheState (_state_of_the_state & ~InitialConnecting);
+ cerr << "InitialConnectingUN set\n";
/* now handle the whole enchilada as if it was one
graph reorder event.
return;
}
+ /* every track/bus asked for this to be handled but it was deferred because
+ we were connecting. do it now.
+ */
+
+ request_input_change_handling ();
+
resort_routes ();
/* force all diskstreams to update their capture offset values to
return 0;
}
-#define transport_work_requested() g_atomic_int_get(&butler_should_do_transport_work)
-
void *
Session::butler_thread_work ()
{
*/
if (non_realtime_work_pending()) {
- immediate_events.insert (immediate_events.end(), ev);
- _remove_event (ev);
- return;
+
+ /* except locates, which we have the capability to handle */
+
+ if (ev->type != Event::Locate) {
+ immediate_events.insert (immediate_events.end(), ev);
+ _remove_event (ev);
+ return;
+ }
}
switch (ev->type) {
}
if (non_realtime_work_pending()) {
- if (g_atomic_int_get (&butler_should_do_transport_work) == 0) {
+ if (!transport_work_requested ()) {
post_transport ();
}
}
#include <pbd/pathscanner.h>
#include <pbd/pthread_utils.h>
#include <pbd/strsplit.h>
+#include <pbd/stacktrace.h>
#include <ardour/audioengine.h>
#include <ardour/configuration.h>
_engine.Halted.connect (mem_fun (*this, &Session::engine_halted));
_engine.Xrun.connect (mem_fun (*this, &Session::xrun_recovery));
- if (_engine.running()) {
- when_engine_running();
- } else {
- first_time_running = _engine.Running.connect (mem_fun (*this, &Session::when_engine_running));
- }
+ when_engine_running();
send_full_time_code ();
_engine.transport_locate (0);
xml_path = _path;
xml_path += snapshot_name;
xml_path += _statefile_suffix;
+
bak_path = xml_path;
bak_path += ".bak";
- // Make backup of state file
+ if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
+
+ // Make backup of state file
- if ((access (xml_path.c_str(), F_OK) == 0) &&
- (rename(xml_path.c_str(), bak_path.c_str()))) {
- error << _("could not backup old state file, current state not saved.") << endmsg;
- return -1;
+ ifstream in (xml_path.c_str());
+ ofstream out (bak_path.c_str());
+
+ if (!in) {
+ error << string_compose (_("Could not open existing session file %1 for backup"), xml_path) << endmsg;
+ return -1;
+ }
+
+ if (!out) {
+ error << string_compose (_("Could not open backup session file %1"), bak_path) << endmsg;
+ return -1;
+ }
+
+ out << in.rdbuf();
+
+ if (!in || !out) {
+ error << string_compose (_("Could not copy existing session file %1 to %2 for backup"), xml_path, bak_path) << endmsg;
+ unlink (bak_path.c_str());
+ return -1;
+ }
}
} else {
}
+ string tmp_path;
+
+ tmp_path = _path;
+ tmp_path += snapshot_name;
+ tmp_path += ".tmp";
+
cerr << "actually writing state\n";
- if (!tree.write (xml_path)) {
- error << string_compose (_("state could not be saved to %1"), xml_path) << endmsg;
+ if (!tree.write (tmp_path)) {
+ error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
+ unlink (tmp_path.c_str());
+ return -1;
- /* don't leave a corrupt file lying around if it is
- possible to fix.
- */
+ } else {
- if (unlink (xml_path.c_str())) {
- error << string_compose (_("could not remove corrupt state file %1"), xml_path) << endmsg;
- } else {
- if (!pending) {
- if (rename (bak_path.c_str(), xml_path.c_str())) {
- error << string_compose (_("could not restore state file from backup %1"), bak_path) << endmsg;
- }
- }
+ if (rename (tmp_path.c_str(), xml_path.c_str()) != 0) {
+ error << string_compose (_("could not rename temporary session file %1 to %2"), tmp_path, xml_path) << endmsg;
+ unlink (tmp_path.c_str());
+ return -1;
}
-
- return -1;
}
if (!pending) {
- save_history(snapshot_name);
+
+ save_history (snapshot_name);
bool was_dirty = dirty();
#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>
void
Session::request_input_change_handling ()
{
- Event* ev = new Event (Event::InputConfigurationChange, Event::Add, Event::Immediate, 0, 0.0);
- queue_event (ev);
+ if (!(_state_of_the_state & (InitialConnecting|Deletion))) {
+ stacktrace (cerr);
+ Event* ev = new Event (Event::InputConfigurationChange, Event::Add, Event::Immediate, 0, 0.0);
+ queue_event (ev);
+ }
}
void
void
Session::butler_transport_work ()
{
+ restart:
+ bool finished;
boost::shared_ptr<RouteList> r = routes.reader ();
boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
+ int on_entry = g_atomic_int_get (&butler_should_do_transport_work);
+ finished = true;
+
if (post_transport_work & PostTransportCurveRealloc) {
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
(*i)->curve_reallocate();
cumulative_rf_motion = 0;
reset_rf_scale (0);
- for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
- if (!(*i)->hidden()) {
- if ((*i)->speed() != 1.0f || (*i)->speed() != -1.0f) {
- (*i)->seek ((nframes_t) (_transport_frame * (double) (*i)->speed()));
+ /* don't seek if locate will take care of that in non_realtime_stop() */
+
+ if (!(post_transport_work & PostTransportLocate)) {
+
+ for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+ if (!(*i)->hidden()) {
+ if ((*i)->speed() != 1.0f || (*i)->speed() != -1.0f) {
+ (*i)->seek ((nframes_t) (_transport_frame * (double) (*i)->speed()));
+ }
+ else {
+ (*i)->seek (_transport_frame);
+ }
}
- else {
- (*i)->seek (_transport_frame);
+ if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) {
+ /* new request, stop seeking, and start again */
+ g_atomic_int_dec_and_test (&butler_should_do_transport_work);
+ goto restart;
}
}
}
}
if (post_transport_work & (PostTransportStop|PostTransportLocate)) {
- non_realtime_stop (post_transport_work & PostTransportAbort);
+ non_realtime_stop (post_transport_work & PostTransportAbort, on_entry, finished);
+ if (!finished) {
+ g_atomic_int_dec_and_test (&butler_should_do_transport_work);
+ goto restart;
+ }
}
if (post_transport_work & PostTransportOverWrite) {
- non_realtime_overwrite ();
+ non_realtime_overwrite (on_entry, finished);
+ if (!finished) {
+ g_atomic_int_dec_and_test (&butler_should_do_transport_work);
+ goto restart;
+ }
}
if (post_transport_work & PostTransportAudition) {
non_realtime_set_audition ();
}
-
+
g_atomic_int_dec_and_test (&butler_should_do_transport_work);
}
}
void
-Session::non_realtime_overwrite ()
+Session::non_realtime_overwrite (int on_entry, bool& finished)
{
boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
if ((*i)->pending_overwrite) {
(*i)->overwrite_existing_buffers ();
}
+ if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) {
+ finished = false;
+ return;
+ }
}
}
void
-Session::non_realtime_stop (bool abort)
+Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
{
struct tm* now;
time_t xnow;
(*i)->seek (_transport_frame);
}
}
+ if (on_entry != g_atomic_int_get (&butler_should_do_transport_work)) {
+ finished = false;
+ /* we will be back */
+ return;
+ }
}
#ifdef LEAVE_TRANSPORT_UNADJUSTED
}
} 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);
if (post_transport_work & PostTransportLocate) {
if ((Config->get_auto_play() && !_exporting) || (post_transport_work & PostTransportRoll)) {
-
start_transport ();
} else {
void
Session::engine_halted ()
{
+ bool ignored;
+
/* there will be no more calls to process(), so
we'd better clean up for ourselves, right now.
stop_butler ();
realtime_stop (false);
- non_realtime_stop (false);
+ non_realtime_stop (false, 0, ignored);
transport_sub_state = 0;
TransportStateChange (); /* EMIT SIGNAL */