2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_session_h__
22 #define __ardour_session_h__
34 #include <glibmm/thread.h>
36 #include <pbd/error.h>
41 #include <midi++/types.h>
42 #include <midi++/mmc.h>
44 #include <pbd/stateful.h>
46 #include <ardour/ardour.h>
47 #include <ardour/configuration.h>
48 #include <ardour/location.h>
49 #include <ardour/gain.h>
50 #include <ardour/io.h>
69 class AudioDiskstream;
74 class AudioFileSource;
89 class ControlProtocolManager;
91 struct AudioExportSpecification;
100 class Session : public sigc::trackable, public Stateful
104 typedef std::pair<boost::shared_ptr<Route>,bool> RouteBooleanState;
105 typedef vector<RouteBooleanState> GlobalRouteBooleanState;
106 typedef std::pair<boost::shared_ptr<Route>,MeterPoint> RouteMeterState;
107 typedef vector<RouteMeterState> GlobalRouteMeterState;
122 enum AutoConnectOption {
123 AutoConnectPhysical = 0x1,
124 AutoConnectMaster = 0x2
141 InputConfigurationChange,
145 /* only one of each of these events
146 can be queued at any one time
162 jack_nframes_t action_frame;
163 jack_nframes_t target_frame;
169 Session::SlaveSource slave;
173 list<AudioRange> audio_range;
174 list<MusicRange> music_range;
176 Event(Type t, Action a, jack_nframes_t when, jack_nframes_t where, float spd, bool yn = false)
180 target_frame (where),
184 void set_ptr (void* p) {
188 bool before (const Event& other) const {
189 return action_frame < other.action_frame;
192 bool after (const Event& other) const {
193 return action_frame > other.action_frame;
196 static bool compare (const Event *e1, const Event *e2) {
197 return e1->before (*e2);
200 void *operator new (size_t ignored) {
201 return pool.alloc ();
204 void operator delete(void *ptr, size_t size) {
208 static const jack_nframes_t Immediate = 0;
211 static MultiAllocSingleReleasePool pool;
214 /* creating from an XML file */
216 Session (AudioEngine&,
218 string snapshot_name,
219 string* mix_template = 0);
221 /* creating a new Session */
223 Session (AudioEngine&,
225 string snapshot_name,
226 AutoConnectOption input_auto_connect,
227 AutoConnectOption output_auto_connect,
228 uint32_t control_out_channels,
229 uint32_t master_out_channels,
230 uint32_t n_physical_in,
231 uint32_t n_physical_out,
232 jack_nframes_t initial_length);
237 static int find_session (string str, string& path, string& snapshot, bool& isnew);
239 string path() const { return _path; }
240 string name() const { return _name; }
241 string snap_name() const { return _current_snapshot_name; }
243 void set_snap_name ();
247 bool dirty() const { return _state_of_the_state & Dirty; }
248 sigc::signal<void> DirtyChanged;
250 std::string sound_dir () const;
251 std::string tape_dir () const;
252 std::string peak_dir () const;
253 std::string dead_sound_dir () const;
254 std::string automation_dir () const;
256 static string suffixed_search_path (std::string suffix, bool data);
257 static string control_protocol_path ();
258 static string template_path ();
259 static string template_dir ();
260 static void get_template_list (list<string>&);
262 static string change_audio_path_by_name (string oldpath, string oldname, string newname, bool destructive);
263 static string peak_path_from_audio_path (string);
264 string audio_path_from_name (string, uint32_t nchans, uint32_t chan, bool destructive);
266 void process (jack_nframes_t nframes);
268 vector<Sample*>& get_passthru_buffers() { return _passthru_buffers; }
269 vector<Sample*>& get_silent_buffers (uint32_t howmany);
270 vector<Sample*>& get_send_buffers () { return _send_buffers; }
272 AudioDiskstream *diskstream_by_id (const PBD::ID& id);
273 AudioDiskstream *diskstream_by_name (string name);
275 bool have_captured() const { return _have_captured; }
277 void refill_all_diskstream_buffers ();
278 uint32_t diskstream_buffer_size() const { return dstream_buffer_size; }
280 /* XXX fix required here when we get new diskstream types *, but
281 not sure of the direction to take this in until then.
284 uint32_t get_next_diskstream_id() const { return n_audio_diskstreams(); }
285 uint32_t n_audio_diskstreams() const;
287 typedef list<AudioDiskstream *> AudioDiskstreamList;
289 Session::AudioDiskstreamList audio_disk_streams() const {
290 Glib::RWLock::ReaderLock lm (diskstream_lock);
291 return audio_diskstreams; /* XXX yes, force a copy */
294 void foreach_audio_diskstream (void (AudioDiskstream::*func)(void));
295 template<class T> void foreach_audio_diskstream (T *obj, void (T::*func)(AudioDiskstream&));
297 typedef std::list<boost::shared_ptr<Route> > RouteList;
299 boost::shared_ptr<RouteList> get_routes() const {
300 return routes.reader ();
303 uint32_t nroutes() const { return routes.reader()->size(); }
304 uint32_t ntracks () const;
305 uint32_t nbusses () const;
307 struct RoutePublicOrderSorter {
308 bool operator() (boost::shared_ptr<Route>, boost::shared_ptr<Route> b);
311 template<class T> void foreach_route (T *obj, void (T::*func)(Route&));
312 template<class T> void foreach_route (T *obj, void (T::*func)(boost::shared_ptr<Route>));
313 template<class T, class A> void foreach_route (T *obj, void (T::*func)(Route&, A), A arg);
315 boost::shared_ptr<Route> route_by_name (string);
316 boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
318 bool route_name_unique (string) const;
320 bool get_record_enabled() const {
321 return (record_status () >= Enabled);
324 RecordState record_status() const {
325 return (RecordState) g_atomic_int_get (&_record_status);
328 bool actively_recording () {
329 return record_status() == Recording;
332 bool record_enabling_legal () const;
333 void maybe_enable_record ();
334 void disable_record (bool rt_context, bool force = false);
335 void step_back_from_record ();
337 sigc::signal<void> going_away;
339 /* Proxy signal for region hidden changes */
341 sigc::signal<void,Region*> RegionHiddenChange;
343 /* Emitted when all i/o connections are complete */
345 sigc::signal<void> IOConnectionsComplete;
347 /* Record status signals */
349 sigc::signal<void> RecordStateChanged;
351 /* Transport mechanism signals */
353 sigc::signal<void> TransportStateChange; /* generic */
354 sigc::signal<void,jack_nframes_t> PositionChanged; /* sent after any non-sequential motion */
355 sigc::signal<void> DurationChanged;
356 sigc::signal<void> HaltOnXrun;
358 sigc::signal<void,boost::shared_ptr<Route> > RouteAdded;
359 sigc::signal<void,AudioDiskstream*> AudioDiskstreamAdded;
361 void request_roll ();
362 void request_bounded_roll (jack_nframes_t start, jack_nframes_t end);
363 void request_stop (bool abort = false);
364 void request_locate (jack_nframes_t frame, bool with_roll = false);
365 void request_auto_loop (bool yn);
366 jack_nframes_t last_transport_start() const { return _last_roll_location; }
367 void goto_end () { request_locate (end_location->start(), false);}
368 void goto_start () { request_locate (start_location->start(), false); }
369 void use_rf_shuttle_speed ();
370 void request_transport_speed (float speed);
371 void request_overwrite_buffer (AudioDiskstream*);
372 void request_diskstream_speed (AudioDiskstream&, float speed);
373 void request_input_change_handling ();
375 bool locate_pending() const { return static_cast<bool>(post_transport_work&PostTransportLocate); }
376 bool transport_locked () const;
379 int wipe_diskstream (AudioDiskstream *);
381 int remove_region_from_region_list (Region&);
383 jack_nframes_t get_maximum_extent () const;
384 jack_nframes_t current_end_frame() const { return end_location->start(); }
385 jack_nframes_t current_start_frame() const { return start_location->start(); }
386 jack_nframes_t frame_rate() const { return _current_frame_rate; }
387 double frames_per_smpte_frame() const { return _frames_per_smpte_frame; }
388 jack_nframes_t frames_per_hour() const { return _frames_per_hour; }
389 jack_nframes_t smpte_frames_per_hour() const { return _smpte_frames_per_hour; }
393 Locations *locations() { return &_locations; }
395 sigc::signal<void,Location*> auto_loop_location_changed;
396 sigc::signal<void,Location*> auto_punch_location_changed;
397 sigc::signal<void> locations_modified;
399 void set_auto_punch_location (Location *);
400 void set_auto_loop_location (Location *);
430 sigc::signal<void,ControlType> ControlChanged;
432 void set_auto_play (bool yn);
433 void set_auto_return (bool yn);
434 void set_auto_input (bool yn);
435 void reset_input_monitor_state ();
436 void set_input_auto_connect (bool yn);
437 void set_output_auto_connect (AutoConnectOption);
438 void set_punch_in (bool yn);
439 void set_punch_out (bool yn);
440 void set_send_mtc (bool yn);
441 void set_send_mmc (bool yn);
442 void set_mmc_control (bool yn);
443 void set_midi_feedback (bool yn);
444 void set_midi_control (bool yn);
445 void set_do_not_record_plugins (bool yn);
446 void set_crossfades_active (bool yn);
447 void set_seamless_loop (bool yn);
449 bool get_auto_play () const { return auto_play; }
450 bool get_auto_input () const { return auto_input; }
451 bool get_auto_loop () const { return auto_loop; }
452 bool get_seamless_loop () const { return seamless_loop; }
453 bool get_punch_in () const { return punch_in; }
454 bool get_punch_out () const { return punch_out; }
455 bool get_all_safe () const { return all_safe; }
456 bool get_auto_return () const { return auto_return; }
457 bool get_send_mtc () const;
458 bool get_send_mmc () const;
459 bool get_mmc_control () const;
460 bool get_midi_feedback () const;
461 bool get_midi_control () const;
462 bool get_do_not_record_plugins () const { return do_not_record_plugins; }
463 bool get_crossfades_active () const { return crossfades_active; }
465 bool get_input_auto_connect () const;
466 AutoConnectOption get_output_auto_connect () const { return output_auto_connect; }
474 void set_layer_model (LayerModel);
475 LayerModel get_layer_model () const { return layer_model; }
477 void set_xfade_model (CrossfadeModel);
478 CrossfadeModel get_xfade_model () const { return xfade_model; }
480 void add_event (jack_nframes_t action_frame, Event::Type type, jack_nframes_t target_frame = 0);
481 void remove_event (jack_nframes_t frame, Event::Type type);
482 void clear_events (Event::Type type);
484 jack_nframes_t get_block_size() const { return current_block_size; }
485 jack_nframes_t worst_output_latency () const { return _worst_output_latency; }
486 jack_nframes_t worst_input_latency () const { return _worst_input_latency; }
487 jack_nframes_t worst_track_latency () const { return _worst_track_latency; }
489 int save_state (string snapshot_name, bool pending = false);
490 int restore_state (string snapshot_name);
491 int save_template (string template_name);
493 static int rename_template (string old_name, string new_name);
495 static int delete_template (string name);
497 sigc::signal<void,string> StateSaved;
498 sigc::signal<void> StateReady;
500 vector<string*>* possible_states() const;
501 static vector<string*>* possible_states(string path);
503 XMLNode& get_state();
504 int set_state(const XMLNode& node);
505 XMLNode& get_template();
507 void add_instant_xml (XMLNode&, const std::string& dir);
509 enum StateOfTheState {
514 InitialConnecting = 0x8,
519 StateOfTheState state_of_the_state() const { return _state_of_the_state; }
521 RouteGroup* add_edit_group (string);
522 RouteGroup* add_mix_group (string);
524 void remove_edit_group (RouteGroup&);
525 void remove_mix_group (RouteGroup&);
527 RouteGroup *mix_group_by_name (string);
528 RouteGroup *edit_group_by_name (string);
530 sigc::signal<void,RouteGroup*> edit_group_added;
531 sigc::signal<void,RouteGroup*> mix_group_added;
532 sigc::signal<void> edit_group_removed;
533 sigc::signal<void> mix_group_removed;
535 void foreach_edit_group (sigc::slot<void,RouteGroup*> sl) {
536 for (list<RouteGroup *>::iterator i = edit_groups.begin(); i != edit_groups.end(); i++) {
541 void foreach_mix_group (sigc::slot<void,RouteGroup*> sl) {
542 for (list<RouteGroup *>::iterator i = mix_groups.begin(); i != mix_groups.end(); i++) {
547 /* fundamental operations. duh. */
549 boost::shared_ptr<AudioTrack> new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal);
550 boost::shared_ptr<Route> new_audio_route (int input_channels, int output_channels);
552 void remove_route (boost::shared_ptr<Route>);
554 void resort_routes ();
555 void resort_routes_using (boost::shared_ptr<RouteList>);
556 void resort_routes_proxy (void* src) {
560 AudioEngine &engine() { return _engine; };
562 /* configuration. there should really be accessors/mutators
566 float meter_hold () { return _meter_hold; }
567 void set_meter_hold (float);
568 sigc::signal<void> MeterHoldChanged;
570 float meter_falloff () { return _meter_falloff; }
571 void set_meter_falloff (float);
572 sigc::signal<void> MeterFalloffChanged;
576 string click_emphasis_sound;
578 bool click_requested;
579 jack_nframes_t over_length_short;
580 jack_nframes_t over_length_long;
581 bool send_midi_timecode;
582 bool send_midi_machine_control;
583 float shuttle_speed_factor;
584 float shuttle_speed_threshold;
586 float smpte_frames_per_second;
587 bool smpte_drop_frames;
593 jack_nframes_t transport_frame () const {return _transport_frame; }
594 jack_nframes_t audible_frame () const;
596 int set_smpte_type (float fps, bool drop_frames);
598 void bbt_time (jack_nframes_t when, BBT_Time&);
599 void smpte_to_sample( SMPTE::Time& smpte, jack_nframes_t& sample, bool use_offset, bool use_subframes ) const;
600 void sample_to_smpte( jack_nframes_t sample, SMPTE::Time& smpte, bool use_offset, bool use_subframes ) const;
601 void smpte_time (SMPTE::Time &);
602 void smpte_time (jack_nframes_t when, SMPTE::Time&);
603 void smpte_time_subframes (jack_nframes_t when, SMPTE::Time&);
605 void smpte_duration (jack_nframes_t, SMPTE::Time&) const;
606 void smpte_duration_string (char *, jack_nframes_t) const;
608 void set_smpte_offset (jack_nframes_t);
609 jack_nframes_t smpte_offset () const { return _smpte_offset; }
610 void set_smpte_offset_negative (bool);
611 bool smpte_offset_negative () const { return _smpte_offset_negative; }
613 jack_nframes_t convert_to_frames_at (jack_nframes_t position, AnyTime&);
615 static sigc::signal<void> SMPTEOffsetChanged;
616 sigc::signal<void> SMPTETypeChanged;
618 void request_slave_source (SlaveSource, jack_nframes_t pos = 0);
619 SlaveSource slave_source() const { return _slave_type; }
620 bool synced_to_jack() const { return _slave_type == JACK; }
621 float transport_speed() const { return _transport_speed; }
622 bool transport_stopped() const { return _transport_speed == 0.0f; }
623 bool transport_rolling() const { return _transport_speed != 0.0f; }
625 int jack_slave_sync (jack_nframes_t);
627 TempoMap& tempo_map() { return *_tempo_map; }
631 sigc::signal<void,AudioRegion *> AudioRegionAdded;
632 sigc::signal<void,AudioRegion *> AudioRegionRemoved;
634 int region_name (string& result, string base = string(""), bool newlevel = false) const;
635 string new_region_name (string);
636 string path_from_region_name (string name, string identifier);
638 AudioRegion* find_whole_file_parent (AudioRegion&);
639 void find_equivalent_playlist_regions (AudioRegion&, std::vector<AudioRegion*>& result);
641 AudioRegion *XMLRegionFactory (const XMLNode&, bool full);
643 template<class T> void foreach_audio_region (T *obj, void (T::*func)(AudioRegion *));
645 /* source management */
647 struct import_status : public InterThreadInfo {
653 volatile bool freeze;
657 std::vector<AudioRegion*> new_regions;
661 int import_audiofile (import_status&);
662 bool sample_rate_convert (import_status&, string infile, string& outfile);
663 string build_tmp_convert_name (string file);
665 Session::SlaveSource post_export_slave;
666 jack_nframes_t post_export_position;
668 int start_audio_export (ARDOUR::AudioExportSpecification&);
669 int stop_audio_export (ARDOUR::AudioExportSpecification&);
671 void add_audio_source (AudioSource *);
672 void remove_source (Source *);
673 int cleanup_audio_file_source (AudioFileSource&);
675 struct cleanup_report {
676 vector<string> paths;
680 int cleanup_sources (cleanup_report&);
681 int cleanup_trash_sources (cleanup_report&);
683 int destroy_region (Region*);
684 int destroy_regions (list<Region*>);
686 int remove_last_capture ();
688 /* handlers should return -1 for "stop cleanup", 0 for
689 "yes, delete this playlist" and 1 for "no, don't delete
693 sigc::signal<int,ARDOUR::Playlist*> AskAboutPlaylistDeletion;
696 /* handlers should return !0 for use pending state, 0 for
700 static sigc::signal<int> AskAboutPendingState;
702 sigc::signal<void,Source *> SourceAdded;
703 sigc::signal<void,Source *> SourceRemoved;
705 AudioFileSource *create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive);
707 Source *source_by_id (const PBD::ID&);
709 /* playlist management */
711 Playlist* playlist_by_name (string name);
712 void add_playlist (Playlist *);
713 sigc::signal<void,Playlist*> PlaylistAdded;
714 sigc::signal<void,Playlist*> PlaylistRemoved;
716 Playlist *get_playlist (string name);
718 uint32_t n_playlists() const;
720 template<class T> void foreach_playlist (T *obj, void (T::*func)(Playlist *));
722 /* named selections */
724 NamedSelection* named_selection_by_name (string name);
725 void add_named_selection (NamedSelection *);
726 void remove_named_selection (NamedSelection *);
728 template<class T> void foreach_named_selection (T& obj, void (T::*func)(NamedSelection&));
729 sigc::signal<void> NamedSelectionAdded;
730 sigc::signal<void> NamedSelectionRemoved;
734 float get_default_fade_length () const { return default_fade_msecs; }
735 float get_default_fade_steepness () const { return default_fade_steepness; }
736 void set_default_fade (float steepness, float msecs);
740 boost::shared_ptr<Auditioner> the_auditioner() { return auditioner; }
741 void audition_playlist ();
742 void audition_region (AudioRegion&);
743 void cancel_audition ();
744 bool is_auditioning () const;
746 sigc::signal<void,bool> AuditionActive;
748 /* flattening stuff */
750 int write_one_audio_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt, bool overwrite, vector<AudioSource*>&,
751 InterThreadInfo& wot);
752 int freeze (InterThreadInfo&);
754 /* session-wide solo/mute/rec-enable */
761 bool soloing() const { return currently_soloing; }
763 SoloModel solo_model() const { return _solo_model; }
764 void set_solo_model (SoloModel);
766 bool solo_latched() const { return _solo_latched; }
767 void set_solo_latched (bool yn);
769 void set_all_solo (bool);
770 void set_all_mute (bool);
772 sigc::signal<void,bool> SoloActive;
774 void record_disenable_all ();
775 void record_enable_all ();
777 /* control/master out */
779 boost::shared_ptr<IO> control_out() const { return _control_out; }
780 boost::shared_ptr<IO> master_out() const { return _master_out; }
782 /* insert/send management */
784 uint32_t n_port_inserts() const { return _port_inserts.size(); }
785 uint32_t n_plugin_inserts() const { return _plugin_inserts.size(); }
786 uint32_t n_sends() const { return _sends.size(); }
788 string next_send_name();
789 string next_insert_name();
791 /* s/w "RAID" management */
793 jack_nframes_t available_capture_duration();
795 /* I/O Connections */
797 template<class T> void foreach_connection (T *obj, void (T::*func)(Connection *));
798 void add_connection (Connection *);
799 void remove_connection (Connection *);
800 Connection *connection_by_name (string) const;
802 sigc::signal<void,Connection *> ConnectionAdded;
803 sigc::signal<void,Connection *> ConnectionRemoved;
807 int set_mtc_port (string port_tag);
808 int set_mmc_port (string port_tag);
809 int set_midi_port (string port_tag);
810 MIDI::Port *mtc_port() const { return _mtc_port; }
811 MIDI::Port *mmc_port() const { return _mmc_port; }
812 MIDI::Port *midi_port() const { return _midi_port; }
814 sigc::signal<void> MTC_PortChanged;
815 sigc::signal<void> MMC_PortChanged;
816 sigc::signal<void> MIDI_PortChanged;
818 void set_trace_midi_input (bool, MIDI::Port* port = 0);
819 void set_trace_midi_output (bool, MIDI::Port* port = 0);
821 bool get_trace_midi_input(MIDI::Port *port = 0);
822 bool get_trace_midi_output(MIDI::Port *port = 0);
824 void send_midi_message (MIDI::Port * port, MIDI::eventType ev, MIDI::channel_t, MIDI::EventTwoBytes);
826 void deliver_midi (MIDI::Port*, MIDI::byte*, int32_t size);
830 void start_scrub (jack_nframes_t where);
832 void set_scrub_speed (float);
833 jack_nframes_t scrub_buffer_size() const;
834 sigc::signal<void> ScrubReady;
836 /* History (for editors, mixers, UIs etc.) */
838 void undo (uint32_t n) {
841 void redo (uint32_t n) {
845 uint32_t undo_depth() const { return history.undo_depth(); }
846 uint32_t redo_depth() const { return history.redo_depth(); }
847 string next_undo() const { return history.next_undo(); }
848 string next_redo() const { return history.next_redo(); }
850 void begin_reversible_command (string cmd_name, UndoAction *private_undo = 0);
851 void commit_reversible_command (UndoAction* private_redo = 0);
853 void add_undo (const UndoAction& ua) {
854 current_cmd.add_undo (ua);
856 void add_redo (const UndoAction& ua) {
857 current_cmd.add_redo (ua);
859 void add_redo_no_execute (const UndoAction& ua) {
860 current_cmd.add_redo_no_execute (ua);
863 UndoAction global_solo_memento (void *src);
864 UndoAction global_mute_memento (void *src);
865 UndoAction global_record_enable_memento (void *src);
866 UndoAction global_metering_memento (void *src);
870 void set_edit_mode (EditMode);
871 EditMode get_edit_mode () const { return _edit_mode; }
875 boost::shared_ptr<IO> click_io() { return _click_io; }
876 void set_clicking (bool yn);
877 bool get_clicking() const;
879 void set_click_sound (string path);
880 void set_click_emphasis_sound (string path);
884 struct TimeStretchRequest {
885 ARDOUR::AudioRegion* region;
886 float fraction; /* session: read ; GUI: write */
887 float progress; /* session: write ; GUI: read */
888 bool running; /* read/write */
889 bool quick_seek; /* GUI: write */
890 bool antialias; /* GUI: write */
892 TimeStretchRequest () : region (0) {}
895 AudioRegion* tempoize_region (TimeStretchRequest&);
897 string raid_path() const;
898 void set_raid_path(string);
900 /* need to call this whenever we change native file formats */
902 void reset_native_file_format();
904 /* disk, buffer loads */
906 uint32_t playback_load ();
907 uint32_t capture_load ();
908 uint32_t playback_load_min ();
909 uint32_t capture_load_min ();
911 void reset_playback_load_min ();
912 void reset_capture_load_min ();
914 float read_data_rate () const;
915 float write_data_rate () const;
919 void set_audio_range (list<AudioRange>&);
920 void set_music_range (list<MusicRange>&);
922 void request_play_range (bool yn);
923 bool get_play_range () const { return _play_range; }
926 typedef vector<string> FavoriteDirs;
928 static int read_favorite_dirs (FavoriteDirs&);
930 static int write_favorite_dirs (FavoriteDirs&);
934 static const char* template_suffix() { return _template_suffix; }
935 static const char* statefile_suffix() { return _statefile_suffix; }
936 static const char* pending_suffix() { return _pending_suffix; }
938 /* buffers for gain and pan */
940 gain_t* gain_automation_buffer () const { return _gain_automation_buffer; }
941 pan_t** pan_automation_buffer() const { return _pan_automation_buffer; }
943 /* buffers for conversion */
950 char * conversion_buffer(RunContext context) { return _conversion_buffers[context]; }
954 static long vst_callback (AEffect* effect,
961 typedef float (*compute_peak_t) (Sample *, jack_nframes_t, float);
962 typedef void (*apply_gain_to_buffer_t) (Sample *, jack_nframes_t, float);
963 typedef void (*mix_buffers_with_gain_t) (Sample *, Sample *, jack_nframes_t, float);
964 typedef void (*mix_buffers_no_gain_t) (Sample *, Sample *, jack_nframes_t);
966 static compute_peak_t compute_peak;
967 static apply_gain_to_buffer_t apply_gain_to_buffer;
968 static mix_buffers_with_gain_t mix_buffers_with_gain;
969 static mix_buffers_no_gain_t mix_buffers_no_gain;
971 static sigc::signal<void> SendFeedback;
975 PBD::Controllable* controllable_by_id (const PBD::ID&);
978 friend class AudioEngine;
979 void set_block_size (jack_nframes_t nframes);
980 void set_frame_rate (jack_nframes_t nframes);
983 friend class AudioDiskstream;
985 void wait_till_butler_finished();
989 void schedule_curve_reallocation ();
990 void update_latency_compensation (bool, bool);
993 int create (bool& new_session, string* mix_template, jack_nframes_t initial_length);
995 static const char* _template_suffix;
996 static const char* _statefile_suffix;
997 static const char* _pending_suffix;
1000 PendingDeclickIn = 0x1,
1001 PendingDeclickOut = 0x2,
1002 StopPendingCapture = 0x4,
1003 AutoReturning = 0x10,
1004 PendingLocate = 0x20,
1005 PendingSetLoop = 0x40
1008 /* stuff used in process() should be close together to
1012 typedef void (Session::*process_function_type)(jack_nframes_t);
1014 AudioEngine &_engine;
1015 mutable gint processing_prohibited;
1016 process_function_type process_function;
1017 process_function_type last_process_function;
1018 jack_nframes_t _current_frame_rate;
1019 int transport_sub_state;
1020 mutable gint _record_status;
1021 jack_nframes_t _transport_frame;
1022 Location* end_location;
1023 Location* start_location;
1025 SlaveSource _slave_type;
1026 volatile float _transport_speed;
1027 volatile float _desired_transport_speed;
1028 float _last_transport_speed;
1029 jack_nframes_t _last_slave_transport_frame;
1030 jack_nframes_t maximum_output_latency;
1031 jack_nframes_t last_stop_frame;
1032 vector<Sample *> _passthru_buffers;
1033 vector<Sample *> _silent_buffers;
1034 vector<Sample *> _send_buffers;
1035 map<RunContext,char*> _conversion_buffers;
1036 jack_nframes_t current_block_size;
1037 jack_nframes_t _worst_output_latency;
1038 jack_nframes_t _worst_input_latency;
1039 jack_nframes_t _worst_track_latency;
1040 bool _have_captured;
1042 float _meter_falloff;
1043 bool _end_location_is_free;
1045 void set_worst_io_latencies ();
1046 void set_worst_io_latencies_x (IOChange asifwecare, void *ignored) {
1047 set_worst_io_latencies ();
1050 void update_latency_compensation_proxy (void* ignored);
1052 void ensure_passthru_buffers (uint32_t howmany);
1054 void process_scrub (jack_nframes_t);
1055 void process_without_events (jack_nframes_t);
1056 void process_with_events (jack_nframes_t);
1057 void process_audition (jack_nframes_t);
1058 int process_export (jack_nframes_t, ARDOUR::AudioExportSpecification*);
1060 /* slave tracking */
1062 static const int delta_accumulator_size = 25;
1063 int delta_accumulator_cnt;
1064 long delta_accumulator[delta_accumulator_size];
1065 long average_slave_delta;
1067 bool have_first_delta_accumulator;
1075 SlaveState slave_state;
1076 jack_nframes_t slave_wait_end;
1078 void reset_slave_state ();
1079 bool follow_slave (jack_nframes_t, jack_nframes_t);
1082 int prepare_to_export (ARDOUR::AudioExportSpecification&);
1084 void prepare_diskstreams ();
1085 void commit_diskstreams (jack_nframes_t, bool& session_requires_butler);
1086 int process_routes (jack_nframes_t, jack_nframes_t);
1087 int silent_process_routes (jack_nframes_t, jack_nframes_t);
1089 bool get_rec_monitors_input () {
1090 if (actively_recording()) {
1101 int get_transport_declick_required () {
1103 if (transport_sub_state & PendingDeclickIn) {
1104 transport_sub_state &= ~PendingDeclickIn;
1106 } else if (transport_sub_state & PendingDeclickOut) {
1113 bool maybe_stop (jack_nframes_t limit) {
1114 if ((_transport_speed > 0.0f && _transport_frame >= limit) || (_transport_speed < 0.0f && _transport_frame == 0)) {
1121 void check_declick_out ();
1123 MIDI::MachineControl* mmc;
1124 MIDI::Port* _mmc_port;
1125 MIDI::Port* _mtc_port;
1126 MIDI::Port* _midi_port;
1129 bool do_not_record_plugins;
1139 jack_nframes_t last_loopend;
1141 bool crossfades_active;
1150 RingBuffer<Event*> pending_events;
1153 void when_engine_running ();
1154 sigc::connection first_time_running;
1155 void graph_reordered ();
1157 string _current_snapshot_name;
1159 XMLTree* state_tree;
1160 bool state_was_pending;
1161 StateOfTheState _state_of_the_state;
1164 int load_options (const XMLNode&);
1165 XMLNode& get_options () const;
1166 int load_state (string snapshot_name);
1168 jack_nframes_t _last_roll_location;
1169 jack_nframes_t _last_record_location;
1170 bool pending_locate_roll;
1171 jack_nframes_t pending_locate_frame;
1173 bool pending_locate_flush;
1175 bool pending_auto_loop;
1177 Sample* butler_mixdown_buffer;
1178 float* butler_gain_buffer;
1179 pthread_t butler_thread;
1180 Glib::Mutex butler_request_lock;
1181 Glib::Cond butler_paused;
1182 bool butler_should_run;
1183 mutable gint butler_should_do_transport_work;
1184 int butler_request_pipe[2];
1186 struct ButlerRequest {
1195 enum PostTransportWork {
1196 PostTransportStop = 0x1,
1197 PostTransportDisableRecord = 0x2,
1198 PostTransportPosition = 0x8,
1199 PostTransportDidRecord = 0x20,
1200 PostTransportDuration = 0x40,
1201 PostTransportLocate = 0x80,
1202 PostTransportRoll = 0x200,
1203 PostTransportAbort = 0x800,
1204 PostTransportOverWrite = 0x1000,
1205 PostTransportSpeed = 0x2000,
1206 PostTransportAudition = 0x4000,
1207 PostTransportScrub = 0x8000,
1208 PostTransportReverse = 0x10000,
1209 PostTransportInputChange = 0x20000,
1210 PostTransportCurveRealloc = 0x40000
1213 static const PostTransportWork ProcessCannotProceedMask =
1214 PostTransportWork (PostTransportInputChange|
1216 PostTransportReverse|
1217 PostTransportCurveRealloc|
1219 PostTransportAudition|
1220 PostTransportLocate|
1223 PostTransportWork post_transport_work;
1225 void summon_butler ();
1226 void schedule_butler_transport_work ();
1227 int start_butler_thread ();
1228 void terminate_butler_thread ();
1229 static void *_butler_thread_work (void *arg);
1230 void* butler_thread_work ();
1232 uint32_t cumulative_rf_motion;
1235 void set_rf_speed (float speed);
1236 void reset_rf_scale (jack_nframes_t frames_moved);
1238 Locations _locations;
1239 void locations_changed ();
1240 void locations_added (Location*);
1241 void handle_locations_changed (Locations::LocationList&);
1243 sigc::connection auto_punch_start_changed_connection;
1244 sigc::connection auto_punch_end_changed_connection;
1245 sigc::connection auto_punch_changed_connection;
1246 void auto_punch_start_changed (Location *);
1247 void auto_punch_end_changed (Location *);
1248 void auto_punch_changed (Location *);
1250 sigc::connection auto_loop_start_changed_connection;
1251 sigc::connection auto_loop_end_changed_connection;
1252 sigc::connection auto_loop_changed_connection;
1253 void auto_loop_changed (Location *);
1255 typedef list<Event *> Events;
1257 Events immediate_events;
1258 Events::iterator next_event;
1260 /* there can only ever be one of each of these */
1262 Event *auto_loop_event;
1263 Event *punch_out_event;
1264 Event *punch_in_event;
1268 void dump_events () const;
1269 void queue_event (Event *ev);
1270 void merge_event (Event*);
1271 void replace_event (Event::Type, jack_nframes_t action_frame, jack_nframes_t target = 0);
1272 bool _replace_event (Event*);
1273 bool _remove_event (Event *);
1274 void _clear_event_type (Event::Type);
1276 void first_stage_init (string path, string snapshot_name);
1277 int second_stage_init (bool new_tracks);
1278 void find_current_end ();
1279 void remove_empty_sounds ();
1281 void setup_midi_control ();
1282 int midi_read (MIDI::Port *);
1284 void enable_record ();
1286 void increment_transport_position (uint32_t val) {
1287 if (max_frames - val < _transport_frame) {
1288 _transport_frame = max_frames;
1290 _transport_frame += val;
1294 void decrement_transport_position (uint32_t val) {
1295 if (val < _transport_frame) {
1296 _transport_frame -= val;
1298 _transport_frame = 0;
1302 void post_transport_motion ();
1303 static void *session_loader_thread (void *arg);
1307 void set_next_event ();
1308 void process_event (Event *);
1310 /* MIDI Machine Control */
1312 void deliver_mmc (MIDI::MachineControl::Command, jack_nframes_t);
1313 void deliver_midi_message (MIDI::Port * port, MIDI::eventType ev, MIDI::channel_t, MIDI::EventTwoBytes);
1314 void deliver_data (MIDI::Port* port, MIDI::byte*, int32_t size);
1316 void spp_start (MIDI::Parser&);
1317 void spp_continue (MIDI::Parser&);
1318 void spp_stop (MIDI::Parser&);
1320 void mmc_deferred_play (MIDI::MachineControl &);
1321 void mmc_stop (MIDI::MachineControl &);
1322 void mmc_step (MIDI::MachineControl &, int);
1323 void mmc_pause (MIDI::MachineControl &);
1324 void mmc_record_pause (MIDI::MachineControl &);
1325 void mmc_record_strobe (MIDI::MachineControl &);
1326 void mmc_record_exit (MIDI::MachineControl &);
1327 void mmc_track_record_status (MIDI::MachineControl &,
1328 uint32_t track, bool enabled);
1329 void mmc_fast_forward (MIDI::MachineControl &);
1330 void mmc_rewind (MIDI::MachineControl &);
1331 void mmc_locate (MIDI::MachineControl &, const MIDI::byte *);
1332 void mmc_shuttle (MIDI::MachineControl &mmc, float speed, bool forw);
1333 void mmc_record_enable (MIDI::MachineControl &mmc, size_t track, bool enabled);
1335 struct timeval last_mmc_step;
1338 typedef sigc::slot<bool> MidiTimeoutCallback;
1339 typedef list<MidiTimeoutCallback> MidiTimeoutList;
1341 MidiTimeoutList midi_timeouts;
1342 bool mmc_step_timeout ();
1344 MIDI::byte mmc_buffer[32];
1345 MIDI::byte mtc_msg[16];
1346 MIDI::byte mtc_smpte_bits; /* encoding of SMTPE type for MTC */
1347 MIDI::byte midi_msg[16];
1348 jack_nframes_t outbound_mtc_smpte_frame;
1349 SMPTE::Time transmitting_smpte_time;
1350 int next_quarter_frame_to_send;
1352 double _frames_per_smpte_frame; /* has to be floating point because of drop frame */
1353 jack_nframes_t _frames_per_hour;
1354 jack_nframes_t _smpte_frames_per_hour;
1355 jack_nframes_t _smpte_offset;
1356 bool _smpte_offset_negative;
1358 /* cache the most-recently requested time conversions.
1359 this helps when we have multiple clocks showing the
1360 same time (e.g. the transport frame)
1363 bool last_smpte_valid;
1364 jack_nframes_t last_smpte_when;
1365 SMPTE::Time last_smpte;
1367 int send_full_time_code ();
1368 int send_midi_time_code ();
1370 void send_full_time_code_in_another_thread ();
1371 void send_midi_time_code_in_another_thread ();
1372 void send_time_code_in_another_thread (bool full);
1373 void send_mmc_in_another_thread (MIDI::MachineControl::Command, jack_nframes_t frame = 0);
1375 jack_nframes_t adjust_apparent_position (jack_nframes_t frames);
1377 void reset_record_status ();
1379 int no_roll (jack_nframes_t nframes, jack_nframes_t offset);
1381 bool non_realtime_work_pending() const { return static_cast<bool>(post_transport_work); }
1382 bool process_can_proceed() const { return !(post_transport_work & ProcessCannotProceedMask); }
1384 struct MIDIRequest {
1397 MIDI::MachineControl::Command mmc_cmd;
1398 jack_nframes_t locate_frame;
1400 // for SendMessage type
1403 MIDI::channel_t chan;
1405 MIDI::EventTwoBytes data;
1416 void *operator new(size_t ignored) {
1417 return pool.alloc ();
1420 void operator delete(void *ptr, size_t size) {
1425 static MultiAllocSingleReleasePool pool;
1428 Glib::Mutex midi_lock;
1429 pthread_t midi_thread;
1430 int midi_request_pipe[2];
1431 mutable gint butler_active;
1432 RingBuffer<MIDIRequest*> midi_requests;
1434 int start_midi_thread ();
1435 void terminate_midi_thread ();
1436 void poke_midi_thread ();
1437 static void *_midi_thread_work (void *arg);
1438 void midi_thread_work ();
1439 void change_midi_ports ();
1440 int use_config_midi_ports ();
1442 bool waiting_to_start;
1444 void set_auto_loop (bool yn);
1445 void overwrite_some_buffers (AudioDiskstream*);
1446 void flush_all_redirects ();
1447 void locate (jack_nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
1448 void start_locate (jack_nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
1449 void force_locate (jack_nframes_t frame, bool with_roll = false);
1450 void set_diskstream_speed (AudioDiskstream*, float speed);
1451 void set_transport_speed (float speed, bool abort = false);
1452 void stop_transport (bool abort = false);
1453 void start_transport ();
1454 void actually_start_transport ();
1455 void realtime_stop (bool abort);
1456 void non_realtime_start_scrub ();
1457 void non_realtime_set_speed ();
1458 void non_realtime_stop (bool abort);
1459 void non_realtime_overwrite ();
1460 void non_realtime_buffer_fill ();
1461 void butler_transport_work ();
1462 void post_transport ();
1463 void engine_halted ();
1464 void xrun_recovery ();
1466 TempoMap *_tempo_map;
1467 void tempo_map_changed (Change);
1469 /* edit/mix groups */
1471 int load_route_groups (const XMLNode&, bool is_edit);
1472 int load_edit_groups (const XMLNode&);
1473 int load_mix_groups (const XMLNode&);
1476 list<RouteGroup *> edit_groups;
1477 list<RouteGroup *> mix_groups;
1481 AudioDiskstreamList audio_diskstreams;
1482 mutable Glib::RWLock diskstream_lock;
1483 uint32_t dstream_buffer_size;
1484 void add_diskstream (AudioDiskstream*);
1485 int load_diskstreams (const XMLNode&);
1489 SerializedRCUManager<RouteList> routes;
1491 void add_route (boost::shared_ptr<Route>);
1492 uint32_t destructive_index;
1494 int load_routes (const XMLNode&);
1495 boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&);
1500 SoloModel _solo_model;
1501 bool solo_update_disabled;
1502 bool currently_soloing;
1504 void route_mute_changed (void *src);
1505 void route_solo_changed (void *src, boost::shared_ptr<Route>);
1506 void catch_up_on_solo ();
1507 void update_route_solo_state ();
1508 void modify_solo_mute (bool, bool);
1509 void strip_portname_for_solo (string& portname);
1511 /* REGION MANAGEMENT */
1513 mutable Glib::Mutex region_lock;
1514 typedef map<PBD::ID,AudioRegion *> AudioRegionList;
1515 AudioRegionList audio_regions;
1517 void region_renamed (Region *);
1518 void region_changed (Change, Region *);
1519 void add_region (Region *);
1520 void remove_region (Region *);
1522 int load_regions (const XMLNode& node);
1526 mutable Glib::Mutex audio_source_lock;
1527 typedef std::map<PBD::ID,AudioSource *> AudioSourceList;
1529 AudioSourceList audio_sources;
1531 int load_sources (const XMLNode& node);
1532 XMLNode& get_sources_as_xml ();
1534 Source *XMLSourceFactory (const XMLNode&);
1538 mutable Glib::Mutex playlist_lock;
1539 typedef set<Playlist *> PlaylistList;
1540 PlaylistList playlists;
1541 PlaylistList unused_playlists;
1543 int load_playlists (const XMLNode&);
1544 int load_unused_playlists (const XMLNode&);
1545 void remove_playlist (Playlist *);
1546 void track_playlist (Playlist *, bool);
1548 Playlist *playlist_factory (string name);
1549 Playlist *XMLPlaylistFactory (const XMLNode&);
1551 void playlist_length_changed (Playlist *);
1552 void diskstream_playlist_changed (AudioDiskstream *);
1554 /* NAMED SELECTIONS */
1556 mutable Glib::Mutex named_selection_lock;
1557 typedef set<NamedSelection *> NamedSelectionList;
1558 NamedSelectionList named_selections;
1560 int load_named_selections (const XMLNode&);
1562 NamedSelection *named_selection_factory (string name);
1563 NamedSelection *XMLNamedSelectionFactory (const XMLNode&);
1565 /* DEFAULT FADE CURVES */
1567 float default_fade_steepness;
1568 float default_fade_msecs;
1572 boost::shared_ptr<Auditioner> auditioner;
1573 void set_audition (AudioRegion*);
1574 void non_realtime_set_audition ();
1575 AudioRegion *pending_audition_region;
1581 int flatten_one_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt);
1583 /* INSERT AND SEND MANAGEMENT */
1585 list<PortInsert *> _port_inserts;
1586 list<PluginInsert *> _plugin_inserts;
1587 list<Send *> _sends;
1589 uint32_t insert_cnt;
1591 void add_redirect (Redirect *);
1592 void remove_redirect (Redirect *);
1596 struct space_and_path {
1597 uint32_t blocks; /* 4kB blocks */
1605 struct space_and_path_ascending_cmp {
1606 bool operator() (space_and_path a, space_and_path b) {
1607 return a.blocks > b.blocks;
1611 void setup_raid_path (string path);
1613 vector<space_and_path> session_dirs;
1614 vector<space_and_path>::iterator last_rr_session_dir;
1615 uint32_t _total_free_4k_blocks;
1616 Glib::Mutex space_lock;
1618 static const char* sound_dir_name;
1619 static const char* tape_dir_name;
1620 static const char* dead_sound_dir_name;
1621 static const char* peak_dir_name;
1623 string discover_best_sound_dir (bool destructive = false);
1624 int ensure_sound_dir (string, string&);
1625 void refresh_disk_space ();
1627 mutable gint _playback_load;
1628 mutable gint _capture_load;
1629 mutable gint _playback_load_min;
1630 mutable gint _capture_load_min;
1632 /* I/O Connections */
1634 typedef list<Connection *> ConnectionList;
1635 mutable Glib::Mutex connection_lock;
1636 ConnectionList _connections;
1637 int load_connections (const XMLNode&);
1639 int set_slave_source (SlaveSource, jack_nframes_t);
1641 void reverse_diskstream_buffers ();
1643 UndoHistory history;
1644 UndoCommand current_cmd;
1646 GlobalRouteBooleanState get_global_route_boolean (bool (Route::*method)(void) const);
1647 GlobalRouteMeterState get_global_route_metering ();
1649 void set_global_route_boolean (GlobalRouteBooleanState s, void (Route::*method)(bool, void*), void *arg);
1650 void set_global_route_metering (GlobalRouteMeterState s, void *arg);
1652 void set_global_mute (GlobalRouteBooleanState s, void *src);
1653 void set_global_solo (GlobalRouteBooleanState s, void *src);
1654 void set_global_record_enable (GlobalRouteBooleanState s, void *src);
1656 void jack_timebase_callback (jack_transport_state_t, jack_nframes_t, jack_position_t*, int);
1657 int jack_sync_callback (jack_transport_state_t, jack_position_t*);
1658 void record_enable_change_all (bool yn);
1660 XMLNode& state(bool);
1665 jack_nframes_t start;
1666 jack_nframes_t duration;
1667 jack_nframes_t offset;
1670 Click (jack_nframes_t s, jack_nframes_t d, const Sample *b)
1671 : start (s), duration (d), data (b) { offset = 0; }
1673 void *operator new(size_t ignored) {
1674 return pool.alloc ();
1677 void operator delete(void *ptr, size_t size) {
1685 typedef list<Click*> Clicks;
1689 boost::shared_ptr<IO> _click_io;
1691 Sample* click_emphasis_data;
1692 jack_nframes_t click_length;
1693 jack_nframes_t click_emphasis_length;
1694 mutable Glib::RWLock click_lock;
1696 static const Sample default_click[];
1697 static const jack_nframes_t default_click_length;
1698 static const Sample default_click_emphasis[];
1699 static const jack_nframes_t default_click_emphasis_length;
1702 void setup_click_sounds (int which);
1703 void clear_clicks ();
1704 void click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t offset);
1706 vector<Route*> master_outs;
1708 EditMode _edit_mode;
1709 EditMode pending_edit_mode;
1711 /* range playback */
1713 list<AudioRange> current_audio_range;
1715 void set_play_range (bool yn);
1716 void setup_auto_play ();
1721 boost::shared_ptr<IO> _master_out;
1722 boost::shared_ptr<IO> _control_out;
1724 AutoConnectOption input_auto_connect;
1725 AutoConnectOption output_auto_connect;
1727 gain_t* _gain_automation_buffer;
1728 pan_t** _pan_automation_buffer;
1729 void allocate_pan_automation_buffers (jack_nframes_t nframes, uint32_t howmany, bool force);
1730 uint32_t _npan_buffers;
1734 long _vst_callback (VSTPlugin*,
1741 /* number of hardware audio ports we're using,
1742 based on max (requested,available)
1745 uint32_t n_physical_outputs;
1746 uint32_t n_physical_inputs;
1748 void remove_pending_capture_state ();
1750 int find_all_sources (std::string path, std::set<std::string>& result);
1751 int find_all_sources_across_snapshots (std::set<std::string>& result, bool exclude_this_snapshot);
1753 LayerModel layer_model;
1754 CrossfadeModel xfade_model;
1756 typedef std::list<PBD::Controllable*> Controllables;
1757 Glib::Mutex controllables_lock;
1758 Controllables controllables;
1760 void add_controllable (PBD::Controllable*);
1761 void remove_controllable (PBD::Controllable*);
1764 } // namespace ARDOUR
1766 #endif /* __ardour_session_h__ */