X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fardour%2Fio.h;h=5511f64dd683b3becf62f58ac146134ab12135f4;hb=f022784014d4ae1b3bb75a1c02f206ba8a28d7d6;hp=83b6378daee4a93f22b2fe3b6843672be14bb76a;hpb=449aab3c465bbbf66d221fac3d7ea559f1720357;p=ardour.git diff --git a/libs/ardour/ardour/io.h b/libs/ardour/ardour/io.h index 83b6378dae..5511f64dd6 100644 --- a/libs/ardour/ardour/io.h +++ b/libs/ardour/ardour/io.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2000 Paul Davis + Copyright (C) 2000 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,367 +23,237 @@ #include #include #include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using std::string; -using std::vector; + +#include + +#include "pbd/fastlog.h" +#include "pbd/undo.h" +#include "pbd/statefuldestructible.h" +#include "pbd/controllable.h" + +#include "ardour/ardour.h" +#include "ardour/automation_control.h" +#include "ardour/bundle.h" +#include "ardour/chan_count.h" +#include "ardour/data_type.h" +#include "ardour/latent.h" +#include "ardour/port_set.h" +#include "ardour/session_object.h" +#include "ardour/libardour_visibility.h" +#include "ardour/types.h" +#include "ardour/utils.h" +#include "ardour/buffer_set.h" class XMLNode; namespace ARDOUR { -class Session; +class Amp; class AudioEngine; +class AudioPort; class Bundle; -class AutoBundle; -class Panner; +class MidiPort; class PeakMeter; class Port; -class AudioPort; -class MidiPort; -class BufferSet; - +class Processor; +class Session; +class UserBundle; -/** A collection of input and output ports with connections. +/** A collection of ports (all input or all output) with connections. * * An IO can contain ports of varying types, making routes/inserts/etc with * varied combinations of types (eg MIDI and audio) possible. */ - -class IO : public Automatable, public Latent +class LIBARDOUR_API IO : public SessionObject, public Latent { public: - static const string state_node_name; - - IO (Session&, const string& name, - int input_min = -1, int input_max = -1, - int output_min = -1, int output_max = -1, - DataType default_type = DataType::AUDIO, - bool public_ports = true); - - IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO); - - virtual ~IO(); + static const std::string state_node_name; - ChanCount input_minimum() const { return _input_minimum; } - ChanCount input_maximum() const { return _input_maximum; } - ChanCount output_minimum() const { return _output_minimum; } - ChanCount output_maximum() const { return _output_maximum; } - - void set_input_minimum (ChanCount n); - void set_input_maximum (ChanCount n); - void set_output_minimum (ChanCount n); - void set_output_maximum (ChanCount n); - - bool active() const { return _active; } - void set_active (bool yn); - - DataType default_type() const { return _default_type; } - void set_default_type(DataType t) { _default_type = t; } - - bool set_name (const string& str); - - virtual void silence (nframes_t, nframes_t offset); + enum Direction { + Input, + Output + }; - void collect_input (BufferSet& bufs, nframes_t nframes, nframes_t offset); - void deliver_output (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, - nframes_t nframes, nframes_t offset); - void just_meter_input (nframes_t start_frame, nframes_t end_frame, - nframes_t nframes, nframes_t offset); + IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false); + IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false); - gain_t gain () const { return _desired_gain; } - virtual gain_t effective_gain () const; - - void set_denormal_protection (bool yn, void *src); - bool denormal_protection() const { return _denormal_protection; } - - void set_phase_invert (bool yn, void *src); - bool phase_invert() const { return _phase_invert; } + virtual ~IO(); - Panner& panner() { return *_panner; } - PeakMeter& peak_meter() { return *_meter; } - const Panner& panner() const { return *_panner; } - - int ensure_io (ChanCount in, ChanCount out, bool clear, void *src); + Direction direction() const { return _direction; } - int connect_input_ports_to_bundle (boost::shared_ptr, void *src); - int connect_output_ports_to_bundle (boost::shared_ptr, void *src); + DataType default_type() const { return _default_type; } + void set_default_type(DataType t) { _default_type = t; } - std::vector > bundles_connected_to_inputs (); - std::vector > bundles_connected_to_outputs (); + bool active() const { return _active; } + void set_active(bool yn) { _active = yn; } - boost::shared_ptr bundle_for_inputs () { return _bundle_for_inputs; } - boost::shared_ptr bundle_for_outputs () { return _bundle_for_outputs; } - - int add_input_port (string source, void *src, DataType type = DataType::NIL); - int add_output_port (string destination, void *src, DataType type = DataType::NIL); + bool set_name (const std::string& str); + void set_pretty_name (const std::string& str); + std::string pretty_name () const { return _pretty_name_prefix; } - int remove_input_port (Port *, void *src); - int remove_output_port (Port *, void *src); + virtual void silence (framecnt_t); + void increment_port_buffer_offset (pframes_t offset); - int set_input (Port *, void *src); + int ensure_io (ChanCount cnt, bool clear, void *src); - int connect_input (Port *our_port, string other_port, void *src); - int connect_output (Port *our_port, string other_port, void *src); + int connect_ports_to_bundle (boost::shared_ptr, bool exclusive, void *); + int disconnect_ports_from_bundle (boost::shared_ptr, void *); - int disconnect_input (Port *our_port, string other_port, void *src); - int disconnect_output (Port *our_port, string other_port, void *src); + BundleList bundles_connected (); - int disconnect_inputs (void *src); - int disconnect_outputs (void *src); + boost::shared_ptr bundle () { return _bundle; } - nframes_t signal_latency() const { return _own_latency; } - nframes_t output_latency() const; - nframes_t input_latency() const; - void set_port_latency (nframes_t); + int add_port (std::string connection, void *src, DataType type = DataType::NIL); + int remove_port (boost::shared_ptr, void *src); + int connect (boost::shared_ptr our_port, std::string other_port, void *src); + int disconnect (boost::shared_ptr our_port, std::string other_port, void *src); + int disconnect (void *src); + bool connected_to (boost::shared_ptr) const; + bool connected_to (const std::string&) const; + bool connected () const; + bool physically_connected () const; - void update_port_total_latencies (); + framecnt_t signal_latency () const { return 0; } + framecnt_t latency () const; - const PortSet& inputs() const { return _inputs; } - const PortSet& outputs() const { return _outputs; } + PortSet& ports() { return _ports; } + const PortSet& ports() const { return _ports; } - Port *output (uint32_t n) const { - if (n < _outputs.num_ports()) { - return _outputs.port(n); - } else { - return 0; - } - } + bool has_port (boost::shared_ptr) const; - Port *input (uint32_t n) const { - if (n < _inputs.num_ports()) { - return _inputs.port(n); + boost::shared_ptr nth (uint32_t n) const { + if (n < _ports.num_ports()) { + return _ports.port(n); } else { - return 0; + return boost::shared_ptr (); } } - AudioPort* audio_input(uint32_t n) const; - AudioPort* audio_output(uint32_t n) const; - MidiPort* midi_input(uint32_t n) const; - MidiPort* midi_output(uint32_t n) const; + boost::shared_ptr port_by_name (const std::string& str) const; - const ChanCount& n_inputs () const { return _inputs.count(); } - const ChanCount& n_outputs () const { return _outputs.count(); } + boost::shared_ptr audio(uint32_t n) const; + boost::shared_ptr midi(uint32_t n) const; - void attach_buffers(ChanCount ignored); - - sigc::signal active_changed; + const ChanCount& n_ports () const { return _ports.count(); } - sigc::signal input_changed; - sigc::signal output_changed; + /* The process lock will be held on emission of this signal if + * IOChange contains ConfigurationChanged. In other cases, + * the process lock status is undefined. + */ + PBD::Signal2 changed; virtual XMLNode& state (bool full); XMLNode& get_state (void); - int set_state (const XMLNode&); - - static int disable_connecting (void); - - static int enable_connecting (void); - - static int disable_ports (void); - - static int enable_ports (void); - - static int disable_panners (void); - - static int reset_panners (void); - - static sigc::signal PortsLegal; - static sigc::signal PannersLegal; - static sigc::signal ConnectingLegal; - /// raised when the number of input or output ports changes - static sigc::signal PortCountChanged; - static sigc::signal PortsCreated; - - static void update_meters(); - - private: - - static sigc::signal Meter; - static Glib::StaticMutex m_meter_signal_lock; - sigc::connection m_meter_connection; - - public: - - /* automation */ - - struct GainControl : public AutomationControl { - GainControl (std::string name, IO& i, boost::shared_ptr al) - : AutomationControl (i._session, al, name) - , _io (i) - {} - - void set_value (float val); - float get_value (void) const; - - IO& _io; + int set_state (const XMLNode&, int version); + int set_state_2X (const XMLNode&, int, bool); + static void prepare_for_reset (XMLNode&, const std::string&); + + class BoolCombiner { + public: + + typedef bool result_type; + + template + result_type operator() (Iter first, Iter last) const { + bool r = false; + while (first != last) { + if (*first) { + r = true; + } + ++first; + } + + return r; + } }; - boost::shared_ptr gain_control() { - return _gain_control; - } - boost::shared_ptr gain_control() const { - return _gain_control; - } - - void clear_automation (); - - void set_parameter_automation_state (Parameter, AutoState); + /** Emitted when the port count is about to change. Objects + * can attach to this, and return `true' if they want to prevent + * the change from happening. + */ + PBD::Signal1 PortCountChanging; - virtual void transport_stopped (nframes_t now); - virtual void automation_snapshot (nframes_t now, bool force); + static int disable_connecting (); + static int enable_connecting (); - void start_pan_touch (uint32_t which); - void end_pan_touch (uint32_t which); + static PBD::Signal1 PortCountChanged; // emitted when the number of ports changes - void defer_pan_reset (); - void allow_pan_reset (); + static std::string name_from_state (const XMLNode&); + static void set_name_in_state (XMLNode&, const std::string&); - /* the session calls this for master outs before - anyone else. controls outs too, at some point. + /* we have to defer/order port connection. this is how we do it. */ + static PBD::Signal0 ConnectingLegal; + static bool connecting_legal; + XMLNode *pending_state_node; - int ports_became_legal (); + int pending_state_node_version; + bool pending_state_node_in; - private: - mutable Glib::Mutex io_lock; + /* three utility functions - this just seems to be simplest place to put them */ - protected: - Panner* _panner; - BufferSet* _output_buffers; //< Set directly to output port buffers - bool _active; - gain_t _gain; - gain_t _effective_gain; - gain_t _desired_gain; - Glib::Mutex declick_lock; - PortSet _outputs; - PortSet _inputs; - PeakMeter* _meter; - bool no_panner_reset; - bool _phase_invert; - bool _denormal_protection; - XMLNode* deferred_state; - DataType _default_type; - bool _public_ports; - - virtual void set_deferred_state() {} - - void reset_panner (); - - virtual uint32_t pans_required() const - { return _inputs.count().n_audio(); } - - boost::shared_ptr _gain_control; - - virtual void set_gain (gain_t g, void *src); - void inc_gain (gain_t delta, void *src); - - bool apply_gain_automation; - - virtual int load_automation (std::string path); + void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset); + void process_input (boost::shared_ptr, framepos_t start_frame, framepos_t end_frame, pframes_t nframes); + void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, framecnt_t offset); /* AudioTrack::deprecated_use_diskstream_connections() needs these */ - int set_inputs (const string& str); - int set_outputs (const string& str); - - static bool connecting_legal; - static bool ports_legal; - - BufferSet& output_buffers() { return *_output_buffers; } + int set_ports (const std::string& str); private: + mutable Glib::Threads::Mutex io_lock; - friend class Send; + protected: + PortSet _ports; + Direction _direction; + DataType _default_type; + bool _active; + bool _sendish; - static bool panners_legal; - + private: int connecting_became_legal (); - int panners_became_legal (); - sigc::connection connection_legal_c; - sigc::connection port_legal_c; - sigc::connection panner_legal_c; - - ChanCount _input_minimum; ///< minimum number of input channels (0 for no minimum) - ChanCount _input_maximum; ///< maximum number of input channels (ChanCount::INFINITE for no maximum) - ChanCount _output_minimum; ///< minimum number of output channels (0 for no minimum) - ChanCount _output_maximum; ///< maximum number of output channels (ChanCount::INFINITE for no maximum) + PBD::ScopedConnection connection_legal_c; - boost::shared_ptr _bundle_for_inputs; ///< a bundle representing our inputs - boost::shared_ptr _bundle_for_outputs; ///< a bundle representing our outputs + boost::shared_ptr _bundle; ///< a bundle representing our ports struct UserBundleInfo { UserBundleInfo (IO*, boost::shared_ptr b); - boost::shared_ptr bundle; - sigc::connection configuration_will_change; - sigc::connection configuration_has_changed; - sigc::connection ports_will_change; - sigc::connection ports_have_changed; + PBD::ScopedConnection changed; }; - - std::vector _bundles_connected_to_outputs; ///< user bundles connected to our outputs - std::vector _bundles_connected_to_inputs; ///< user bundles connected to our inputs - static int parse_io_string (const string&, vector& chns); + std::vector _bundles_connected; ///< user bundles connected to our ports - static int parse_gain_string (const string&, vector& chns); - - int set_sources (vector&, void *src, bool add); - int set_destinations (vector&, void *src, bool add); + static int parse_io_string (const std::string&, std::vector& chns); + static int parse_gain_string (const std::string&, std::vector& chns); - int ensure_inputs (ChanCount, bool clear, bool lockit, void *src); - int ensure_outputs (ChanCount, bool clear, bool lockit, void *src); + int ensure_ports (ChanCount, bool clear, void *src); - void check_bundles_connected_to_inputs (); - void check_bundles_connected_to_outputs (); - void check_bundles (std::vector&, const PortSet&); + void check_bundles_connected (); - void bundle_configuration_will_change (); - void bundle_configuration_has_changed (); - void bundle_ports_will_change (int); - void bundle_ports_have_changed (int); + void bundle_changed (Bundle::Change); - int create_ports (const XMLNode&); - int make_connections (const XMLNode&); + int get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr& c); + int get_port_counts_2X (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr& c); + int create_ports (const XMLNode&, int version); + int make_connections (const XMLNode&, int, bool); + int make_connections_2X (const XMLNode &, int, bool); - void setup_peak_meters (); - void meter (); + boost::shared_ptr find_possible_bundle (const std::string &desired_name); - bool ensure_inputs_locked (ChanCount, bool clear, void *src); - bool ensure_outputs_locked (ChanCount, bool clear, void *src); + int ensure_ports_locked (ChanCount, bool clear, bool& changed); - std::string build_legal_port_name (DataType type, bool for_input); - int32_t find_input_port_hole (const char* base); - int32_t find_output_port_hole (const char* base); + std::string build_legal_port_name (DataType type); + int32_t find_port_hole (const char* base); - void create_bundles_for_inputs_and_outputs (); - void setup_bundles_for_inputs_and_outputs (); + void setup_bundle (); + std::string bundle_channel_name (uint32_t, uint32_t, DataType) const; - void maybe_add_input_bundle_to_list (boost::shared_ptr, std::vector >*); - void maybe_add_output_bundle_to_list (boost::shared_ptr, std::vector >*); + void apply_pretty_name (); + std::string _pretty_name_prefix; + BufferSet _buffers; + void disconnect_check (boost::shared_ptr, boost::shared_ptr); }; } // namespace ARDOUR