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 "selection_memento.h"
22 #include "public_editor.h"
26 SelectionMemento::SelectionMemento ()
30 SelectionMemento::~SelectionMemento ()
35 SelectionMemento::get_state () {
37 XMLNode* node = new XMLNode ("SelectionMemento");
39 PublicEditor& editor = PublicEditor::instance();
41 node->add_property ("mouse-mode", enum2str(editor.current_mouse_mode()));
42 snprintf (buf, sizeof(buf), "%" PRId64, editor.get_current_zoom());
43 node->add_property ("zoom", buf);
44 snprintf (buf, sizeof (buf), "%" PRIi64, editor.leftmost_sample());
45 node->add_property ("left-frame", buf);
46 snprintf (buf, sizeof (buf), "%f", editor.get_y_origin());
47 node->add_property ("y-origin", buf);
49 node->add_child_nocopy (editor.get_selection().get_state());
54 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
56 const XMLProperty* prop;
57 PublicEditor& editor = PublicEditor::instance();
58 if (node.name() != X_("SelectionMemento")) {
62 if ((prop = node.property ("mouse-mode"))) {
63 Editing::MouseMode m = Editing::str2mousemode(prop->value());
64 editor.set_mouse_mode (m, true);
67 if ((prop = node.property ("zoom"))) {
68 /* older versions of ardour used floating point samples_per_pixel */
69 double f = PBD::atof (prop->value());
70 editor.reset_zoom (llrintf (f));
73 if ((prop = node.property ("left-frame")) != 0) {
75 if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
79 editor.reset_x_origin (pos);
83 if ((prop = node.property ("y-origin")) != 0) {
84 editor.reset_y_origin (atof (prop->value ().c_str()));
87 XMLNodeList children = node.children ();
88 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
89 editor.get_selection().set_state (**i, Stateful::current_state_version);