Skip to content

Commit fe5b20d

Browse files
authored
Merge branch 'main' into dev/ai_module
2 parents d8c52ef + 3158fb5 commit fe5b20d

46 files changed

Lines changed: 9881 additions & 1538 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 60 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading

examples/graphics/source/examples/Svg.h

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ class SvgDemo : public yup::Component
2727
SvgDemo()
2828
{
2929
updateListOfSvgFiles();
30+
loadDemoFont();
3031

3132
parseSvgFile (currentSvgFileIndex);
3233
}
3334

34-
void resized() override
35-
{
36-
//drawable.setBounds (getLocalBounds());
37-
}
38-
3935
void mouseDown (const yup::MouseEvent& event) override
4036
{
41-
++currentSvgFileIndex;
37+
if (event.isLeftButtonDown())
38+
++currentSvgFileIndex;
39+
else if (event.isRightButtonDown())
40+
--currentSvgFileIndex;
4241

4342
parseSvgFile (currentSvgFileIndex);
4443
}
@@ -59,12 +58,17 @@ class SvgDemo : public yup::Component
5958
.getParentDirectory()
6059
.getParentDirectory();
6160

61+
dataDirectory = riveBasePath.getChildFile ("data");
62+
6263
auto files = riveBasePath.getChildFile ("data/svg").findChildFiles (yup::File::findFiles, false, "*.svg");
6364
if (files.isEmpty())
6465
return;
6566

6667
for (const auto& svgFile : files)
68+
{
69+
//if (svgFile.getFileName() == "mozilla2.svg")
6770
svgFiles.add (svgFile);
71+
}
6872
}
6973

7074
void parseSvgFile (int index)
@@ -83,12 +87,97 @@ class SvgDemo : public yup::Component
8387
YUP_DBG ("Showing " << svgFiles[currentSvgFileIndex].getFullPathName());
8488

8589
drawable.clear();
86-
drawable.parseSVG (svgFiles[currentSvgFileIndex]);
90+
drawable.parseSVG (svgFiles[currentSvgFileIndex], createParseOptions (svgFiles[currentSvgFileIndex]));
8791

8892
repaint();
8993
}
9094

95+
void loadDemoFont()
96+
{
97+
yup::Font font;
98+
if (font.loadFromFile (dataDirectory.getChildFile ("RobotoFlex-VariableFont.ttf")).wasOk())
99+
demoFont = std::move (font);
100+
}
101+
102+
std::optional<yup::Image> fetchHttpImage (const yup::String& href)
103+
{
104+
if (! href.startsWithIgnoreCase ("http:") && ! href.startsWithIgnoreCase ("https:"))
105+
return std::nullopt;
106+
107+
if (httpImageCache.contains (href))
108+
return httpImageCache[href];
109+
110+
yup::MemoryBlock imageData;
111+
int statusCode = 0;
112+
113+
auto streamOptions = yup::URL::InputStreamOptions (yup::URL::ParameterHandling::inAddress)
114+
.withConnectionTimeoutMs (5000)
115+
.withNumRedirectsToFollow (5)
116+
.withStatusCode (&statusCode)
117+
.withExtraHeaders ("User-Agent: YUP SVG Demo\r\nAccept: image/*\r\n");
118+
119+
auto stream = yup::URL (href).createInputStream (streamOptions);
120+
if (stream == nullptr)
121+
{
122+
YUP_DBG ("Unable to fetch SVG image href: " << href);
123+
return std::nullopt;
124+
}
125+
126+
stream->readIntoMemoryBlock (imageData);
127+
128+
if ((statusCode != 0 && (statusCode < 200 || statusCode >= 300)) || imageData.isEmpty())
129+
{
130+
YUP_DBG ("Unable to fetch SVG image href: " << href << " status: " << statusCode);
131+
return std::nullopt;
132+
}
133+
134+
auto imageResult = yup::Image::loadFromData (imageData.asBytes());
135+
if (imageResult.failed())
136+
{
137+
YUP_DBG ("Unable to decode SVG image href: " << href << " error: " << imageResult.getErrorMessage());
138+
return std::nullopt;
139+
}
140+
141+
auto image = imageResult.getValue();
142+
httpImageCache.set (href, image);
143+
return image;
144+
}
145+
146+
yup::Drawable::ParseOptions createParseOptions (const yup::File& svgFile)
147+
{
148+
yup::Drawable::ParseOptions options;
149+
options.baseDirectory = svgFile.getParentDirectory();
150+
options.imageResolver = [this] (yup::StringRef href, const yup::File&) -> std::optional<yup::Image>
151+
{
152+
return fetchHttpImage (yup::String (href.text));
153+
};
154+
155+
options.fontResolver = [this] (yup::StringRef, float fontSize, int weight, bool italic) -> std::optional<yup::Font>
156+
{
157+
if (demoFont)
158+
{
159+
auto font = *demoFont;
160+
font.setAxisValue ("wght", static_cast<float> (weight));
161+
if (italic)
162+
font.setAxisValue ("slnt", -10.0f);
163+
else
164+
font.setAxisValue ("slnt", 0.0f);
165+
return font.withHeight (fontSize);
166+
}
167+
168+
if (auto theme = yup::ApplicationTheme::getGlobalTheme())
169+
return theme->getDefaultFont().withHeight (fontSize);
170+
171+
return std::nullopt;
172+
};
173+
174+
return options;
175+
}
176+
91177
yup::Drawable drawable;
92178
yup::Array<yup::File> svgFiles;
179+
yup::File dataDirectory;
180+
std::optional<yup::Font> demoFont;
181+
yup::HashMap<yup::String, yup::Image> httpImageCache;
93182
int currentSvgFileIndex = 0;
94183
};

