1 /*
2 * Hydrogen
3 * Copyright(c) 2015-2016 by Przemysław Sitek
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 #include <hydrogen/automation_path_serializer.h>
23
24 namespace H2Core
25 {
26
27 const char* AutomationPathSerializer::__class_name = "AutomationPathSerializer";
28
29
AutomationPathSerializer()30 AutomationPathSerializer::AutomationPathSerializer()
31 : Object(__class_name)
32 {
33 }
34
read_automation_path(const QDomNode & node,AutomationPath & path)35 void AutomationPathSerializer::read_automation_path(const QDomNode &node, AutomationPath &path)
36 {
37 auto point = node.firstChildElement();
38 while (! point.isNull()) {
39 if (point.tagName() == "point") {
40 bool hasX = false;
41 bool hasY = false;
42 float x = point.attribute("x").toFloat(&hasX);
43 float y = point.attribute("y").toFloat(&hasY);
44
45 if (hasX && hasY) {
46 path.add_point(x, y);
47 }
48
49 }
50 point = point.nextSiblingElement();
51 }
52 }
53
54
write_automation_path(QDomNode & node,const AutomationPath & path)55 void AutomationPathSerializer::write_automation_path(QDomNode &node, const AutomationPath &path)
56 {
57 for (auto point : path) {
58 auto element = node.ownerDocument().createElement("point");
59 element.setAttribute("x", point.first);
60 element.setAttribute("y", point.second);
61 node.appendChild(element);
62 }
63 }
64
65
66 }
67