11namespace tracktion {
inline namespace engine
15 : edit (e), source (v, prop, &e.getUndoManager()), state (v)
20SourceFileReference::~SourceFileReference()
24juce::String SourceFileReference::findPathFromFile (Edit& edit,
const juce::File& newFile,
bool useRelativePath)
28 jassert (edit.editFileRetriever && edit.editFileRetriever().existsAsFile());
29 jassert (edit.filePathResolver);
31 if (edit.editFileRetriever && edit.filePathResolver)
42 if (sourceDescription.
isEmpty())
45 ProjectItemID pid (sourceDescription);
49 if (
auto projectItem = edit.engine.getProjectManager().getProjectItem (pid))
50 return projectItem->getSourceFile();
55 if (edit.filePathResolver)
56 return edit.filePathResolver (sourceDescription);
64 return findFileFromString (edit, source.get());
67bool SourceFileReference::isUsingProjectReference()
const
69 return getSourceProjectItemID().isValid();
72ProjectItemID SourceFileReference::getSourceProjectItemID()
const
75 return ProjectItemID (source.get());
78ProjectItem::Ptr SourceFileReference::getSourceProjectItem()
const
81 ProjectItemID pid (source.get());
84 return edit.engine.getProjectManager().getProjectItem (pid);
89void SourceFileReference::setToDirectFileReference (
const juce::File& newFile,
bool useRelativePath)
91 source = findPathFromFile (edit, newFile, useRelativePath);
94void SourceFileReference::setToProjectFileReference (
const juce::File& file,
bool updateProjectItem)
96 auto oldFile = getFile();
99 if (updateProjectItem)
101 if (
auto projectItem = getSourceProjectItem())
104 if (! projectItem->getSourceFile().existsAsFile())
106 projectItem->setSourceFile (file);
108 else if (project !=
nullptr)
111 if (
auto existingItem = project->getProjectItemForFile (file))
114 setToProjectFileReference (existingItem->getID());
119 projectItem = project->createNewItem (file, ProjectItem::waveItemType(),
120 file.getFileNameWithoutExtension(),
121 {}, ProjectItem::Category::imported,
124 if (projectItem !=
nullptr)
125 setToProjectFileReference (projectItem->getID());
129 else if (project !=
nullptr)
132 projectItem = project->createNewItem (file, ProjectItem::waveItemType(),
133 file.getFileNameWithoutExtension(),
135 ProjectItem::Category::imported,
138 if (projectItem !=
nullptr)
139 setToProjectFileReference (projectItem->getID());
144 if (project !=
nullptr)
145 if (
auto existingProjectItem = project->getProjectItemForFile (file))
146 setToProjectFileReference (existingProjectItem->getID());
149 if (getFile() != oldFile)
150 edit.restartPlayback();
153void SourceFileReference::setToProjectFileReference (
ProjectItemID newID)
155 auto oldFile = getFile();
156 source = newID.toString();
158 if (getFile() != oldFile)
159 edit.restartPlayback();
const String & getFullPathName() const noexcept
File getChildFile(StringRef relativeOrAbsolutePath) const
String getRelativePathFrom(const File &directoryToBeRelativeTo) const
const String & toString() const noexcept
bool isEmpty() const noexcept
An ID representing one of the items in a Project.
void ignoreUnused(Types &&...) noexcept
juce::File getEditFileFromProjectManager(Edit &edit)
Uses the ProjectManager to look up the file for an Edit.
Project::Ptr getProjectForEdit(const Edit &e)
Tries to find the project that contains this edit (but may return nullptr!)