rework Stateful::set_state() patch to avoid default version argument
[ardour.git] / libs / ardour / tempo_map_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/tempo_map_importer.h"
22
23 #include <sstream>
24
25 #include "ardour/session.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/compose.h"
28 #include "pbd/error.h"
29
30 #include "i18n.h"
31
32 using namespace std;
33 using namespace PBD;
34 using namespace ARDOUR;
35
36 /**** Handler ***/
37 TempoMapImportHandler::TempoMapImportHandler (XMLTree const & source, Session & session) :
38   ElementImportHandler (source, session)
39 {
40         XMLNode const * root = source.root();
41         XMLNode const * tempo_map;
42
43         if (!(tempo_map = root->child (X_("TempoMap")))) {
44                 throw failed_constructor();
45         }
46
47         elements.push_back (ElementPtr ( new TempoMapImporter (source, session, *tempo_map)));
48 }
49
50 string
51 TempoMapImportHandler::get_info () const
52 {
53         return _("Tempo map");
54 }
55
56 /*** TempoMapImporter ***/
57 TempoMapImporter::TempoMapImporter (XMLTree const & source, Session & session, XMLNode const & node) :
58   ElementImporter (source, session),
59   xml_tempo_map (node)
60 {
61         name = _("Tempo Map");
62 }
63
64 string
65 TempoMapImporter::get_info () const
66 {
67         std::ostringstream oss;
68         unsigned int tempos = 0;
69         unsigned int meters = 0;
70         XMLNodeList children = xml_tempo_map.children();
71
72         for (XMLNodeIterator it = children.begin(); it != children.end(); it++) {
73                 if ((*it)->name() == "Tempo") {
74                         tempos++;
75                 } else if ((*it)->name() == "Meters") {
76                         meters++;
77                 }
78         }
79
80         // return info
81         oss << _("Tempo marks: ") << tempos << _("\nMeter marks: ") << meters;
82
83         return oss.str();
84 }
85
86 bool
87 TempoMapImporter::_prepare_move ()
88 {
89         // Prompt user for verification
90         bool replace = Prompt (_("This will replace the current tempo map!\nAre you shure you want to do this?"));
91         return replace;
92 }
93
94 void
95 TempoMapImporter::_cancel_move ()
96 {
97 }
98
99 void
100 TempoMapImporter::_move ()
101 {
102         session.tempo_map().set_state (xml_tempo_map, Stateful::current_state_version);
103 }