1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "NotationElement.h"
#include "misc/Debug.h"
#include "base/BaseProperties.h"
#include "base/Event.h"
#include "base/Exception.h"
#include "base/NotationTypes.h"
#include "base/ViewElement.h"
#include <tqcanvas.h>
namespace Rosegarden
{
NotationElement::NotationElement(Event *event)
: ViewElement(event),
m_recentlyRegenerated(false),
m_isColliding(false),
m_canvasItem(0),
m_extraItems(0)
{
// NOTATION_DEBUG << "new NotationElement "
// << this << " wrapping " << event << endl;
}
NotationElement::~NotationElement()
{
removeCanvasItem();
}
timeT
NotationElement::getViewAbsoluteTime() const
{
return event()->getNotationAbsoluteTime();
}
timeT
NotationElement::getViewDuration() const
{
return event()->getNotationDuration();
}
double
NotationElement::getCanvasX()
{
if (m_canvasItem)
return m_canvasItem->x();
else {
std::cerr << "ERROR: No canvas item for this notation element:";
event()->dump(std::cerr);
throw NoCanvasItem("No canvas item for notation element of type " +
event()->getType(), __FILE__, __LINE__);
}
}
double
NotationElement::getCanvasY()
{
if (m_canvasItem)
return m_canvasItem->y();
else {
std::cerr << "ERROR: No canvas item for this notation element:";
event()->dump(std::cerr);
throw NoCanvasItem("No canvas item for notation element of type " +
event()->getType(), __FILE__, __LINE__);
}
}
bool
NotationElement::isRest() const
{
return event()->isa(Note::EventRestType);
}
bool
NotationElement::isNote() const
{
return event()->isa(Note::EventType);
}
bool
NotationElement::isTuplet() const
{
return event()->has(BaseProperties::BEAMED_GROUP_TUPLET_BASE);
}
bool
NotationElement::isGrace() const
{
return event()->has(BaseProperties::IS_GRACE_NOTE) &&
event()->get
<Bool>(BaseProperties::IS_GRACE_NOTE);
}
void
NotationElement::setCanvasItem(TQCanvasItem *e, double canvasX, double canvasY)
{
removeCanvasItem();
m_recentlyRegenerated = true;
m_canvasItem = e;
e->move(canvasX, canvasY);
}
void
NotationElement::addCanvasItem(TQCanvasItem *e, double canvasX, double canvasY)
{
if (!m_canvasItem) {
std::cerr << "ERROR: Attempt to add extra canvas item to element without main canvas item:";
event()->dump(std::cerr);
throw NoCanvasItem("No canvas item for notation element of type " +
event()->getType(), __FILE__, __LINE__);
}
if (!m_extraItems) {
m_extraItems = new ItemList;
}
e->move(canvasX, canvasY);
m_extraItems->push_back(e);
}
void
NotationElement::removeCanvasItem()
{
m_recentlyRegenerated = false;
delete m_canvasItem;
m_canvasItem = 0;
if (m_extraItems) {
for (ItemList::iterator i = m_extraItems->begin();
i != m_extraItems->end(); ++i)
delete *i;
m_extraItems->clear();
delete m_extraItems;
m_extraItems = 0;
}
}
void
NotationElement::reposition(double canvasX, double canvasY)
{
m_recentlyRegenerated = false;
if (!m_canvasItem)
return ;
double dx = canvasX - m_canvasItem->x();
double dy = canvasY - m_canvasItem->y();
m_canvasItem->move(canvasX, canvasY);
if (m_extraItems) {
for (ItemList::iterator i = m_extraItems->begin();
i != m_extraItems->end(); ++i) {
(*i)->moveBy(dx, dy);
}
}
}
bool
NotationElement::isSelected()
{
return m_canvasItem ? m_canvasItem->isSelected() : false;
}
void
NotationElement::setSelected(bool selected)
{
m_recentlyRegenerated = false;
if (m_canvasItem)
m_canvasItem->setSelected(selected);
}
}
|