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");
39 PublicEditor& editor = PublicEditor::instance();
41 node->set_property ("mouse-mode", enum2str(editor.current_mouse_mode()));
42 node->set_property ("zoom", editor.get_current_zoom());
43 node->set_property ("left-frame", editor.leftmost_sample());
44 node->set_property ("y-origin", editor.get_y_origin());
46 node->add_child_nocopy (editor.get_selection().get_state());
51 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
53 PublicEditor& editor = PublicEditor::instance();
54 if (node.name() != X_("SelectionMemento")) {
59 if (node.get_property ("mouse-mode", str)) {
60 Editing::MouseMode m = Editing::str2mousemode (str);
61 editor.set_mouse_mode (m, true);
65 if (node.get_property ("zoom", zoom)) {
66 /* older versions of ardour used floating point samples_per_pixel */
67 editor.reset_zoom (llrintf (zoom));
71 if (node.get_property ("left-frame", pos)) {
75 editor.reset_x_origin (pos);
79 if (node.get_property ("y-origin", y_origin)) {
80 editor.reset_y_origin (y_origin);
83 XMLNodeList children = node.children ();
84 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
85 editor.get_selection().set_state (**i, Stateful::current_state_version);