ardour
element_importer.cc
Go to the documentation of this file.
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 
22 
23 #include <sstream>
24 #include <iomanip>
25 
26 #include "pbd/convert.h"
27 #include "ardour/session.h"
28 
29 #include "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  // Get samplerate
45  XMLProperty *prop;
46  prop = source.root()->property ("sample-rate");
47  if (prop) {
48  std::istringstream iss (prop->value());
49  iss >> sample_rate;
50  }
51 }
52 
54 {
55 }
56 
57 void
59 {
60  if (!_queued) { return; }
61  _move ();
62 }
63 
64 bool
66 {
67  if (_queued) {
68  return true;
69  }
71  return _queued;
72 }
73 
74 void
76 {
77  if (!_queued) { return; }
78  _cancel_move ();
79 }
80 
81 string
82 ElementImporter::timecode_to_string(Timecode::Time & time) const
83 {
84  std::ostringstream oss;
85  oss << std::setfill('0') << std::right <<
86  std::setw(2) <<
87  time.hours << ":" <<
88  std::setw(2) <<
89  time.minutes << ":" <<
90  std::setw(2) <<
91  time.seconds << ":" <<
92  std::setw(2) <<
93  time.frames;
94 
95  return oss.str();
96 }
97 
100 {
101  if (sample_rate == session.frame_rate()) {
102  return samples;
103  }
104 
105  // +0.5 for proper rounding
106  return static_cast<framecnt_t> (samples * (static_cast<double> (session.nominal_frame_rate()) / sample_rate) + 0.5);
107 }
108 
109 string
110 ElementImporter::rate_convert_samples (string const & samples) const
111 {
112  return to_string (rate_convert_samples (atoi (samples)), std::dec);
113 }
virtual bool _prepare_move()=0
framecnt_t sample_rate
The sample rate of the session from which we are importing.
framecnt_t nominal_frame_rate() const
Definition: session.h:367
std::string to_string(T t, std::ios_base &(*f)(std::ios_base &))
Definition: convert.h:53
int atoi(const string &s)
Definition: convert.cc:140
const std::string & value() const
Definition: xml++.h:159
Definition: Beats.hpp:239
virtual void _cancel_move()=0
Cancel move.
ARDOUR::Session & session
Target session.
framecnt_t rate_convert_samples(framecnt_t samples) const
Converts samples so that times match the sessions sample rate.
framecnt_t frame_rate() const
Definition: session.h:365
Definition: xml++.h:55
int64_t framecnt_t
Definition: types.h:76
XMLProperty * property(const char *)
Definition: xml++.cc:413
XMLNode * root() const
Definition: xml++.h:62
Definition: amp.h:29
void move()
Moves the element to the taget session.
virtual void _move()=0
Definition: debug.h:30
std::string timecode_to_string(Timecode::Time &time) const
Converts timecode time to a string.