Skip to content

Commit

Permalink
Move dict_utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Jun 7, 2015
1 parent f77a1f8 commit ee6edd5
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 96 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,28 @@ PREPROCESS=gcc\
MAX4LIVE=~/Music/Ableton/User\ Library/Presets/MIDI\ Effects/Max\ MIDI\ Effect

all:\
conductor\
crossmatrix\
lfo\
nanolaser\
onscene\
show_runner\
speedlimit\
tests\
wind_mapper\
conductor\
lfo\
onscene\
write_lom


crossmatrix: max/crossmatrix/crossmatrix.jso
nanolaser : max/nanolaser/nanolaser.jso
speedlimit: max/speedlimit/speedlimit.jso
show_runner: max/wind_mapper/show_runner.jso
speedlimit: max/speedlimit/speedlimit.jso
wind_mapper: max/wind_mapper/wind_mapper.jso
tests: max/tests/run_tests.jso

conductor: ${MAX4LIVE}/conductor/conductor.jso
onscene: ${MAX4LIVE}/onscene/onscene.jso
lfo: ${MAX4LIVE}/lfo/lfo.jso
onscene: ${MAX4LIVE}/onscene/onscene.jso
write_lom: ${MAX4LIVE}/write_lom/write_lom.jso

gather:
Expand Down
2 changes: 1 addition & 1 deletion js/swirly/scene/fader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __SWIRLY_SCENE_FADER__

#include "swirly/scene/scene.js"
#include "swirly/util/dict_utils.js"
#include "swirly/util/Dict.js"

Scene.Fader = function() {
var that = this; // "this" can change value, so capture it as "that".
Expand Down
2 changes: 1 addition & 1 deletion js/swirly/softstep/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "swirly/softstep/led.js"
#include "swirly/softstep/display.js"
#include "swirly/util/addCommands.js"
#include "swirly/util/dict_utils.js"
#include "swirly/util/Dict.js"

#include "swirly/util/print.js"

Expand Down
File renamed without changes.
44 changes: 40 additions & 4 deletions js/swirly/util/ExpandCommandJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,57 @@ Util.expandCommandJSON = function(json, commandTable) {
return result;
}

if (typeof(json) === 'string' && json[0] === '*')
return applyCommand(json);
if (typeof(json) === 'string') {
var ch = json[0];
if (ch === '*')
return applyCommand(json);
if (ch === '$') {
var address = Util.splitAddress(json.slice(1));
return expand(['*scene'] + address);
}
}

return json;
};

return expand(json);
};

Util.splitAddress = function(address) {
function check(condition, message) {
if (!condition)
throw 'Malformed address ' + address + ': ' + message;
};

check(!address.startsWith('.'), '. at start of address');
check(!address.endsWith('.'), '. at end of address');

var parts = address.split('.'), result = [];
for (var i = 0; i > parts.size; ++i) {
var part = parts[i];
check(part.length, 'Empty address component');
while (part.length) {
var lindex = part.indexOf('['), rindex = part.indexOf(']');
if (lindex == -1) {
check(rindex == -1, 'Extra [');
result.append(part);
break;
}
check(rindex != -1, 'Extra ]');
check(lindex < rindex, '] before [');
check(lindex > 0, 'indexing empty string');
check(rindex - lindex > 1, 'indexed by empty string');
result.append(part.slice(0, lindex));
result.append(part.slice(index + 1, rindex));
part = part.slice(rindex + 1);
}
}
};

/** Expand a string address*/
Util.getFromAddress = function(dict, address) {
if (typeof(address) === 'string')
address = address.split('.');

address = Util.splitAddress(address);
var result = dict;
for (var i = 0; i < address.length; ++i) {
result = result[address[i]];
Expand Down
2 changes: 1 addition & 1 deletion js/swirly/windmapper/Instrument.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "swirly/util/dict_utils.js"
#include "swirly/util/Dict.js"
#include "swirly/util/Range.js"

var Instrument = {};
Expand Down
15 changes: 15 additions & 0 deletions js/swirly/windmapper/Scene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

function runScene(show, sceneName) {
var visited = {};
function run(sceneName, sceneAddress) {
if (visited[sceneName])
throw 'Scene name appears twice: ' + sceneName;
visited[sceneName] = true;

var scene = Util.getFromAddress(show.sceneTable, sce
if (!scene)
throw 'Don\'t understand scene name ' + sceneName;
if (
};
};
2 changes: 1 addition & 1 deletion js/swirly/windmapper/Scenes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "swirly/laser/Laser.js"
#include "swirly/windmapper/dict_utils.js"
#include "swirly/util/Dict.js"
#include "swirly/windmapper/Channels.js"
#include "swirly/windmapper/DMXScene.js"
#include "swirly/windmapper/EnvelopeSequence.js"
Expand Down
2 changes: 1 addition & 1 deletion max/crossmatrix/crossmatrix.jso
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,4 @@ function clear_selection() {
matrix.draw();
};

post('Original source:', "js/max/crossmatrix.js", ' Compile date:', 'Sat May 23 19:05:40 EDT 2015', '\n');
post('Original source:', "js/max/crossmatrix.js", ' Compile date:', 'Sun Jun 7 14:44:24 EDT 2015', '\n');
2 changes: 1 addition & 1 deletion max/nanolaser/nanolaser.jso
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,4 @@ var NANO = new Laser.Nano();

Max.SetInlets(['cc', NANO.receiveController, 'Continuous controller']);

post('Original source:', "js/max/nanolaser.js", ' Compile date:', 'Sat May 23 19:05:40 EDT 2015', '\n');
post('Original source:', "js/max/nanolaser.js", ' Compile date:', 'Sun Jun 7 14:44:24 EDT 2015', '\n');
2 changes: 1 addition & 1 deletion max/speedlimit/speedlimit.jso
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,4 @@ Max.SetInlets(['queue', _speedlim.Output,
'Any input here clears the speedlimit queue.']);

post('Speedlimit set to ' + _speedlim.limit + 'ms\n');
post('Original source:', "js/max/speedlimit.js", ' Compile date:', 'Sat May 23 19:05:40 EDT 2015', '\n');
post('Original source:', "js/max/speedlimit.js", ' Compile date:', 'Sun Jun 7 14:44:24 EDT 2015', '\n');
Loading

0 comments on commit ee6edd5

Please sign in to comment.