9487d021b49273f2292e26b6466917ecbaa7b379
[ardour.git] / libs / ardour / export_channel_configuration.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "ardour/export_channel_configuration.h"
22
23 #include "ardour/export_handler.h"
24 #include "ardour/export_filename.h"
25 #include "ardour/export_timespan.h"
26
27 #include "ardour/audio_port.h"
28 #include "ardour/export_failed.h"
29 #include "ardour/midi_port.h"
30 #include "ardour/session.h"
31 #include "ardour/audioengine.h"
32
33 #include "pbd/convert.h"
34 #include "pbd/enumwriter.h"
35 #include "pbd/pthread_utils.h"
36
37 using namespace PBD;
38
39 namespace ARDOUR
40 {
41
42 /* ExportChannelConfiguration */
43
44 ExportChannelConfiguration::ExportChannelConfiguration (Session & session)
45   : session (session)
46   , split (false)
47   , region_type (RegionExportChannelFactory::None)
48 {
49
50 }
51
52 XMLNode &
53 ExportChannelConfiguration::get_state ()
54 {
55         XMLNode * root = new XMLNode ("ExportChannelConfiguration");
56         XMLNode * channel;
57
58         root->add_property ("split", get_split() ? "true" : "false");
59         root->add_property ("channels", to_string (get_n_chans(), std::dec));
60
61         switch (region_type) {
62         case RegionExportChannelFactory::None:
63                 // Do nothing
64                 break;
65         default:
66                 root->add_property ("region-processing", enum_2_string (region_type));
67                 break;
68         }
69
70         uint32_t i = 1;
71         for (ExportChannelConfiguration::ChannelList::const_iterator c_it = channels.begin(); c_it != channels.end(); ++c_it) {
72                 channel = root->add_child ("Channel");
73                 if (!channel) { continue; }
74
75                 channel->add_property ("number", to_string (i, std::dec));
76                 (*c_it)->get_state (channel);
77
78                 ++i;
79         }
80
81         return *root;
82 }
83
84 int
85 ExportChannelConfiguration::set_state (const XMLNode & root)
86 {
87         XMLProperty const * prop;
88
89         if ((prop = root.property ("split"))) {
90                 set_split (!prop->value().compare ("true"));
91         }
92
93         if ((prop = root.property ("region-processing"))) {
94                 set_region_processing_type ((RegionExportChannelFactory::Type)
95                         string_2_enum (prop->value(), RegionExportChannelFactory::Type));
96         }
97
98         XMLNodeList channels = root.children ("Channel");
99         for (XMLNodeList::iterator it = channels.begin(); it != channels.end(); ++it) {
100                 ExportChannelPtr channel (new PortExportChannel ());
101                 channel->set_state (*it, session);
102                 register_channel (channel);
103         }
104
105         return 0;
106 }
107
108 bool
109 ExportChannelConfiguration::all_channels_have_ports () const
110 {
111         for (ChannelList::const_iterator it = channels.begin(); it != channels.end(); ++it) {
112                 if ((*it)->empty ()) { return false; }
113         }
114
115         return true;
116 }
117
118 void
119 ExportChannelConfiguration::configurations_for_files (std::list<boost::shared_ptr<ExportChannelConfiguration> > & configs)
120 {
121         configs.clear ();
122
123         if (!split) {
124                 configs.push_back (shared_from_this ());
125                 return;
126         }
127
128         for (ChannelList::const_iterator it = channels.begin (); it != channels.end (); ++it) {
129                 boost::shared_ptr<ExportChannelConfiguration> config (new ExportChannelConfiguration (session));
130                 config->set_name (_name);
131                 config->register_channel (*it);
132                 configs.push_back (config);
133         }
134 }
135
136 } // namespace ARDOUR