ardour
selection_memento.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 Paul Davis
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
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include "ardour/lmath.h"
21 #include "selection_memento.h"
22 #include "editing.h"
23 #include "public_editor.h"
24 
25 #include "i18n.h"
26 
28 {
29 }
30 
32 {
33 }
34 
35 XMLNode&
37 
38  XMLNode* node = new XMLNode ("SelectionMemento");
39  char buf[32];
41 
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);
49 
50  node->add_child_nocopy (editor.get_selection().get_state());
51  return *node;
52 }
53 
54 int
55 SelectionMemento::set_state (const XMLNode& node, int /*version*/) {
56 
57  const XMLProperty* prop;
59  if (node.name() != X_("SelectionMemento")) {
60  return -1;
61  }
62 
63  if ((prop = node.property ("mouse-mode"))) {
65  editor.set_mouse_mode (m, true);
66  }
67 
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));
72  }
73 
74  if ((prop = node.property ("left-frame")) != 0) {
75  framepos_t pos;
76  if (sscanf (prop->value().c_str(), "%" PRId64, &pos) == 1) {
77  if (pos < 0) {
78  pos = 0;
79  }
80  editor.reset_x_origin (pos);
81  }
82  }
83 
84  if ((prop = node.property ("y-origin")) != 0) {
85  editor.reset_y_origin (atof (prop->value ().c_str()));
86  }
87 
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);
91  }
92 
93  return 0;
94 }
MouseMode
Definition: editing.h:91
const std::string & value() const
Definition: xml++.h:159
virtual Editing::MouseMode current_mouse_mode() const =0
virtual void reset_y_origin(double pos)=0
const std::string & name() const
Definition: xml++.h:104
Representation of the interface of the Editor class.
tuple f
Definition: signals.py:35
int set_state(const XMLNode &, int version)
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
#define X_(Text)
Definition: i18n.h:13
XMLProperty * property(const char *)
Definition: xml++.cc:413
virtual framecnt_t get_current_zoom() const =0
const char * enum2str(SnapType m)
Definition: editing.h:54
virtual double get_y_origin() const =0
virtual Selection & get_selection() const =0
XMLProperty * add_property(const char *name, const std::string &value)
static PublicEditor & instance()
void add_child_nocopy(XMLNode &)
Definition: xml++.cc:357
MouseMode str2mousemode(const string &str)
Definition: editing.cc:103
virtual void set_mouse_mode(Editing::MouseMode m, bool force=false)=0
Definition: xml++.h:95
XMLNode & get_state() const
Definition: selection.cc:1208
virtual framepos_t leftmost_sample() const =0
int64_t framepos_t
virtual void reset_x_origin(framepos_t frame)=0
double atof(const string &s)
Definition: convert.cc:158
virtual void reset_zoom(framecnt_t)=0
int set_state(XMLNode const &, int)
Definition: selection.cc:1307