Initial backend support for external export encoder
[ardour.git] / libs / ardour / element_importer.cc
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 #include "ardour/element_importer.h"
22
23 #include <sstream>
24 #include <iomanip>
25
26 #include "pbd/string_convert.h"
27 #include "ardour/session.h"
28
29 #include "pbd/i18n.h"
30
31 using namespace std;
32 using namespace PBD;
33 using namespace ARDOUR;
34
35 Signal2<std::pair<bool, string>,string, string> ElementImporter::Rename;
36 Signal1 <bool,string> ElementImporter::Prompt;
37
38 ElementImporter::ElementImporter (XMLTree const & source, ARDOUR::Session & session) :
39   source (source),
40   session(session),
41   _queued (false),
42   _broken (false)
43 {
44         source.root()->get_property ("sample-rate", sample_rate);
45 }
46
47 ElementImporter::~ElementImporter ()
48 {
49 }
50
51 void
52 ElementImporter::move ()
53 {
54         if (!_queued) { return; }
55         _move ();
56 }
57
58 bool
59 ElementImporter::prepare_move ()
60 {
61         if (_queued) {
62                 return true;
63         }
64         _queued = _prepare_move ();
65         return _queued;
66 }
67
68 void
69 ElementImporter::cancel_move ()
70 {
71         if (!_queued) { return; }
72         _cancel_move ();
73 }
74
75 string
76 ElementImporter::timecode_to_string(Timecode::Time & time) const
77 {
78         std::ostringstream oss;
79         oss << std::setfill('0') << std::right <<
80           std::setw(2) <<
81           time.hours << ":" <<
82           std::setw(2) <<
83           time.minutes << ":" <<
84           std::setw(2) <<
85           time.seconds << ":" <<
86           std::setw(2) <<
87           time.frames;
88
89         return oss.str();
90 }
91
92 samplecnt_t
93 ElementImporter::rate_convert_samples (samplecnt_t samples) const
94 {
95         if (sample_rate == session.sample_rate()) {
96                 return samples;
97         }
98
99         // +0.5 for proper rounding
100         return static_cast<samplecnt_t> (samples * (static_cast<double> (session.nominal_sample_rate()) / sample_rate) + 0.5);
101 }
102
103 string
104 ElementImporter::rate_convert_samples (string const & samples) const
105 {
106         return to_string (rate_convert_samples (string_to<uint32_t>(samples)));
107 }