Commit read-only stack security fix for 64bit processors.
[ardour.git] / libs / ardour / ardour / io.h
index 8ae45fe65c1b42fa28bf1ef931e955f512828f0f..e1ed7aef9501c9aff6a0310d60550f51f64b4e5d 100644 (file)
 
 #include <pbd/fastlog.h>
 #include <pbd/undo.h>
-
-#include <midi++/controllable.h>
+#include <pbd/statefuldestructible.h> 
+#include <pbd/controllable.h>
 
 #include <ardour/ardour.h>
-#include <ardour/stateful.h>
 #include <ardour/utils.h>
-#include <ardour/state_manager.h>
 #include <ardour/curve.h>
+#include <ardour/types.h>
+#include <ardour/data_type.h>
 
 using std::string;
 using std::vector;
@@ -53,7 +53,12 @@ class Port;
 class Connection;
 class Panner;
 
-class IO : public Stateful, public ARDOUR::StateManager
+/** A collection of input and output ports 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 PBD::StatefulDestructible
 {
 
   public:
@@ -61,9 +66,10 @@ class IO : public Stateful, public ARDOUR::StateManager
 
        IO (Session&, string name, 
            int input_min = -1, int input_max = -1, 
-           int output_min = -1, int output_max = -1);
+           int output_min = -1, int output_max = -1,
+               DataType default_type = DataType::AUDIO);
 
-       virtual ~IO();
+virtual ~IO();
 
        int input_minimum() const { return _input_minimum; }
        int input_maximum() const { return _input_maximum; }
@@ -75,25 +81,29 @@ class IO : public Stateful, public ARDOUR::StateManager
        void set_output_minimum (int n);
        void set_output_maximum (int n);
 
+       DataType default_type() const { return _default_type; }
+
        const string& name() const { return _name; }
        virtual int set_name (string str, void *src);
        
-       virtual void silence  (jack_nframes_t, jack_nframes_t offset);
+       virtual void silence  (nframes_t, nframes_t offset);
 
-       void pan (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff);
-       void pan_automated (vector<Sample*>& 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<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
-       void deliver_output (vector<Sample *>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
-       void deliver_output_no_pan (vector<Sample *>&, 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);
+       // These should be moved in to a separate object that manipulates an IO
+       
+       void pan (vector<Sample*>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
+       void pan_automated (vector<Sample*>& bufs, uint32_t nbufs, nframes_t start_frame, nframes_t end_frame, 
+                           nframes_t nframes, nframes_t offset);
+       void collect_input  (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
+       void deliver_output (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
+       void deliver_output_no_pan (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
+       void just_meter_input (nframes_t start_frame, nframes_t end_frame, 
+                              nframes_t nframes, nframes_t offset);
 
        virtual uint32_t n_process_buffers () { return 0; }
 
        virtual void   set_gain (gain_t g, void *src);
-       void   inc_gain (gain_t delta, void *src);
-       gain_t         gain () const                      { return _desired_gain; }
+       void           inc_gain (gain_t delta, void *src);
+       gain_t         gain () const { return _desired_gain; }
        virtual gain_t effective_gain () const;
 
        Panner& panner() { return *_panner; }
@@ -106,8 +116,8 @@ class IO : public Stateful, public ARDOUR::StateManager
        Connection *input_connection() const { return _input_connection; }
        Connection *output_connection() const { return _output_connection; }
 
-       int add_input_port (string source, void *src);
-       int add_output_port (string destination, void *src);
+       int add_input_port (string source, void *src, DataType type = DataType::NIL);
+       int add_output_port (string destination, void *src, DataType type = DataType::NIL);
 
        int remove_input_port (Port *, void *src);
        int remove_output_port (Port *, void *src);
@@ -123,9 +133,9 @@ class IO : public Stateful, public ARDOUR::StateManager
        int disconnect_inputs (void *src);
        int disconnect_outputs (void *src);
 
-       jack_nframes_t output_latency() const;
-       jack_nframes_t input_latency() const;
-       void           set_port_latency (jack_nframes_t);
+       nframes_t output_latency() const;
+       nframes_t input_latency() const;
+       void           set_port_latency (nframes_t);
 
        Port *output (uint32_t n) const {
                if (n < _noutputs) {
@@ -156,19 +166,11 @@ class IO : public Stateful, public ARDOUR::StateManager
        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<int> PortsLegal;
@@ -177,25 +179,10 @@ class IO : public Stateful, public ARDOUR::StateManager
        static sigc::signal<void,uint32_t> MoreOutputs;
        static sigc::signal<int> 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;
+       PBD::Controllable& gain_control() {
+               return _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) { 
@@ -238,16 +225,7 @@ public:
        AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); }
        sigc::signal<void> 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);
+       virtual void transport_stopped (nframes_t now);
 
        ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; }
 
@@ -257,8 +235,6 @@ public:
        void start_pan_touch (uint32_t which);
        void end_pan_touch (uint32_t which);
 
-       id_t id() const { return _id; }
-
        void defer_pan_reset ();
        void allow_pan_reset ();
 
@@ -286,9 +262,11 @@ public:
        string              _name;
        Connection*         _input_connection;
        Connection*         _output_connection;
-       id_t                _id;
        bool                 no_panner_reset;
        XMLNode*             deferred_state;
+       DataType            _default_type;
+       bool                _ignore_gain_on_deliver;
+       
 
        virtual void set_deferred_state() {}
 
@@ -297,40 +275,21 @@ public:
 
        virtual uint32_t pans_required() const { return _ninputs; }
 
-       static void apply_declick (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, 
+       static void apply_declick (vector<Sample*>&, uint32_t nbufs, 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);
-
+       struct GainControllable : public PBD::Controllable {
+           GainControllable (std::string name, IO& i) : Controllable (name), io (i) {}
+        
+           void set_value (float val);
+           float get_value (void) const;
+   
            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 */
-
-       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;
+       GainControllable _gain_control;
 
-    AutoState      _gain_automation_state;
+       AutoState      _gain_automation_state;
        AutoStyle      _gain_automation_style;
 
        bool     apply_gain_automation;
@@ -406,6 +365,6 @@ public:
        int32_t find_output_port_hole ();
 };
 
-}; /* namespace ARDOUR */
+} // namespace ARDOUR
 
 #endif /*__ardour_io_h__ */