Update comments & icon of rubberband example Lua script
[ardour.git] / gtk2_ardour / selection_memento.cc
1 /*
2  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
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 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.
17  */
18
19 #include "ardour/lmath.h"
20 #include "selection_memento.h"
21 #include "editing.h"
22 #include "public_editor.h"
23
24 #include "pbd/i18n.h"
25
26 SelectionMemento::SelectionMemento ()
27 {
28 }
29
30 SelectionMemento::~SelectionMemento ()
31 {
32 }
33
34 XMLNode&
35 SelectionMemento::get_state () {
36
37         XMLNode* node = new XMLNode ("SelectionMemento");
38         PublicEditor& editor = PublicEditor::instance();
39
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());
44
45         node->add_child_nocopy (editor.get_selection().get_state());
46         return *node;
47 }
48
49 int
50 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
51
52         PublicEditor& editor = PublicEditor::instance();
53         if (node.name() != X_("SelectionMemento")) {
54                 return -1;
55         }
56
57         std::string str;
58         if (node.get_property ("mouse-mode", str)) {
59                 Editing::MouseMode m = Editing::str2mousemode (str);
60                 editor.set_mouse_mode (m, true);
61         }
62
63         float zoom;
64         if (node.get_property ("zoom", zoom)) {
65                 /* older versions of ardour used floating point samples_per_pixel */
66                 editor.reset_zoom (llrintf (zoom));
67         }
68
69         samplepos_t pos;
70         if (node.get_property ("left-frame", pos)) {
71                 if (pos < 0) {
72                         pos = 0;
73                 }
74                 editor.reset_x_origin (pos);
75         }
76
77         double y_origin;
78         if (node.get_property ("y-origin", y_origin)) {
79                 editor.reset_y_origin (y_origin);
80         }
81
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);
85         }
86
87         return 0;
88 }