53fbda24c7fda7fd58277ecd2956db617a08149e
[ardour.git] / libs / ardour / io_processor.cc
1 /*
2     Copyright (C) 2001 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <fstream>
21 #include <algorithm>
22 #include <string>
23 #include <cerrno>
24 #include <unistd.h>
25 #include <sstream>
26
27 #include <sigc++/bind.h>
28
29 #include "pbd/xml++.h"
30 #include "pbd/enumwriter.h"
31
32 #include "ardour/io_processor.h"
33 #include "ardour/session.h"
34 #include "ardour/utils.h"
35 #include "ardour/send.h"
36 #include "ardour/port_insert.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/io.h"
39
40 #include "i18n.h"
41
42 using namespace std;
43 using namespace ARDOUR;
44 using namespace PBD;
45
46 IOProcessor::IOProcessor (Session& s, const string& proc_name, const string io_name, DataType dtype)
47         : Processor(s, proc_name)
48         , _io (new IO(s, io_name != "" ? io_name : proc_name, dtype))
49 {
50         _active = false;
51         _sort_key = 0;
52         _gui = 0;
53         _extra_xml = 0;
54 }
55
56 IOProcessor::IOProcessor (Session& s, IO* io, const string& proc_name, DataType dtype)
57         : Processor(s, proc_name)
58         , _io (io)
59 {
60         _active = false;
61         _sort_key = 0;
62         _gui = 0;
63         _extra_xml = 0;
64 }
65
66 IOProcessor::~IOProcessor ()
67 {
68         notify_callbacks ();
69 }
70
71 XMLNode&
72 IOProcessor::state (bool full_state)
73 {
74         XMLNode& node = Processor::state(full_state);
75         
76         node.add_child_nocopy (_io->state (full_state));
77
78         return node;
79 }
80
81 int
82 IOProcessor::set_state (const XMLNode& node)
83 {
84         const XMLProperty *prop;
85         const XMLNode *io_node = 0;
86
87         Processor::set_state(node);
88
89         XMLNodeList nlist = node.children();
90         XMLNodeIterator niter;
91
92         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
93                 if ((*niter)->name() == IO::state_node_name) {
94                         io_node = (*niter);
95                         break;
96                 } else if ((*niter)->name() == "Redirect") {
97                         XMLNodeList rlist = (*niter)->children();
98                         XMLNodeIterator riter;
99
100                         for (riter = rlist.begin(); riter != rlist.end(); ++riter) {
101                                 if ( (*riter)->name() == IO::state_node_name) {
102                                         warning << _("Found legacy IO in a redirect") << endmsg;
103                                         io_node = (*riter);
104                                         break;
105                                 }
106                         }
107                 }
108         }
109
110         if (io_node) {
111                 _io->set_state(*io_node);
112
113                 // legacy sessions: use IO name
114                 if ((prop = node.property ("name")) == 0) {
115                         set_name(_io->name());
116                 }
117
118         } else {
119                 error << _("XML node describing a redirect is missing an IO node") << endmsg;
120                 return -1;
121         }
122
123         return 0;
124 }
125
126 void
127 IOProcessor::silence (nframes_t nframes)
128 {
129         _io->silence (nframes);
130 }
131
132 ChanCount
133 IOProcessor::output_streams() const
134 {
135         return _io->n_outputs();
136 }
137
138 ChanCount
139 IOProcessor::input_streams () const
140 {
141         return _io->n_inputs();
142 }
143
144 ChanCount
145 IOProcessor::natural_output_streams() const
146 {
147         return _io->n_outputs();
148 }
149
150 ChanCount
151 IOProcessor::natural_input_streams () const
152 {
153         return _io->n_inputs();
154 }
155
156 void
157 IOProcessor::automation_snapshot (nframes_t now, bool force)
158 {
159         _io->automation_snapshot(now, force);
160 }
161