Skip to content

Commit 93a4906

Browse files
authored
Var conversion bugfix (#46)
* Fix bug where ValueTree property was incorrectly converted to string * Fix formatting
1 parent 607d725 commit 93a4906

File tree

5 files changed

+68
-59
lines changed

5 files changed

+68
-59
lines changed

Source/CommandLine.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,35 @@ File getOutputDir (const ArgumentList& args)
175175

176176
std::vector<double> getSampleRates (const ArgumentList& args)
177177
{
178-
StringArray input = StringArray::fromTokens(getOptionValue (args, "--sample-rates", String ("44100,48000,96000") , "Missing sample rate list argument!").toString(),
179-
",",
180-
"\""
181-
);
178+
StringArray input = StringArray::fromTokens (getOptionValue (args,
179+
"--sample-rates",
180+
String ("44100,48000,96000"),
181+
"Missing sample rate list argument!")
182+
.toString(),
183+
",",
184+
"\"");
182185
std::vector<double> output;
183-
for(String sr: input) {
184-
output.push_back(sr.getDoubleValue());
185-
}
186+
for (String sr : input)
187+
{
188+
output.push_back (sr.getDoubleValue());
189+
}
186190
return output;
187191
}
188192

189193
std::vector<int> getBlockSizes (const ArgumentList& args)
190194
{
191-
StringArray input = StringArray::fromTokens(getOptionValue (args, "--block-sizes", String ("64,128,256,512,1024") , "Missing block size list argument!").toString(),
192-
",",
193-
"\""
194-
);
195+
StringArray input = StringArray::fromTokens (getOptionValue (args,
196+
"--block-sizes",
197+
String ("64,128,256,512,1024"),
198+
"Missing block size list argument!")
199+
.toString(),
200+
",",
201+
"\"");
195202
std::vector<int> output;
196-
for(String sr: input) {
197-
output.push_back(sr.getIntValue());
198-
}
203+
for (String sr : input)
204+
{
205+
output.push_back (sr.getIntValue());
206+
}
199207
return output;
200208
}
201209

@@ -249,7 +257,7 @@ static Option possibleOptions[] =
249257
{ "--repeat", true },
250258
{ "--randomise", false },
251259
{ "--sample-rates", true },
252-
{ "--block-sizes", true },
260+
{ "--block-sizes", true },
253261
};
254262

255263
StringArray mergeEnvironmentVariables (StringArray args, std::function<String (const String& name, const String& defaultValue)> environmentVariableProvider = [] (const String& name, const String& defaultValue) { return SystemStats::getEnvironmentVariable (name, defaultValue); })

Source/Validator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ class ValidatorChildProcess : public ChildProcessSlave,
481481
options.outputDir = File (v[IDs::outputDir].toString());
482482
options.withGUI = v.getProperty (IDs::withGUI, true);
483483
options.disabledTests = StringArray::fromLines (v.getProperty (IDs::disabledTests).toString());
484-
options.sampleRates = juce::VariantConverter<std::vector<double>>::fromVar( v.getProperty (IDs::sampleRates).toString() );
485-
options.blockSizes = juce::VariantConverter<std::vector<int>>::fromVar( v.getProperty (IDs::blockSizes).toString() );
486-
484+
options.sampleRates = juce::VariantConverter<std::vector<double>>::fromVar (v.getProperty (IDs::sampleRates));
485+
options.blockSizes = juce::VariantConverter<std::vector<int>>::fromVar (v.getProperty (IDs::blockSizes));
486+
487487
for (auto c : v)
488488
{
489489
String fileOrID;
@@ -674,8 +674,8 @@ class ValidatorParentProcess : public ChildProcessMaster
674674
v.setProperty (IDs::outputDir, options.outputDir.getFullPathName(), nullptr);
675675
v.setProperty (IDs::withGUI, options.withGUI, nullptr);
676676
v.setProperty (IDs::disabledTests, options.disabledTests.joinIntoString ("\n"), nullptr);
677-
v.setProperty (IDs::sampleRates, juce::VariantConverter<std::vector<double>>::toVar(options.sampleRates), nullptr);
678-
v.setProperty (IDs::blockSizes, juce::VariantConverter<std::vector<int>>::toVar(options.blockSizes), nullptr);
677+
v.setProperty (IDs::sampleRates, juce::VariantConverter<std::vector<double>>::toVar (options.sampleRates), nullptr);
678+
v.setProperty (IDs::blockSizes, juce::VariantConverter<std::vector<int>>::toVar (options.blockSizes), nullptr);
679679

680680
return v;
681681
}

Source/Validator.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,29 @@
2727

2828
namespace juce
2929
{
30-
template<typename T>
30+
template <typename T>
3131
struct VariantConverter<std::vector<T>>
3232
{
3333
static std::vector<T> fromVar (const var& v)
3434
{
35-
jassert (v.isArray());
36-
Array<var>* vr = v.getArray();
35+
jassert (v.isString());
36+
3737
std::vector<T> vc;
38-
for (var vItem : *vr)
39-
{
40-
vc.push_back (static_cast<T> (vItem));
41-
}
38+
39+
for (auto token : StringArray::fromTokens (v.toString(), ",", ""))
40+
vc.push_back (static_cast<T> (var (token)));
41+
4242
return vc;
4343
}
44+
4445
static var toVar (const std::vector<T>& vc)
4546
{
46-
juce::var vr;
47-
for (T t : vc)
48-
{
49-
vr.append (t);
50-
}
51-
return vr;
47+
if (vc.empty())
48+
return "";
49+
50+
String text { vc.front() };
51+
std::for_each (std::next (vc.begin()), vc.end(), [&] (const T& t) { text << ',' << t; });
52+
return text;
5253
}
5354
};
5455
}// namespace juce

