119 lines
4.4 KiB
JSON
119 lines
4.4 KiB
JSON
{
|
|
"source": "JSON",
|
|
"data": "BLOCK",
|
|
"version": "0.0.1",
|
|
"type": "javascript.adsr",
|
|
"language": "javascript",
|
|
"extension": "webaudio",
|
|
"help": "ADSR",
|
|
"label": "ADSR",
|
|
"color": "#D3C124",
|
|
"group": "Sound",
|
|
"codes": [
|
|
{
|
|
"name": "function",
|
|
"code": "\nEnvelope = function(context, a, d, s, r, g) {\nthis.node = context.createGain()\nthis.context = context;\nthis.node.gain.value = 0;\nthis.a = a / 1000.0;\nthis.d = d / 1000.0;\nthis.s = s / 1000.0;\nthis.r = r / 1000.0;\nthis.g = g;\n}\n\nEnvelope.prototype.play = function(e) {\nvar time = this.context.currentTime;\n// Zero\nthis.node.gain.linearRampToValueAtTime(0, time);\n// Attack time\ntime += this.a;\nthis.node.gain.linearRampToValueAtTime(1, time);\n// Decay time\ntime += this.d;\nthis.node.gain.linearRampToValueAtTime(0.5, time);\n// Sustain time (do nothing)\ntime += this.s;\n// Release time\ntime += this.r;\nthis.node.gain.linearRampToValueAtTime(0, time);\n}\n\nEnvelope.prototype.seta = function(a) {\n this.a = parseFloat(a)/1000.0;\n}\n\nEnvelope.prototype.setd = function(d) {\n this.d = parseFloat(d)/1000.0;\n}\n\nEnvelope.prototype.sets = function(s) {\n this.s = parseFloat(s)/1000.0;\n}\n\nEnvelope.prototype.setr = function(r) {\n this.r = parseFloat(r)/1000.0;\n}\n\nEnvelope.prototype.setg = function(g) {\n this.g = parseFloat(g);\n}\n"
|
|
},
|
|
{
|
|
"name": "declaration",
|
|
"code": "\n// block_$id$ = $label$\n\nvar block_$id$_obj = new Envelope(context, $prop[a]$, $prop[d]$, $prop[s]$, $prop[r]$, $prop[g]$);\nvar $port[input]$ = block_$id$_obj.node;\nvar $port[output]$ = block_$id$_obj.node;\n\nvar $port[a]$ = function(value){\n block_$id$_obj.seta(value);\n};\n\nvar $port[d]$ = function(value){\n block_$id$_obj.setd(value);\n};\n\nvar $port[s]$ = function(value){\n block_$id$_obj.sets(value);\n};\n\nvar $port[r]$ = function(value){\n block_$id$_obj.setr(value);\n};\n\nvar $port[g]$ = function(value){\n block_$id$_obj.setg(value);\n};\n\nvar $port[play]$ = function(value){\n if (value != 0) {\n block_$id$_obj.play();\n }\n};\n"
|
|
}
|
|
],
|
|
"properties": [
|
|
{
|
|
"name": "a",
|
|
"label": "Attack",
|
|
"type": "Float",
|
|
"lower": 0,
|
|
"upper": 10000,
|
|
"step": 1,
|
|
"value": 200
|
|
},
|
|
{
|
|
"name": "d",
|
|
"label": "Decay",
|
|
"type": "Float",
|
|
"lower": 0,
|
|
"upper": 10000,
|
|
"step": 1,
|
|
"value": 20
|
|
},
|
|
{
|
|
"name": "s",
|
|
"label": "Sustain",
|
|
"type": "Float",
|
|
"lower": 0,
|
|
"upper": 10000,
|
|
"step": 1,
|
|
"value": 100
|
|
},
|
|
{
|
|
"name": "r",
|
|
"label": "Release",
|
|
"type": "Float",
|
|
"lower": 0,
|
|
"upper": 10000,
|
|
"step": 1,
|
|
"value": 50
|
|
},
|
|
{
|
|
"name": "g",
|
|
"label": "Gain",
|
|
"type": "Float",
|
|
"lower": 0,
|
|
"upper": 10000,
|
|
"step": 1,
|
|
"value": 0.8
|
|
}
|
|
],
|
|
"ports": [
|
|
{
|
|
"conn_type": "input",
|
|
"name": "input",
|
|
"label": "Input",
|
|
"type": "javascript.sound"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "a",
|
|
"label": "Attack",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "d",
|
|
"label": "Decay",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "s",
|
|
"label": "Sustain",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "r",
|
|
"label": "Release",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "g",
|
|
"label": "Gain",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "input",
|
|
"name": "play",
|
|
"label": "Event Play",
|
|
"type": "javascript.float"
|
|
},
|
|
{
|
|
"conn_type": "output",
|
|
"name": "output",
|
|
"label": "Output",
|
|
"type": "javascript.sound"
|
|
}
|
|
]
|
|
} |