2 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "ardour/lmath.h"
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");
38 PublicEditor& editor = PublicEditor::instance();
40 node->set_property ("mouse-mode", enum2str(editor.current_mouse_mode()));
41 node->set_property ("zoom", editor.get_current_zoom());
42 node->set_property ("left-frame", editor.leftmost_sample());
43 node->set_property ("y-origin", editor.get_y_origin());
45 node->add_child_nocopy (editor.get_selection().get_state());
50 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
52 PublicEditor& editor = PublicEditor::instance();
53 if (node.name() != X_("SelectionMemento")) {
58 if (node.get_property ("mouse-mode", str)) {
59 Editing::MouseMode m = Editing::str2mousemode (str);
60 editor.set_mouse_mode (m, true);
64 if (node.get_property ("zoom", zoom)) {
65 /* older versions of ardour used floating point samples_per_pixel */
66 editor.reset_zoom (llrintf (zoom));
70 if (node.get_property ("left-frame", pos)) {
74 editor.reset_x_origin (pos);
78 if (node.get_property ("y-origin", y_origin)) {
79 editor.reset_y_origin (y_origin);
82 XMLNodeList children = node.children ();
83 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
84 editor.get_selection().set_state (**i, Stateful::current_state_version);