-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruntime.coffee
More file actions
242 lines (215 loc) · 9.98 KB
/
runtime.coffee
File metadata and controls
242 lines (215 loc) · 9.98 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# sndflo - Flowhub.io sound processing runtime based on SuperCollider
# (c) 2014 Jon Nordby
# sndflo may be freely distributed under the MIT license
chai = require 'chai'
sndflo = require '../sndflo.coffee'
utils = require './utils'
fs = require 'fs'
debug = false
oscPort = 57230
wsPort = 3888
startupTimeout = 5*1000
readSync = (filename) ->
ret = ""
if fs.existsSync(filename)
ret = fs.readFileSync(filename, {encoding: 'utf-8'})
return ret
if readSync('/proc/cpuinfo').indexOf(': BCM2708') != -1
console.log 'is RPi'
startupTimeout = 50*1000
if process.env.SNDFLO_TESTS_DEBUG?
debug = true
oscPort = 57120
verbose = process.env.SNDFLO_TESTS_VERBOSE?
graph = 'graphs/sawsynth.json'
rtoptions =
port: wsPort
oscPort: oscPort
debug: debug
verbose: verbose
graph: graph
describe 'FBP runtime API,', () ->
ui = new utils.MockUi
runtime = new sndflo.Runtime rtoptions
before (done) ->
@timeout startupTimeout
runtime.start (err) ->
throw err if err
ui.connect rtoptions.port
ui.on 'connected', () ->
done()
after ->
runtime.stop()
ui.disconnect()
describe 'runtime info', ->
info = null
it 'should be returned on getruntime', (done) ->
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', () ->
info = ui.runtimeinfo
chai.expect(info).to.be.an 'object'
done()
it 'type should be "sndflo"', ->
chai.expect(info.type).to.equal "sndflo"
it 'protocol version should be "0.4"', ->
chai.expect(info.version).to.be.a "string"
chai.expect(info.version).to.equal "0.4"
it 'capabilities should include "protocol:component"', ->
chai.expect(info.capabilities).to.be.an "array"
chai.expect(info.capabilities).to.include 'protocol:component'
it 'capabilities should include "protocol:graph"', ->
chai.expect(info.capabilities).to.include 'protocol:graph'
it 'capabilities should include "protocol:network"', ->
chai.expect(info.capabilities).to.include 'protocol:network'
it 'capabilities should include "protocol:runtime"', ->
chai.expect(info.capabilities).to.include 'protocol:runtime'
it 'capabilities should include "component:getsource"', ->
chai.expect(info.capabilities).to.include 'component:getsource'
it 'capabilities should include "component:setsource"', ->
chai.expect(info.capabilities).to.include 'component:setsource'
describe 'initial ports information', ->
info = null
it 'should be returned on getruntime', (done) ->
ui.send "runtime", "getruntime"
ui.once 'runtime-ports-changed', (i) ->
info = i
chai.expect(info).to.be.an 'object'
done()
it 'should have intial graph', ->
chai.expect(info.graph).to.equal 'default/main'
it 'should have inports', ->
chai.expect(info.inPorts).to.be.an 'array'
chai.expect(info.inPorts).to.have.length 2
it 'should have outports', ->
chai.expect(info.outPorts).to.be.an 'array'
chai.expect(info.outPorts).to.have.length 0
# TODO: get rid of once https://github.com/noflo/noflo-ui/issues/390 is fixed
describe 'component:getsource for default graph', ->
info = null
it 'should be return json in component:source', (done) ->
ui.once 'component-source-changed', (source) ->
chai.expect(source.library).to.equal 'default'
chai.expect(source.name).to.equal 'main'
chai.expect(source.language).to.equal 'json'
chai.expect(JSON.parse(source.code)).to.contain.keys ['processes', 'connections']
done()
ui.send "component", "getsource", { name: 'default/main' }
describe 'removing a port', ->
it 'should return updated ports list', (done) ->
ui.send "graph", "removeinport", { public: 'freq' }
ui.once 'runtime-ports-changed', (info) ->
chai.expect(info.inPorts).to.be.an 'array'
chai.expect(info.inPorts).to.have.length 1
done()
describe 'adding a port', ->
it 'should return updated ports list', (done) ->
ui.send "graph", "addinport", { public: 'freq', node: 'f', port: 'freq' }
ui.once 'runtime-ports-changed', (info) ->
chai.expect(info.inPorts).to.be.an 'array'
chai.expect(info.inPorts).to.have.length 2
done()
describe.skip 'sending packet in', ->
graphName = 'default/main'
it 'gives packet out', (done) ->
ui.on 'runtime-packet', (data) ->
chai.expect(data.event).to.equal 'data'
chai.expect(data.graph).to.equal graphName
chai.expect(data.port).to.equal 'output'
chai.expect(data.payload).to.contain 'http://localhost'
chai.expect(data.payload).to.contain '/process'
done()
ui.send 'runtime', 'packet',
event: 'data'
graph: graphName
port: 'x'
payload: 32
describe 'sending component list', ->
it 'should return at least 3 components', (done) ->
ui.send "component", "list"
checkAdded = (name, definition) ->
numberOfComponents = Object.keys(ui.components).length
if numberOfComponents == 3
ui.removeListener 'component-added', checkAdded
done()
ui.on 'component-added', checkAdded
it 'should contain AudioOut', ->
chai.expect(ui.components['synth/AudioOut']).to.be.an 'object'
describe 'AudioOut component', ->
component = 'synth/AudioOut'
it 'should have a "in" bus port', ->
input = ui.components[component].inPorts.filter (p) -> p.id == 'in'
chai.expect(input.length).to.equal 1
chai.expect(input[0].type).to.equal "bus"
it 'should have icon "fa-music"', ->
chai.expect(ui.components[component].icon).to.equal 'music'
it 'should have description', ->
chai.expect(ui.components[component].description).to.equal 'Play out on soundcard'
describe 'building graph', ->
# TODO: find a way to verify results. Output to file?
it 'should not crash', (done) ->
ui.send "graph", "clear"
ui.send "graph", "addnode", {id: 'in', component: 'synth/SawWave'}
ui.send "graph", "addnode", {id: 'filter', component: 'synth/LowPassFilter'}
ui.send "graph", "addnode", {id: 'out', component: 'synth/AudioOut'}
ui.send "graph", "addedge", {src: {node: 'in', port: 'out'}, tgt: {node: 'filter', port: 'in'}}
ui.send "graph", "addedge", {src: {node: 'filter', port: 'out'}, tgt: {node: 'out', port: 'in'}}
ui.send "graph", "addinitial", {src: {data: 220}, tgt: {node: 'in', port: 'freq'}}
ui.send "graph", "addinitial", {src: {data: 330}, tgt: {node: 'filter', port: 'freq'}}
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', ->
done()
describe 'tearing down graph', ->
# TODO: find a way to verify results.
it 'should not crash', (done) ->
ui.send "graph", "removeinitial", {tgt: {node: 'in', port: 'freq'}}
ui.send "graph", "removeinitial", {tgt: {node: 'filter', port: 'freq'}}
ui.send "graph", "removeedge", {src: {node: 'in', port: 'out'}, tgt: {node: 'filter', port: 'in'}}
ui.send "graph", "removeedge", {src: {node: 'filter', port: 'out'}, tgt: {node: 'out', port: 'in'}}
ui.send "graph", "removenode", {id: 'in'}
ui.send "graph", "removenode", {id: 'filter'}
ui.send "graph", "removenode", {id: 'out'}
ui.send "runtime", "getruntime"
ui.once 'runtime-info-changed', ->
done()
describe 'component:getsource', ->
it 'should respond with compoent code', (done) ->
ui.send "component", "getsource", { name: "synth/AudioOut" }
ui.once 'component-source-changed', (info) ->
chai.expect(info.name).to.equal "synth/AudioOut"
chai.expect(info.language).to.equal 'supercollider'
chai.expect(info.code).to.contain 'SynthDef("AudioOut"'
done()
describe 'component:source', ->
code = """
SynthDef("AudioOut2", {
arg in=SndFloLibrary.silentIn, out=0;
Out.ar(out, In.ar(in))
},
metadata: (
description: "Uploaded over FBP"
)
)
"""
it 'should respond with component change', (done) ->
ui.send "component", "source", { name: "synth/AudioOut2", code }
ui.once 'component-added', (name, definition) ->
chai.expect(name).to.equal "synth/AudioOut2"
chai.expect(definition.description).to.equal 'Uploaded over FBP'
chai.expect(definition.icon).to.equal 'music'
chai.expect(definition.inPorts).to.have.length 1
chai.expect(definition.outPorts).to.have.length 1
done()
describe 'starting the network', ->
it 'should respond with network started', (done) ->
setTimeout ->
ui.send "network", "start"
ui.once 'network-running', (running) ->
done() if running
, 100
describe 'stopping the network', ->
it 'should respond with network stopped', (done) ->
setTimeout ->
ui.send "network", "stop"
ui.once 'network-running', (running) ->
done() if not running
, 300