11namespace tracktion {
inline namespace engine
21 notifyListenersOfDeletion();
29 if (getTakesTree().isValid())
43 copyValueTree (takes, other->state.getChildWithName (IDs::TAKES),
nullptr);
57 if (sourceLength == 0s)
87 if (
hasAnyTakes() && compManager !=
nullptr && compManager->isCurrentTakeComp())
88 return compManager->getCurrentCompFile();
90 return sourceFileReference.getFile();
105 ^
static_cast<HashCode
> ((clipEffects ==
nullptr || !
canHaveEffects()) ? 0 : clipEffects->getHash());
116 auto& ts =
edit.tempoSequence;
120 loopInfo.
setNumerator (ts.getTimeSigAt (pos.getStart()).numerator);
123 loopInfo.
setDenominator (ts.getTimeSigAt (pos.getStart()).denominator);
129void WaveAudioClip::reassignReferencedItem (
const ReferencedItem& item,
132 const auto newStartTime = TimeDuration::fromSeconds (newStartTimeSeconds);
136 auto indexInList = getReferencedItems().indexOf (item);
147 auto take = getTakesTree().
getChild (indexInList);
152 if (indexInList == 0)
162 AudioClipBase::reassignReferencedItem (item, newItemID, newStartTimeSeconds);
186 sfr.setToDirectFileReference (f,
true);
189 takesTree.addChild (take, -1, um);
206 for (
auto t : takesTree)
207 if (t.hasProperty (IDs::source))
208 takes.
add (ProjectItemID::fromProperty (t, IDs::source));
218 compManager =
nullptr;
225 if (currentTakeIndex == takeIndexNeedsUpdating)
227 currentTakeIndex = -1;
229 auto takesTree = getTakesTree();
230 auto pid = sourceFileReference.getSourceProjectItemID().toString();
232 for (
int i = takesTree.getNumChildren(); --i >= 0;)
234 if (takesTree.getChild (i).getProperty (IDs::source) == pid)
236 currentTakeIndex = i;
242 return currentTakeIndex;
245void WaveAudioClip::invalidateCurrentTake() noexcept
247 currentTakeIndex = takeIndexNeedsUpdating;
250void WaveAudioClip::invalidateCurrentTake (
const juce::ValueTree& parentState)
noexcept
252 if (parentState.hasType (IDs::TAKES))
253 invalidateCurrentTake();
256void WaveAudioClip::valueTreePropertyChanged (
juce::ValueTree& treeWhosePropertyHasChanged,
259 AudioClipBase::valueTreePropertyChanged (treeWhosePropertyHasChanged, property);
261 if (property == IDs::source)
262 invalidateCurrentTake();
267 AudioClipBase::valueTreeChildAdded (p, c);
268 invalidateCurrentTake (p);
273 AudioClipBase::valueTreeChildRemoved (p, c, oldIndex);
274 invalidateCurrentTake (p);
277void WaveAudioClip::valueTreeChildOrderChanged (
juce::ValueTree& p,
int oldIndex,
int newIndex)
279 AudioClipBase::valueTreeChildOrderChanged (p, oldIndex, newIndex);
280 invalidateCurrentTake (p);
286 auto takesTree = getTakesTree();
287 auto numTakes = takesTree.getNumChildren();
291 auto take = takesTree.getChild (takeIndex);
294 auto takeSourceID = ProjectItemID::fromProperty (take, IDs::source);
295 auto mo =
edit.engine.getProjectManager().getProjectItem (takeSourceID);
296 invalidateCurrentTake();
321 for (
int i = 0; i < takes.size(); ++i)
323 if (compManager ==
nullptr || ! compManager->isTakeComp (i))
325 if (
auto projectItem =
edit.engine.getProjectManager().getProjectItem (takes.getReference (i)))
345 #if JUCE_MODAL_LOOPS_PERMITTED
349 .createAlertWindow (title, message,
351 juce::AlertWindow::QuestionIcon, 0,
nullptr));
354 delFilesButton.
setSize (400, 20);
356 w->addCustomComponent (&delFilesButton);
357 w->addTextBlock (
TRANS(
"(This will also delete these from any other Edits in this project)"));
361 const int res = w->runModalLoop();
369 if (showWarning (
TRANS(
"Flatten Takes"),
370 TRANS(
"This will permanently remove all takes in this clip, replacing it with"
371 " the current comp. This operation can not be undone.")
373 +
TRANS(
"Are you sure you want to do this?"),
374 deleteSourceFiles) == 1)
381 bool userIsSure =
true;
383 #if JUCE_MODAL_LOOPS_PERMITTED
384 userIsSure = (showWarning (
TRANS(
"Delete Unused Takes"),
385 TRANS(
"This will permanently delete all wave files that are listed as takes in this "
386 "clip, apart from the ones currently being used.")
388 +
TRANS(
"Are you sure you want to do this?"),
389 deleteSourceFiles) == 1);
400 for (
auto& c : t->getClips())
402 if (c->getSourceFileReference().getSourceProjectItemID() == takeProjectItemID)
406 if (wac != &clip && wac->getTakes().contains (takeProjectItemID))
423 for (
int i = takes.size(); --i >= 0;)
425 auto takeProjectItemID = takes.getReference (i);
427 if (! isTakeInUse (*
this, takeProjectItemID))
429 bool removedOk = ! deleteSourceFiles
430 || proj->getProjectItemForID (takeProjectItemID) ==
nullptr
431 || proj->removeProjectItem (takeProjectItemID,
true);
435 for (
auto child :
state)
437 if (ProjectItemID::fromProperty (child, IDs::source) == takeProjectItemID)
454 edit.engine.getUIBehaviour().showWarningAlert (
TRANS(
"Delete Unused Takes"),
455 TRANS(
"Some of the wave files couldn't be deleted"));
459 compManager =
nullptr;
471 if (shouldBeShowingTakes)
476 if (! clipNode.isValid())
479 clipNode.
removeChild (clipNode.getChildWithName (IDs::TAKES),
nullptr);
481 int trackIndex = t->getIndexInEditTrackList();
485 for (
int i = 0; i < takes.size(); ++i)
487 if (compManager->isTakeComp (i))
492 if (toNewTracks || targetTrack ==
nullptr)
493 targetTrack = t->edit.insertNewAudioTrack (
TrackInsertPoint (t->getParentTrack(), t.get()),
nullptr);
495 if (targetTrack !=
nullptr)
501 if (shouldBeShowingTakes)
512 if (compManager ==
nullptr)
515 auto ptr =
edit.engine.getCompFactory().getCompManager (*
this);
518 if (compManager !=
nullptr)
519 compManager->initialise();
530 TRACKTION_ASSERT_MESSAGE_THREAD
533 if (
auto existing =
edit.engine.getRenderManager().getRenderJobWithoutCreating (destFile))
539 j->setName (
TRANS(
"Rendering Clip Effects") +
": " +
getName());
552 auto j = WarpTimeRenderJob::getOrCreateRenderJob (*
this,
getOriginalFile(), destFile.getFile());
562 TRACKTION_ASSERT_MESSAGE_THREAD
567 const float progress = renderJob ==
nullptr ? 1.0f : renderJob->getCurrentTaskProgress();
void add(const ElementType &newElement)
virtual void setName(const String &newName)
void setSize(int newWidth, int newHeight)
static const int escapeKey
static const int returnKey
static LookAndFeel & getDefaultLookAndFeel() noexcept
void add(String stringToAdd)
void removeChild(const ValueTree &child, UndoManager *undoManager)
ValueTree getChild(int index) const
int getNumChildren() const noexcept
ValueTree & setProperty(const Identifier &name, const var &newValue, UndoManager *undoManager)
void addChild(const ValueTree &child, int index, UndoManager *undoManager)
ValueTree createCopy() const
ValueTree getChildWithName(const Identifier &type) const
ValueTree getOrCreateChildWithName(const Identifier &type, UndoManager *undoManager)
Base class for Clips that produce some kind of audio e.g.
WarpTimeManager & getWarpTimeManager() const
Returns the WarpTimeManager for this clip used to maipluate warp markers.
virtual bool canHaveEffects() const
Returns true if this clip can have ClipEffects added to it.
void updateSourceFile()
Checks the current source file to see if it's up to date and then triggers a source render if needed.
virtual bool isUsingFile(const AudioFile &)
Should return true if the clip is referencing the file in any way.
virtual void renderComplete()
Callback to indicate that the render has completed.
virtual AudioFile getAudioFile() const
Returns the file used to play back the source and will get proxied etc.
bool getWarpTime() const
Returns true if warp time is enabled.
bool isLooping() const override
Returns true if this clip is currently looping.
bool isUsingMelodyne() const
Returns true if this clip is using Melodyne.
void initialise() override
Initialises the Clip.
bool getIsReversed() const noexcept
Returns true if the clip's source material is reversed.
void markAsDirty()
Resets the dirty flag so that a new render will be attempted.
bool canUseProxy() const noexcept
Retuns true if this clip can use a proxy file.
void changed() override
This should be called to send a change notification to any SelectableListeners that are registered wi...
void cloneFrom(Clip *) override
Clones the given clip to this clip.
Base class for items that can contain clips.
virtual juce::String getName() const override
Returns the name of the clip.
void setOffset(TimeDuration newOffset)
Sets the offset of the clip, i.e.
juce::ValueTree state
The ValueTree of the Clip state.
Track * getTrack() const override
Returns the parent Track this clip is on (if any).
virtual void sourceMediaChanged()
Called when the source media file reference (attribute "source") has changed - i.e.
virtual void setShowingTakes(bool shouldShow)
Sets whether the clip should be showing takes.
double getSpeedRatio() const noexcept
Returns the speed ratio i.e.
virtual bool isShowingTakes() const
Returns true if the clip is showing takes.
juce::UndoManager * getUndoManager() const
Returns the UndoManager.
ClipPosition getPosition() const override
Returns the ClipPosition on the parent Track.
void setCurrentSourceFile(const juce::File &)
Sets a new source file for this clip.
void setActiveTakeIndex(int index)
Sets the active take index.
bool isCurrentTakeComp() const
Returns true if the current take is a comp.
int getNumTakes() const
Returns the number of takes that are not comps.
void setNumerator(int newNumerator)
Sets the numerator of the object.
void setDenominator(int newDenominator)
Sets the denominator of the object.
int getDenominator() const
Returns the denominator of the object.
double getNumBeats() const
Returns the number of beats.
int getNumerator() const
Returns the numerator of the object.
void setNumBeats(double newNumBeats)
Sets the number of beats.
An ID representing one of the items in a Project.
static Ptr getOrCreateRenderJob(Engine &e, const juce::File &source, const juce::File &destination)
Returns a job that will have been started to generate the Render described by the params.
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
This class wraps a string that is generally held in a 'source' property, and which is a reference to ...
void setToProjectFileReference(const juce::File &, bool updateProjectItem)
Points this source at a new file via a project item.
Type
Defines the types of item that can live on Track[s].
HashCode getHash() const
Returns a hash representing this warp list.
An audio clip that uses an audio file as its source.
juce::File getOriginalFile() const override
Must return the file that the source ProjectItemID refers to.
int getCurrentTake() const override
Returns the current take index.
void renderComplete() override
Callback to indicate that the render has completed.
juce::Array< ProjectItemID > getTakes() const override
Returns the ProjectItemID of the clip's takes.
int getNumTakes(bool includeComps) override
Returns the total number of takes.
juce::String getRenderMessage() override
Override this to return a custom message to be displayed over waveforms during rendering.
bool hasAnyTakes() const override
Returns true if this clip has any takes.
void deleteAllUnusedTakesConfirmingWithUser(bool deleteSourceFiles)
Deletes all but the current takes but shows a confirmation dialog first.
WaveAudioClip(const juce::ValueTree &, EditItemID, ClipOwner &)
Creates a WaveAudioClip from a given state.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
bool needsRender() const override
Subclasses should override this to return true if they need the rest of the render callbacks.
RenderManager::Job::Ptr getRenderJob(const AudioFile &destFile) override
Subclasses should override this to return a RenderJob suitable for rendering its source file.
HashCode getHash() const override
Must return a unique hash for this clip's source.
~WaveAudioClip() override
Destructor.
bool isCurrentTakeComp() override
Returns true if the current take is a comp.
TimeDuration getSourceLength() const override
Must return the length in seconds of the source material e.g.
void deleteAllUnusedTakes(bool deleteSourceFiles)
Deletes all but the current takes.
void sourceMediaChanged() override
Called when the source media file reference (attribute "source") has changed - i.e.
void setCurrentTake(int takeIndex) override
Sets a given take index to be the current take.
void cloneFrom(Clip *) override
Clones the given clip to this clip.
bool isUsingFile(const AudioFile &) override
Should return true if the clip is referencing the file in any way.
void setLoopDefaults() override
Override this to fill in the LoopInfo structure as best fits the source.
WaveCompManager & getCompManager()
Returns the WaveCompManager for this clip.
juce::StringArray getTakeDescriptions() const override
Returns the descriptions of any takes.
void clearTakes() override
Clears any takes this clip has.
void initialise() override
Initialises the Clip.
void addTake(ProjectItemID)
Adds a new take with the ProjectItemID as the source.
Clip::Array unpackTakes(bool toNewTracks) override
Attempts to unpack the takes to new clips.
void flattenTake(int takeIndex, bool deleteSourceFiles) override
Should flatten the comp and remove all other takes.
#define TRANS(stringLiteral)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
int roundToInt(const FloatType value) noexcept
juce::Array< Track * > getAllTracks(const Edit &edit)
Returns all the tracks in an Edit.
juce::Array< ClipTrack * > getClipTracks(const Edit &edit)
Returns all the ClipTracks in an Edit.
Project::Ptr getProjectForEdit(const Edit &e)
Tries to find the project that contains this edit (but may return nullptr!)
Represents a duration in real-life time.
ID for objects of type EditElement - e.g.
Defines the place to insert Track[s].
#define CRASH_TRACER
This macro adds the current location to a stack which gets logged if a crash happens.