Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions modules/tracktion_engine/model/clips/tracktion_Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,37 @@ void Clip::setOffset (TimeDuration newOffset)
setPosition (pos);
}

void Clip::setStart (BeatPosition newStart, bool preserveSync, bool keepLength)
{
setStart (edit.tempoSequence.toTime (newStart), preserveSync, keepLength);
}

void Clip::setLength (BeatDuration newLength, bool preserveSync)
{
const auto startBeats = edit.tempoSequence.toBeats (getPosition().time.getStart());
setEnd (edit.tempoSequence.toTime (startBeats + newLength), preserveSync);
}

void Clip::setEnd (BeatPosition newEnd, bool preserveSync)
{
setEnd (edit.tempoSequence.toTime (newEnd), preserveSync);
}

BeatPosition Clip::getStartBeats() const
{
return edit.tempoSequence.toBeats (getPosition().time.getStart());
}

BeatPosition Clip::getEndBeats() const
{
return edit.tempoSequence.toBeats (getPosition().time.getEnd());
}

BeatDuration Clip::getLengthBeats() const
{
return getEndBeats() - getStartBeats();
}

juce::Array<TimePosition> Clip::getInterestingTimes()
{
juce::Array<TimePosition> times;
Expand Down
34 changes: 34 additions & 0 deletions modules/tracktion_engine/model/clips/tracktion_Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,40 @@ class Clip : public TrackItem,
*/
void setOffset (TimeDuration newOffset);

/** Sets the start position of the clip in beats.
Converts to time using the Edit's TempoSequence, so the resulting
TimePosition tracks tempo curves correctly.
@param newStart The start position in beats
@param preserveSync Whether the source material position should be kept static in relation to the Edit's timeline.
@param keepLength Whether the end should be moved to keep the same length.
*/
void setStart (BeatPosition newStart, bool preserveSync, bool keepLength);

/** Sets the length of the clip in beats.
The end is computed as (current start in beats) + newLength and converted
through the Edit's TempoSequence, so this is tempo-curve aware rather than
a flat-tempo seconds calculation.
@param newLength The length in beats
@param preserveSync Whether the source material position should be kept static in relation to the Edit's timeline.
*/
void setLength (BeatDuration newLength, bool preserveSync);

/** Sets the end position of the clip in beats.
Converts to time using the Edit's TempoSequence.
@param newEnd The end position in beats
@param preserveSync Whether the source material position should be kept static in relation to the Edit's timeline.
*/
void setEnd (BeatPosition newEnd, bool preserveSync);

/** Returns the start position of the clip in beats. */
BeatPosition getStartBeats() const;

/** Returns the end position of the clip in beats. */
BeatPosition getEndBeats() const;

/** Returns the length of the clip in beats. */
BeatDuration getLengthBeats() const;

/** Trims away any part of the clip that overlaps this region. */
void trimAwayOverlap (TimeRange editRangeToTrim);

Expand Down
2 changes: 1 addition & 1 deletion modules/tracktion_engine/model/edit/tracktion_Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3049,7 +3049,7 @@ std::unique_ptr<Edit> Edit::createEditForPreviewingPreset (Engine& engine, juce:
if (auto firstClip = track->getClips().getFirst())
{
length = TimeDuration::fromSeconds (length.inSeconds() * clipTempo / songTempo);
firstClip->setStart ({}, false, true);
firstClip->setStart (TimePosition(), false, true);
firstClip->setLength (length, true);

edit->getTransport().setLoopRange ({ TimePosition(), length });
Expand Down
Loading