2 Copyright (C) 2014 Paul Davis
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.
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.
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.
20 #include "ardour/lmath.h"
21 #include "selection_memento.h"
23 #include "public_editor.h"
27 SelectionMemento::SelectionMemento ()
31 SelectionMemento::~SelectionMemento ()
36 SelectionMemento::get_state () {
38 XMLNode* node = new XMLNode ("SelectionMemento");
40 PublicEditor& editor = PublicEditor::instance();
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);
50 node->add_child_nocopy (editor.get_selection().get_state());
55 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
57 const XMLProperty* prop;
58 PublicEditor& editor = PublicEditor::instance();
59 if (node.name() != X_("SelectionMemento")) {
63 if ((prop = node.property ("mouse-mode"))) {
64 Editing::MouseMode m = Editing::str2mousemode(prop->value());
65 editor.set_mouse_mode (m, true);
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));
74 if ((prop = node.property ("left-frame")) != 0) {
76 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
80 editor.reset_x_origin (pos);
84 if ((prop = node.property ("y-origin")) != 0) {
85 editor.reset_y_origin (atof (prop->value ().c_str()));
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);