aboutsummaryrefslogtreecommitdiff
path: root/examples/example4.csd
blob: b6bc78c3c795f725de6ea824b39106be5a20866e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
    csound-json example 4

    fill JSON object with various data at init time

*/
<CsoundSynthesizer>
<CsLicence>
    Released into the public domain under the Unlicense license
    http://unlicense.org/
</CsLicence>
<CsOptions>
-d
-m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 64
nchnls = 2
0dbfs = 1


instr boot

    ; empty object
    iJson jsoninit

    ; add key/value combination as "description" object
    Skeys[] fillarray "colour", "taste", "smell"
    Svalues[] fillarray "blue", "sweet", "vile"
    iJsonSub1 jsoninit
    jsoninsertval iJsonSub1, Skeys, Svalues
    jsoninsert iJson, "description", iJsonSub1

    ; add key/value combination and additional value to iJsonSub2
    Skeys[] fillarray "height", "width"
    ivalues[] fillarray 35.4, 6.41
    iJsonSub2 jsoninit
    jsoninsertval iJsonSub2, Skeys, ivalues
    jsoninsertval iJsonSub2, "depth", 16.439

    ; add iJsonSub2 to array along with new specified string objects
    iJsonObjects[] fillarray iJsonSub2, jsonloads("{\"not\": \"much\"}"), jsonloads("[1,2,3]")

    ; add all of the above iJsonObjects back into the main object under "measurements" key
    jsoninsert iJson, "measurements", iJsonObjects

    ; show the result
    prints sprintf("%s\n\n", jsondumps(iJson))
endin


</CsInstruments>
<CsScore>
i"boot" 0 1
</CsScore>
</CsoundSynthesizer>