Only show user-presets in favorite sidebar
[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 "ardour/tempo.h"
27 #include "pbd/failed_constructor.h"
28
29 #include "pbd/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
50 TempoMapImportHandler::get_info () const
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
64 TempoMapImporter::get_info () const
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
86 TempoMapImporter::_prepare_move ()
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
94 TempoMapImporter::_cancel_move ()
95 {
96 }
97
98 void
99 TempoMapImporter::_move ()
100 {
101         session.tempo_map().set_state (xml_tempo_map, Stateful::current_state_version);
102 }