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
|
// -*- c-basic-offset: 4 -*-
/*
Rosegarden
A 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 right of the authors to claim authorship of this work
has been asserted.
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 "ViewElement.h"
#include <iostream>
#include <cassert>
namespace Rosegarden
{
extern const int MIN_SUBORDERING;
ViewElement::ViewElement(Event *e) :
m_layoutX(0.0),
m_layoutY(0.0),
m_event(e)
{
// nothing
}
ViewElement::~ViewElement()
{
// nothing
}
//////////////////////////////////////////////////////////////////////
bool
operator<(const ViewElement &a, const ViewElement &b)
{
timeT at = a.getViewAbsoluteTime(), bt = b.getViewAbsoluteTime();
/*
if (at < bt) {
if (!(*(a.event()) < *(b.event()))) {
std::cerr << " types: a: " << a.event()->getType() << " b: " << b.event()->getType() << std::endl;
std::cerr << "performed: a: " << a.event()->getAbsoluteTime() << " b: " << b.event()->getAbsoluteTime() << std::endl;
std::cerr << " notated: a: " << a.getViewAbsoluteTime() << " b: " << b.getViewAbsoluteTime() << std::endl;
// assert(*(a.event()) < *(b.event()));
}
}
else if (at > bt) {
if (*(a.event()) < *(b.event())) {
std::cerr << " types: a: " << a.event()->getType() << " b: " << b.event()->getType() << std::endl;
std::cerr << "performed: a: " << a.event()->getAbsoluteTime() << " b: " << b.event()->getAbsoluteTime() << std::endl;
std::cerr << " notated: a: " << a.getViewAbsoluteTime() << " b: " << b.getViewAbsoluteTime() << std::endl;
// assert(!(*(a.event()) < *(b.event())));
}
}
*/
if (at == bt) return *(a.event()) < *(b.event());
else return (at < bt);
}
//////////////////////////////////////////////////////////////////////
ViewElementList::~ViewElementList()
{
for (iterator i = begin(); i != end(); ++i) {
delete (*i);
}
}
void
ViewElementList::insert(ViewElement* el)
{
set_type::insert(el);
}
void
ViewElementList::erase(iterator pos)
{
delete *pos;
set_type::erase(pos);
}
void
ViewElementList::erase(iterator from, iterator to)
{
for (iterator i = from; i != to; ++i) {
delete *i;
}
set_type::erase(from, to);
}
void
ViewElementList::eraseSingle(ViewElement *el)
{
iterator elPos = findSingle(el);
if (elPos != end()) erase(elPos);
}
ViewElementList::iterator
ViewElementList::findPrevious(const std::string &type, iterator i)
{
// what to return on failure? I think probably
// end(), as begin() could be a success case
if (i == begin()) return end();
--i;
for (;;) {
if ((*i)->event()->isa(type)) return i;
if (i == begin()) return end();
--i;
}
}
ViewElementList::iterator
ViewElementList::findNext(const std::string &type, iterator i)
{
if (i == end()) return i;
for (++i; i != end() && !(*i)->event()->isa(type); ++i);
return i;
}
ViewElementList::iterator
ViewElementList::findSingle(ViewElement *el)
{
iterator res = end();
std::pair<iterator, iterator> interval = equal_range(el);
for (iterator i = interval.first; i != interval.second; ++i) {
if (*i == el) {
res = i;
break;
}
}
return res;
}
ViewElementList::iterator
ViewElementList::findTime(timeT time)
{
Event dummy("dummy", time, 0, MIN_SUBORDERING);
ViewElement dummyT(&dummy);
return lower_bound(&dummyT);
}
ViewElementList::iterator
ViewElementList::findNearestTime(timeT t)
{
iterator i = findTime(t);
if (i == end() || (*i)->getViewAbsoluteTime() > t) {
if (i == begin()) return end();
else --i;
}
return i;
}
}
|