Skip to content

Commit

Permalink
First stages are working.
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Sep 13, 2015
1 parent 5225dc8 commit 1e61604
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 75 deletions.
1 change: 0 additions & 1 deletion js/max4live/show.js
Expand Up @@ -9,7 +9,6 @@ outlets = 0;
#include "swirly/util/print.js"

var _showRunner = new ShowRunner();
Max.ObjectInlets(_showRunner);

function anything() {
var env = new Live.Environment();
Expand Down
14 changes: 5 additions & 9 deletions js/swirly/instrument/Bank.js
Expand Up @@ -3,17 +3,13 @@
#include "swirly/instrument/DMXOutput.js"
#include "swirly/util/ForEach.js"

Instrument.Instance = function(name, description, offset) {
this.name = name;
this.description = description;
this.offset = offset;
};

/** A Bank is a named collection of instrument instances. */
Instrument.makeBank = function(json, dmx, maxObjects) {
var bank = {};
Instrument.makeBank = function(show) {
var bank = {},
maxObjects = show.objects.maxclass,
dmx = maxObjects.dmxusbpro;

forEach(json.instruments, function(name, instrument) {
forEach(show.json.instruments, function(name, instrument) {
var definitionName = instrument.definition || name.split('_')[0],
definition = json.definitions[definitionName],
multislider = maxObjects[instrument.multislider || name],
Expand Down
5 changes: 3 additions & 2 deletions js/swirly/instrument/Inputs.js
Expand Up @@ -4,8 +4,9 @@
#include "swirly/util/Dict.js"
#include "swirly/util/ForEach.js"

Instrument.makeInputs = function(json, callbackTable) {
return applyEach(json, function(desc) {
Instrument.makeInputs = function(show) {
var callbackTable = show.callbackTable;
return applyEach(show.json.inputs, function(desc) {
var name = desc.name,
help = name + (desc.help ? ': ' + desc.help : ''),
callback;
Expand Down
6 changes: 3 additions & 3 deletions js/swirly/instrument/Processor.js
Expand Up @@ -45,10 +45,10 @@ Instrument.makeListeners = function(desc, lights) {
});
};

Instrument.makeProcessors = function(lights, json) {
return applyEach(json, function(processor) {
Instrument.makeProcessors = function(show) {
return applyEach(show.json.processor, function(processor) {
return applyEach(processor, function(desc) {
var listeners = Instrument.makeListener(desc, lights);
var listeners = Instrument.makeListener(desc, show.lights);
return function(value, offset) {
forEach(listeners, function(listener) {
listener(value, offset);
Expand Down
21 changes: 12 additions & 9 deletions js/swirly/live/Environment.js
Expand Up @@ -2,22 +2,25 @@

#include "swirly/util/Dict.js"
#include "swirly/util/Error.js"
#include "swirly/live/PropertyMapper.js"
#include "swirly/live/TrackDictionary.js"

/** A class with everything from live reachable from it. */
Live.Environment = function() {
this.tracks = Live.trackDictionary();
var self = this,
tracks = Live.trackDictionary().byName,
liveSet = new LiveAPI('live_set'),
propertyManager = Live.propertyMapper({
tempo: {object: liveSet, type: Number},
is_playing: {object: liveSet, type: Boolean},
});

var liveSet = new LiveAPI('live_set');
this.liveSet = new Live.PropertyMapper({
tempo: {object: liveSet, type: Number},
is_playing: {object: liveSet, type: Boolean},
});

this.info = function() {
function info() {
return ['LiveSet']
.concat(liveSet.info.split('\n'))
.concat(['', 'Tracks'])
.concat(this.tracks.info());
.concat(self.tracks.info());
};

return {tracks: tracks, info: info, liveSet: propertyManager};
};
12 changes: 7 additions & 5 deletions js/swirly/live/PropertyMapper.js
Expand Up @@ -16,20 +16,22 @@
string before it hands it back to you, and stringent with its inputs,
requiring everything to be the right type, which results in the `type` field.
*/
Live.PropertyMapper = function(properties) {
var getter = Dict.getter(properties, 'PropertyMapper');
Live.propertyMapper = function(properties) {
var getter = Dict.getter(properties, 'propertyMapper');

this.get = function(name) {
function get(name) {
var prop = getter(name);
return prop.type(prop.object.get(prop.name || name));
};

this.set = function(name, value) {
function set(name, value) {
var prop = getter(name);
return prop.object.set(prop.name || name, prop.type(value));
};

this.has = function(name) {
function has(name) {
return name in properties;
};

return {get: get, set: set, has: has};
};
2 changes: 1 addition & 1 deletion js/swirly/live/TrackDictionary.js
Expand Up @@ -11,7 +11,7 @@ Live.track = function(index) {
volume = new LiveAPI(
['live_set', 'tracks', index, 'mixer_device', 'volume']),

mapper = new Live.PropertyMapper({
mapper = Live.propertyMapper({
level: {object: volume, name: 'value', type: Number},
mute: {object: track, type: Boolean},
name: {object: track, type: String},
Expand Down
6 changes: 4 additions & 2 deletions js/swirly/max/NewInlets.js
Expand Up @@ -7,13 +7,15 @@
Max.messagenameOmit = {msg_int: true, msg_float: true, list: true};

Max.setInlets = function(json) {
if (!Max.inlets) {
if (!Max.newInlets) {
inlets = json.length;
forEach(json, function(desc, i) {
setinletassist(i, desc.name + ': ' + desc.help);
});
} else {
post('Replacing inputs\n');
}
Max.inlets = json;
Max.newInlets = json;
};

function anything(_) {
Expand Down
2 changes: 1 addition & 1 deletion js/swirly/max/outlets.js
Expand Up @@ -108,7 +108,7 @@ Max.SetOutlets = function(_) {
Max._outlets = {};
for (var i = 0; i < arguments.length; i++) {
var name = arguments[i], help = name;
if (!Util.IsString(name)) {
if (! (name instanceof String)) {
help = name[1] || name;
name = name[0];
}
Expand Down
12 changes: 12 additions & 0 deletions js/swirly/scene/Channel.js
@@ -0,0 +1,12 @@
#pragma once

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

Scene.channel = function(name, args) {
return Dict.union(args || {}, {
mute: Scene.setter('vl70', 'mute'),
level: Scene.setter('vl70', 'level'),
// send: {}, // TODO
});
};
27 changes: 27 additions & 0 deletions js/swirly/scene/Scene.js
@@ -0,0 +1,27 @@
#pragma once

#include "swirly/util/ForEach.js"

var Scene = {};

Scene.makeEach = function(show, args, makerTable) {
return applyEach(args, function(arg, name) {
return makerTable[name](show, arg);
});
};

Scene.muter = function(track, muted) {
muted = muted ? 1 : 0;
return function() {
track.set('mute', muted);
};
};

Scene.setter = function(trackName, propName) {
return function(show, value) {
var track = show.tracks[trackName];
return function() {
track.set(propName, value);
};
};
};
37 changes: 37 additions & 0 deletions js/swirly/scene/SceneMaker.js
@@ -0,0 +1,37 @@
#pragma once

#include "swirly/scene/VL.js"
#include "swirly/scene/Scene.js"

// Show.partMaker = {
// vl: function(args) {
// return Util
// var program = args.program && Program(args.program),
// mute = args.pro

// return function(show) [
// program && program(show);

// };
// },
// };

Show.Scene = function(show, args) {
/**
VL70: program change, level, effect send.
mic: enable, level, effects send.
WX-7: send to instrument.
tempo:
lights:
processors:
displays:
*/
return makeSequence(args, Show.partMaker);
};
19 changes: 19 additions & 0 deletions js/swirly/scene/VL.js
@@ -0,0 +1,19 @@
#pragma once

#include "swirly/scene/Channel.js"
#include "swirly/show/VLProgram.js"

Scene.VL = {};

Scene.VL.maker = Scene.channel('vl70', {
program: function(show, name) {
var program = VL.getProgram(name),
bank = program[0],
pc = program[1],
object = show.objects.maxclass.unpack;

return function() {
object.message(bank, pc);
};
},
});
6 changes: 5 additions & 1 deletion js/swirly/show/ExpandJson.js
Expand Up @@ -10,7 +10,7 @@ Show.expandJson = function(json, execute) {
function expand(json) {
if (json instanceof Array) {
var first = json[0];
if (typeof(first) === 'string' && first.startswith(Show.prefix))
if (typeof(first) === 'string' && first[0] === Show.prefix)
return execute[first.slice(1)](json.slice(1));
}

Expand All @@ -23,6 +23,10 @@ Show.expandJson = function(json, execute) {
return expand(json);
};

Show.showJson = function(show) {
return Show.expandJson(show.jsonReader('show'), show.execute);
};

Show.readJson = function(filename, args) {
return Show.expandJson(args.read(filename), args);
};
19 changes: 12 additions & 7 deletions js/swirly/show/ShowRunner.js
Expand Up @@ -3,25 +3,30 @@
#include "swirly/instrument/Bank.js"
#include "swirly/instrument/Inputs.js"
#include "swirly/instrument/Processor.js"
#include "swirly/live/Environment.js"
#include "swirly/max/findObjects.js"
#include "swirly/max/NewInlets.js"
#include "swirly/show/ExpandJson.js"
// #include "swirly/show/MakeScenes.js"
#include "swirly/scene/SceneMaker.js"
#include "swirly/util/FileReader.js"
#include "swirly/util/ForEach.js"


function ShowRunner() {
var self = this;
self.callbackTable = {};
self.objects = Max.findAll();
self.dmxusbpro = objects.maxclass.dmxusbpro;
self.jsonReader = FileReader.jsonReader('/development/swirly/data');
self.execute = {readFile: self.jsonReader};
self.json = Show.expandJson(self.jsonReader('show'), self.execute);
self.inputs = Instrument.makeInputs(self.json.inputs, self.callbackTable);
self.lights = Instrument.makeBank(self.json.lights, dmxusbpro, objects);
self.processors = Instrument.makeProcessors(self, self.json.processors);
self.scenes = Show.makeScenes(self, self.json.scenes);

self.json = Show.showJson(self);
self.inputs = Instrument.makeInputs(self);
Max.setInlets(self.inputs);

self.setup = function() {
self.live = new Live.Environment();
self.lights = Instrument.makeBank(self);
self.processors = Instrument.makeProcessors(self);
self.scenes = Show.makeScenes(self);
};
};
39 changes: 29 additions & 10 deletions js/swirly/show/VLProgram.js
@@ -1,5 +1,7 @@
#pragma once

#include "swirly/util/ForEach.js"

var VLPrograms = {
'Trumpet': [0, 0],
'Maynard': [0, 1],
Expand Down Expand Up @@ -260,15 +262,32 @@ var VLPrograms = {
'KennyGee': [3, 12],
}

function VLProgramFunction(name) {
var program = VLPrograms[name];
if (!program) {
post('ERROR: Don\'t understand program named', name);
return;
}
var bank = program[0], pc = program[1];
var VL = {};

VL.normalize = function(s) {
return s.replace(/_/g, '').toLowerCase();
};

VL.normalizedTable = function(table) {
var result = {};
forEach(table, function(pc, name) {
result[VL.normalize(name)] = pc;
});
return result;
};

VL.programs = VL.normalizedTable(VLPrograms);


VL.getProgram = function(name) {
return VL.programs[VL.normalize(name)];
};

VL.Program = function(show, name) {
var program = VL.getProgram(name),
bank = program[0],
pc = program[1],
object = show.objects.maxclass.unpack;

return function(show) {
show.objects.maxclass.unpack.message(bank, pc);
};
return function() { object.message(bank, pc); };
};
4 changes: 2 additions & 2 deletions js/swirly/util/Dict.js
Expand Up @@ -56,7 +56,7 @@ Dict.GetCommandFromMap = function(map, input) {
return;
}

if (Util.IsString(map))
if (map instanceof String)
return {command: map, data: input.slice(i + 1)};

if (i >= input.length) {
Expand Down Expand Up @@ -90,7 +90,7 @@ Dict.offset = function(offset, dict) {
Dict.union = function(_) {
var result = {};
for (var i in arguments)
update(result, arguments[i]);
Dict.update(result, arguments[i]);
return result;
};

Expand Down
6 changes: 2 additions & 4 deletions js/swirly/util/FileReader.js
Expand Up @@ -86,12 +86,10 @@ FileReader.readJson = function(filename, length) {
};

FileReader.jsonReader = function(baseDirectory, length) {
if (! baseDirectory.endsWith('/'))
baseDirectory += '/';
baseDirectory = Util.addSuffix(baseDirectory, '/');

return function(filename) {
if (! filename.endswith('.json'))
filename += '.json';
filename = Util.addSuffix(filename, '.json');
return FileReader.readJson(baseDirectory + filename, length);
};
};

0 comments on commit 1e61604

Please sign in to comment.