enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / selection_memento.cc
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "ardour/lmath.h"
21 #include "selection_memento.h"
22 #include "editing.h"
23 #include "public_editor.h"
24
25 #include "pbd/i18n.h"
26
27 SelectionMemento::SelectionMemento ()
28 {
29 }
30
31 SelectionMemento::~SelectionMemento ()
32 {
33 }
34
35 XMLNode&
36 SelectionMemento::get_state () {
37
38         XMLNode* node = new XMLNode ("SelectionMemento");
39         char buf[32];
40         PublicEditor& editor = PublicEditor::instance();
41
42         node->add_property ("mouse-mode", enum2str(editor.current_mouse_mode()));
43         snprintf (buf, sizeof(buf), "%" PRId64, editor.get_current_zoom());
44         node->add_property ("zoom", buf);
45         snprintf (buf, sizeof (buf), "%" PRIi64, editor.leftmost_sample());
46         node->add_property ("left-frame", buf);
47         snprintf (buf, sizeof (buf), "%f", editor.get_y_origin());
48         node->add_property ("y-origin", buf);
49
50         node->add_child_nocopy (editor.get_selection().get_state());
51         return *node;
52 }
53
54 int
55 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
56
57         XMLProperty const * prop;
58         PublicEditor& editor = PublicEditor::instance();
59         if (node.name() != X_("SelectionMemento")) {
60                 return -1;
61         }
62
63         if ((prop = node.property ("mouse-mode"))) {
64                 Editing::MouseMode m = Editing::str2mousemode(prop->value());
65                 editor.set_mouse_mode (m, true);
66         }
67
68         if ((prop = node.property ("zoom"))) {
69                 /* older versions of ardour used floating point samples_per_pixel */
70                 double f = PBD::atof (prop->value());
71                 editor.reset_zoom (llrintf (f));
72         }
73
74         if ((prop = node.property ("left-frame")) != 0) {
75                 framepos_t pos;
76                 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
77                         if (pos < 0) {
78                                 pos = 0;
79                         }
80                         editor.reset_x_origin (pos);
81                 }
82         }
83
84         if ((prop = node.property ("y-origin")) != 0) {
85                 editor.reset_y_origin (atof (prop->value ().c_str()));
86         }
87
88         XMLNodeList children = node.children ();
89         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
90                 editor.get_selection().set_state (**i, Stateful::current_state_version);
91         }
92
93         return 0;
94 }