1 /*
2  * Copyright (C) 2000-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005-2009 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2006-2007 Jesse Chappell <jesse@essej.net>
5  * Copyright (C) 2006-2009 Sampo Savolainen <v2@iki.fi>
6  * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
7  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
8  * Copyright (C) 2007-2015 Tim Mayberry <mojofunk@gmail.com>
9  * Copyright (C) 2008-2009 Hans Baier <hansfbaier@googlemail.com>
10  * Copyright (C) 2008-2009 Sakari Bergen <sakari.bergen@beatwaves.net>
11  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
12  * Copyright (C) 2013-2017 Nick Mainsbridge <mainsbridge@gmail.com>
13  * Copyright (C) 2013-2018 John Emmas <john@creativepost.co.uk>
14  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
15  * Copyright (C) 2015-2018 Len Ovens <len@ovenwerks.net>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, write to the Free Software Foundation, Inc.,
29  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30  */
31 
32 #ifndef __ardour_session_h__
33 #define __ardour_session_h__
34 
35 #ifdef WAF_BUILD
36 #include "libardour-config.h"
37 #endif
38 
39 #include <exception>
40 #include <list>
41 #include <map>
42 #include <set>
43 #include <string>
44 #include <vector>
45 #include <queue>
46 #include <stdint.h>
47 
48 #include <boost/dynamic_bitset.hpp>
49 #include <boost/scoped_ptr.hpp>
50 #include <boost/weak_ptr.hpp>
51 #include <boost/utility.hpp>
52 
53 #include <glibmm/threads.h>
54 
55 #include <ltc.h>
56 
57 #include "pbd/error.h"
58 #include "pbd/event_loop.h"
59 #include "pbd/file_archive.h"
60 #include "pbd/rcu.h"
61 #include "pbd/reallocpool.h"
62 #include "pbd/statefuldestructible.h"
63 #include "pbd/signals.h"
64 #include "pbd/undo.h"
65 #include "pbd/g_atomic_compat.h"
66 
67 #include "lua/luastate.h"
68 
69 #include "evoral/Range.h"
70 
71 #include "midi++/types.h"
72 #include "midi++/mmc.h"
73 
74 #include "temporal/time.h"
75 
76 #include "ardour/ardour.h"
77 #include "ardour/chan_count.h"
78 #include "ardour/delivery.h"
79 #include "ardour/interthread_info.h"
80 #include "ardour/luascripting.h"
81 #include "ardour/location.h"
82 #include "ardour/monitor_processor.h"
83 #include "ardour/presentation_info.h"
84 #include "ardour/rc_configuration.h"
85 #include "ardour/session_configuration.h"
86 #include "ardour/session_event.h"
87 #include "ardour/interpolation.h"
88 #include "ardour/plugin.h"
89 #include "ardour/presentation_info.h"
90 #include "ardour/route.h"
91 #include "ardour/route_graph.h"
92 #include "ardour/transport_api.h"
93 
94 class XMLTree;
95 class XMLNode;
96 struct _AEffect;
97 typedef struct _AEffect AEffect;
98 
99 class PTFFormat;
100 
101 namespace MIDI {
102 class Port;
103 class MachineControl;
104 class Parser;
105 }
106 
107 namespace PBD {
108 class Controllable;
109 }
110 
111 namespace luabridge {
112 	class LuaRef;
113 }
114 
115 namespace Evoral {
116 class Curve;
117 }
118 
119 namespace ARDOUR {
120 
121 class Amp;
122 class AsyncMIDIPort;
123 class AudioEngine;
124 class AudioFileSource;
125 class AudioRegion;
126 class AudioSource;
127 class AudioTrack;
128 class Auditioner;
129 class AutomationList;
130 class AuxInput;
131 class BufferSet;
132 class Bundle;
133 class Butler;
134 class Click;
135 class CoreSelection;
136 class ExportHandler;
137 class ExportStatus;
138 class Graph;
139 class IO;
140 class IOProcessor;
141 class ImportStatus;
142 class MidiClockTicker;
143 class MidiControlUI;
144 class MidiPortManager;
145 class MidiPort;
146 class MidiRegion;
147 class MidiSource;
148 class MidiTrack;
149 class Playlist;
150 class PluginInsert;
151 class PluginInfo;
152 class Port;
153 class PortInsert;
154 class ProcessThread;
155 class Progress;
156 class Processor;
157 class Region;
158 class Return;
159 class Route;
160 class RouteGroup;
161 class RTTaskList;
162 class SMFSource;
163 class Send;
164 class SceneChanger;
165 class SessionDirectory;
166 class SessionMetadata;
167 class SessionPlaylists;
168 class SoloMuteRelease;
169 class Source;
170 class Speakers;
171 class TempoMap;
172 class TransportMaster;
173 struct TransportFSM;
174 class Track;
175 class UI_TransportMaster;
176 class VCAManager;
177 class WindowsVSTPlugin;
178 
179 extern void setup_enum_writer ();
180 
181 class LIBARDOUR_API SessionException: public std::exception {
182 public:
SessionException(const std::string msg)183 	explicit SessionException(const std::string msg) : _message(msg) {}
~SessionException()184 	virtual ~SessionException() throw() {}
185 
what()186 	virtual const char* what() const throw() { return _message.c_str(); }
187 
188 private:
189 	std::string _message;
190 };
191 
192 /** Ardour Session */
193 class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionList, public SessionEventManager, public TransportAPI
194 {
195 private:
196 
197 public:
198 	enum RecordState {
199 		Disabled = 0,
200 		Enabled = 1,
201 		Recording = 2
202 	};
203 
204 	/* a new session might have non-empty mix_template, an existing session should always have an empty one.
205 	   the bus profile can be null if no master out bus is required.
206 	*/
207 
208 	Session (AudioEngine&,
209 	         const std::string& fullpath,
210 	         const std::string& snapshot_name,
211 	         BusProfile const * bus_profile = 0,
212 	         std::string mix_template = "",
213 	         bool unnamed = false);
214 
215 	virtual ~Session ();
216 
217 	static int get_info_from_path (const std::string& xmlpath, float& sample_rate, SampleFormat& data_format, std::string& program_version, XMLNode* engine_hints = 0);
218 	static std::string get_snapshot_from_instant (const std::string& session_dir);
219 
220 	/** a monotonic counter used for naming user-visible things uniquely
221 	 * (curently the sidechain port).
222 	 * Use sparingly to keep the numbers low, prefer PBD::ID for all
223 	 * internal, not user-visible IDs */
224 	static unsigned int next_name_id ();
225 
path()226 	std::string path() const { return _path; }
name()227 	std::string name() const { return _name; }
snap_name()228 	std::string snap_name() const { return _current_snapshot_name; }
229 	std::string raid_path () const;
230 	bool path_is_within_session (const std::string&);
231 
writable()232 	bool writable() const { return _writable; }
233 	void set_clean ();   // == Clean and emit DirtyChanged IFF session was Dirty
234 	void set_dirty ();   // |= Dirty and emit DirtyChanged (unless already dirty or Loading, Deletion)
235 	void unset_dirty (bool emit_dirty_changed = false); // &= ~Dirty
236 	void set_deletion_in_progress ();   // |= Deletion
237 	void clear_deletion_in_progress (); // &= ~Deletion
238 
reconnection_in_progress()239 	bool reconnection_in_progress () const         { return _reconnecting_routes_in_progress; }
routes_deletion_in_progress()240 	bool routes_deletion_in_progress () const      { return _route_deletion_in_progress; }
dirty()241 	bool dirty () const                            { return _state_of_the_state & Dirty; }
deletion_in_progress()242 	bool deletion_in_progress () const             { return _state_of_the_state & Deletion; }
peaks_cleanup_in_progres()243 	bool peaks_cleanup_in_progres () const         { return _state_of_the_state & PeakCleanup; }
loading()244 	bool loading () const                          { return _state_of_the_state & Loading; }
cannot_save()245 	bool cannot_save () const                      { return _state_of_the_state & CannotSave; }
in_cleanup()246 	bool in_cleanup () const                       { return _state_of_the_state & InCleanup; }
inital_connect_or_deletion_in_progress()247 	bool inital_connect_or_deletion_in_progress () const { return _state_of_the_state & (InitialConnecting | Deletion); }
248 	bool unnamed() const;
249 
250 	void end_unnamed_status () const;
251 
252 	PBD::Signal0<void> DirtyChanged;
253 
session_directory()254 	const SessionDirectory& session_directory () const { return *(_session_dir.get()); }
255 
256 	static PBD::Signal1<void,std::string> Dialog;
257 
258 	PBD::Signal0<void> BatchUpdateStart;
259 	PBD::Signal0<void> BatchUpdateEnd;
260 
261 	int ensure_subdirs ();
262 
263 	std::string automation_dir () const;  ///< Automation data
264 	std::string analysis_dir () const;    ///< Analysis data
265 	std::string plugins_dir () const;     ///< Plugin state
266 	std::string externals_dir () const;   ///< Links to external files
267 
268 	std::string construct_peak_filepath (const std::string& audio_path, const bool in_session = false, const bool old_peak_name = false) const;
269 
270 	bool audio_source_name_is_unique (const std::string& name);
271 	std::string format_audio_source_name (const std::string& legalized_base, uint32_t nchan, uint32_t chan, bool take_required, uint32_t cnt, bool related_exists);
272 	std::string new_audio_source_path_for_embedded (const std::string& existing_path);
273 	std::string new_audio_source_path (const std::string&, uint32_t nchans, uint32_t chan, bool take_required);
274 	std::string new_midi_source_path (const std::string&, bool need_source_lock = true);
275 
276 	/** create a new track or bus from a template (XML path)
277 	 * @param how_many how many tracks or busses to create
278 	 * @param template_path path to xml template file
279 	 * @param insert_at position where to add new track, use PresentationInfo::max_order to append at the end.
280 	 * @param name name (prefix) of the route to create
281 	 * @param pd Playlist disposition
282 	 * @return list of newly created routes
283 	 */
284 	RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, const std::string& template_path, const std::string& name, PlaylistDisposition pd = NewPlaylist);
285 	RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, XMLNode&, const std::string& name, PlaylistDisposition pd = NewPlaylist);
286 	std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
287 	                                                    uint32_t channels, std::vector<std::string> const & smf_track_names);
288 
289 	int bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t,std::string)> callback);
290 
291 	void process (pframes_t nframes);
292 
293 	void send_ltc_for_cycle (samplepos_t, samplepos_t, pframes_t);
294 	void send_mclk_for_cycle (samplepos_t, samplepos_t, pframes_t, samplecnt_t);
295 
296 	BufferSet& get_silent_buffers (ChanCount count = ChanCount::ZERO);
297 	BufferSet& get_noinplace_buffers (ChanCount count = ChanCount::ZERO);
298 	BufferSet& get_scratch_buffers (ChanCount count = ChanCount::ZERO, bool silence = true);
299 	BufferSet& get_route_buffers (ChanCount count = ChanCount::ZERO, bool silence = true);
300 	BufferSet& get_mix_buffers (ChanCount count = ChanCount::ZERO);
301 
302 	bool have_rec_enabled_track () const;
303 	bool have_rec_disabled_track () const;
304 
have_captured()305 	bool have_captured() const { return _have_captured; }
306 
capture_duration()307 	samplecnt_t capture_duration () const { return _capture_duration; }
capture_xruns()308 	unsigned int capture_xruns () const { return _capture_xruns; }
export_xruns()309 	unsigned int export_xruns () const { return _export_xruns; }
310 
311 	void refill_all_track_buffers ();
butler()312 	Butler* butler() { return _butler; }
313 	void butler_transport_work (bool have_process_lock = false);
314 
315 	void refresh_disk_space ();
316 
317 	int load_routes (const XMLNode&, int);
get_routes()318 	boost::shared_ptr<RouteList> get_routes() const {
319 		return routes.reader ();
320 	}
321 
rt_tasklist()322 	boost::shared_ptr<RTTaskList> rt_tasklist () { return _rt_tasklist; }
323 
324 	RouteList get_routelist (bool mixer_order = false, PresentationInfo::Flag fl = PresentationInfo::MixerRoutes) const;
325 
selection()326 	CoreSelection& selection () const { return *_selection; }
327 
328 	/* because the set of Stripables consists of objects managed
329 	 * independently, in multiple containers within the Session (or objects
330 	 * owned by the session), we fill out a list in-place rather than
331 	 * return a pointer to a copy of the (RCU) managed list, as happens
332 	 * with get_routes()
333 	 */
334 
335 	void get_stripables (StripableList&, PresentationInfo::Flag fl = PresentationInfo::MixerStripables) const;
336 	StripableList get_stripables () const;
337 	boost::shared_ptr<RouteList> get_tracks() const;
338 	boost::shared_ptr<RouteList> get_routes_with_internal_returns() const;
339 	boost::shared_ptr<RouteList> get_routes_with_regions_at (samplepos_t const) const;
340 
341 	boost::shared_ptr<AudioTrack> get_nth_audio_track (uint32_t) const;
342 
343 	uint32_t nstripables (bool with_monitor = false) const;
nroutes()344 	uint32_t nroutes() const { return routes.reader()->size(); }
345 	uint32_t ntracks () const;
346 	uint32_t naudiotracks () const;
347 	uint32_t nbusses () const;
348 
349 	bool plot_process_graph (std::string const& file_name) const;
350 
bundles()351 	boost::shared_ptr<BundleList> bundles () {
352 		return _bundles.reader ();
353 	}
354 
355 	void notify_presentation_info_change ();
356 
357 	template<class T> void foreach_route (T *obj, void (T::*func)(Route&), bool sort = true);
358 	template<class T> void foreach_route (T *obj, void (T::*func)(boost::shared_ptr<Route>), bool sort = true);
359 	template<class T, class A> void foreach_route (T *obj, void (T::*func)(Route&, A), A arg, bool sort = true);
360 
361 	template<class A>            void foreach_track (void (Track::*method)(A), A arg);
362 	template<class A1, class A2> void foreach_track (void (Track::*method)(A1, A2), A1 arg1, A2 arg2);
363 
364 	template<class A>            void foreach_route (void (Route::*method)(A), A arg);
365 	template<class A1, class A2> void foreach_route (void (Route::*method)(A1, A2), A1 arg1, A2 arg2);
366 
367 	static const std::string session_name_is_legal (const std::string&);
368 
369 	bool io_name_is_legal (const std::string&) const;
370 	boost::shared_ptr<Route> route_by_name (std::string) const;
371 	boost::shared_ptr<Route> route_by_id (PBD::ID) const;
372 	boost::shared_ptr<Stripable> stripable_by_id (PBD::ID) const;
373 	boost::shared_ptr<Stripable> get_remote_nth_stripable (PresentationInfo::order_t n, PresentationInfo::Flag) const;
374 	boost::shared_ptr<Route> get_remote_nth_route (PresentationInfo::order_t n) const;
375 	boost::shared_ptr<Route> route_by_selected_count (uint32_t cnt) const;
376 	void routes_using_input_from (const std::string& str, RouteList& rl);
377 
378 	bool route_name_unique (std::string) const;
379 	bool route_name_internal (std::string) const;
380 
track_number_decimals()381 	uint32_t track_number_decimals () const {
382 		return _track_number_decimals;
383 	}
384 
get_record_enabled()385 	bool get_record_enabled() const {
386 		return (record_status () >= Enabled);
387 	}
388 
record_status()389 	RecordState record_status() const {
390 		return (RecordState) g_atomic_int_get (&_record_status);
391 	}
392 
actively_recording()393 	bool actively_recording () const {
394 		return record_status() == Recording;
395 	}
396 
397 	bool record_enabling_legal () const;
398 	void maybe_enable_record (bool rt_context = false);
399 	void disable_record (bool rt_context, bool force = false);
400 	void step_back_from_record ();
401 
402 	void set_all_tracks_record_enabled(bool);
403 
404 	void maybe_write_autosave ();
405 
406 	/* Emitted when all i/o connections are complete */
407 
408 	PBD::Signal0<void> IOConnectionsComplete;
409 
410 	/* Record status signals */
411 
412 	PBD::Signal0<void> RecordStateChanged; /* signals changes in recording state (i.e. are we recording) */
413 	/* XXX may 2015: paul says: it isn't clear to me that this has semantics that cannot be inferrred
414 	   from the previous signal and session state.
415 	*/
416 	PBD::Signal0<void> RecordArmStateChanged; /* signals changes in recording arming */
417 
418 	PBD::Signal0<void> UpdateRouteRecordState; /* signals potential change in route recording arming */
419 
420 	/* Emited when session is loaded */
421 	PBD::Signal0<void> SessionLoaded;
422 
423 	/* Transport mechanism signals */
424 
425 	/** Emitted on the following changes in transport state:
426 	 *  - stop (from the butler thread)
427 	 *  - change in whether or not we are looping (from the process thread)
428 	 *  - change in the play range (from the process thread)
429 	 *  - start (from the process thread)
430 	 *  - engine halted
431 	 */
432 	PBD::Signal0<void> TransportStateChange;
433 
434 	PBD::Signal1<void,samplepos_t> PositionChanged; /* sent after any non-sequential motion */
435 	PBD::Signal1<void,samplepos_t> Xrun;
436 	PBD::Signal0<void> TransportLooped;
437 
438 	/** emitted when a locate has occurred */
439 	PBD::Signal0<void> Located;
440 
441 	PBD::Signal1<void,RouteList&> RouteAdded;
442 	/** Emitted when a property of one of our route groups changes.
443 	 *  The parameter is the RouteGroup that has changed.
444 	 */
445 	PBD::Signal1<void, RouteGroup *> RouteGroupPropertyChanged;
446 	/** Emitted when a route is added to one of our route groups.
447 	 *  First parameter is the RouteGroup, second is the route.
448 	 */
449 	PBD::Signal2<void, RouteGroup *, boost::weak_ptr<Route> > RouteAddedToRouteGroup;
450 	/** Emitted when a route is removed from one of our route groups.
451 	 *  First parameter is the RouteGroup, second is the route.
452 	 */
453 	PBD::Signal2<void, RouteGroup *, boost::weak_ptr<Route> > RouteRemovedFromRouteGroup;
454 
455 	/** Emitted when a foldback send is created or deleted
456 	 */
457 	PBD::Signal0<void> FBSendsChanged;
458 
459 	/* Step Editing status changed */
460 	PBD::Signal1<void,bool> StepEditStatusChange;
461 
462 	/* Timecode state signals */
463 	PBD::Signal0<void> MtcOrLtcInputPortChanged;
464 
465 	void queue_event (SessionEvent*);
466 
467 	void request_roll_at_and_return (samplepos_t start, samplepos_t return_to);
468 	void request_bounded_roll (samplepos_t start, samplepos_t end);
469 	void request_roll (TransportRequestSource origin = TRS_UI);
470 	void request_stop (bool abort = false, bool clear_state = false, TransportRequestSource origin = TRS_UI);
471 	void request_locate (samplepos_t sample, LocateTransportDisposition ltd = RollIfAppropriate, TransportRequestSource origin = TRS_UI);
472 
473 	void request_play_loop (bool yn, bool leave_rolling = false);
get_play_loop()474 	bool get_play_loop () const { return play_loop; }
475 
last_transport_start()476 	samplepos_t last_transport_start () const { return _last_roll_location; }
477 	void goto_end ();
478 	void goto_start (bool and_roll = false);
479 	void use_rf_shuttle_speed ();
480 	void allow_auto_play (bool yn);
481 
482 	void reset_transport_speed (TransportRequestSource origin = TRS_UI);
483 	void request_transport_speed (double speed, bool as_default = true, TransportRequestSource origin = TRS_UI);
484 	void request_transport_speed_nonzero (double, bool as_default = true, TransportRequestSource origin = TRS_UI);
485 	void request_overwrite_buffer (boost::shared_ptr<Track>, OverwriteReason);
486 	void adjust_playback_buffering();
487 	void adjust_capture_buffering();
488 
global_locate_pending()489 	bool global_locate_pending() const { return _global_locate_pending; }
490 	bool locate_pending() const;
491 	bool locate_initiated() const;
492 	bool declick_in_progress () const;
493 	bool transport_locked () const;
494 
495 	bool had_destructive_tracks () const;
496 	void set_had_destructive_tracks (bool yn);
497 
498 	int wipe ();
499 
500 	samplepos_t current_end_sample () const;
501 	samplepos_t current_start_sample () const;
502 	/** "actual" sample rate of session, set by current audioengine rate, pullup/down etc. */
sample_rate()503 	samplecnt_t sample_rate () const { return _current_sample_rate; }
504 	/** "native" sample rate of session, regardless of current audioengine rate, pullup/down etc */
nominal_sample_rate()505 	samplecnt_t nominal_sample_rate () const { return _nominal_sample_rate; }
frames_per_hour()506 	samplecnt_t frames_per_hour () const { return _frames_per_hour; }
507 
samples_per_timecode_frame()508 	double samples_per_timecode_frame() const { return _samples_per_timecode_frame; }
timecode_frames_per_hour()509 	samplecnt_t timecode_frames_per_hour() const { return _timecode_frames_per_hour; }
510 
get_mtc_timecode_bits()511 	MIDI::byte get_mtc_timecode_bits() const {
512 		return mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
513 	}
514 
515 	double timecode_frames_per_second() const;
516 	bool timecode_drop_frames() const;
517 
518 	/* Locations */
519 
locations()520 	Locations *locations() { return _locations; }
521 
522 	PBD::Signal1<void,Location*>    auto_loop_location_changed;
523 	PBD::Signal1<void,Location*>    auto_punch_location_changed;
524 	PBD::Signal0<void>              locations_modified;
525 
526 	void set_auto_punch_location (Location *);
527 	void set_auto_loop_location (Location *);
528 	void set_session_extents (samplepos_t start, samplepos_t end);
session_range_is_free()529 	bool session_range_is_free () const { return _session_range_is_free; }
530 	void set_session_range_is_free (bool);
531 
get_block_size()532 	pframes_t get_block_size () const         { return current_block_size; }
worst_output_latency()533 	samplecnt_t worst_output_latency () const { return _worst_output_latency; }
worst_input_latency()534 	samplecnt_t worst_input_latency () const  { return _worst_input_latency; }
worst_route_latency()535 	samplecnt_t worst_route_latency () const  { return _worst_route_latency; }
536 	samplecnt_t worst_latency_preroll () const;
537 	samplecnt_t worst_latency_preroll_buffer_size_ceil () const;
538 
539 	PBD::Signal1<void, bool> LatencyUpdated;
540 
541 	struct SaveAs {
542 		std::string new_parent_folder;  /* parent folder where new session folder will be created */
543 		std::string new_name;           /* name of newly saved session */
544 		bool        switch_to;     /* true if we should be working on newly saved session after save-as; false otherwise */
545 		bool        include_media; /* true if the newly saved session should contain references to media */
546 		bool        copy_media;    /* true if media files (audio, media, etc) should be copied into newly saved session; false otherwise */
547 		bool        copy_external; /* true if external media should be consolidated into the newly saved session; false otherwise */
548 
549 		std::string final_session_folder_name; /* filled in by * Session::save_as(), provides full path to newly saved session */
550 
551 		/* emitted as we make progress. 3 arguments passed to signal
552 		 * handler:
553 		 *
554 		 *  1: percentage complete measured as a fraction (0-1.0) of
555 		 *     total data copying done.
556 		 *  2: number of files copied so far
557 		 *  3: total number of files to copy
558 		 *
559 		 * Handler should return true for save-as to continue, or false
560 		 * to stop (and remove all evidence of partial save-as).
561 		 */
562 		PBD::Signal3<bool,float,int64_t,int64_t> Progress;
563 
564 		/* if save_as() returns non-zero, this string will indicate the reason why.
565 		 */
566 		std::string failure_message;
567 	};
568 
569 	int save_as (SaveAs&);
570 
571 	/** save session
572 	 * @param snapshot_name name of the session (use an empty string for the current name)
573 	 * @param pending save a 'recovery', not full state (default: false)
574 	 * @param switch_to_snapshot switch to given snapshot after saving (default: false)
575 	 * @param template_only save a session template (default: false)
576 	 * @param for_archive save only data relevant for session-archive
577 	 * @param only_used_assets skip Sources that are not used, mainly useful with \p for_archive
578 	 * @return zero on success
579 	 */
580 	int save_state (std::string snapshot_name = "",
581 	                bool pending = false,
582 	                bool switch_to_snapshot = false,
583 	                bool template_only = false,
584 	                bool for_archive = false,
585 	                bool only_used_assets = false);
586 
587 	enum ArchiveEncode {
588 		NO_ENCODE,
589 		FLAC_16BIT,
590 		FLAC_24BIT
591 	};
592 
593 	int archive_session (const std::string&, const std::string&,
594 	                     ArchiveEncode compress_audio = FLAC_16BIT,
595 	                     PBD::FileArchive::CompressionLevel compression_level = PBD::FileArchive::CompressGood,
596 	                     bool only_used_sources = false,
597 	                     Progress* p = 0);
598 
599 	int restore_state (std::string snapshot_name);
600 	int save_template (const std::string& template_name, const std::string& description = "", bool replace_existing = false);
601 	int save_history (std::string snapshot_name = "");
602 	int restore_history (std::string snapshot_name);
603 	void remove_state (std::string snapshot_name);
604 	void rename_state (std::string old_name, std::string new_name);
605 	void remove_pending_capture_state ();
606 	int rename (const std::string&);
get_nsm_state()607 	bool get_nsm_state () const { return _under_nsm_control; }
set_nsm_state(bool state)608 	void set_nsm_state (bool state) { _under_nsm_control = state; }
609 	bool save_default_options ();
610 
611 	PBD::Signal1<void,std::string> StateSaved;
612 	PBD::Signal0<void> StateReady;
613 
614 	/* emitted when session needs to be saved due to some internal
615 	 * event or condition (i.e. not in response to a user request).
616 	 *
617 	 * Only one object should
618 	 * connect to this signal and take responsibility.
619 	 *
620 	 * Argument is the snapshot name to use when saving.
621 	 */
622 	PBD::Signal1<void,std::string> SaveSessionRequested;
623 
624 	/* emitted during a session save to allow other entities to add state, via
625 	 * extra XML, to the session state
626 	 */
627 	PBD::Signal0<void> SessionSaveUnderway;
628 
629 	std::vector<std::string> possible_states() const;
630 	static std::vector<std::string> possible_states (std::string path);
631 
632 	bool export_track_state (boost::shared_ptr<RouteList> rl, const std::string& path);
633 
634 	/// The instant xml file is written to the session directory
635 	void add_instant_xml (XMLNode&, bool write_to_config = true);
636 	XMLNode* instant_xml (const std::string& str);
637 
638 	enum StateOfTheState {
639 		Clean = 0x0,
640 		Dirty = 0x1,
641 		CannotSave = 0x2,
642 		Deletion = 0x4,
643 		InitialConnecting = 0x8,
644 		Loading = 0x10,
645 		InCleanup = 0x20,
646 		PeakCleanup = 0x40
647 	};
648 
649 	class StateProtector {
650 		public:
StateProtector(Session * s)651 			StateProtector (Session* s) : _session (s) {
652 				g_atomic_int_inc (&s->_suspend_save);
653 			}
~StateProtector()654 			~StateProtector () {
655 				if (g_atomic_int_dec_and_test (&_session->_suspend_save)) {
656 					while (_session->_save_queued) {
657 						_session->_save_queued = false;
658 						_session->save_state ("");
659 					}
660 					while (_session->_save_queued_pending) {
661 						_session->_save_queued_pending = false;
662 						_session->save_state ("", true);
663 					}
664 				}
665 			}
666 		private:
667 			Session * _session;
668 	};
669 
670 	class ProcessorChangeBlocker {
671 	public:
672 		ProcessorChangeBlocker (Session* s, bool rc = true)
_session(s)673 			: _session (s)
674 			, _reconfigure_on_delete (rc)
675 		{
676 			g_atomic_int_inc (&s->_ignore_route_processor_changes);
677 		}
678 
~ProcessorChangeBlocker()679 		~ProcessorChangeBlocker ()
680 		{
681 			if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) {
682 				if (g_atomic_int_compare_and_exchange (&_session->_ignored_a_processor_change, 1, 0)) {
683 					if (_reconfigure_on_delete) {
684 						_session->route_processors_changed (RouteProcessorChange ());
685 					}
686 				}
687 			}
688 		}
689 	private:
690 		Session* _session;
691 		bool _reconfigure_on_delete;
692 	};
693 
694 	RouteGroup* new_route_group (const std::string&);
695 	void add_route_group (RouteGroup *);
remove_route_group(RouteGroup * rg)696 	void remove_route_group (RouteGroup* rg) { if (rg) remove_route_group (*rg); }
697 	void remove_route_group (RouteGroup&);
698 	void reorder_route_groups (std::list<RouteGroup*>);
699 
700 	RouteGroup* route_group_by_name (std::string);
701 	RouteGroup& all_route_group() const;
702 
703 	PBD::Signal1<void,RouteGroup*> route_group_added;
704 	PBD::Signal0<void>             route_group_removed;
705 	PBD::Signal0<void>             route_groups_reordered;
706 
foreach_route_group(boost::function<void (RouteGroup *)> f)707 	void foreach_route_group (boost::function<void(RouteGroup*)> f) {
708 		for (std::list<RouteGroup *>::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) {
709 			f (*i);
710 		}
711 	}
712 
route_groups()713 	std::list<RouteGroup*> const & route_groups () const {
714 		return _route_groups;
715 	}
716 
717 	/* fundamental operations. duh. */
718 
719 	std::list<boost::shared_ptr<AudioTrack> > new_audio_track (
720 		int input_channels,
721 		int output_channels,
722 		RouteGroup* route_group,
723 		uint32_t how_many,
724 		std::string name_template,
725 		PresentationInfo::order_t order,
726 		TrackMode mode = Normal,
727 		bool input_auto_connect = true
728 		);
729 
730 	std::list<boost::shared_ptr<MidiTrack> > new_midi_track (
731 		const ChanCount& input, const ChanCount& output, bool strict_io,
732 		boost::shared_ptr<PluginInfo> instrument,
733 		Plugin::PresetRecord* pset,
734 		RouteGroup* route_group, uint32_t how_many, std::string name_template,
735 		PresentationInfo::order_t,
736 		TrackMode mode = Normal,
737 		bool input_auto_connect = true
738 		);
739 
740 	RouteList new_audio_route (int input_channels, int output_channels, RouteGroup* route_group, uint32_t how_many, std::string name_template, PresentationInfo::Flag, PresentationInfo::order_t);
741 	RouteList new_midi_route (RouteGroup* route_group, uint32_t how_many, std::string name_template, bool strict_io, boost::shared_ptr<PluginInfo> instrument, Plugin::PresetRecord*, PresentationInfo::Flag, PresentationInfo::order_t);
742 
743 	void remove_routes (boost::shared_ptr<RouteList>);
744 	void remove_route (boost::shared_ptr<Route>);
745 
746 	void resort_routes ();
747 	void resort_routes_using (boost::shared_ptr<RouteList>);
748 
engine()749 	AudioEngine & engine() { return _engine; }
engine()750 	AudioEngine const & engine () const { return _engine; }
751 
752 	static std::string default_track_name_pattern (DataType);
753 
754 	/* Time */
755 
transport_sample()756 	samplepos_t transport_sample () const { return _transport_sample; }
record_location()757 	samplepos_t record_location () const { return _last_record_location; }
758 	samplepos_t audible_sample (bool* latent_locate = NULL) const;
requested_return_sample()759 	samplepos_t requested_return_sample() const { return _requested_return_sample; }
760 	void set_requested_return_sample(samplepos_t return_to);
nominal_jack_transport_sample()761 	boost::optional<samplepos_t> const & nominal_jack_transport_sample() { return _nominal_jack_transport_sample; }
762 
763 	bool compute_audible_delta (samplepos_t& pos_and_delta) const;
remaining_latency_preroll()764 	samplecnt_t remaining_latency_preroll () const { return _remaining_latency_preroll; }
765 
766 	enum PullupFormat {
767 		pullup_Plus4Plus1,
768 		pullup_Plus4,
769 		pullup_Plus4Minus1,
770 		pullup_Plus1,
771 		pullup_None,
772 		pullup_Minus1,
773 		pullup_Minus4Plus1,
774 		pullup_Minus4,
775 		pullup_Minus4Minus1
776 	};
777 
778 	void sync_time_vars();
779 
780 	void bbt_time (samplepos_t when, Timecode::BBT_Time&);
781 	void timecode_to_sample(Timecode::Time& timecode, samplepos_t& sample, bool use_offset, bool use_subframes) const;
782 	void sample_to_timecode(samplepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const;
783 	void timecode_time (Timecode::Time &);
784 	void timecode_time (samplepos_t when, Timecode::Time&);
785 	void timecode_time_subframes (samplepos_t when, Timecode::Time&);
786 
787 	void timecode_duration (samplecnt_t, Timecode::Time&) const;
788 	void timecode_duration_string (char *, size_t len, samplecnt_t) const;
789 
790 	samplecnt_t convert_to_samples (AnyTime const & position);
791 	samplecnt_t any_duration_to_samples (samplepos_t position, AnyTime const & duration);
792 
793 	static PBD::Signal1<void, samplepos_t> StartTimeChanged;
794 	static PBD::Signal1<void, samplepos_t> EndTimeChanged;
795 
796 	void   request_sync_source (boost::shared_ptr<TransportMaster>);
797 	bool   synced_to_engine() const;
798 
engine_speed()799 	double engine_speed() const { return _engine_speed; }
800 	double actual_speed() const;
801 	double transport_speed() const;
802 	/** @return true if the transport state (TFSM) is stopped */
803 	bool   transport_stopped() const;
804 	/** @return true if the transport state (TFSM) is stopped or stopping */
805 	bool   transport_stopped_or_stopping() const;
806 	/** @return true if the transport state (TFSM) is rolling.
807 	 *  Note: the transport may not yet move if pre-roll or count-in in ongoing.
808 	 */
809 	bool   transport_state_rolling() const;
810 	/** @return true if the the transport is actively (audible) rolling.
811 	 *  playback speed is not zero, and count-in as well as latency-preroll is complete,
812 	 *  and _transport_sample changes every process cycle.
813 	 */
814 	bool   transport_rolling() const;
815 	bool   transport_will_roll_forwards() const;
816 
silent()817 	bool silent () { return _silent; }
818 
819 	bool punch_is_possible () const;
820 	bool loop_is_possible () const;
821 	PBD::Signal0<void> PunchLoopConstraintChange;
822 
tempo_map()823 	TempoMap&       tempo_map()       { return *_tempo_map; }
tempo_map()824 	const TempoMap& tempo_map() const { return *_tempo_map; }
825 	void maybe_update_tempo_from_midiclock_tempo (float bpm);
826 
get_xrun_count()827 	unsigned int    get_xrun_count () const {return _xrun_count; }
828 	void            reset_xrun_count ();
829 
830 	/* region info  */
831 
832 	boost::shared_ptr<Region> find_whole_file_parent (boost::shared_ptr<Region const>) const;
833 
834 	boost::shared_ptr<Region>      XMLRegionFactory (const XMLNode&, bool full);
835 	boost::shared_ptr<AudioRegion> XMLAudioRegionFactory (const XMLNode&, bool full);
836 	boost::shared_ptr<MidiRegion>  XMLMidiRegionFactory (const XMLNode&, bool full);
837 
838 	/* source management */
839 
840 	void import_files (ImportStatus&);
841 	bool sample_rate_convert (ImportStatus&, std::string infile, std::string& outfile);
842 	std::string build_tmp_convert_name (std::string file);
843 
844 	boost::shared_ptr<ExportHandler> get_export_handler ();
845 	boost::shared_ptr<ExportStatus> get_export_status ();
846 
847 	int start_audio_export (samplepos_t position, bool realtime = false, bool region_export = false);
848 
849 	PBD::Signal1<int, samplecnt_t> ProcessExport;
850 	static PBD::Signal2<void,std::string, std::string> Exported;
851 
852 	void add_source (boost::shared_ptr<Source>);
853 	void remove_source (boost::weak_ptr<Source>);
854 
855 	void cleanup_regions();
856 	bool can_cleanup_peakfiles () const;
857 	int  cleanup_peakfiles ();
858 	int  cleanup_sources (CleanupReport&);
859 	int  cleanup_trash_sources (CleanupReport&);
860 
861 	int destroy_sources (std::list<boost::shared_ptr<Source> > const&);
862 
863 	int remove_last_capture ();
864 	void get_last_capture_sources (std::list<boost::shared_ptr<Source> >&);
865 
866 	/** handlers should return -1 for "stop cleanup",
867 	    0 for "yes, delete this playlist",
868 	    1 for "no, don't delete this playlist".
869 	*/
870 	static PBD::Signal1<int,boost::shared_ptr<Playlist> >  AskAboutPlaylistDeletion;
871 
872 	/** handlers should return 0 for "ignore the rate mismatch",
873 	    !0 for "do not use this session"
874 	*/
875 	static PBD::Signal2<int, samplecnt_t, samplecnt_t> AskAboutSampleRateMismatch;
876 
877 	/** non interactive message */
878 	static PBD::Signal2<void, samplecnt_t, samplecnt_t> NotifyAboutSampleRateMismatch;
879 
880 	/** handlers should return !0 for use pending state, 0 for ignore it.
881 	 */
882 	static PBD::Signal0<int> AskAboutPendingState;
883 
884 	boost::shared_ptr<AudioFileSource> create_audio_source_for_session (
885 		size_t, std::string const &, uint32_t);
886 
887 	boost::shared_ptr<MidiSource> create_midi_source_for_session (std::string const &);
888 	boost::shared_ptr<MidiSource> create_midi_source_by_stealing_name (boost::shared_ptr<Track>);
889 
890 	boost::shared_ptr<Source> source_by_id (const PBD::ID&);
891 	boost::shared_ptr<AudioFileSource> audio_source_by_path_and_channel (const std::string&, uint16_t) const;
892 	boost::shared_ptr<MidiSource> midi_source_by_path (const std::string&, bool need_source_lock) const;
893 	uint32_t count_sources_by_origin (const std::string&);
894 
895 	void add_playlist (boost::shared_ptr<Playlist>, bool unused = false);
896 
897 	/* Curves and AutomationLists (TODO when they go away) */
898 	void add_automation_list(AutomationList*);
899 
900 	/* auditioning */
901 
the_auditioner()902 	boost::shared_ptr<Auditioner> the_auditioner() { return auditioner; }
903 	void audition_playlist ();
904 	void audition_region (boost::shared_ptr<Region>);
905 	void cancel_audition ();
906 	bool is_auditioning () const;
907 
908 	PBD::Signal1<void,bool> AuditionActive;
909 
910 	/* session script */
911 	void register_lua_function (const std::string&, const std::string&, const LuaScriptParamList&);
912 	void unregister_lua_function (const std::string& name);
913 	std::vector<std::string> registered_lua_functions ();
registered_lua_function_count()914 	uint32_t registered_lua_function_count () const { return _n_lua_scripts; }
915 	void scripts_changed (); // called from lua, updates _n_lua_scripts
916 
917 	PBD::Signal0<void> LuaScriptsChanged;
918 
919 	/* flattening stuff */
920 
921 	boost::shared_ptr<Region> write_one_track (Track&, samplepos_t start, samplepos_t end,
922 	                                           bool overwrite, std::vector<boost::shared_ptr<Source> >&, InterThreadInfo& wot,
923 	                                           boost::shared_ptr<Processor> endpoint,
924 	                                           bool include_endpoint, bool for_export, bool for_freeze, std::string const& name);
925 	int freeze_all (InterThreadInfo&);
926 
927 	/* session-wide solo/mute/rec-enable */
928 
929 	bool muted () const;
930 	std::vector<boost::weak_ptr<AutomationControl> > cancel_all_mute ();
931 
soloing()932 	bool soloing () const { return _non_soloed_outs_muted; }
933 	bool listening () const;
solo_isolated()934 	bool solo_isolated () const { return _solo_isolated_cnt > 0; }
935 	void cancel_all_solo ();
936 
937 	bool solo_selection_active ();
938 	void solo_selection (StripableList&, bool);
939 
940 	void clear_all_solo_state (boost::shared_ptr<RouteList>);
941 	void prepare_momentary_solo (SoloMuteRelease* smr = NULL, bool exclusive = false, boost::shared_ptr<Route> route = boost::shared_ptr<Route> ());
942 
943 	static const SessionEvent::RTeventCallback rt_cleanup;
944 
945 	/* Control-based methods */
946 
947 	void set_controls (boost::shared_ptr<ControlList>, double val, PBD::Controllable::GroupControlDisposition);
948 	void set_control (boost::shared_ptr<AutomationControl>, double val, PBD::Controllable::GroupControlDisposition);
949 
950 	void set_exclusive_input_active (boost::shared_ptr<RouteList> rt, bool onoff, bool flip_others = false);
951 
952 	PBD::Signal1<void,bool> SoloActive;
953 	PBD::Signal0<void> SoloChanged;
954 	PBD::Signal0<void> MuteChanged;
955 	PBD::Signal0<void> IsolatedChanged;
956 	PBD::Signal0<void> MonitorChanged;
957 	PBD::Signal0<void> MonitorBusAddedOrRemoved;
958 
959 	PBD::Signal0<void> session_routes_reconnected;
960 
961 	/* monitor/master out */
962 	int add_master_bus (ChanCount const&);
963 
964 	void reset_monitor_section ();
monitor_active()965 	bool monitor_active() const { return (_monitor_out && _monitor_out->monitor_control () && _monitor_out->monitor_control ()->monitor_active()); }
966 
monitor_out()967 	boost::shared_ptr<Route> monitor_out() const { return _monitor_out; }
master_out()968 	boost::shared_ptr<Route> master_out() const { return _master_out; }
969 	boost::shared_ptr<GainControl>  master_volume () const;
970 
master_order_key()971 	PresentationInfo::order_t master_order_key () const { return _master_out ? _master_out->presentation_info ().order () : -1; }
972 	bool ensure_stripable_sort_order ();
973 
974 	void globally_add_internal_sends (boost::shared_ptr<Route> dest, Placement p, bool);
975 	void globally_set_send_gains_from_track (boost::shared_ptr<Route> dest);
976 	void globally_set_send_gains_to_zero (boost::shared_ptr<Route> dest);
977 	void globally_set_send_gains_to_unity (boost::shared_ptr<Route> dest);
978 	void add_internal_sends (boost::shared_ptr<Route> dest, Placement p, boost::shared_ptr<RouteList> senders);
979 	void add_internal_send (boost::shared_ptr<Route>, int, boost::shared_ptr<Route>);
980 	void add_internal_send (boost::shared_ptr<Route>, boost::shared_ptr<Processor>, boost::shared_ptr<Route>);
981 
set_disable_all_loaded_plugins(bool yn)982 	static void set_disable_all_loaded_plugins (bool yn) {
983 		_disable_all_loaded_plugins = yn;
984 	}
get_disable_all_loaded_plugins()985 	static bool get_disable_all_loaded_plugins() {
986 		return _disable_all_loaded_plugins;
987 	}
set_bypass_all_loaded_plugins(bool yn)988 	static void set_bypass_all_loaded_plugins (bool yn) {
989 		_bypass_all_loaded_plugins = yn;
990 	}
get_bypass_all_loaded_plugins()991 	static bool get_bypass_all_loaded_plugins() {
992 		return _bypass_all_loaded_plugins;
993 	}
994 
995 	uint32_t next_send_id();
996 	uint32_t next_aux_send_id();
997 	uint32_t next_return_id();
998 	uint32_t next_insert_id();
999 	void mark_send_id (uint32_t);
1000 	void mark_aux_send_id (uint32_t);
1001 	void mark_return_id (uint32_t);
1002 	void mark_insert_id (uint32_t);
1003 	void unmark_send_id (uint32_t);
1004 	void unmark_aux_send_id (uint32_t);
1005 	void unmark_return_id (uint32_t);
1006 	void unmark_insert_id (uint32_t);
1007 
1008 	/* s/w "RAID" management */
1009 
1010 	boost::optional<samplecnt_t> available_capture_duration();
1011 
1012 	/* I/O bundles */
1013 
1014 	void add_bundle (boost::shared_ptr<Bundle>, bool emit_signal = true);
1015 	void remove_bundle (boost::shared_ptr<Bundle>);
1016 	boost::shared_ptr<Bundle> bundle_by_name (std::string) const;
1017 
1018 	PBD::Signal0<void> BundleAddedOrRemoved;
1019 
1020 	void midi_panic ();
1021 
1022 	/* History (for editors, mixers, UIs etc.) */
1023 
1024 	/** Undo some transactions.
1025 	 * @param n Number of transactions to undo.
1026 	 */
1027 	void undo (uint32_t n);
1028 	/** Redo some transactions.
1029 	 * @param n Number of transactions to undo.
1030 	 */
1031 	void redo (uint32_t n);
1032 
history()1033 	UndoHistory& history() { return _history; }
1034 
undo_depth()1035 	uint32_t undo_depth() const { return _history.undo_depth(); }
redo_depth()1036 	uint32_t redo_depth() const { return _history.redo_depth(); }
next_undo()1037 	std::string next_undo() const { return _history.next_undo(); }
next_redo()1038 	std::string next_redo() const { return _history.next_redo(); }
1039 
1040 	/** begin collecting undo information
1041 	 *
1042 	 * This call must always be followed by either
1043 	 * begin_reversible_command() or commit_reversible_command()
1044 	 *
1045 	 * @param cmd_name human readable name for the undo operation
1046 	 */
1047 	void begin_reversible_command (const std::string& cmd_name);
1048 	void begin_reversible_command (GQuark);
1049 	/** abort an open undo command
1050 	 * This must only be called after begin_reversible_command ()
1051 	 */
1052 	void abort_reversible_command ();
1053 	/** finalize an undo command and commit pending transactions
1054 	 *
1055 	 * This must only be called after begin_reversible_command ()
1056 	 * @param cmd (additional) command to add
1057 	 */
1058 	void commit_reversible_command (Command* cmd = 0);
1059 
1060 	void add_command (Command *const cmd);
1061 
1062 	/** create an StatefulDiffCommand from the given object and add it to the stack.
1063 	 *
1064 	 * This function must only be called after  begin_reversible_command.
1065 	 * Failing to do so may lead to a crash.
1066 	 *
1067 	 * @param sfd the object to diff
1068 	 * @returns the allocated StatefulDiffCommand (already added via add_command)
1069 	 */
1070 	PBD::StatefulDiffCommand* add_stateful_diff_command (boost::shared_ptr<PBD::StatefulDestructible> sfd);
1071 
1072 	/** @return The list of operations that are currently in progress */
current_operations()1073 	std::list<GQuark> const & current_operations () {
1074 		return _current_trans_quarks;
1075 	}
1076 
1077 	bool operation_in_progress (GQuark) const;
1078 
1079 	/**
1080 	 * Test if any undo commands were added since the
1081 	 * call to begin_reversible_command ()
1082 	 *
1083 	 * This is is useful to determine if an undoable
1084 	 * action was performed before adding additional
1085 	 * information (e.g. selection changes) to the
1086 	 * undo transaction.
1087 	 *
1088 	 * @return true if undo operation is valid but empty
1089 	 */
collected_undo_commands()1090 	bool collected_undo_commands () const {
1091 		return _current_trans && !_current_trans->empty ();
1092 	}
1093 
1094 	/**
1095 	 * Abort reversible commend IFF no undo changes
1096 	 * have been collected.
1097 	 * @return true if undo operation was aborted.
1098 	 */
1099 	bool abort_empty_reversible_command ();
1100 
1101 	void add_commands (std::vector<Command*> const & cmds);
1102 
1103 	std::map<PBD::ID,PBD::StatefulDestructible*> registry;
1104 
1105 	// these commands are implemented in libs/ardour/session_command.cc
1106 	Command* memento_command_factory(XMLNode* n);
1107 	Command* stateful_diff_command_factory (XMLNode *);
1108 	void register_with_memento_command_factory(PBD::ID, PBD::StatefulDestructible*);
1109 
1110 	/* clicking */
1111 
click_io()1112 	boost::shared_ptr<IO> click_io() { return _click_io; }
click_gain()1113 	boost::shared_ptr<Amp> click_gain() { return _click_gain; }
1114 
1115 	/* disk, buffer loads */
1116 
1117 	uint32_t playback_load ();
1118 	uint32_t capture_load ();
1119 
1120 	/* ranges */
1121 
1122 	void request_play_range (std::list<AudioRange>*, bool leave_rolling = false);
1123 	void request_cancel_play_range ();
get_play_range()1124 	bool get_play_range () const { return _play_range; }
1125 
1126 	void maybe_update_session_range (samplepos_t, samplepos_t);
1127 
1128 	/* preroll */
1129 	samplecnt_t preroll_samples (samplepos_t) const;
1130 
1131 	void request_preroll_record_trim (samplepos_t start, samplecnt_t preroll);
1132 	void request_count_in_record ();
1133 
preroll_record_trim_len()1134 	samplecnt_t preroll_record_trim_len () const { return _preroll_record_trim_len; }
1135 
1136 	/* temporary hacks to allow selection to be pushed from GUI into backend.
1137 	   Whenever we move the selection object into libardour, these will go away.
1138 	 */
1139 	void set_range_selection (samplepos_t start, samplepos_t end);
1140 	void set_object_selection (samplepos_t start, samplepos_t end);
1141 	void clear_range_selection ();
1142 	void clear_object_selection ();
1143 
1144 	/* buffers for gain and pan */
1145 
1146 	gain_t* gain_automation_buffer () const;
1147 	gain_t* trim_automation_buffer () const;
1148 	gain_t* send_gain_automation_buffer () const;
1149 	gain_t* scratch_automation_buffer () const;
1150 	pan_t** pan_automation_buffer () const;
1151 
1152 	void ensure_buffer_set (BufferSet& buffers, const ChanCount& howmany);
1153 
1154 	/* VST support */
1155 
1156 	static int  vst_current_loading_id;
1157 	static const char* vst_can_do_strings[];
1158 	static const int vst_can_do_string_count;
1159 
1160 	static intptr_t vst_callback (
1161 		AEffect* effect,
1162 		int32_t opcode,
1163 		int32_t index,
1164 		intptr_t value,
1165 		void* ptr,
1166 		float opt
1167 		);
1168 
1169 	static PBD::Signal0<void> SendFeedback;
1170 
1171 	/* Speakers */
1172 
1173 	boost::shared_ptr<Speakers> get_speakers ();
1174 
1175 	/* Controllables */
1176 
1177 	boost::shared_ptr<Processor> processor_by_id (PBD::ID) const;
1178 
1179 	boost::shared_ptr<PBD::Controllable> controllable_by_id (const PBD::ID&);
1180 	boost::shared_ptr<AutomationControl> automation_control_by_id (const PBD::ID&);
1181 
1182 	void add_controllable (boost::shared_ptr<PBD::Controllable>);
1183 
1184 	boost::shared_ptr<PBD::Controllable> solo_cut_control() const;
1185 	boost::shared_ptr<PBD::Controllable> recently_touched_controllable () const;
1186 
1187 	SessionConfiguration config;
1188 
cfg()1189 	SessionConfiguration* cfg () { return &config; }
1190 
exporting()1191 	bool exporting () const {
1192 		return _exporting;
1193 	}
1194 
realtime_export()1195 	bool realtime_export() const {
1196 		return _realtime_export;
1197 	}
1198 
bounce_processing()1199 	bool bounce_processing() const {
1200 		return _bounce_processing_active;
1201 	}
1202 
1203 	/* this is a private enum, but setup_enum_writer() needs it,
1204 	   and i can't find a way to give that function
1205 	   friend access. sigh.
1206 	*/
1207 
1208 	enum PostTransportWork {
1209 		PostTransportStop               = 0x1,
1210 		PostTransportLocate             = 0x2,
1211 		PostTransportAbort              = 0x8,
1212 		PostTransportOverWrite          = 0x10,
1213 		PostTransportAudition           = 0x20,
1214 		PostTransportReverse            = 0x40,
1215 		PostTransportClearSubstate      = 0x80,
1216 		PostTransportAdjustPlaybackBuffering  = 0x100,
1217 		PostTransportAdjustCaptureBuffering   = 0x200,
1218 		PostTransportLoopChanged        = 0x400
1219 	};
1220 
playlists()1221 	boost::shared_ptr<SessionPlaylists> playlists () const { return _playlists; }
1222 
1223 	void send_mmc_locate (samplepos_t);
queue_full_time_code()1224 	void queue_full_time_code () { _send_timecode_update = true; }
queue_song_position_pointer()1225 	void queue_song_position_pointer () { /* currently does nothing */ }
1226 
step_editing()1227 	bool step_editing() const { return (_step_editors > 0); }
1228 
1229 	void request_suspend_timecode_transmission ();
1230 	void request_resume_timecode_transmission ();
1231 	bool timecode_transmission_suspended () const;
1232 
1233 	std::vector<std::string> source_search_path(DataType) const;
1234 	void ensure_search_path_includes (const std::string& path, DataType type);
1235 	void remove_dir_from_search_path (const std::string& path, DataType type);
1236 
1237 	std::list<std::string> unknown_processors () const;
1238 
1239 	std::list<std::string> missing_filesources (DataType) const;
1240 
1241 	/** Emitted when a feedback cycle has been detected within Ardour's signal
1242 	    processing path.  Until it is fixed (by the user) some (unspecified)
1243 	    routes will not be run.
1244 	*/
1245 	static PBD::Signal0<void> FeedbackDetected;
1246 
1247 	/** Emitted when a graph sort has successfully completed, which means
1248 	    that it has no feedback cycles.
1249 	*/
1250 	static PBD::Signal0<void> SuccessfulGraphSort;
1251 
1252 	/* handlers can return an integer value:
1253 	   0: config.set_audio_search_path() or config.set_midi_search_path() was used
1254 	   to modify the search path and we should try to find it again.
1255 	   1: quit entire session load
1256 	   2: as 0, but don't ask about other missing files
1257 	   3: don't ask about other missing files, and just mark this one missing
1258 	   -1: just mark this one missing
1259 	   any other value: as -1
1260 	*/
1261 	static PBD::Signal3<int,Session*,std::string,DataType> MissingFile;
1262 
set_missing_file_replacement(const std::string & mfr)1263 	void set_missing_file_replacement (const std::string& mfr) {
1264 		_missing_file_replacement = mfr;
1265 	}
1266 
1267 	/** Emitted when the session wants Ardour to quit */
1268 	static PBD::Signal0<void> Quit;
1269 
1270 	/** Emitted when Ardour is asked to load a session in an older session
1271 	 * format, and makes a backup copy.
1272 	 */
1273 	static PBD::Signal2<void,std::string,std::string> VersionMismatch;
1274 
scene_changer()1275 	SceneChanger* scene_changer() const { return _scene_changer; }
1276 
1277 	/* asynchronous MIDI control ports */
1278 
1279 	boost::shared_ptr<Port> mmc_output_port () const;
1280 	boost::shared_ptr<Port> mmc_input_port () const;
1281 	boost::shared_ptr<Port> scene_input_port () const;
1282 	boost::shared_ptr<Port> scene_output_port () const;
1283 
1284 	boost::shared_ptr<AsyncMIDIPort> vkbd_output_port () const;
1285 
1286 	/* synchronous MIDI ports used for synchronization */
1287 
1288 	boost::shared_ptr<MidiPort> midi_clock_output_port () const;
1289 	boost::shared_ptr<MidiPort> mtc_output_port () const;
ltc_output_port()1290 	boost::shared_ptr<Port> ltc_output_port() const { return _ltc_output_port; }
1291 
mmc()1292 	MIDI::MachineControl& mmc() { return *_mmc; }
1293 
1294 	void reconnect_midi_scene_ports (bool);
1295 	void reconnect_mmc_ports (bool);
1296 
1297 	void reconnect_ltc_output ();
1298 
vca_manager()1299 	VCAManager& vca_manager() { return *_vca_manager; }
vca_manager_ptr()1300 	VCAManager* vca_manager_ptr() { return _vca_manager; }
1301 
1302 	void auto_connect_thread_wakeup ();
1303 
1304 	double compute_speed_from_master (pframes_t nframes);
1305 	bool   transport_master_is_external() const;
1306 	bool   transport_master_no_external_or_using_engine() const;
1307 	boost::shared_ptr<TransportMaster> transport_master() const;
1308 
1309 	void import_pt_sources (PTFFormat& ptf, ImportStatus& status);
1310 	void import_pt_rest (PTFFormat& ptf);
1311 	bool import_sndfile_as_region (std::string path, SrcQuality quality, samplepos_t& pos, SourceList& sources, ImportStatus& status, uint32_t current, uint32_t total);
1312 
1313 	struct ptflookup {
1314 		uint16_t index1;
1315 		uint16_t index2;
1316 		PBD::ID  id;
1317 
1318 		bool operator ==(const struct ptflookup& other) {
1319 			return (this->index1 == other.index1);
1320 		}
1321 	};
1322 	std::vector<struct ptflookup> ptfwavpair;
1323 	SourceList pt_imported_sources;
1324 
1325 	enum TimingTypes {
1326 		OverallProcess = 0,
1327 		ProcessFunction = 1,
1328 		NoRoll = 2,
1329 		Roll = 3,
1330 		/* end */
1331 		NTT = 4
1332 	};
1333 
1334 	PBD::TimingStats dsp_stats[NTT];
1335 
1336 protected:
1337 	friend class AudioEngine;
1338 	void set_block_size (pframes_t nframes);
1339 	void set_sample_rate (samplecnt_t nframes);
1340 
1341 	friend class Route;
1342 	void update_latency_compensation (bool force, bool called_from_backend);
1343 
1344 	/* transport API */
1345 
1346 	void locate (samplepos_t, bool for_loop_end=false, bool force=false, bool with_mmc=true);
1347 	void stop_transport (bool abort = false, bool clear_state = false);
1348 	void start_transport ();
1349 	void butler_completed_transport_work ();
1350 	void post_locate ();
1351 	void schedule_butler_for_transport_work ();
1352 	bool should_roll_after_locate () const;
1353 	bool user_roll_after_locate () const;
1354 	bool should_stop_before_locate () const;
position()1355 	samplepos_t position() const { return _transport_sample; }
1356 	void set_transport_speed (double speed);
1357 	bool need_declick_before_locate () const;
1358 
1359 private:
1360 	int  create (const std::string& mix_template, BusProfile const *, bool unnamed);
1361 	void destroy ();
1362 
1363 	static guint _name_id_counter;
1364 	static void init_name_id_counter (guint n);
1365 	static unsigned int name_id_counter ();
1366 
1367 	boost::shared_ptr<SessionPlaylists> _playlists;
1368 
1369 	/* stuff used in process() should be close together to
1370 	   maximise cache hits
1371 	*/
1372 
1373 	typedef void (Session::*process_function_type)(pframes_t);
1374 
1375 	AudioEngine&            _engine;
1376 	process_function_type    process_function;
1377 	process_function_type    last_process_function;
1378 	bool                    _bounce_processing_active;
1379 	bool                     waiting_for_sync_offset;
1380 	samplecnt_t             _base_sample_rate;     // sample-rate of the session at creation time, "native" SR
1381 	samplecnt_t             _nominal_sample_rate;  // overridden by audioengine setting
1382 	samplecnt_t             _current_sample_rate;  // this includes video pullup offset
1383 	samplepos_t             _transport_sample;
1384 	GATOMIC_QUAL gint       _seek_counter;
1385 	GATOMIC_QUAL gint       _butler_seek_counter;
1386 	Location*               _session_range_location; ///< session range, or 0 if there is nothing in the session yet
1387 	bool                    _session_range_is_free;
1388 	bool                    _silent;
1389 	samplecnt_t             _remaining_latency_preroll;
1390 
1391 	// varispeed playback -- TODO: move out of session to backend.
1392 	double                  _engine_speed;
1393 	double                  _default_transport_speed;
1394 	double                  _default_engine_speed;
1395 	double                  _last_transport_speed;
1396 	double                  _requested_transport_speed;
1397 	double                  _signalled_varispeed;
1398 
1399 	bool                     auto_play_legal;
1400 	samplepos_t             _requested_return_sample;
1401 	pframes_t                current_block_size;
1402 	samplecnt_t             _worst_output_latency;
1403 	samplecnt_t             _worst_input_latency;
1404 	samplecnt_t             _worst_route_latency;
1405 	uint32_t                _send_latency_changes;
1406 	bool                    _have_captured;
1407 	samplecnt_t             _capture_duration;
1408 	unsigned int            _capture_xruns;
1409 	unsigned int            _export_xruns;
1410 	bool                    _non_soloed_outs_muted;
1411 	bool                    _listening;
1412 	uint32_t                _listen_cnt;
1413 	uint32_t                _solo_isolated_cnt;
1414 	bool                    _writable;
1415 	bool                    _was_seamless;
1416 	bool                    _under_nsm_control;
1417 	unsigned int            _xrun_count;
1418 
1419 	std::string             _missing_file_replacement;
1420 
1421 	mutable GATOMIC_QUAL gint _processing_prohibited;
1422 	mutable GATOMIC_QUAL gint _record_status;
1423 
1424 	void add_monitor_section ();
1425 	void remove_monitor_section ();
1426 
1427 	void update_latency (bool playback);
1428 	bool update_route_latency (bool reverse, bool apply_to_delayline, bool* delayline_update_needed);
1429 	void initialize_latencies ();
1430 	void set_worst_output_latency ();
1431 	void set_worst_input_latency ();
1432 
1433 	void send_latency_compensation_change ();
1434 
1435 	void ensure_buffers (ChanCount howmany = ChanCount::ZERO);
1436 
1437 	void process_scrub          (pframes_t);
1438 	void process_without_events (pframes_t);
1439 	void process_with_events    (pframes_t);
1440 	void process_audition       (pframes_t);
1441 	void process_export         (pframes_t);
1442 	void process_export_fw      (pframes_t);
1443 
1444 	samplecnt_t calc_preroll_subcycle (samplecnt_t) const;
1445 
block_processing()1446 	void block_processing() { g_atomic_int_set (&_processing_prohibited, 1); }
unblock_processing()1447 	void unblock_processing() { g_atomic_int_set (&_processing_prohibited, 0); }
processing_blocked()1448 	bool processing_blocked() const { return g_atomic_int_get (&_processing_prohibited); }
1449 
1450 	static const samplecnt_t bounce_chunk_size;
1451 
1452 	/* Transport master DLL */
1453 
1454 	enum TransportMasterState {
1455 		Stopped, /* no incoming or invalid signal/data for master to run with */
1456 		Waiting, /* waiting to get full lock on incoming signal/data */
1457 		Running  /* lock achieved, master is generating meaningful speed & position */
1458 	};
1459 
1460 	samplepos_t master_wait_end;
1461 
1462 	enum TransportMasterAction {
1463 		TransportMasterRelax,
1464 		TransportMasterNoRoll,
1465 		TransportMasterLocate,
1466 		TransportMasterStart,
1467 		TransportMasterStop,
1468 		TransportMasterWait,
1469 	};
1470 
1471 	struct TransportMasterStrategy {
1472 		TransportMasterAction action;
1473 		samplepos_t target;
1474 		LocateTransportDisposition roll_disposition;
1475 		double catch_speed;
1476 
TransportMasterStrategyTransportMasterStrategy1477 		TransportMasterStrategy ()
1478 			: action (TransportMasterRelax)
1479 			, target (0)
1480 			, roll_disposition (MustStop)
1481 			, catch_speed (0.) {}
1482 	};
1483 
1484 	TransportMasterStrategy transport_master_strategy;
1485 	double plan_master_strategy (pframes_t nframes, double master_speed, samplepos_t master_transport_sample, double catch_speed);
1486 	double plan_master_strategy_engine (pframes_t nframes, double master_speed, samplepos_t master_transport_sample, double catch_speed);
1487 	bool implement_master_strategy ();
1488 
1489 	bool follow_transport_master (pframes_t nframes);
1490 
1491 	void sync_source_changed (SyncSource, samplepos_t pos, pframes_t cycle_nframes);
1492 
1493 	bool post_export_sync;
1494 	samplepos_t post_export_position;
1495 
1496 	bool _exporting;
1497 	bool _export_rolling;
1498 	bool _realtime_export;
1499 	bool _region_export;
1500 	samplepos_t _export_preroll;
1501 
1502 	boost::shared_ptr<ExportHandler> export_handler;
1503 	boost::shared_ptr<ExportStatus>  export_status;
1504 
1505 	int  pre_export ();
1506 	int  stop_audio_export ();
1507 	void finalize_audio_export (TransportRequestSource trs);
1508 	void finalize_export_internal (bool stop_freewheel);
1509 	bool _pre_export_mmc_enabled;
1510 
1511 	PBD::ScopedConnection export_freewheel_connection;
1512 
1513 	void get_track_statistics ();
1514 	int  process_routes (pframes_t, bool& need_butler);
1515 	int  silent_process_routes (pframes_t, bool& need_butler);
1516 
1517 	/** @return 1 if there is a pending declick fade-in,
1518 	    -1 if there is a pending declick fade-out,
1519 	    0 if there is no pending declick.
1520 	*/
1521 	bool maybe_stop (samplepos_t limit);
1522 	bool maybe_sync_start (pframes_t &);
1523 
1524 	std::string             _path;
1525 	std::string             _name;
1526 	bool                    _is_new;
1527 	bool                    _send_qf_mtc;
1528 	/** Number of process samples since the last MTC output (when sending MTC); used to
1529 	 *  know when to send full MTC messages every so often.
1530 	 */
1531 	pframes_t               _pframes_since_last_mtc;
1532 	bool                     play_loop;
1533 	bool                     loop_changing;
1534 	samplepos_t              last_loopend;
1535 
1536 	boost::scoped_ptr<SessionDirectory> _session_dir;
1537 
1538 	void hookup_io ();
1539 	void graph_reordered (bool called_from_backend);
1540 
1541 	/** current snapshot name, without the .ardour suffix */
1542 	void set_snapshot_name (const std::string &);
1543 	void save_snapshot_name (const std::string &);
1544 	std::string _current_snapshot_name;
1545 
1546 	XMLTree*         state_tree;
1547 	bool             state_was_pending;
1548 	StateOfTheState _state_of_the_state;
1549 
1550 	friend class    StateProtector;
1551 	GATOMIC_QUAL gint  _suspend_save;
1552 	volatile bool      _save_queued;
1553 	volatile bool      _save_queued_pending;
1554 
1555 	Glib::Threads::Mutex save_state_lock;
1556 	Glib::Threads::Mutex save_source_lock;
1557 	Glib::Threads::Mutex peak_cleanup_lock;
1558 
1559 	int        load_options (const XMLNode&);
1560 	int        load_state (std::string snapshot_name, bool from_template = false);
1561 	static int parse_stateful_loading_version (const std::string&);
1562 
1563 	samplepos_t _last_roll_location;
1564 	/** the session sample time at which we last rolled, located, or changed transport direction */
1565 	samplepos_t _last_roll_or_reversal_location;
1566 	samplepos_t _last_record_location;
1567 
1568 	bool              pending_abort;
1569 	bool              pending_auto_loop;
1570 
1571 	PBD::ReallocPool _mempool;
1572 	LuaState lua;
1573 	Glib::Threads::Mutex lua_lock;
1574 	luabridge::LuaRef * _lua_run;
1575 	luabridge::LuaRef * _lua_add;
1576 	luabridge::LuaRef * _lua_del;
1577 	luabridge::LuaRef * _lua_list;
1578 	luabridge::LuaRef * _lua_load;
1579 	luabridge::LuaRef * _lua_save;
1580 	luabridge::LuaRef * _lua_cleanup;
1581 	uint32_t            _n_lua_scripts;
1582 
1583 	void setup_lua ();
1584 	void try_run_lua (pframes_t);
1585 
1586 	Butler* _butler;
1587 
1588 	TransportFSM* _transport_fsm;
1589 
1590 	static const PostTransportWork ProcessCannotProceedMask = PostTransportWork (PostTransportAudition);
1591 
1592 	GATOMIC_QUAL gint _post_transport_work; /* accessed only atomic ops */
post_transport_work()1593 	PostTransportWork post_transport_work() const        { return (PostTransportWork) g_atomic_int_get (&_post_transport_work); }
set_post_transport_work(PostTransportWork ptw)1594 	void set_post_transport_work (PostTransportWork ptw) { g_atomic_int_set (&_post_transport_work, (gint) ptw); }
1595 	void add_post_transport_work (PostTransportWork ptw);
1596 
1597 	void schedule_playback_buffering_adjustment ();
1598 	void schedule_capture_buffering_adjustment ();
1599 
1600 	Locations*       _locations;
1601 	void location_added (Location*);
1602 	void location_removed (Location*);
1603 	void locations_changed ();
1604 	void _locations_changed (const Locations::LocationList&);
1605 
1606 	void update_skips (Location*, bool consolidate);
1607 	void update_marks (Location* loc);
1608 	void consolidate_skips (Location*);
1609 	void sync_locations_to_skips ();
1610 	void _sync_locations_to_skips ();
1611 
1612 	PBD::ScopedConnectionList skip_update_connections;
1613 	bool _ignore_skips_updates;
1614 
1615 	PBD::ScopedConnectionList punch_connections;
1616 	void             auto_punch_start_changed (Location *);
1617 	void             auto_punch_end_changed (Location *);
1618 	void             auto_punch_changed (Location *);
1619 
1620 	PBD::ScopedConnectionList loop_connections;
1621 	void             auto_loop_changed (Location *);
1622 
1623 	void pre_engine_init (std::string path);
1624 	int  post_engine_init ();
1625 	int  immediately_post_engine ();
1626 	void remove_empty_sounds ();
1627 
1628 	void session_loaded ();
1629 
1630 	void setup_midi_control ();
1631 	int  midi_read (MIDI::Port *);
1632 
1633 	void enable_record ();
1634 
increment_transport_position(samplecnt_t val)1635 	void increment_transport_position (samplecnt_t val) {
1636 		if (max_samplepos - val < _transport_sample) {
1637 			_transport_sample = max_samplepos;
1638 		} else {
1639 			_transport_sample += val;
1640 		}
1641 	}
1642 
decrement_transport_position(samplecnt_t val)1643 	void decrement_transport_position (samplecnt_t val) {
1644 		if (val < _transport_sample) {
1645 			_transport_sample -= val;
1646 		} else {
1647 			_transport_sample = 0;
1648 		}
1649 	}
1650 
1651 	void post_transport_motion ();
1652 	static void *session_loader_thread (void *arg);
1653 
1654 	void *do_work();
1655 
1656 	/* Signal Forwarding */
1657 	void emit_route_signals ();
1658 	void emit_thread_run ();
1659 	static void *emit_thread (void *);
1660 	void emit_thread_start ();
1661 	void emit_thread_terminate ();
1662 
1663 	pthread_t       _rt_emit_thread;
1664 	bool            _rt_thread_active;
1665 
1666 	pthread_mutex_t _rt_emit_mutex;
1667 	pthread_cond_t  _rt_emit_cond;
1668 	bool            _rt_emit_pending;
1669 
1670 	/* Auto Connect Thread */
1671 	static void *auto_connect_thread (void *);
1672 	void auto_connect_thread_run ();
1673 	void auto_connect_thread_start ();
1674 	void auto_connect_thread_terminate ();
1675 
1676 	pthread_t       _auto_connect_thread;
1677 	gint            _ac_thread_active;
1678 	pthread_mutex_t _auto_connect_mutex;
1679 	pthread_cond_t  _auto_connect_cond;
1680 
1681 	struct AutoConnectRequest {
1682 		public:
AutoConnectRequestAutoConnectRequest1683 		AutoConnectRequest (boost::shared_ptr <Route> r,
1684 				bool ci, bool co,
1685 				const ChanCount& is,
1686 				const ChanCount& os,
1687 				const ChanCount& io,
1688 				const ChanCount& oo)
1689 			: route (boost::weak_ptr<Route> (r))
1690 			, connect_inputs (ci)
1691 			, connect_outputs (co)
1692 			, input_start (is)
1693 			, output_start (os)
1694 			, input_offset (io)
1695 			, output_offset (oo)
1696 		{}
1697 
1698 		boost::weak_ptr <Route> route;
1699 		bool connect_inputs;
1700 		bool connect_outputs;
1701 		ChanCount input_start;
1702 		ChanCount output_start;
1703 		ChanCount input_offset;
1704 		ChanCount output_offset;
1705 	};
1706 
1707 	Glib::Threads::Mutex  _update_latency_lock;
1708 
1709 	typedef std::queue<AutoConnectRequest> AutoConnectQueue;
1710 	Glib::Threads::Mutex _auto_connect_queue_lock;
1711 	AutoConnectQueue     _auto_connect_queue;
1712 	GATOMIC_QUAL guint   _latency_recompute_pending;
1713 
1714 	void get_physical_ports (std::vector<std::string>& inputs, std::vector<std::string>& outputs, DataType type,
1715 	                         MidiPortFlags include = MidiPortFlags (0),
1716 	                         MidiPortFlags exclude = MidiPortFlags (0));
1717 
1718 	void auto_connect (const AutoConnectRequest&);
1719 	void queue_latency_recompute ();
1720 
1721 	/* SessionEventManager interface */
1722 
1723 	void process_event (SessionEvent*);
1724 	void set_next_event ();
1725 	void cleanup_event (SessionEvent*,int);
1726 
1727 	/* MIDI Machine Control */
1728 
1729 	void spp_start ();
1730 	void spp_continue ();
1731 	void spp_stop ();
1732 
1733 	void mmc_deferred_play (MIDI::MachineControl &);
1734 	void mmc_stop (MIDI::MachineControl &);
1735 	void mmc_step (MIDI::MachineControl &, int);
1736 	void mmc_pause (MIDI::MachineControl &);
1737 	void mmc_record_pause (MIDI::MachineControl &);
1738 	void mmc_record_strobe (MIDI::MachineControl &);
1739 	void mmc_record_exit (MIDI::MachineControl &);
1740 	void mmc_track_record_status (MIDI::MachineControl &, uint32_t track, bool enabled);
1741 	void mmc_fast_forward (MIDI::MachineControl &);
1742 	void mmc_rewind (MIDI::MachineControl &);
1743 	void mmc_locate (MIDI::MachineControl &, const MIDI::byte *);
1744 	void mmc_shuttle (MIDI::MachineControl &mmc, float speed, bool forw);
1745 	void mmc_record_enable (MIDI::MachineControl &mmc, size_t track, bool enabled);
1746 
1747 	struct timeval last_mmc_step;
1748 	double step_speed;
1749 
1750 	typedef boost::function<bool()> MidiTimeoutCallback;
1751 	typedef std::list<MidiTimeoutCallback> MidiTimeoutList;
1752 
1753 	MidiTimeoutList midi_timeouts;
1754 	bool mmc_step_timeout ();
1755 	void send_immediate_mmc (MIDI::MachineControlCommand);
1756 
1757 	MIDI::byte mtc_msg[16];
1758 	MIDI::byte mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
1759 	MIDI::byte midi_msg[16];
1760 	double outbound_mtc_timecode_frame;
1761 	Timecode::Time transmitting_timecode_time;
1762 	int next_quarter_frame_to_send;
1763 
1764 	double _samples_per_timecode_frame; /* has to be floating point because of drop sample */
1765 	samplecnt_t _frames_per_hour;
1766 	samplecnt_t _timecode_frames_per_hour;
1767 
1768 	/* cache the most-recently requested time conversions. This helps when we
1769 	 * have multiple clocks showing the same time (e.g. the transport sample) */
1770 	bool last_timecode_valid;
1771 	samplepos_t last_timecode_when;
1772 	Timecode::Time last_timecode;
1773 
1774 	bool _send_timecode_update; ///< Flag to send a full sample (Timecode) MTC message this cycle
1775 
1776 	int send_midi_time_code_for_cycle (samplepos_t, samplepos_t, pframes_t nframes);
1777 
1778 	LTCEncoder*       ltc_encoder;
1779 	ltcsnd_sample_t*  ltc_enc_buf;
1780 
1781 	Timecode::TimecodeFormat ltc_enc_tcformat;
1782 	int32_t           ltc_buf_off;
1783 	int32_t           ltc_buf_len;
1784 
1785 	double            ltc_speed;
1786 	int32_t           ltc_enc_byte;
1787 	samplepos_t       ltc_enc_pos;
1788 	double            ltc_enc_cnt;
1789 	samplepos_t       ltc_enc_off;
1790 	bool              restarting;
1791 	samplepos_t       ltc_prev_cycle;
1792 
1793 	samplepos_t       ltc_timecode_offset;
1794 	bool              ltc_timecode_negative_offset;
1795 
1796 	LatencyRange      ltc_out_latency;
1797 	LatencyRange      mtc_out_latency;
1798 
1799 	void ltc_tx_initialize();
1800 	void ltc_tx_cleanup();
1801 	void ltc_tx_reset();
1802 	void ltc_tx_resync_latency (bool);
1803 	void ltc_tx_recalculate_position();
1804 	void ltc_tx_parse_offset();
1805 	PBD::ScopedConnectionList ltc_tx_connections;
1806 
1807 	void reset_record_status ();
1808 
1809 	int no_roll (pframes_t nframes);
1810 	int fail_roll (pframes_t nframes);
1811 
non_realtime_work_pending()1812 	bool non_realtime_work_pending() const { return static_cast<bool>(post_transport_work()); }
process_can_proceed()1813 	bool process_can_proceed() const { return !(post_transport_work() & ProcessCannotProceedMask); }
1814 
1815 	MidiControlUI* midi_control_ui;
1816 
1817 	int           start_midi_thread ();
1818 
1819 	bool should_ignore_transport_request (TransportRequestSource, TransportRequestType);
1820 
1821 	void set_play_loop (bool yn, bool change_transport_state);
1822 	void unset_play_loop (bool change_transport_state = false);
1823 	void overwrite_some_buffers (boost::shared_ptr<Route>, OverwriteReason);
1824 	void flush_all_inserts ();
1825 	int  micro_locate (samplecnt_t distance);
1826 
1827 	enum PunchLoopLock {
1828 		NoConstraint,
1829 		OnlyPunch,
1830 		OnlyLoop,
1831 	};
1832 
1833 	GATOMIC_QUAL gint _punch_or_loop; // enum PunchLoopLock
1834 	GATOMIC_QUAL gint _current_usecs_per_track;
1835 
1836 	bool punch_active () const;
1837 	void unset_punch ();
1838 	void reset_punch_loop_constraint ();
1839 	bool maybe_allow_only_loop (bool play_loop = false);
1840 	bool maybe_allow_only_punch ();
1841 
1842 	void force_locate (samplepos_t sample, LocateTransportDisposition);
1843 	void realtime_stop (bool abort, bool clear_state);
1844 	void realtime_locate (bool);
1845 	void non_realtime_start_scrub ();
1846 	void non_realtime_set_speed ();
1847 	void non_realtime_locate ();
1848 	void non_realtime_stop (bool abort, int entry_request_count, bool& finished);
1849 	void non_realtime_overwrite (int entry_request_count, bool& finished, bool reset_loop_declicks);
1850 	void engine_halted ();
1851 	void engine_running ();
1852 	void xrun_recovery ();
1853 	void set_track_loop (bool);
1854 	bool select_playhead_priority_target (samplepos_t&);
1855 	void follow_playhead_priority ();
1856 
1857 	/* These are synchronous and so can only be called from within the process
1858 	 * cycle
1859 	 */
1860 
1861 	void mtc_tx_resync_latency (bool);
1862 	int  send_full_time_code (samplepos_t, pframes_t nframes);
1863 	void send_song_position_pointer (samplepos_t);
1864 
1865 	TempoMap    *_tempo_map;
1866 	void          tempo_map_changed (const PBD::PropertyChange&);
1867 
1868 	/* edit/mix groups */
1869 
1870 	int load_route_groups (const XMLNode&, int);
1871 
1872 	std::list<RouteGroup *> _route_groups;
1873 	RouteGroup*             _all_route_group;
1874 
1875 	/* routes stuff */
1876 
1877 	boost::shared_ptr<Graph> _process_graph;
1878 
1879 	SerializedRCUManager<RouteList>  routes;
1880 
1881 	void add_routes (RouteList&, bool input_auto_connect, bool output_auto_connect, PresentationInfo::order_t);
1882 	void add_routes_inner (RouteList&, bool input_auto_connect, bool output_auto_connect, PresentationInfo::order_t);
1883 	bool _adding_routes_in_progress;
1884 	bool _reconnecting_routes_in_progress;
1885 	bool _route_deletion_in_progress;
1886 
1887 	void load_and_connect_instruments (RouteList&,
1888 			bool strict_io,
1889 			boost::shared_ptr<PluginInfo> instrument,
1890 			Plugin::PresetRecord* pset,
1891 			ChanCount& existing_outputs
1892 			);
1893 
1894 	boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&, int);
1895 	boost::shared_ptr<Route> XMLRouteFactory_2X (const XMLNode&, int);
1896 	boost::shared_ptr<Route> XMLRouteFactory_3X (const XMLNode&, int);
1897 
1898 	void route_processors_changed (RouteProcessorChange);
1899 
1900 	bool find_route_name (std::string const &, uint32_t& id, std::string& name, bool);
1901 	void count_existing_track_channels (ChanCount& in, ChanCount& out);
1902 	void auto_connect_route (boost::shared_ptr<Route>, bool, bool, const ChanCount&, const ChanCount&, const ChanCount& io = ChanCount(), const ChanCount& oo = ChanCount());
1903 	void midi_output_change_handler (IOChange change, void* /*src*/, boost::weak_ptr<Route> midi_track);
1904 
1905 	/* track numbering */
1906 
1907 	void reassign_track_numbers ();
1908 	uint32_t _track_number_decimals;
1909 
1910 	/* solo/mute/notifications */
1911 
1912 	void route_listen_changed (PBD::Controllable::GroupControlDisposition, boost::weak_ptr<Route>);
1913 	void route_mute_changed ();
1914 	void route_solo_changed (bool self_solo_change, PBD::Controllable::GroupControlDisposition group_override, boost::weak_ptr<Route>);
1915 	void route_solo_isolated_changed (boost::weak_ptr<Route>);
1916 
1917 	void update_route_solo_state (boost::shared_ptr<RouteList> r = boost::shared_ptr<RouteList>());
1918 
1919 	void listen_position_changed ();
1920 	void solo_control_mode_changed ();
1921 
1922 	/* REGION MANAGEMENT */
1923 
1924 	mutable Glib::Threads::Mutex region_lock;
1925 
1926 	int load_regions (const XMLNode& node);
1927 	int load_compounds (const XMLNode& node);
1928 
1929 	void route_added_to_route_group (RouteGroup *, boost::weak_ptr<Route>);
1930 	void route_removed_from_route_group (RouteGroup *, boost::weak_ptr<Route>);
1931 	void route_group_property_changed (RouteGroup *);
1932 
1933 	/* SOURCES */
1934 
1935 	mutable Glib::Threads::Mutex source_lock;
1936 
1937 public:
1938 
1939 	/* Emited when a new source is added to the session */
1940 	PBD::Signal1< void, boost::weak_ptr<Source> > SourceAdded;
1941 	PBD::Signal1< void, boost::weak_ptr<Source> > SourceRemoved;
1942 
1943 	typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap;
1944 
foreach_source(boost::function<void (boost::shared_ptr<Source>)> f)1945 	void foreach_source (boost::function<void( boost::shared_ptr<Source> )> f) {
1946 		Glib::Threads::Mutex::Lock ls (source_lock);
1947 		for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
1948 			f ( (*i).second );
1949 		}
1950 	}
1951 
1952 	bool playlist_is_active( boost::shared_ptr<Playlist>);
1953 
1954 private:
1955 	void reset_write_sources (bool mark_write_complete, bool force = false);
1956 	SourceMap sources;
1957 
1958 	int load_sources (const XMLNode& node);
1959 	XMLNode& get_sources_as_xml ();
1960 
1961 	boost::shared_ptr<Source> XMLSourceFactory (const XMLNode&);
1962 
1963 	/* PLAYLISTS */
1964 
1965 	void remove_playlist (boost::weak_ptr<Playlist>);
1966 	void track_playlist_changed (boost::weak_ptr<Track>);
1967 	void playlist_region_added (boost::weak_ptr<Region>);
1968 	void playlist_ranges_moved (std::list<Evoral::RangeMove<samplepos_t> > const &);
1969 	void playlist_regions_extended (std::list<Evoral::Range<samplepos_t> > const &);
1970 
1971 	/* CURVES and AUTOMATION LISTS */
1972 	std::map<PBD::ID, AutomationList*> automation_lists;
1973 
1974 	/** load 2.X Sessions. Diskstream-ID to playlist-name mapping */
1975 	std::map<PBD::ID, std::string> _diskstreams_2X;
1976 
1977 	/* DEFAULT FADE CURVES */
1978 
1979 	float default_fade_steepness;
1980 	float default_fade_msecs;
1981 
1982 	/* AUDITIONING */
1983 
1984 	boost::shared_ptr<Auditioner> auditioner;
1985 	void set_audition (boost::shared_ptr<Region>);
1986 	void non_realtime_set_audition ();
1987 	boost::shared_ptr<Region> pending_audition_region;
1988 
1989 	/* EXPORT */
1990 
1991 	/* FLATTEN */
1992 
1993 	int flatten_one_track (AudioTrack&, samplepos_t start, samplecnt_t cnt);
1994 
1995 	/* INSERT AND SEND MANAGEMENT */
1996 
1997 	boost::dynamic_bitset<uint32_t> send_bitset;
1998 	boost::dynamic_bitset<uint32_t> aux_send_bitset;
1999 	boost::dynamic_bitset<uint32_t> return_bitset;
2000 	boost::dynamic_bitset<uint32_t> insert_bitset;
2001 
2002 	/* S/W RAID */
2003 
2004 	struct space_and_path {
2005 		uint32_t blocks;     ///< 4kB blocks
2006 		bool blocks_unknown; ///< true if blocks is unknown
2007 		std::string path;
2008 
space_and_pathspace_and_path2009 		space_and_path ()
2010 			: blocks (0)
2011 			, blocks_unknown (true)
2012 		{}
2013 	};
2014 
2015 	struct space_and_path_ascending_cmp {
operatorspace_and_path_ascending_cmp2016 		bool operator() (space_and_path a, space_and_path b) {
2017 			if (a.blocks_unknown != b.blocks_unknown) {
2018 				return !a.blocks_unknown;
2019 			}
2020 			return a.blocks > b.blocks;
2021 		}
2022 	};
2023 
2024 	void setup_raid_path (std::string path);
2025 
2026 	std::vector<space_and_path> session_dirs;
2027 	std::vector<space_and_path>::iterator last_rr_session_dir;
2028 	uint32_t _total_free_4k_blocks;
2029 	/** If this is true, _total_free_4k_blocks is not definite,
2030 	    as one or more of the session directories' filesystems
2031 	    could not report free space.
2032 	*/
2033 	bool _total_free_4k_blocks_uncertain;
2034 	Glib::Threads::Mutex space_lock;
2035 
2036 	bool no_questions_about_missing_files;
2037 
2038 	std::string get_best_session_directory_for_new_audio ();
2039 
2040 	mutable GATOMIC_QUAL gint _playback_load;
2041 	mutable GATOMIC_QUAL gint _capture_load;
2042 
2043 	/* I/O bundles */
2044 
2045 	SerializedRCUManager<BundleList> _bundles;
2046 	XMLNode* _bundle_xml_node;
2047 	int load_bundles (XMLNode const &);
2048 
2049 	UndoHistory      _history;
2050 	/** current undo transaction, or 0 */
2051 	UndoTransaction* _current_trans;
2052 	/** GQuarks to describe the reversible commands that are currently in progress.
2053 	 *  These may be nested, in which case more recently-started commands are toward
2054 	 *  the front of the list.
2055 	 */
2056 	std::list<GQuark> _current_trans_quarks;
2057 
2058 	int  backend_sync_callback (TransportState, samplepos_t);
2059 
2060 	void process_rtop (SessionEvent*);
2061 
2062 	enum snapshot_t {
2063 		NormalSave,
2064 		SnapshotKeep,
2065 		SwitchToSnapshot
2066 	};
2067 
2068 	XMLNode& state (bool save_template,
2069 	                snapshot_t snapshot_type = NormalSave,
2070 	                bool only_used_assets = false);
2071 
2072 	XMLNode& get_state ();
2073 	int      set_state (const XMLNode& node, int version); // not idempotent
2074 	XMLNode& get_template ();
2075 
2076 	/* click track */
2077 	typedef std::list<Click*>     Clicks;
2078 	Clicks                        clicks;
2079 	bool                         _clicking;
2080 	bool                         _click_rec_only;
2081 	boost::shared_ptr<IO>        _click_io;
2082 	boost::shared_ptr<Amp>       _click_gain;
2083 	Sample*                       click_data;
2084 	Sample*                       click_emphasis_data;
2085 	samplecnt_t                   click_length;
2086 	samplecnt_t                   click_emphasis_length;
2087 	mutable Glib::Threads::RWLock click_lock;
2088 	samplecnt_t                  _click_io_latency;
2089 	PBD::ScopedConnection        _click_io_connection;
2090 
2091 	static const Sample     default_click[];
2092 	static const samplecnt_t default_click_length;
2093 	static const Sample     default_click_emphasis[];
2094 	static const samplecnt_t default_click_emphasis_length;
2095 
2096 	Click* get_click();
2097 	samplepos_t _clicks_cleared;
2098 	samplecnt_t _count_in_samples;
2099 	void setup_click_sounds (int which);
2100 	void setup_click_sounds (Sample**, Sample const *, samplecnt_t*, samplecnt_t, std::string const &);
2101 	void clear_clicks ();
2102 	void click (samplepos_t start, samplecnt_t nframes);
2103 	void run_click (samplepos_t start, samplecnt_t nframes);
2104 	void add_click (samplepos_t pos, bool emphasis);
2105 	void click_io_resync_latency (bool);
2106 
2107 	/* range playback */
2108 
2109 	std::list<AudioRange> current_audio_range;
2110 	bool _play_range;
2111 	void set_play_range (std::list<AudioRange>&, bool leave_rolling);
2112 	void unset_play_range ();
2113 
2114 	/* temporary hacks to allow selection to be pushed from GUI into backend
2115 	   Whenever we move the selection object into libardour, these will go away.
2116 	*/
2117 	Evoral::Range<samplepos_t> _range_selection;
2118 	Evoral::Range<samplepos_t> _object_selection;
2119 
2120 	void unset_preroll_record_trim ();
2121 
2122 	samplecnt_t _preroll_record_trim_len;
2123 	bool _count_in_once;
2124 
2125 	/* main outs */
2126 	uint32_t main_outs;
2127 
2128 	boost::shared_ptr<Route> _master_out;
2129 	boost::shared_ptr<Route> _monitor_out;
2130 
2131 	void auto_connect_master_bus ();
2132 
2133 	void setup_route_monitor_sends (bool enable, bool need_process_lock);
2134 
2135 	int find_all_sources (std::string path, std::set<std::string>& result);
2136 	int find_all_sources_across_snapshots (std::set<std::string>& result, bool exclude_this_snapshot);
2137 
2138 	typedef std::set<boost::shared_ptr<PBD::Controllable> > Controllables;
2139 	Glib::Threads::Mutex controllables_lock;
2140 	Controllables controllables;
2141 
2142 	boost::shared_ptr<PBD::Controllable> _solo_cut_control;
2143 
2144 	void controllable_touched (boost::weak_ptr<PBD::Controllable>);
2145 	boost::weak_ptr<PBD::Controllable> _recently_touched_controllable;
2146 
2147 	void reset_native_file_format();
2148 	bool first_file_data_format_reset;
2149 	bool first_file_header_format_reset;
2150 
2151 	void config_changed (std::string, bool);
2152 
2153 	XMLNode& get_control_protocol_state ();
2154 
2155 	void set_history_depth (uint32_t depth);
2156 
2157 	static bool _disable_all_loaded_plugins;
2158 	static bool _bypass_all_loaded_plugins;
2159 
2160 	mutable bool have_looped; ///< Used in \ref audible_sample
2161 
2162 	void update_route_record_state ();
2163 	GATOMIC_QUAL gint _have_rec_enabled_track;
2164 	GATOMIC_QUAL gint _have_rec_disabled_track;
2165 
2166 	static int ask_about_playlist_deletion (boost::shared_ptr<Playlist>);
2167 
2168 	/* realtime "apply to set of routes" operations */
2169 	template<typename T> SessionEvent*
get_rt_event(boost::shared_ptr<RouteList> rl,T targ,SessionEvent::RTeventCallback after,PBD::Controllable::GroupControlDisposition group_override,void (Session::* method)(boost::shared_ptr<RouteList>,T,PBD::Controllable::GroupControlDisposition))2170 		get_rt_event (boost::shared_ptr<RouteList> rl, T targ, SessionEvent::RTeventCallback after, PBD::Controllable::GroupControlDisposition group_override,
2171 		              void (Session::*method) (boost::shared_ptr<RouteList>, T, PBD::Controllable::GroupControlDisposition)) {
2172 		SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
2173 		ev->rt_slot = boost::bind (method, this, rl, targ, group_override);
2174 		ev->rt_return = after;
2175 		ev->event_loop = PBD::EventLoop::get_event_loop_for_thread ();
2176 
2177 		return ev;
2178 	}
2179 
2180 	/* specialized version realtime "apply to set of routes" operations */
2181 	template<typename T1, typename T2> SessionEvent*
get_rt_event(boost::shared_ptr<RouteList> rl,T1 t1arg,T2 t2arg,SessionEvent::RTeventCallback after,PBD::Controllable::GroupControlDisposition group_override,void (Session::* method)(boost::shared_ptr<RouteList>,T1,T2,PBD::Controllable::GroupControlDisposition))2182 		get_rt_event (boost::shared_ptr<RouteList> rl, T1 t1arg, T2 t2arg, SessionEvent::RTeventCallback after, PBD::Controllable::GroupControlDisposition group_override,
2183 		              void (Session::*method) (boost::shared_ptr<RouteList>, T1, T2, PBD::Controllable::GroupControlDisposition)) {
2184 		SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
2185 		ev->rt_slot = boost::bind (method, this, rl, t1arg, t2arg, group_override);
2186 		ev->rt_return = after;
2187 		ev->event_loop = PBD::EventLoop::get_event_loop_for_thread ();
2188 
2189 		return ev;
2190 	}
2191 
2192 	/* specialized version realtime "apply to set of controls" operations */
get_rt_event(boost::shared_ptr<ControlList> cl,double arg,PBD::Controllable::GroupControlDisposition group_override)2193 	SessionEvent* get_rt_event (boost::shared_ptr<ControlList> cl, double arg, PBD::Controllable::GroupControlDisposition group_override) {
2194 		SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
2195 		ev->rt_slot = boost::bind (&Session::rt_set_controls, this, cl, arg, group_override);
2196 		ev->rt_return = Session::rt_cleanup;
2197 		ev->event_loop = PBD::EventLoop::get_event_loop_for_thread ();
2198 
2199 		return ev;
2200 	}
2201 
2202 	void rt_set_controls (boost::shared_ptr<ControlList>, double val, PBD::Controllable::GroupControlDisposition group_override);
2203 	void rt_clear_all_solo_state (boost::shared_ptr<RouteList>, bool yn, PBD::Controllable::GroupControlDisposition group_override);
2204 
2205 	void setup_midi_machine_control ();
2206 
2207 	void step_edit_status_change (bool);
2208 	uint32_t _step_editors;
2209 
2210 	/** true if timecode transmission by the transport is suspended, otherwise false */
2211 	mutable GATOMIC_QUAL gint _suspend_timecode_transmission;
2212 
2213 	void update_locations_after_tempo_map_change (const Locations::LocationList &);
2214 
2215 	void start_time_changed (samplepos_t);
2216 	void end_time_changed (samplepos_t);
2217 
2218 	void set_track_monitor_input_status (bool);
2219 	samplepos_t compute_stop_limit () const;
2220 
2221 	boost::shared_ptr<Speakers> _speakers;
2222 	void load_nested_sources (const XMLNode& node);
2223 
2224 	/** The directed graph of routes that is currently being used for audio processing
2225 	    and solo/mute computations.
2226 	*/
2227 	GraphEdges _current_route_graph;
2228 
2229 	void ensure_route_presentation_info_gap (PresentationInfo::order_t, uint32_t gap_size);
2230 
2231 	friend class ProcessorChangeBlocker;
2232 	GATOMIC_QUAL gint _ignore_route_processor_changes;
2233 	GATOMIC_QUAL gint _ignored_a_processor_change;
2234 
2235 	MidiClockTicker* midi_clock;
2236 
2237 	boost::shared_ptr<Port>  _ltc_output_port;
2238 
2239 	boost::shared_ptr<RTTaskList> _rt_tasklist;
2240 
2241 	/* Scene Changing */
2242 	SceneChanger* _scene_changer;
2243 
2244 	/* persistent, non-track related MIDI ports */
2245 	MidiPortManager* _midi_ports;
2246 	MIDI::MachineControl* _mmc;
2247 
2248 	void setup_ltc ();
2249 	void setup_click ();
2250 	void setup_click_state (const XMLNode*);
2251 	void setup_bundles ();
2252 
2253 	void save_as_bring_callback (uint32_t, uint32_t, std::string);
2254 
2255 	static const uint32_t session_end_shift;
2256 
2257 	std::string _template_state_dir;
2258 
2259 	VCAManager* _vca_manager;
2260 
2261 	boost::shared_ptr<Route> get_midi_nth_route_by_id (PresentationInfo::order_t n) const;
2262 
2263 	std::string created_with;
2264 
2265 	void midi_track_presentation_info_changed (PBD::PropertyChange const &, boost::weak_ptr<MidiTrack>);
2266 	void rewire_selected_midi (boost::shared_ptr<MidiTrack>);
2267 	void rewire_midi_selection_ports ();
2268 	boost::weak_ptr<MidiTrack> current_midi_target;
2269 
2270 	StripableList _soloSelection;  //the items that are soloe'd during a solo-selection operation; need to unsolo after the roll
2271 
2272 	CoreSelection* _selection;
2273 
2274 	bool _global_locate_pending;
2275 	boost::optional<samplepos_t> _nominal_jack_transport_sample;
2276 
2277 	bool _had_destructive_tracks;
2278 
2279 	std::string unnamed_file_name () const;
2280 
2281 	GATOMIC_QUAL gint _update_pretty_names;
2282 };
2283 
2284 
2285 } // namespace ARDOUR
2286 
2287 #endif /* __ardour_session_h__ */
2288