add new debug bit for backend callbacks
[ardour.git] / libs / ardour / element_importer.cc
1 /*
2  * Copyright (C) 2008 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2009 David Robillard <d@drobilla.net>
6  * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "ardour/element_importer.h"
24
25 #include <sstream>
26 #include <iomanip>
27
28 #include "pbd/string_convert.h"
29 #include "ardour/session.h"
30
31 #include "pbd/i18n.h"
32
33 using namespace std;
34 using namespace PBD;
35 using namespace ARDOUR;
36
37 Signal2<std::pair<bool, string>,string, string> ElementImporter::Rename;
38 Signal1 <bool,string> ElementImporter::Prompt;
39
40 ElementImporter::ElementImporter (XMLTree const & source, ARDOUR::Session & session) :
41   source (source),
42   session(session),
43   _queued (false),
44   _broken (false)
45 {
46         source.root()->get_property ("sample-rate", sample_rate);
47 }
48
49 ElementImporter::~ElementImporter ()
50 {
51 }
52
53 void
54 ElementImporter::move ()
55 {
56         if (!_queued) { return; }
57         _move ();
58 }
59
60 bool
61 ElementImporter::prepare_move ()
62 {
63         if (_queued) {
64                 return true;
65         }
66         _queued = _prepare_move ();
67         return _queued;
68 }
69
70 void
71 ElementImporter::cancel_move ()
72 {
73         if (!_queued) { return; }
74         _cancel_move ();
75 }
76
77 string
78 ElementImporter::timecode_to_string(Timecode::Time & time) const
79 {
80         std::ostringstream oss;
81         oss << std::setfill('0') << std::right <<
82           std::setw(2) <<
83           time.hours << ":" <<
84           std::setw(2) <<
85           time.minutes << ":" <<
86           std::setw(2) <<
87           time.seconds << ":" <<
88           std::setw(2) <<
89           time.frames;
90
91         return oss.str();
92 }
93
94 samplecnt_t
95 ElementImporter::rate_convert_samples (samplecnt_t samples) const
96 {
97         if (sample_rate == session.sample_rate()) {
98                 return samples;
99         }
100
101         // +0.5 for proper rounding
102         return static_cast<samplecnt_t> (samples * (static_cast<double> (session.nominal_sample_rate()) / sample_rate) + 0.5);
103 }
104
105 string
106 ElementImporter::rate_convert_samples (string const & samples) const
107 {
108         return to_string (rate_convert_samples (string_to<uint32_t>(samples)));
109 }