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>
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.
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.
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.
23 #include "ardour/element_importer.h"
28 #include "pbd/string_convert.h"
29 #include "ardour/session.h"
35 using namespace ARDOUR;
37 Signal2<std::pair<bool, string>,string, string> ElementImporter::Rename;
38 Signal1 <bool,string> ElementImporter::Prompt;
40 ElementImporter::ElementImporter (XMLTree const & source, ARDOUR::Session & session) :
46 source.root()->get_property ("sample-rate", sample_rate);
49 ElementImporter::~ElementImporter ()
54 ElementImporter::move ()
56 if (!_queued) { return; }
61 ElementImporter::prepare_move ()
66 _queued = _prepare_move ();
71 ElementImporter::cancel_move ()
73 if (!_queued) { return; }
78 ElementImporter::timecode_to_string(Timecode::Time & time) const
80 std::ostringstream oss;
81 oss << std::setfill('0') << std::right <<
85 time.minutes << ":" <<
87 time.seconds << ":" <<
95 ElementImporter::rate_convert_samples (samplecnt_t samples) const
97 if (sample_rate == session.sample_rate()) {
101 // +0.5 for proper rounding
102 return static_cast<samplecnt_t> (samples * (static_cast<double> (session.nominal_sample_rate()) / sample_rate) + 0.5);
106 ElementImporter::rate_convert_samples (string const & samples) const
108 return to_string (rate_convert_samples (string_to<uint32_t>(samples)));