summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/export_channel_configuration.h
blob: b8d7fa6bf178358e3d12fff974ef5877c27240b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    Copyright (C) 2008 Paul Davis
    Author: Sakari Bergen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __ardour_export_channel_configuration_h__
#define __ardour_export_channel_configuration_h__

#include <list>

#include <glibmm/ustring.h>

#include "ardour/export_channel.h"
#include "ardour/export_status.h"
#include "ardour/ardour.h"

#include "pbd/xml++.h"

namespace ARDOUR
{

class ExportHandler;
class AudioPort;
class ExportChannel;
class ExportFormatSpecification;
class ExportFilename;
class ExportProcessor;
class ExportTimespan;
class Session;

class ExportChannelConfiguration
{
  private:
	typedef boost::shared_ptr<ExportProcessor> ProcessorPtr;
	typedef boost::shared_ptr<ExportTimespan> TimespanPtr;
	typedef boost::shared_ptr<ExportFormatSpecification const> FormatPtr;
	typedef boost::shared_ptr<ExportFilename> FilenamePtr;

	typedef std::pair<FormatPtr, FilenamePtr> FileConfig;
	typedef std::list<FileConfig> FileConfigList;

	/// Struct for threading, acts like a pointer to a ExportChannelConfiguration
	struct WriterThread {
		WriterThread (ExportChannelConfiguration & channel_config) :
			channel_config (channel_config), running (false) {}

		ExportChannelConfiguration * operator-> () { return &channel_config; }
		ExportChannelConfiguration & operator* () { return channel_config; }

		ExportChannelConfiguration & channel_config;

		pthread_t thread;
		bool      running;
	};

  private:
	friend class ExportElementFactory;
	ExportChannelConfiguration (Session & session);

  public:
	XMLNode & get_state ();
	int set_state (const XMLNode &);

	typedef std::list<ExportChannelPtr> ChannelList;

	ChannelList const & get_channels () const { return channels; }
	bool all_channels_have_ports () const;

	Glib::ustring name () const { return _name; }
	void set_name (Glib::ustring name) { _name = name; }
	void set_split (bool value) { split = value; }

	bool get_split () const { return split; }
	uint32_t get_n_chans () const { return channels.size(); }

	void register_channel (ExportChannelPtr channel) { channels.push_back (channel); }
	void register_file_config (FormatPtr format, FilenamePtr filename) { file_configs.push_back (FileConfig (format, filename)); }

	void clear_channels () { channels.clear (); }

	/// Writes all files for this channel config @return true if a new thread was spawned
	bool write_files (boost::shared_ptr<ExportProcessor> new_processor);
	boost::signals2::signal<void()> FilesWritten;

	// Tells the handler the necessary information for it to handle tempfiles
	void register_with_timespan (TimespanPtr timespan);

	void unregister_all ();

  private:

	typedef boost::shared_ptr<ExportStatus> ExportStatusPtr;

	Session & session;

	// processor has to be prepared before doing this.
	void write_file ();

	/// The actual write files, needed for threading
	static void *  _write_files (void *arg);
	WriterThread    writer_thread;
	ProcessorPtr    processor;
	ExportStatusPtr status;

	bool            files_written;

	TimespanPtr     timespan;
	ChannelList     channels;
	FileConfigList  file_configs;

	bool            split; // Split to mono files
	Glib::ustring  _name;
};

} // namespace ARDOUR

#endif /* __ardour_export_channel_configuration_h__ */