modules/yup_audio_basics/sources/yup_BufferingAudioSource.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,12 @@ void BufferingAudioSource::releaseResources()
107107

108108
buffer.setSize (numberOfChannels, 0);
109109

110-
// MSVC2017 seems to need this if statement to not generate a warning during linking.
111-
// As source is set in the constructor, there is no way that source could
112-
// ever equal this, but it seems to make MSVC2017 happy.
113-
if (source != this)
114-
source->releaseResources();
110+
source->releaseResources();
115111
}
116112

117113
void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
118114
{
119-
const auto bufferRange = getValidBufferRange (info.numSamples);
115+
auto [playPos, bufferRange] = getValidBufferRangeAndAdvance (info.numSamples);
120116

121117
if (bufferRange.isEmpty())
122118
{
@@ -143,8 +139,8 @@ void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info
143139
{
144140
jassert (buffer.getNumSamples() > 0);
145141

146-
const auto startBufferIndex = (int) ((validStart + nextPlayPos) % buffer.getNumSamples());
147-
const auto endBufferIndex = (int) ((validEnd + nextPlayPos) % buffer.getNumSamples());
142+
const auto startBufferIndex = (int) ((validStart + playPos) % buffer.getNumSamples());
143+
const auto endBufferIndex = (int) ((validEnd + playPos) % buffer.getNumSamples());
148144

149145
if (startBufferIndex < endBufferIndex)
150146
{
@@ -155,13 +151,10 @@ void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info
155151
const auto initialSize = buffer.getNumSamples() - startBufferIndex;
156152

157153
info.buffer->copyFrom (chan, info.startSample + validStart, buffer, chan, startBufferIndex, initialSize);
158-
159154
info.buffer->copyFrom (chan, info.startSample + validStart + initialSize, buffer, chan, 0, (validEnd - validStart) - initialSize);
160155
}
161156
}
162157
}
163-
164-
nextPlayPos += info.numSamples;
165158
}
166159

167160
bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelInfo& info, uint32 timeout)
@@ -235,6 +228,18 @@ Range<int> BufferingAudioSource::getValidBufferRange (int numSamples) const
235228
(int) (jlimit (bufferValidStart, bufferValidEnd, pos + numSamples) - pos) };
236229
}
237230

