Ardour  8.12
export_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2013 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6  * Copyright (C) 2013-2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
7  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __ardour_export_handler_h__
25 #define __ardour_export_handler_h__
26 
27 #include <map>
28 #include <memory>
29 
30 #include <boost/operators.hpp>
31 
32 #include "pbd/gstdio_compat.h"
33 #include "pbd/pthread_utils.h"
34 
35 #include "ardour/export_pointers.h"
36 #include "ardour/session.h"
38 #include "ardour/types.h"
39 #include "pbd/signals.h"
40 
41 namespace AudioGrapher {
42  class BroadcastInfo;
43 }
44 
45 namespace ARDOUR
46 {
47 
48 class ExportTimespan;
49 class ExportChannelConfiguration;
50 class ExportFormatSpecification;
51 class ExportFilename;
52 class ExportGraphBuilder;
53 class Location;
54 
56 {
57  public:
58 
61 
63 
65 
69 
72 
73  private:
75 };
76 
78 class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::trackable
79 {
80  public:
81  struct FileSpec {
82  FileSpec() {}
84  ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
85  : channel_config (channel_config)
86  , format (format)
87  , filename (filename)
88  , broadcast_info (broadcast_info)
89  {}
90 
95  };
96 
97  private:
98  /* Session::get_export_handler() should be used to obtain an export handler
99  * This ensures that it doesn't go out of scope before finalize_audio_export is called
100  */
101 
102  friend std::shared_ptr<ExportHandler> Session::get_export_handler();
104 
105  void command_output(std::string output, size_t size);
106 
107  public:
109 
111  ExportFormatSpecPtr format, ExportFilenamePtr filename,
112  BroadcastInfoPtr broadcast_info);
113  int do_export ();
114 
115  std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
116 
120  PBD::Signal3<void, double, double, std::string> SoundcloudProgress;
121 
122  /* upload credentials & preferences */
123  std::string soundcloud_username;
124  std::string soundcloud_password;
128 
129  void reset ();
130 
131  private:
132 
134  int process (samplecnt_t samples);
135 
137  std::shared_ptr<ExportGraphBuilder> graph_builder;
139 
140  /* The timespan and corresponding file specifications that we are exporting;
141  there can be multiple FileSpecs for each ExportTimespan.
142  */
143  typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
145 
147 
148  /* Timespan management */
149 
151 
152  static void* _timespan_thread_run (void*);
154  std::atomic<int> _timespan_thread_active;
155  pthread_mutex_t _timespan_mutex;
156  pthread_cond_t _timespan_cond;
157 
160  int post_process ();
162 
163  typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
166 
169 
170  /* CD Marker stuff */
171 
172  struct CDMarkerStatus {
173  CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
174  ExportFormatSpecPtr format, std::string filename)
175  : path (out_file)
176  , timespan (timespan)
177  , format (format)
178  , filename (filename)
179  , marker(0)
180  , track_number (1)
181  , track_position (0)
182  , track_duration (0)
183  , track_start_sample (0)
184  , index_number (1)
185  , index_position (0)
186  {}
187 
189 
190  /* I/O */
191  std::string path;
192  std::stringstream out;
193 
194  /* General info */
197  std::string filename;
199 
200  /* Track info */
201  uint32_t track_number;
205 
206  /* Index info */
207  uint32_t index_number;
209  };
210 
211 
213  std::string filename, CDMarkerFormat format);
214 
218 
222 
226 
227  void samples_to_cd_frame_string (char* buf, samplepos_t when);
229 
230  std::string toc_escape_cdtext (const std::string&);
231  std::string toc_escape_filename (const std::string&);
232  std::string cue_escape_cdtext (const std::string& txt);
233 
236 };
237 
238 } // namespace ARDOUR
239 
240 #endif /* __ardour_export_handler_h__ */
ExportElementFactory(Session &session)
ExportFormatSpecPtr add_format(XMLNode const &state)
ExportFormatSpecPtr add_format_copy(ExportFormatSpecPtr other)
ExportFormatSpecPtr add_format()
ExportChannelConfigPtr add_channel_config()
ExportFilenamePtr add_filename_copy(ExportFilenamePtr other)
ExportTimespanPtr add_timespan()
ExportFilenamePtr add_filename()
ExportHandler(Session &session)
PBD::Signal3< void, double, double, std::string > SoundcloudProgress
int process_timespan(samplecnt_t samples)
void write_track_info_toc(CDMarkerStatus &status)
PBD::ScopedConnection process_connection
void write_cue_header(CDMarkerStatus &status)
bool add_export_config(ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format, ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
void export_cd_marker_file(ExportTimespanPtr timespan, ExportFormatSpecPtr file_format, std::string filename, CDMarkerFormat format)
void handle_duplicate_format_extensions()
void write_track_info_mp4ch(CDMarkerStatus &status)
std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format)
pthread_mutex_t _timespan_mutex
std::string toc_escape_filename(const std::string &)
void write_track_info_cue(CDMarkerStatus &status)
void write_index_info_mp4ch(CDMarkerStatus &status)
void write_toc_header(CDMarkerStatus &status)
void samples_to_chapter_marks_string(char *buf, samplepos_t when)
std::atomic< int > _timespan_thread_active
PBD::Thread * _timespan_thread
void write_mp4ch_header(CDMarkerStatus &status)
int process(samplecnt_t samples)
void command_output(std::string output, size_t size)
void write_index_info_cue(CDMarkerStatus &status)
std::string soundcloud_username
ExportTimespanPtr current_timespan
void write_index_info_toc(CDMarkerStatus &status)
void samples_to_cd_frame_string(char *buf, samplepos_t when)
std::string toc_escape_cdtext(const std::string &)
static void * _timespan_thread_run(void *)
std::string cue_escape_cdtext(const std::string &txt)
std::multimap< ExportTimespanPtr, FileSpec > ConfigMap
std::shared_ptr< ExportGraphBuilder > graph_builder
ExportStatusPtr export_status
pthread_cond_t _timespan_cond
std::string soundcloud_password
samplepos_t process_position
std::pair< ConfigMap::iterator, ConfigMap::iterator > TimespanBounds
TimespanBounds timespan_bounds
std::shared_ptr< ExportHandler > get_export_handler()
Definition: xml++.h:114
#define LIBARDOUR_API
void session(lua_State *L)
std::shared_ptr< ExportFilename > ExportFilenamePtr
std::shared_ptr< ExportChannelConfiguration > ExportChannelConfigPtr
std::shared_ptr< AudioGrapher::BroadcastInfo > BroadcastInfoPtr
std::shared_ptr< ExportStatus > ExportStatusPtr
Temporal::samplecnt_t samplecnt_t
std::shared_ptr< ExportFormatSpecification > ExportFormatSpecPtr
Temporal::samplepos_t samplepos_t
CDMarkerStatus(std::string out_file, ExportTimespanPtr timespan, ExportFormatSpecPtr format, std::string filename)
ExportChannelConfigPtr channel_config
FileSpec(ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format, ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)