Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
25 
26 #include <map>
27 #include <memory>
28 
29 #include <boost/operators.hpp>
30 
31 #include "pbd/gstdio_compat.h"
32 #include "pbd/pthread_utils.h"
33 
34 #include "ardour/export_pointers.h"
35 #include "ardour/session.h"
37 #include "ardour/types.h"
38 #include "pbd/signals.h"
39 
40 namespace AudioGrapher {
41  class BroadcastInfo;
42 }
43 
44 namespace ARDOUR
45 {
46 
47 class ExportTimespan;
48 class ExportChannelConfiguration;
49 class ExportFormatSpecification;
50 class ExportFilename;
51 class ExportGraphBuilder;
52 class Location;
53 
55 {
56  public:
57 
60 
62 
64 
68 
71 
72  private:
74 };
75 
77 class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::trackable
78 {
79  public:
80  struct FileSpec {
81  FileSpec() {}
83  ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
84  : channel_config (channel_config)
85  , format (format)
86  , filename (filename)
87  , broadcast_info (broadcast_info)
88  {}
89 
94  };
95 
96  private:
97  /* Session::get_export_handler() should be used to obtain an export handler
98  * This ensures that it doesn't go out of scope before finalize_audio_export is called
99  */
100 
101  friend std::shared_ptr<ExportHandler> Session::get_export_handler();
103 
104  void command_output(std::string output, size_t size);
105 
106  public:
108 
110  ExportFormatSpecPtr format, ExportFilenamePtr filename,
111  BroadcastInfoPtr broadcast_info);
112  int do_export ();
113 
114  std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
115 
119  PBD::Signal<void(double, double, std::string)> SoundcloudProgress;
120 
121  /* upload credentials & preferences */
122  std::string soundcloud_username;
123  std::string soundcloud_password;
127 
128  void reset ();
129 
130  private:
131 
133  int process (samplecnt_t samples);
134 
136  std::shared_ptr<ExportGraphBuilder> graph_builder;
138 
139  /* The timespan and corresponding file specifications that we are exporting;
140  there can be multiple FileSpecs for each ExportTimespan.
141  */
142  typedef std::multimap<ExportTimespanPtr, FileSpec> ConfigMap;
144 
146 
147  /* Timespan management */
148 
150 
151  static void* _timespan_thread_run (void*);
153  std::atomic<int> _timespan_thread_active;
154  pthread_mutex_t _timespan_mutex;
155  pthread_cond_t _timespan_cond;
156 
159  int post_process ();
161 
162  typedef std::pair<ConfigMap::iterator, ConfigMap::iterator> TimespanBounds;
165 
168 
169  /* CD Marker stuff */
170 
171  struct CDMarkerStatus {
172  CDMarkerStatus (std::string out_file, ExportTimespanPtr timespan,
173  ExportFormatSpecPtr format, std::string filename)
174  : path (out_file)
175  , timespan (timespan)
176  , format (format)
177  , filename (filename)
178  , marker(0)
179  , track_number (1)
180  , track_position (0)
181  , track_duration (0)
182  , track_start_sample (0)
183  , index_number (1)
184  , index_position (0)
185  {}
186 
188 
189  /* I/O */
190  std::string path;
191  std::stringstream out;
192 
193  /* General info */
196  std::string filename;
198 
199  /* Track info */
200  uint32_t track_number;
204 
205  /* Index info */
206  uint32_t index_number;
208  };
209 
210 
212  std::string filename, CDMarkerFormat format);
213 
217 
221 
225 
226  void samples_to_cd_frame_string (char* buf, samplepos_t when);
228 
229  std::string toc_escape_cdtext (const std::string&);
230  std::string toc_escape_filename (const std::string&);
231  std::string cue_escape_cdtext (const std::string& txt);
232 
235 };
236 
237 } // namespace ARDOUR
238 
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)
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
PBD::Signal< void(double, double, std::string)> SoundcloudProgress
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)