231+
std::tuple<int64, Range<int>> BufferingAudioSource::getValidBufferRangeAndAdvance (int numSamples)
232+
{
233+
const ScopedLock sl (bufferRangeLock);
234+
235+
const auto pos = nextPlayPos.load();
236+
237+
nextPlayPos = pos + numSamples;
238+
239+
return std::make_tuple (
240+
pos, Range<int> { (int) (jlimit (bufferValidStart, bufferValidEnd, pos) - pos), (int) (jlimit (bufferValidStart, bufferValidEnd, pos + numSamples) - pos) });
241+
}
242+
238243
bool BufferingAudioSource::readNextBufferChunk()
239244
{
240245
int64 newBVS, newBVE, sectionToReadStart, sectionToReadEnd;

modules/yup_audio_basics/sources/yup_BufferingAudioSource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class YUP_API BufferingAudioSource : public PositionableAudioSource
117117
private:
118118
//==============================================================================
119119
Range<int> getValidBufferRange (int numSamples) const;
120+
std::tuple<int64, Range<int>> getValidBufferRangeAndAdvance (int numSamples);
120121
bool readNextBufferChunk();
121122
void readBufferSection (int64 start, int length, int bufferOffset);
122123
int useTimeSlice() override;

modules/yup_core/containers/yup_HashMap.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,35 @@ class HashMap
134134

135135
public:
136136
//==============================================================================
137+
/** Creates an empty hash-map.
138+
*/
139+
HashMap()
140+
: HashMap (defaultHashTableSize, HashFunctionType())
141+
{
142+
}
143+
144+
/** Creates an empty hash-map.
145+
146+
@param numberOfSlots Specifies the number of hash entries the map will use. This will be
147+
the "upperLimit" parameter that is passed to your generateHash()
148+
function. The number of hash slots will grow automatically if necessary,
149+
or it can be remapped manually using remapTable().
150+
*/
151+
explicit HashMap (int numberOfSlots)
152+
: HashMap (numberOfSlots, HashFunctionType())
153+
{
154+
}
155+
137156
/** Creates an empty hash-map.
138157
139158
@param numberOfSlots Specifies the number of hash entries the map will use. This will be
140159
the "upperLimit" parameter that is passed to your generateHash()
141160
function. The number of hash slots will grow automatically if necessary,
142161
or it can be remapped manually using remapTable().
143162
@param hashFunction An instance of HashFunctionType, which will be copied and
144-
stored to use with the HashMap. This parameter can be omitted
145-
if HashFunctionType has a default constructor.
163+
stored to use with the HashMap.
146164
*/
147-
explicit HashMap (int numberOfSlots = defaultHashTableSize,
148-
HashFunctionType hashFunction = HashFunctionType())
165+
HashMap (int numberOfSlots, HashFunctionType hashFunction)
149166
: hashFunctionToUse (hashFunction)
150167
{
151168
hashSlots.insertMultiple (0, nullptr, numberOfSlots);

modules/yup_core/files/yup_File.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class YUP_API File final
8181
On the Mac/Linux, the path can include "~" notation for referring to
8282
user home directories.
8383
*/
84-
File (const String& absolutePath);
84+
explicit File (const String& absolutePath);
8585

8686
/** Creates a copy of another file object. */
8787
File (const File&);

modules/yup_core/files/yup_FileSearchPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void FileSearchPath::removeRedundantPaths()
138138
{
139139
const auto checkedIsChildOf = [&] (const auto& a, const auto& b)
140140
{
141-
return File::isAbsolutePath (a) && File::isAbsolutePath (b) && File (a).isAChildOf (b);
141+
return File::isAbsolutePath (a) && File::isAbsolutePath (b) && File (a).isAChildOf (File (b));
142142
};
143143

144144
const auto fContainsDirectory = [&] (const auto& f)

modules/yup_core/native/yup_Files_android.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ File AndroidContentUriResolver::getLocalFileFromContentUri (const URL& url)
251251
if (type == "image")
252252
type = "images";
253253

254-
return getCursorDataColumn (URL ("content://media/external/" + type + "/media"),
255-
"_id=?",
256-
StringArray { mediaId });
254+
return File (getCursorDataColumn (URL ("content://media/external/" + type + "/media"),
255+
"_id=?",
256+
StringArray { mediaId }));
257257
}
258258

259-
return getCursorDataColumn (url);
259+
return File (getCursorDataColumn (url));
260260
}
261261

262262
String AndroidContentUriResolver::getFileNameFromContentUri (const URL& url)
@@ -745,7 +745,7 @@ static File getAppDataDir (bool dataDir)
745745
LocalRef<jobject> applicationInfo (env->CallObjectMethod (getAppContext().get(), AndroidContext.getApplicationInfo));
746746
LocalRef<jobject> jString (env->GetObjectField (applicationInfo.get(), dataDir ? AndroidApplicationInfo.dataDir : AndroidApplicationInfo.publicSourceDir));
747747

748-
return { yupString ((jstring) jString.get()) };
748+
return File (yupString ((jstring) jString.get()));
749749
}
750750

751751
File File::getSpecialLocation (const SpecialLocationType type)

0 commit comments

Comments
 (0)