1 /*
2 Copyright (C) 2007 Remon Sijrier
3
4 This file is part of Traverso
5
6 Traverso is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 */
21
22 #include "Marker.h"
23 #include "Sheet.h"
24
25 #include "TimeLine.h"
26 #include "Utils.h"
27
Marker(TimeLine * tl,const TimeRef when,Type type)28 Marker::Marker(TimeLine* tl, const TimeRef when, Type type)
29 : ContextItem(tl)
30 , Snappable()
31 , m_timeline(tl)
32 , m_when(when)
33 , m_type(type)
34 {
35 QObject::tr("Marker");
36 set_history_stack(m_timeline->get_history_stack());
37 m_id = create_id();
38
39 set_snap_list(m_timeline->get_sheet()->get_snap_list());
40
41 m_description = "";
42 m_performer = "";
43 m_composer = "";
44 m_arranger = "";
45 m_message = "";
46 m_isrc = "";
47 m_preemph = 0;
48 m_copyprotect = 0;
49 m_index = -1;
50 }
51
Marker(TimeLine * tl,const QDomNode node)52 Marker::Marker(TimeLine * tl, const QDomNode node)
53 : ContextItem(tl)
54 , Snappable()
55 , m_timeline(tl)
56 {
57 set_snap_list(m_timeline->get_sheet()->get_snap_list());
58 set_history_stack(m_timeline->get_history_stack());
59 set_state(node);
60 }
61
get_state(QDomDocument doc)62 QDomNode Marker::get_state(QDomDocument doc)
63 {
64 QDomElement domNode = doc.createElement("Marker");
65
66 domNode.setAttribute("position", m_when.universal_frame());
67 domNode.setAttribute("description", m_description);
68 domNode.setAttribute("id", m_id);
69 domNode.setAttribute("performer", m_performer);
70 domNode.setAttribute("composer", m_composer);
71 domNode.setAttribute("songwriter", m_songwriter);
72 domNode.setAttribute("arranger", m_arranger);
73 domNode.setAttribute("message", m_message);
74 domNode.setAttribute("isrc", m_isrc);
75 domNode.setAttribute("preemphasis", m_preemph);
76 domNode.setAttribute("copyprotection", m_copyprotect);
77
78 switch (m_type) {
79 case CDTRACK:
80 domNode.setAttribute("type", "CDTRACK");
81 break;
82 case ENDMARKER:
83 domNode.setAttribute("type", "ENDMARKER");
84 break;
85 }
86
87 return domNode;
88 }
89
set_state(const QDomNode & node)90 int Marker::set_state(const QDomNode & node)
91 {
92 QDomElement e = node.toElement();
93
94 m_description = e.attribute("description", "");
95 QString tp = e.attribute("type", "CDTRACK");
96 m_when = TimeRef(e.attribute("position", "0").toLongLong());
97 m_id = e.attribute("id", "0").toLongLong();
98 m_performer = e.attribute("performer", "");
99 m_composer = e.attribute("composer", "");
100 m_songwriter = e.attribute("songwriter", "");
101 m_arranger = e.attribute("arranger", "");
102 m_message = e.attribute("message", "");
103 m_isrc = e.attribute("isrc", "");
104 m_preemph = e.attribute("preemphasis", "0").toInt();
105 m_copyprotect = e.attribute("copyprotection", "0").toInt();
106
107 if (tp == "CDTRACK") m_type = CDTRACK;
108 if (tp == "ENDMARKER") m_type = ENDMARKER;
109
110 return 1;
111 }
112
set_when(const TimeRef & when)113 void Marker::set_when(const TimeRef& when)
114 {
115 if (m_when == when) return;
116 m_when = when;
117 emit positionChanged();
118 }
119
set_description(const QString & s)120 void Marker::set_description(const QString &s)
121 {
122 if (m_description == s) return;
123 m_description = s;
124 emit descriptionChanged();
125 }
126
set_performer(const QString & s)127 void Marker::set_performer(const QString &s)
128 {
129 m_performer = s;
130 }
131
set_composer(const QString & s)132 void Marker::set_composer(const QString &s)
133 {
134 m_composer = s;
135 }
136
set_songwriter(const QString & s)137 void Marker::set_songwriter(const QString &s)
138 {
139 m_songwriter = s;
140 }
141
set_arranger(const QString & s)142 void Marker::set_arranger(const QString &s)
143 {
144 m_arranger = s;
145 }
146
set_message(const QString & s)147 void Marker::set_message(const QString &s)
148 {
149 m_message = s;
150 }
151
set_isrc(const QString & s)152 void Marker::set_isrc(const QString &s)
153 {
154 m_isrc = s;
155 }
156
set_preemphasis(bool b)157 void Marker::set_preemphasis(bool b)
158 {
159 m_preemph = b;
160 }
161
set_copyprotect(bool b)162 void Marker::set_copyprotect(bool b)
163 {
164 m_copyprotect = b;
165 }
166
get_preemphasis()167 bool Marker::get_preemphasis()
168 {
169 return m_preemph;
170 }
171
get_copyprotect()172 bool Marker::get_copyprotect()
173 {
174 return m_copyprotect;
175 }
176
set_index(int i)177 void Marker::set_index(int i)
178 {
179 m_index = i;
180 emit indexChanged();
181 }
182