Source/tests/BasicTests.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct EditorWhilstProcessingTest : public PluginTest
137137

138138
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
139139
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
140-
140+
141141
jassert (sampleRates.size()>0 && blockSizes.size()>0);
142142
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
143143

@@ -183,18 +183,18 @@ struct AudioProcessingTest : public PluginTest
183183
: PluginTest ("Audio processing", 3)
184184
{
185185
}
186-
186+
187187
static void runAudioProcessingTest (PluginTests& ut, AudioPluginInstance& instance,
188188
bool callReleaseResourcesBeforeSampleRateChange)
189189
{
190190
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
191-
191+
192192
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
193193
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
194-
194+
195195
jassert (sampleRates.size()>0 && blockSizes.size()>0);
196196
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
197-
197+
198198
const int numBlocks = 10;
199199
auto r = ut.getRandom();
200200

@@ -203,12 +203,12 @@ struct AudioProcessingTest : public PluginTest
203203
for (auto bs : blockSizes)
204204
{
205205
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS]")
206-
.replace ("SR", String(sr,0) , false)
207-
.replace ("BS", String(bs), false));
208-
206+
.replace ("SR", String (sr, 0), false)
207+
.replace ("BS", String (bs), false));
208+
209209
if (callReleaseResourcesBeforeSampleRateChange)
210210
instance.releaseResources();
211-
211+
212212
instance.prepareToPlay (sr, bs);
213213

214214
const int numChannelsRequired = jmax (instance.getTotalNumInputChannels(), instance.getTotalNumOutputChannels());
@@ -354,11 +354,11 @@ struct AutomationTest : public PluginTest
354354
{
355355
const bool subnormalsAreErrors = ut.getOptions().strictnessLevel > 5;
356356
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
357-
357+
358358
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
359359
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
360-
361-
jassert (sampleRates.size()>0 && blockSizes.size()>0);
360+
361+
jassert (sampleRates.size() > 0 && blockSizes.size() > 0);
362362
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
363363

364364
auto r = ut.getRandom();
@@ -369,9 +369,9 @@ struct AutomationTest : public PluginTest
369369
{
370370
const int subBlockSize = 32;
371371
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS] and sub-block size [SB]")
372-
.replace ("SR", String(sr,0), false)
373-
.replace ("BS", String(bs), false)
374-
.replace ("SB", String (subBlockSize), false));
372+
.replace ("SR", String (sr, 0), false)
373+
.replace ("BS", String (bs), false)
374+
.replace ("SB", String (subBlockSize), false));
375375

376376
instance.releaseResources();
377377
instance.prepareToPlay (sr, bs);

Source/tests/ExtremeTests.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ struct AllocationsInRealTimeThreadTest : public PluginTest
2626
void runTest (PluginTests& ut, AudioPluginInstance& instance) override
2727
{
2828
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
29-
29+
3030
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
3131
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
32-
33-
jassert (sampleRates.size()>0 && blockSizes.size()>0);
32+
33+
jassert (sampleRates.size() > 0 && blockSizes.size() > 0);
3434
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
3535

3636
const int numBlocks = 10;
@@ -41,8 +41,8 @@ struct AllocationsInRealTimeThreadTest : public PluginTest
4141
for (auto bs : blockSizes)
4242
{
4343
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS]")
44-
.replace ("SR", String(sr,0), false)
45-
.replace ("BS", String(bs), false));
44+
.replace ("SR", String (sr, 0), false)
45+
.replace ("BS", String (bs), false));
4646
instance.releaseResources();
4747
instance.prepareToPlay (sr, bs);
4848

@@ -108,21 +108,21 @@ struct LargerThanPreparedBlockSizeTest : public PluginTest
108108
ut.logMessage ("INFO: Skipping test for plugin format");
109109
return;
110110
}
111-
111+
112112
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
113113
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
114114

115-
jassert (sampleRates.size()>0 && blockSizes.size()>0);
116-
115+
jassert (sampleRates.size() > 0 && blockSizes.size() > 0);
116+
117117
for (auto sr : sampleRates)
118118
{
119119
for (auto preparedBlockSize : blockSizes)
120120
{
121121
const auto processingBlockSize = preparedBlockSize * 2;
122122
ut.logMessage (String ("Preparing with sample rate [SR] and block size [BS], processing with block size [BSP]")
123-
.replace ("SR", String(sr,0), false)
124-
.replace ("BSP", String (processingBlockSize), false)
125-
.replace ("BS", String(preparedBlockSize), false));
123+
.replace ("SR", String (sr, 0), false)
124+
.replace ("BSP", String (processingBlockSize), false)
125+
.replace ("BS", String (preparedBlockSize), false));
126126
instance.releaseResources();
127127
instance.prepareToPlay (sr, preparedBlockSize);
128128

0 commit comments

Comments
 (0)