Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[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
39 #include "i18n.h"
40
41 using namespace std;
42 using namespace ARDOUR;
43 using namespace PBD;
44
45 IOProcessor::IOProcessor (Session& s, const string& name, Placement p,
46                     int input_min, int input_max,
47                     int output_min, int output_max)
48         : Processor(s, name, p)
49         , _io(new IO(s, name, input_min, input_max, output_min, output_max))
50 {
51         _active = false;
52         _sort_key = 0;
53         _gui = 0;
54         _extra_xml = 0;
55 }
56
57 IOProcessor::~IOProcessor ()
58 {
59         notify_callbacks ();
60 }
61
62 XMLNode&
63 IOProcessor::state (bool full_state)
64 {
65         XMLNode& node = Processor::state(full_state);
66         
67         node.add_child_nocopy (_io->state (full_state));
68
69         return node;
70 }
71
72 int
73 IOProcessor::set_state (const XMLNode& node)
74 {
75         const XMLProperty *prop;
76         const XMLNode *io_node = 0;
77
78         Processor::set_state(node);
79
80         XMLNodeList nlist = node.children();
81         XMLNodeIterator niter;
82
83         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
84                 if ((*niter)->name() == IO::state_node_name) {
85                         io_node = (*niter);
86                         break;
87                 } else if ((*niter)->name() == "Redirect") {
88                         XMLNodeList rlist = (*niter)->children();
89                         XMLNodeIterator riter;
90
91                         for (riter = rlist.begin(); riter != rlist.end(); ++riter) {
92                                 if ( (*riter)->name() == IO::state_node_name) {
93                                         warning << _("Found legacy IO in a redirect") << endmsg;
94                                         io_node = (*riter);
95                                         break;
96                                 }
97                         }
98                 }
99         }
100
101         if (io_node) {
102                 _io->set_state(*io_node);
103
104                 // legacy sessions: use IO name
105                 if ((prop = node.property ("name")) == 0) {
106                         set_name(_io->name());
107                 }
108
109         } else {
110                 error << _("XML node describing a redirect is missing an IO node") << endmsg;
111                 return -1;
112         }
113
114         return 0;
115 }
116
117 void
118 IOProcessor::silence (nframes_t nframes, nframes_t offset)
119 {
120         _io->silence(nframes, offset);
121 }