Permalink
Browse files

offsets as a parameter like volume

  • Loading branch information...
1 parent 9389b77 commit 645251ae774c5b1f2a30e31c36a6479459c2fe58 @substack committed Sep 6, 2012
Showing with 28 additions and 5 deletions.
  1. +4 −0 api.txt
  2. +1 −1 package.json
  3. +6 −0 readme.markdown
  4. +17 −4 server.js
View
4 api.txt
@@ -22,3 +22,7 @@ To adjust the volume of a channel, send a POST:
$ curl -X POST -d volume=0.5 http://localhost:5000/3
+To adjust the offset of a channel, send a POST:
+
+ $ curl -X POST -d offset=120 http://localhost:5000/3
+
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "baudio-party",
- "version" : "0.0.5",
+ "version" : "0.0.6",
"description" : "javascript music party http server",
"bin" : {
"baudio-party" : "server.js"
View
6 readme.markdown
@@ -73,6 +73,12 @@ To adjust the volume of a channel, send a POST:
$ curl -X POST -d volume=0.5 http://localhost:5000/3
```
+To adjust the offset of a channel, send a POST:
+
+```
+$ curl -X POST -d offset=120 http://localhost:5000/3
+```
+
# usage
```
View
21 server.js
@@ -50,12 +50,14 @@ function save (ch, src, cb) {
channels[ch].cb = fn;
channels[ch].source = src;
if (!channels[ch].volume) channels[ch].volume = 1.0;
+ if (!channels[ch].offset) channels[ch].offset = 0;
cb();
}
for (var i = 0; i < argv.channels; i++) (function (i) {
- b.push(function () {
- return channels[i].volume * channels[i].cb.apply(this, arguments);
+ b.push(function (t, counter) {
+ var to = (channels[i].offset || 0) + t;
+ return channels[i].volume * channels[i].cb.call(this, to, counter);
});
save(i, 'return ' + function () { return 0 });
})(i);
@@ -117,11 +119,22 @@ server.on('request', function (req, res) {
req.on('end', function () {
var params = qs.parse(data);
+ var matched = false;
+
if (params.volume) {
channels[ch].volume = Number(params.volume);
- res.end('set volume to ' + channels[ch].volume + '\n');
+ res.write('set volume to ' + channels[ch].volume + '\n');
+ matched = true;
+ }
+
+ if (params.offset) {
+ channels[ch].offset = Number(params.offset);
+ res.write('set offset to ' + channels[ch].offset + '\n');
+ matched = true;
}
- else res.end('unknown parameters specified\n')
+
+ if (!matched) res.end('unknown parameters specified\n')
+ else res.end()
});
});

0 comments on commit 645251a

Please sign in to comment.