Mercurial > hg > piper-cpp
comparison json/json-test.cpp @ 5:6e8607ebad03
Promote the more successful experiments (todo: get them to build again)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 13 May 2016 13:48:59 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:25499f505d0e | 5:6e8607ebad03 |
---|---|
1 | |
2 #include "VampJson.h" | |
3 | |
4 using std::cerr; | |
5 using std::endl; | |
6 | |
7 int main(int, char **) | |
8 { | |
9 Vamp::PluginBase::ParameterDescriptor d; | |
10 d.identifier = "threshold"; | |
11 d.name = "Energy rise threshold"; | |
12 d.description = "Energy rise within a frequency bin necessary to count toward broadband total"; | |
13 d.unit = "dB"; | |
14 d.minValue = 0; | |
15 d.maxValue = 20.5; | |
16 d.defaultValue = 3; | |
17 d.isQuantized = false; | |
18 cerr << VampJson::fromParameterDescriptor(d).dump() << endl; | |
19 | |
20 Vamp::Plugin::OutputDescriptor od; | |
21 od.identifier = "powerspectrum"; | |
22 od.name = "Power Spectrum"; | |
23 od.description = "Power values of the frequency spectrum bins calculated from the input signal"; | |
24 od.unit = ""; | |
25 od.hasFixedBinCount = true; | |
26 od.binCount = 513; | |
27 od.hasKnownExtents = false; | |
28 od.isQuantized = false; | |
29 od.sampleType = Vamp::Plugin::OutputDescriptor::OneSamplePerStep; | |
30 cerr << VampJson::fromOutputDescriptor(od).dump() << endl; | |
31 | |
32 cerr << VampJson::fromFeature(Vamp::Plugin::Feature()).dump() << endl; | |
33 | |
34 Vamp::Plugin::Feature f; | |
35 f.hasTimestamp = true; | |
36 f.timestamp = Vamp::RealTime::fromSeconds(3.14159); | |
37 f.hasDuration = false; | |
38 f.values = { 1, 2, 3.000001, 4, 5, 6, 6.5, 7 }; | |
39 f.label = "A feature"; | |
40 cerr << VampJson::fromFeature(f).dump() << endl; | |
41 | |
42 Vamp::Plugin::FeatureSet fs; | |
43 fs[0].push_back(f); | |
44 std::string fs_str = VampJson::fromFeatureSet(fs).dump(); | |
45 cerr << fs_str << endl; | |
46 | |
47 std::string err; | |
48 | |
49 try { | |
50 Vamp::Plugin::ParameterDescriptor d1 = | |
51 VampJson::toParameterDescriptor | |
52 (json11::Json::parse | |
53 (VampJson::fromParameterDescriptor(d).dump(), err)); | |
54 if (err != "") { | |
55 cerr << "error returned from parser: " << err << endl; | |
56 } | |
57 cerr << "\nsuccessfully converted parameter descriptor back from json: serialising it again, we get:" << endl; | |
58 cerr << VampJson::fromParameterDescriptor(d1).dump() << endl; | |
59 } catch (std::runtime_error &e) { | |
60 cerr << "caught exception: " << e.what() << endl; | |
61 } | |
62 | |
63 try { | |
64 Vamp::Plugin::OutputDescriptor od1 = | |
65 VampJson::toOutputDescriptor | |
66 (json11::Json::parse | |
67 (VampJson::fromOutputDescriptor(od).dump(), err)); | |
68 if (err != "") { | |
69 cerr << "error returned from parser: " << err << endl; | |
70 } | |
71 cerr << "\nsuccessfully converted output descriptor back from json: serialising it again, we get:" << endl; | |
72 cerr << VampJson::fromOutputDescriptor(od1).dump() << endl; | |
73 } catch (std::runtime_error &e) { | |
74 cerr << "caught exception: " << e.what() << endl; | |
75 } | |
76 | |
77 try { | |
78 Vamp::Plugin::FeatureSet fs1 = | |
79 VampJson::toFeatureSet | |
80 (json11::Json::parse(fs_str, err)); | |
81 if (err != "") { | |
82 cerr << "error returned from parser: " << err << endl; | |
83 } | |
84 cerr << "\nsuccessfully converted feature set back from json: serialising it again, we get:" << endl; | |
85 cerr << VampJson::fromFeatureSet(fs1).dump() << endl; | |
86 } catch (std::runtime_error &e) { | |
87 cerr << "caught exception: " << e.what() << endl; | |
88 } | |
89 | |
90 return 0; | |
91 } | |
92 | |
93 | |
94 |