ardour
tempo_map_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 
25 #include "ardour/session.h"
26 #include "ardour/tempo.h"
27 #include "pbd/failed_constructor.h"
28 
29 #include "i18n.h"
30 
31 using namespace std;
32 using namespace PBD;
33 using namespace ARDOUR;
34 
35 /**** Handler ***/
36 TempoMapImportHandler::TempoMapImportHandler (XMLTree const & source, Session & session) :
37  ElementImportHandler (source, session)
38 {
39  XMLNode const * root = source.root();
40  XMLNode const * tempo_map;
41 
42  if (!(tempo_map = root->child (X_("TempoMap")))) {
43  throw failed_constructor();
44  }
45 
46  elements.push_back (ElementPtr ( new TempoMapImporter (source, session, *tempo_map)));
47 }
48 
49 string
51 {
52  return _("Tempo map");
53 }
54 
55 /*** TempoMapImporter ***/
56 TempoMapImporter::TempoMapImporter (XMLTree const & source, Session & session, XMLNode const & node) :
57  ElementImporter (source, session),
58  xml_tempo_map (node)
59 {
60  name = _("Tempo Map");
61 }
62 
63 string
65 {
66  std::ostringstream oss;
67  unsigned int tempos = 0;
68  unsigned int meters = 0;
69  XMLNodeList children = xml_tempo_map.children();
70 
71  for (XMLNodeIterator it = children.begin(); it != children.end(); it++) {
72  if ((*it)->name() == "Tempo") {
73  tempos++;
74  } else if ((*it)->name() == "Meters") {
75  meters++;
76  }
77  }
78 
79  // return info
80  oss << _("Tempo marks: ") << tempos << _("\nMeter marks: ") << meters;
81 
82  return oss.str();
83 }
84 
85 bool
87 {
88  // Prompt user for verification
89  boost::optional<bool> replace = Prompt (_("This will replace the current tempo map!\nAre you sure you want to do this?"));
90  return replace.get_value_or (false);
91 }
92 
93 void
95 {
96 }
97 
98 void
100 {
102 }
virtual std::string get_info() const
XMLNodeList::iterator XMLNodeIterator
Definition: xml++.h:48
std::string name
Name of element.
int set_state(const XMLNode &, int version)
Definition: tempo.cc:1675
TempoMap & tempo_map()
Definition: session.h:596
Definition: Beats.hpp:239
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
ARDOUR::Session & session
Target session.
Definition: xml++.h:55
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
#define _(Text)
Definition: i18n.h:11
Virtual interface class for element importers.
#define X_(Text)
Definition: i18n.h:13
static int current_state_version
Definition: stateful.h:89
XMLNode * root() const
Definition: xml++.h:62
Definition: amp.h:29
void _cancel_move()
Cancel move.
Virtual interface class for element import handlers.
ElementList elements
Elements this handler handles.
Definition: xml++.h:95
Definition: debug.h:30
XMLNode * child(const char *) const
Definition: xml++.cc:309
static PBD::Signal1< bool, std::string > Prompt
Signal for ok/cancel prompting.
TempoMapImporter(XMLTree const &source, Session &session, XMLNode const &node)