use new syntax for connecting to backend signals that enforces explicit connection...
[ardour.git] / libs / ardour / ardour / export_channel_configuration.h
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 #ifndef __ardour_export_channel_configuration_h__
22 #define __ardour_export_channel_configuration_h__
23
24 #include <list>
25
26 #include <glibmm/ustring.h>
27
28 #include "ardour/export_channel.h"
29 #include "ardour/export_status.h"
30 #include "ardour/ardour.h"
31
32 #include "pbd/xml++.h"
33
34 namespace ARDOUR
35 {
36
37 class ExportHandler;
38 class AudioPort;
39 class ExportChannel;
40 class ExportFormatSpecification;
41 class ExportFilename;
42 class ExportProcessor;
43 class ExportTimespan;
44 class Session;
45
46 class ExportChannelConfiguration
47 {
48   private:
49         typedef boost::shared_ptr<ExportProcessor> ProcessorPtr;
50         typedef boost::shared_ptr<ExportTimespan> TimespanPtr;
51         typedef boost::shared_ptr<ExportFormatSpecification const> FormatPtr;
52         typedef boost::shared_ptr<ExportFilename> FilenamePtr;
53
54         typedef std::pair<FormatPtr, FilenamePtr> FileConfig;
55         typedef std::list<FileConfig> FileConfigList;
56
57         /// Struct for threading, acts like a pointer to a ExportChannelConfiguration
58         struct WriterThread {
59                 WriterThread (ExportChannelConfiguration & channel_config) :
60                         channel_config (channel_config), running (false) {}
61
62                 ExportChannelConfiguration * operator-> () { return &channel_config; }
63                 ExportChannelConfiguration & operator* () { return channel_config; }
64
65                 ExportChannelConfiguration & channel_config;
66
67                 pthread_t thread;
68                 bool      running;
69         };
70
71   private:
72         friend class ExportElementFactory;
73         ExportChannelConfiguration (Session & session);
74
75   public:
76         XMLNode & get_state ();
77         int set_state (const XMLNode &);
78
79         typedef std::list<ExportChannelPtr> ChannelList;
80
81         ChannelList const & get_channels () const { return channels; }
82         bool all_channels_have_ports () const;
83
84         Glib::ustring name () const { return _name; }
85         void set_name (Glib::ustring name) { _name = name; }
86         void set_split (bool value) { split = value; }
87
88         bool get_split () const { return split; }
89         uint32_t get_n_chans () const { return channels.size(); }
90
91         void register_channel (ExportChannelPtr channel) { channels.push_back (channel); }
92         void register_file_config (FormatPtr format, FilenamePtr filename) { file_configs.push_back (FileConfig (format, filename)); }
93
94         void clear_channels () { channels.clear (); }
95
96         /// Writes all files for this channel config @return true if a new thread was spawned
97         bool write_files (boost::shared_ptr<ExportProcessor> new_processor);
98         PBD::Signal0<void> FilesWritten;
99
100         // Tells the handler the necessary information for it to handle tempfiles
101         void register_with_timespan (TimespanPtr timespan);
102
103         void unregister_all ();
104
105   private:
106
107         typedef boost::shared_ptr<ExportStatus> ExportStatusPtr;
108
109         Session & session;
110
111         // processor has to be prepared before doing this.
112         void write_file ();
113
114         /// The actual write files, needed for threading
115         static void *  _write_files (void *arg);
116         WriterThread    writer_thread;
117         ProcessorPtr    processor;
118         ExportStatusPtr status;
119
120         bool            files_written;
121
122         TimespanPtr     timespan;
123         ChannelList     channels;
124         FileConfigList  file_configs;
125
126         bool            split; // Split to mono files
127         Glib::ustring  _name;
128 };
129
130 } // namespace ARDOUR
131
132 #endif /* __ardour_export_channel_configuration_h__ */