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