X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fardour%2Fio.h;h=adad0c753fa1036f1a2e8474530e8b5a2e9d040b;hb=83e05ec0ec236f4dc327935377206966836027eb;hp=8ae45fe65c1b42fa28bf1ef931e955f512828f0f;hpb=7ff370e79895d7eb293e7214689b791bd98415fb;p=ardour.git diff --git a/libs/ardour/ardour/io.h b/libs/ardour/ardour/io.h index 8ae45fe65c..adad0c753f 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 @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __ardour_io_h__ @@ -24,388 +23,235 @@ #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/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 MidiPort; +class PeakMeter; class Port; -class Connection; -class Panner; - -class IO : public Stateful, public ARDOUR::StateManager +class Processor; +class Session; +class UserBundle; + +/** 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 SessionObject, public Latent { - public: - static const string state_node_name; + static const std::string state_node_name; - IO (Session&, string name, - int input_min = -1, int input_max = -1, - int output_min = -1, int output_max = -1); - - virtual ~IO(); - - int input_minimum() const { return _input_minimum; } - int input_maximum() const { return _input_maximum; } - int output_minimum() const { return _output_minimum; } - int output_maximum() const { return _output_maximum; } - - void set_input_minimum (int n); - void set_input_maximum (int n); - void set_output_minimum (int n); - void set_output_maximum (int n); + enum Direction { + Input, + Output + }; - const string& name() const { return _name; } - virtual int set_name (string str, void *src); - - virtual void silence (jack_nframes_t, jack_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); - void pan (vector& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff); - void pan_automated (vector& bufs, uint32_t nbufs, jack_nframes_t start_frame, jack_nframes_t end_frame, - jack_nframes_t nframes, jack_nframes_t offset); - void collect_input (vector&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset); - void deliver_output (vector&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset); - void deliver_output_no_pan (vector&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset); - void just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame, - jack_nframes_t nframes, jack_nframes_t offset); + virtual ~IO(); - virtual uint32_t n_process_buffers () { return 0; } + Direction direction() const { return _direction; } - virtual void set_gain (gain_t g, void *src); - void inc_gain (gain_t delta, void *src); - gain_t gain () const { return _desired_gain; } - virtual gain_t effective_gain () const; + DataType default_type() const { return _default_type; } + void set_default_type(DataType t) { _default_type = t; } - Panner& panner() { return *_panner; } + bool active() const { return _active; } + void set_active(bool yn) { _active = yn; } - int ensure_io (uint32_t, uint32_t, bool clear, void *src); + bool set_name (const std::string& str); - int use_input_connection (Connection&, void *src); - int use_output_connection (Connection&, void *src); + virtual void silence (framecnt_t); + void increment_port_buffer_offset (pframes_t offset); - Connection *input_connection() const { return _input_connection; } - Connection *output_connection() const { return _output_connection; } + int ensure_io (ChanCount cnt, bool clear, void *src); - int add_input_port (string source, void *src); - int add_output_port (string destination, void *src); + int connect_ports_to_bundle (boost::shared_ptr, bool exclusive, void *); + int disconnect_ports_from_bundle (boost::shared_ptr, void *); - int remove_input_port (Port *, void *src); - int remove_output_port (Port *, void *src); + BundleList bundles_connected (); - int set_input (Port *, void *src); + boost::shared_ptr bundle () { return _bundle; } - int connect_input (Port *our_port, string other_port, void *src); - int connect_output (Port *our_port, string other_port, void *src); + 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; - int disconnect_input (Port *our_port, string other_port, void *src); - int disconnect_output (Port *our_port, string other_port, void *src); + framecnt_t signal_latency () const { return 0; } + framecnt_t latency () const; - int disconnect_inputs (void *src); - int disconnect_outputs (void *src); + PortSet& ports() { return _ports; } + const PortSet& ports() const { return _ports; } - jack_nframes_t output_latency() const; - jack_nframes_t input_latency() const; - void set_port_latency (jack_nframes_t); + bool has_port (boost::shared_ptr) const; - Port *output (uint32_t n) const { - if (n < _noutputs) { - return _outputs[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 (); } } - Port *input (uint32_t n) const { - if (n < _ninputs) { - return _inputs[n]; - } else { - return 0; - } - } + boost::shared_ptr port_by_name (const std::string& str) const; - uint32_t n_inputs () const { return _ninputs; } - uint32_t n_outputs () const { return _noutputs; } + boost::shared_ptr audio(uint32_t n) const; + boost::shared_ptr midi(uint32_t n) const; - sigc::signal input_changed; - sigc::signal output_changed; + const ChanCount& n_ports () const { return _ports.count(); } - sigc::signal gain_changed; - sigc::signal name_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&); - - virtual UndoAction get_memento() const; - - - 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; - static sigc::signal MoreOutputs; - static sigc::signal PortsCreated; - - /* MIDI control */ - - void set_midi_to_gain_function (gain_t (*function)(double val)) { - _midi_gain_control.midi_to_gain = function; - } - - void set_gain_to_midi_function (double (*function)(gain_t gain)) { - _midi_gain_control.gain_to_midi = function; - } - - MIDI::Controllable& midi_gain_control() { - return _midi_gain_control; - } - - virtual void reset_midi_control (MIDI::Port*, bool on); - - virtual void send_all_midi_feedback (); - virtual MIDI::byte* write_midi_feedback (MIDI::byte*, int32_t& bufsize); - - /* Peak metering */ - - float peak_input_power (uint32_t n) { - if (n < std::max (_ninputs, _noutputs)) { - return _visible_peak_power[n]; - } else { - return minus_infinity(); + 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; } - } - - static void update_meters(); - -private: - - static sigc::signal Meter; - static Glib::StaticMutex m_meter_signal_lock; - sigc::connection m_meter_connection; - -public: - - /* automation */ - - void clear_automation (); - - bool gain_automation_recording() const { - return (_gain_automation_curve.automation_state() & (Write|Touch)); - } - - bool gain_automation_playback() const { - return (_gain_automation_curve.automation_state() & Play) || - ((_gain_automation_curve.automation_state() & Touch) && - !_gain_automation_curve.touching()); - } - - virtual void set_gain_automation_state (AutoState); - AutoState gain_automation_state() const { return _gain_automation_curve.automation_state(); } - sigc::signal gain_automation_state_changed; - - virtual void set_gain_automation_style (AutoStyle); - AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); } - sigc::signal gain_automation_style_changed; - - static void set_automation_interval (jack_nframes_t frames) { - _automation_interval = frames; - } - - static jack_nframes_t automation_interval() { - return _automation_interval; - } - - virtual void transport_stopped (jack_nframes_t now); - virtual void automation_snapshot (jack_nframes_t now); - - ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; } + }; - void start_gain_touch (); - void end_gain_touch (); + /** 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; - void start_pan_touch (uint32_t which); - void end_pan_touch (uint32_t which); + static int disable_connecting (); + static int enable_connecting (); - id_t id() const { return _id; } + 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. */ - XMLNode *pending_state_node; - int ports_became_legal (); - - private: - mutable Glib::Mutex io_lock; - - protected: - Session& _session; - Panner* _panner; - gain_t _gain; - gain_t _effective_gain; - gain_t _desired_gain; - Glib::Mutex declick_lock; - vector _outputs; - vector _inputs; - vector _peak_power; - vector _visible_peak_power; - string _name; - Connection* _input_connection; - Connection* _output_connection; - id_t _id; - bool no_panner_reset; - XMLNode* deferred_state; - - virtual void set_deferred_state() {} - - void reset_peak_meters(); - void reset_panner (); - - virtual uint32_t pans_required() const { return _ninputs; } - - static void apply_declick (vector&, uint32_t nbufs, jack_nframes_t nframes, - gain_t initial, gain_t target, bool invert_polarity); - - struct MIDIGainControl : public MIDI::Controllable { - MIDIGainControl (IO&, MIDI::Port *); - void set_value (float); - - void send_feedback (gain_t); - MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, gain_t val, bool force = false); - - IO& io; - bool setting; - MIDI::byte last_written; - - gain_t (*midi_to_gain) (double val); - double (*gain_to_midi) (gain_t gain); - }; - - MIDIGainControl _midi_gain_control; - - /* state management */ + static PBD::Signal0 ConnectingLegal; + static bool connecting_legal; - Change restore_state (State&); - StateManager::State* state_factory (std::string why) const; - - bool get_midi_node_info (XMLNode * node, MIDI::eventType & ev, MIDI::channel_t & chan, MIDI::byte & additional); - bool set_midi_node_info (XMLNode * node, MIDI::eventType ev, MIDI::channel_t chan, MIDI::byte additional); - - /* automation */ - - jack_nframes_t last_automation_snapshot; - static jack_nframes_t _automation_interval; + XMLNode *pending_state_node; + int pending_state_node_version; + bool pending_state_node_in; - AutoState _gain_automation_state; - AutoStyle _gain_automation_style; + /* three utility functions - this just seems to be simplest place to put them */ - bool apply_gain_automation; - Curve _gain_automation_curve; - - int save_automation (const string&); - int load_automation (const string&); - - Glib::Mutex automation_lock; + 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; + int set_ports (const std::string& str); private: + mutable Glib::Threads::Mutex io_lock; - uint32_t _ninputs; - uint32_t _noutputs; + protected: + PortSet _ports; + Direction _direction; + DataType _default_type; + bool _active; + bool _sendish; - /* are these the best variable names ever, or what? */ + private: + int connecting_became_legal (); + PBD::ScopedConnection connection_legal_c; - sigc::connection input_connection_configuration_connection; - sigc::connection output_connection_configuration_connection; - sigc::connection input_connection_connection_connection; - sigc::connection output_connection_connection_connection; + boost::shared_ptr _bundle; ///< a bundle representing our ports - static bool panners_legal; - - int connecting_became_legal (); - int panners_became_legal (); - sigc::connection connection_legal_c; - sigc::connection port_legal_c; - sigc::connection panner_legal_c; + struct UserBundleInfo { + UserBundleInfo (IO*, boost::shared_ptr b); + boost::shared_ptr bundle; + PBD::ScopedConnection changed; + }; - int _input_minimum; - int _input_maximum; - int _output_minimum; - int _output_maximum; + std::vector _bundles_connected; ///< user bundles connected to our ports + static int parse_io_string (const std::string&, std::vector& chns); + static int parse_gain_string (const std::string&, std::vector& chns); - static int parse_io_string (const string&, vector& chns); + int ensure_ports (ChanCount, bool clear, void *src); - 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); + void check_bundles_connected (); - int ensure_inputs (uint32_t, bool clear, bool lockit, void *src); - int ensure_outputs (uint32_t, bool clear, bool lockit, void *src); + void bundle_changed (Bundle::Change); - void drop_input_connection (); - void drop_output_connection (); + 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 input_connection_configuration_changed (); - void input_connection_connection_changed (int); - void output_connection_configuration_changed (); - void output_connection_connection_changed (int); + boost::shared_ptr find_possible_bundle (const std::string &desired_name); - int create_ports (const XMLNode&); - int make_connections (const XMLNode&); + int ensure_ports_locked (ChanCount, bool clear, bool& changed); - void setup_peak_meters (); - void meter (); + std::string build_legal_port_name (DataType type); + int32_t find_port_hole (const char* base); - bool ensure_inputs_locked (uint32_t, bool clear, void *src); - bool ensure_outputs_locked (uint32_t, bool clear, void *src); + void setup_bundle (); + std::string bundle_channel_name (uint32_t, uint32_t, DataType) const; - int32_t find_input_port_hole (); - int32_t find_output_port_hole (); + BufferSet _buffers; + void disconnect_check (boost::shared_ptr, boost::shared_ptr); }; -}; /* namespace ARDOUR */ +} // namespace ARDOUR #endif /*__ardour_io_h__ */