340 mergeSections (origSections, sections);
343 for (
auto&& section : sections)
345 for (
auto element : section.src->getAllAutomatableEditItems())
347 for (
int k = 0; k < element->getNumAutomatableParameters(); k++)
349 AutomatableParameter::Ptr param = element->getAutomatableParameter (k);
351 if (param->getCurve().getNumPoints() > 0)
353 TrackAutomationSection::ActiveParameters ap;
355 ap.curve.setState (param->getCurve().state);
356 ap.curve.setParentState (param->getCurve().parentState);
357 ap.curve.setOwnerParameter (param->getCurve().getOwnerParameter());
359 section.activeParameters.add (ap);
364 for (
auto& ap : section.activeParameters)
365 ap.curve.state = ap.curve.state.createCopy();
371 for (
auto& section : sections)
373 auto sectionTime = section.position;
375 for (
auto&& activeParam : section.activeParameters)
377 auto param = activeParam.param;
378 auto& curve = param->getCurve();
379 constexpr auto tolerance = TimeDuration::fromSeconds (0.0001);
381 auto startValue = curve.getValueAt (sectionTime.getStart() - tolerance);
382 auto endValue = curve.getValueAt (sectionTime.getEnd() + tolerance);
384 auto idx = curve.indexBefore (sectionTime.getEnd() + tolerance);
385 auto endCurve = (idx == -1) ? 0.0f : curve.getPointCurve(idx);
387 curve.removePointsInRegion (sectionTime.expanded (tolerance));
389 if (std::abs (startValue - endValue) < 0.0001f)
391 curve.addPoint (sectionTime.getStart(), startValue, 0.0f);
392 curve.addPoint (sectionTime.getEnd(), endValue, endCurve);
394 else if (startValue > endValue)
396 curve.addPoint (sectionTime.getStart(), startValue, 0.0f);
397 curve.addPoint (sectionTime.getStart(), endValue, 0.0f);
398 curve.addPoint (sectionTime.getEnd(), endValue, endCurve);
402 curve.addPoint (sectionTime.getStart(), startValue, 0.0f);
403 curve.addPoint (sectionTime.getEnd(), startValue, 0.0f);
404 curve.addPoint (sectionTime.getEnd(), endValue, endCurve);
407 curve.removeRedundantPoints (sectionTime.expanded (tolerance));
413 for (
auto& section : sections)
415 for (
auto& activeParam : section.activeParameters)
417 auto sectionTime = section.position;
419 if (
auto dstCurve = (section.src == section.dst) ? &activeParam.param->getCurve()
420 : getDestCurve (*section.dst, activeParam.param))
422 constexpr auto errorMargin = TimeDuration::fromSeconds (0.0001);
424 auto start = sectionTime.getStart();
425 auto end = sectionTime.getEnd();
426 auto newStart = start + offset;
427 auto newEnd = end + offset;
429 auto& srcCurve = activeParam.curve;
431 auto idx1 = srcCurve.indexBefore (newEnd + errorMargin);
432 auto endCurve = idx1 < 0 ? 0 : srcCurve.getPointCurve (idx1);
434 auto idx2 = srcCurve.indexBefore (start - errorMargin);
435 auto startCurve = idx2 < 0 ? 0 : srcCurve.getPointCurve (idx2);
437 auto srcStartVal = srcCurve.getValueAt (start - errorMargin);
438 auto srcEndVal = srcCurve.getValueAt (end + errorMargin);
440 auto dstStartVal = dstCurve->getValueAt (newStart - errorMargin);
441 auto dstEndVal = dstCurve->getValueAt (newEnd + errorMargin);
443 TimeRange totalRegionWithMargin (newStart - errorMargin, newEnd + errorMargin);
444 TimeRange startWithMargin (newStart - errorMargin, newStart + errorMargin);
445 TimeRange endWithMargin (newEnd - errorMargin, newEnd + errorMargin);
449 for (
int i = 0; i < srcCurve.getNumPoints(); ++i)
451 auto pt = srcCurve.getPoint (i);
453 if (pt.time >= start - errorMargin && pt.time <= sectionTime.getEnd() + errorMargin)
457 dstCurve->removePointsInRegion (totalRegionWithMargin);
459 for (
const auto& pt : origPoints)
460 dstCurve->addPoint (pt.time + offset, pt.value, pt.curve);
462 auto startPoints = dstCurve->getPointsInRegion (startWithMargin);
463 auto endPoints = dstCurve->getPointsInRegion (endWithMargin);
465 dstCurve->removePointsInRegion (startWithMargin);
466 dstCurve->removePointsInRegion (endWithMargin);
468 dstCurve->addPoint (newStart, dstStartVal, startCurve);
469 dstCurve->addPoint (newStart, srcStartVal, startCurve);
471 for (
auto& point : startPoints)
472 dstCurve->addPoint (newStart, point.value, point.curve);
474 for (
auto& point : endPoints)
475 dstCurve->addPoint (newEnd, point.value, point.curve);
477 dstCurve->addPoint (newEnd, srcEndVal, endCurve);
478 dstCurve->addPoint (newEnd, dstEndVal, endCurve);
480 dstCurve->removeRedundantPoints (totalRegionWithMargin);
488 for (
auto& section : sections)
490 if (section.src != section.dst)
492 if (! src.contains (section.src.get()))
494 src.add (section.src.get());
495 dst.add (section.dst.get());
500 for (
int i = 0; i < src.size(); ++i)
502 if (
auto ap = src.getUnchecked (i)->getCurrentlyShownAutoParam())
504 for (
auto p : dst.getUnchecked (i)->getAllAutomatableParams())
506 if (p->getPluginAndParamName() == ap->getPluginAndParamName())
508 dst.getUnchecked (i)->setCurrentlyShownAutoParam (p);