tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ReferencedMaterialList.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14//==============================================================================
19{
20public:
21 ReferencedMaterialList (ProjectManager& pm, double handleSizeToUse)
22 : projectManager (pm), handleSize (handleSizeToUse) {}
23
24 //==============================================================================
27 {
28 if (auto projectItem = projectManager.getProjectItem (id))
29 add (projectItem, 0, projectItem->getLength());
30 }
31
33 void add (ProjectItemID id, double startTime, double length)
34 {
35 if (auto projectItem = projectManager.getProjectItem (id))
36 {
37 projectItem->verifyLength();
38 const double srcLen = projectItem->getLength() + 0.001;
39
40 const double start = juce::jlimit (0.0, srcLen, startTime - handleSize);
41 const double end = juce::jlimit (0.0, srcLen, startTime + length + handleSize);
42
43 add (projectItem, start, end - start);
44 }
45 }
46
47 void add (const Exportable::ReferencedItem& item)
48 {
49 add (item.itemID, item.firstTimeUsed, item.lengthUsed);
50 }
51
52 void add (const ProjectItem::Ptr& mop, double start, double length)
53 {
54 if (length <= 0.0)
55 return;
56
57 auto itemID = mop->getID();
58
59 for (int i = ids.size(); --i >= 0;)
60 {
61 if (itemID == ids.getReference(i))
62 {
63 excerpts[i]->addInterval (start, length);
64 return;
65 }
66 }
67
68 ids.add (itemID);
69 auto intervals = new IntervalList();
70 intervals->addInterval (start, length);
71 excerpts.add (intervals);
72 }
73
74 //==============================================================================
75 juce::String getReassignedFileName (ProjectItemID id, double requiredTime,
76 double& newStartTime, double& newLength) const
77 {
78 requiredTime = juce::jmax (0.0, requiredTime);
79
80 if (auto il = getIntervalsForID (id))
81 {
82 for (int j = il->getNumIntervals(); --j >= 0;)
83 {
84 if (requiredTime >= il->getStart(j) - 0.001
85 && requiredTime <= il->getEnd(j))
86 {
87 newStartTime = il->getStart(j);
88 newLength = il->getLength(j);
89
90 if (auto projectItem = projectManager.getProjectItem (id))
91 {
92 auto withoutExtension = juce::File::getCurrentWorkingDirectory()
93 .getChildFile (projectItem->getFileName())
95
96 if (j > 0)
97 withoutExtension << "_" << j;
98
99 return withoutExtension
100 + projectItem->getFileName()
101 .substring (projectItem->getFileName().lastIndexOfChar ('.'));
102 }
103 }
104 }
105
106 // should have found a suitable interval
108 }
109
110 return {};
111 }
112
113 int getTotalNumThingsToExport()
114 {
115 int tot = 0;
116
117 for (auto e : excerpts)
118 tot += e->getNumIntervals();
119
120 return tot;
121 }
122
123 //==============================================================================
126 {
127 IntervalList() {}
128
129 int getNumIntervals() const { return starts.size(); }
130 double getStart (int index) const { return starts[index]; }
131 double getLength (int index) const { return ends[index] - starts[index]; }
132 double getEnd (int index) const { return ends[index]; }
133
134 void addInterval (double start, double length)
135 {
136 starts.add (start);
137 ends.add (start + length);
138
139 // merge all the intervals
140 for (int i = getNumIntervals(); --i >= 0;)
141 {
142 double s1 = getStart(i);
143 double e1 = getEnd(i);
144
145 for (int j = getNumIntervals(); --j > i;)
146 {
147 const double s2 = getStart(j);
148 const double e2 = getEnd(j);
149
150 if (e1 >= s2 && s1 <= e2)
151 {
152 s1 = juce::jmin (s1, s2);
153 e1 = juce::jmax (e1, e2);
154 starts.remove (j);
155 ends.remove (j);
156 }
157 }
158
159 starts.set (i, s1);
160 ends.set (i, e1);
161 }
162 }
163
164 private:
165 juce::Array<double> starts, ends;
166 };
167
168 //==============================================================================
169 ProjectManager& projectManager;
171
172private:
174 double handleSize;
175
176 const IntervalList* getIntervalsForID (ProjectItemID id) const
177 {
178 for (int i = ids.size(); --i >= 0;)
179 if (id == ids.getReference(i))
180 return excerpts[i];
181
182 return {};
183 }
184
186};
187
188}} // namespace tracktion { inline namespace engine
int size() const noexcept
void remove(int indexToRemove)
void add(const ElementType &newElement)
void set(int indexToChange, ParameterType newValue)
ElementType & getReference(int index) noexcept
File getChildFile(StringRef relativeOrAbsolutePath) const
static File getCurrentWorkingDirectory()
String getFileNameWithoutExtension() const
String substring(int startIndex, int endIndex) const
An ID representing one of the items in a Project.
ProjectItem::Ptr getProjectItem(ProjectItemID)
tries to find the project that contains an id, and open it as a ProjectItem.
A list of all the source files needed by an edit (or a section of an edit).
void add(ProjectItemID id)
Adds the whole of a media id to the list.
void add(ProjectItemID id, double startTime, double length)
Adds just a section of a media id to the list.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
constexpr Type jmin(Type a, Type b)
constexpr Type jmax(Type a, Type b)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Represents the sections of a wave file that are being used.