|
@@ -16,7 +16,7 @@ BeatSequence::BeatSequence(BeatIndex size)
|
|
|
void BeatSequence::expand(BeatIndex factor)
|
|
|
{
|
|
|
if(factor < 1) {
|
|
|
- throw "factor may not be less than 1.";
|
|
|
+ throw "factor may not be less than 1.";
|
|
|
}
|
|
|
|
|
|
resize(size() * factor);
|
|
@@ -24,7 +24,7 @@ void BeatSequence::expand(BeatIndex factor)
|
|
|
for(signed int targetIndex = (size() - factor); targetIndex > 0; targetIndex -= factor)
|
|
|
{
|
|
|
BeatIndex sourceIndex = targetIndex / factor;
|
|
|
- at(sourceIndex).swap(at(targetIndex));
|
|
|
+ at(sourceIndex).swap(at(targetIndex));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -33,29 +33,29 @@ void BeatSequence::reduce(BeatIndex factor)
|
|
|
reduce(factor, 0, 0);
|
|
|
}
|
|
|
|
|
|
-void BeatSequence::reduce(BeatIndex factor, ReducationConflictCallback conflictCallback, void* conflictCallbackData)
|
|
|
+void BeatSequence::reduce(BeatIndex factor, ReductionConflictCallback conflictCallback, void* conflictCallbackData)
|
|
|
{
|
|
|
if(factor < 1) {
|
|
|
- throw "factor may not be less than 1.";
|
|
|
+ throw "factor may not be less than 1.";
|
|
|
}
|
|
|
|
|
|
if(conflictCallback != 0) {
|
|
|
for(BeatIndex beatIndex = 0; beatIndex < size(); beatIndex++) {
|
|
|
if(beatIndex % factor != 0 && at(beatIndex).size() > 0) {
|
|
|
- conflictCallback(*this, factor, beatIndex, conflictCallbackData);
|
|
|
+ conflictCallback(*this, factor, beatIndex, conflictCallbackData);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for(BeatIndex beatIndex = 0; beatIndex < size(); beatIndex++) {
|
|
|
if(beatIndex % factor != 0 && at(beatIndex).size() > 0) {
|
|
|
- throw new UnresolvedBeatSequenceReducationConflict(beatIndex);
|
|
|
+ throw new UnresolvedBeatSequenceReductionConflict(beatIndex);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
BeatIndex targetSize = (size() + factor - 1) / factor;
|
|
|
for(BeatIndex targetIndex = 0; targetIndex < targetSize; targetIndex++) {
|
|
|
- BeatIndex sourceIndex = targetIndex * factor;
|
|
|
+ BeatIndex sourceIndex = targetIndex * factor;
|
|
|
at(sourceIndex).swap(at(targetIndex));
|
|
|
}
|
|
|
resize(targetSize);
|
|
@@ -95,13 +95,23 @@ void BeatSequence::print(std::ostream& stream) const
|
|
|
stream << "\n";
|
|
|
stream.flush();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void BeatSequence::reduceToNeighbour(BeatIndex factor)
|
|
|
{
|
|
|
- reduce(factor, moveReducationConflictToNextNeighbour, 0);
|
|
|
+ reduce(factor, moveReductionConflictToNextNeighbour, 0);
|
|
|
}
|
|
|
-
|
|
|
-void BeatSequence::moveReducationConflictToNextNeighbour(BeatSequence& sequence, BeatIndex factor, BeatIndex beatIndex, void* data)
|
|
|
+
|
|
|
+void BeatSequence::reduceErasingConflicts(BeatIndex factor)
|
|
|
+{
|
|
|
+ reduce(factor, eraseReductionConflict, 0);
|
|
|
+}
|
|
|
+
|
|
|
+void BeatSequence::eraseReductionConflict(BeatSequence& sequence, BeatIndex factor, BeatIndex beatIndex, void* data)
|
|
|
+{
|
|
|
+ sequence.at(beatIndex).clear();
|
|
|
+}
|
|
|
+
|
|
|
+void BeatSequence::moveReductionConflictToNextNeighbour(BeatSequence& sequence, BeatIndex factor, BeatIndex beatIndex, void* data)
|
|
|
{
|
|
|
BeatSequence::BeatIndex previousIndex = beatIndex / factor * factor;
|
|
|
|
|
@@ -114,24 +124,24 @@ void BeatSequence::moveReducationConflictToNextNeighbour(BeatSequence& sequence,
|
|
|
targetIndex = 0;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
MessageList& targetBeat = sequence[targetIndex];
|
|
|
targetBeat.splice(targetBeat.end(), sequence[beatIndex]);
|
|
|
}
|
|
|
|
|
|
-UnresolvedBeatSequenceReducationConflict::UnresolvedBeatSequenceReducationConflict(BeatSequence::BeatIndex beatIndex)
|
|
|
+UnresolvedBeatSequenceReductionConflict::UnresolvedBeatSequenceReductionConflict(BeatSequence::BeatIndex beatIndex)
|
|
|
: parent("unresolved beat sequence reducation conflict"), beatIndex(beatIndex)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-const char* UnresolvedBeatSequenceReducationConflict::what() const throw()
|
|
|
+const char* UnresolvedBeatSequenceReductionConflict::what() const throw()
|
|
|
{
|
|
|
std::stringstream info;
|
|
|
info << parent::what() << " at beat #" << getBeatIndex();
|
|
|
return info.str().c_str();
|
|
|
}
|
|
|
|
|
|
-BeatSequence::BeatIndex UnresolvedBeatSequenceReducationConflict::getBeatIndex() const
|
|
|
+BeatSequence::BeatIndex UnresolvedBeatSequenceReductionConflict::getBeatIndex() const
|
|
|
{
|
|
|
return beatIndex;
|
|
|
}
|