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
|
// -*- 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 "TriggerSegment.h"
#include "Segment.h"
#include "Composition.h"
#include "BaseProperties.h"
namespace Rosegarden
{
TriggerSegmentRec::~TriggerSegmentRec()
{
// nothing -- we don't delete the segment here
}
TriggerSegmentRec::TriggerSegmentRec(TriggerSegmentId id,
Segment *segment,
int basePitch,
int baseVelocity,
std::string timeAdjust,
bool retune) :
m_id(id),
m_segment(segment),
m_basePitch(basePitch),
m_baseVelocity(baseVelocity),
m_defaultTimeAdjust(timeAdjust),
m_defaultRetune(retune)
{
if (m_defaultTimeAdjust == "") {
m_defaultTimeAdjust = BaseProperties::TRIGGER_SEGMENT_ADJUST_STQUISH;
}
calculateBases();
updateReferences();
}
TriggerSegmentRec::TriggerSegmentRec(const TriggerSegmentRec &rec) :
m_id(rec.m_id),
m_segment(rec.m_segment),
m_basePitch(rec.m_basePitch),
m_baseVelocity(rec.m_baseVelocity),
m_defaultTimeAdjust(rec.m_defaultTimeAdjust),
m_defaultRetune(rec.m_defaultRetune),
m_references(rec.m_references)
{
// nothing else
}
TriggerSegmentRec &
TriggerSegmentRec::operator=(const TriggerSegmentRec &rec)
{
if (&rec == this) return *this;
m_id = rec.m_id;
m_segment = rec.m_segment;
m_basePitch = rec.m_basePitch;
m_baseVelocity = rec.m_baseVelocity;
m_references = rec.m_references;
return *this;
}
void
TriggerSegmentRec::updateReferences()
{
if (!m_segment) return;
Composition *c = m_segment->getComposition();
if (!c) return;
m_references.clear();
for (Composition::iterator i = c->begin(); i != c->end(); ++i) {
for (Segment::iterator j = (*i)->begin(); j != (*i)->end(); ++j) {
if ((*j)->has(BaseProperties::TRIGGER_SEGMENT_ID) &&
(*j)->get<Int>(BaseProperties::TRIGGER_SEGMENT_ID) == long(m_id)) {
m_references.insert((*i)->getRuntimeId());
break; // from inner loop only: go on to next segment
}
}
}
}
void
TriggerSegmentRec::calculateBases()
{
if (!m_segment) return;
for (Segment::iterator i = m_segment->begin();
m_segment->isBeforeEndMarker(i); ++i) {
if (m_basePitch >= 0 && m_baseVelocity >= 0) return;
if (m_basePitch < 0) {
if ((*i)->has(BaseProperties::PITCH)) {
m_basePitch = (*i)->get<Int>(BaseProperties::PITCH);
}
}
if (m_baseVelocity < 0) {
if ((*i)->has(BaseProperties::VELOCITY)) {
m_baseVelocity = (*i)->get<Int>(BaseProperties::VELOCITY);
}
}
}
if (m_basePitch < 0) m_basePitch = 60;
if (m_baseVelocity < 0) m_baseVelocity = 100;
}
}
|