Logo Search packages:      
Sourcecode: csound version File versions

void csound::VoiceleadingNode::transform ( Score score,
bool  rescaleTime = false 
) [virtual]

Simplifies use out of the context of a music graph.

Definition at line 321 of file VoiceleadingNode.cpp.

References apply(), csound::Score::findScale(), csound::Score::getDuration(), csound::Event::getTime(), csound::Score::indexAfterTime(), csound::Score::indexAtTime(), csound::System::inform(), csound::Score::scaleActualMinima, and csound::Score::sort().

Referenced by produceOrTransform().

  {
    if (operations.empty()) {
      return;
    }
    // Find the time rescale factor.
    score.sort();
    score.findScale();
    double origin = score.scaleActualMinima.getTime();
    double duration = score.getDuration();
    double scoreMaxTime = origin + duration;
    double operationMaxTime = 0.0;
    double timeScale = 1.0;
    std::vector<VoiceleadingOperation *> ops;
    for (std::map<double, VoiceleadingOperation>::iterator it = operations.begin(); it != operations.end(); ++it) {
      if (it->second.beginTime > operationMaxTime) {
        operationMaxTime = it->second.beginTime;
      }
      ops.push_back(&it->second);
    }
    if (rescaleTimes_) {
      if (operationMaxTime > 0.0) {
        timeScale = duration / operationMaxTime;
      }
    }
    System::inform("BEGAN VoiceleadingNode::produceOrTransform  operationMaxTime: %f  origin: %f  duration: %f  scoreMaxTime: %f  timeScale: %f...\n",
                   operationMaxTime,
                   origin,
                   duration,
                   scoreMaxTime,
                   timeScale);
    VoiceleadingOperation *priorOperation = 0;
    VoiceleadingOperation *currentOperation = 0;
    VoiceleadingOperation *nextOperation = 0;
    for (int priorIndex = -1, currentIndex = 0, nextIndex = 1, firstIndex = 0, endIndex = ops.size(), backIndex = ops.size() - 1;
         currentIndex < endIndex;
         priorIndex++, currentIndex++, nextIndex++) {
      if (currentIndex <= firstIndex) {
        priorOperation = ops[currentIndex];
        currentOperation = ops[currentIndex];
      } else {
        priorOperation = ops[priorIndex];
        currentOperation = ops[currentIndex];
      }
      currentOperation->rescaledBeginTime = ((currentOperation->beginTime - origin) * timeScale) + origin;
      currentOperation->begin = score.indexAtTime(currentOperation->rescaledBeginTime);
      if (currentIndex >= backIndex) {
        currentOperation->endTime = std::max(currentOperation->rescaledBeginTime, scoreMaxTime);
        currentOperation->rescaledEndTime = currentOperation->endTime;
        currentOperation->end = score.size();
      } else {
        nextOperation = ops[nextIndex];
        currentOperation->endTime = nextOperation->beginTime;
        currentOperation->rescaledEndTime = currentOperation->endTime * timeScale;
        currentOperation->end = score.indexAfterTime(currentOperation->rescaledEndTime);
      }
      apply(score, *priorOperation, *currentOperation);
    }
    System::inform("ENDED VoiceleadingNode::produceOrTransform.\n");
  }


Generated by  Doxygen 1.6.0   Back to index