Skip to content

Commit

Permalink
cancelAndHold. Controls and distributors.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Sep 18, 2018
1 parent 0a3e036 commit 9d0a1c3
Show file tree
Hide file tree
Showing 21 changed files with 661 additions and 386 deletions.
13 changes: 13 additions & 0 deletions css/theme.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
:root {
--code-bg: #172120;
--black-color: #acb9b8;
}

body,
html {
color: #acb9b8;
Expand All @@ -7,3 +12,11 @@ html {
h1 {
color: #d60a3f;;
}

code {
color: #d60a3f;
}

pre > code {
background-color: #161f1e;
}
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,44 @@ <h1 class="grid-0 midi-icon">{[title]} <span class="text-6">{[version]}</span></
</div>
</header>




<section class="1-2-3-grid grid">
<header class="grid-0">
<h2 class="text-2" style="font-size: 1.875rem;">Functions</h2>
<pre><code class="language-js">// Import Soundstage
import Soundstage from 'http://stephen.band/soundstage/soundstage.js';</code></pre>
</header>

<h2 class="text-3 grid-1">Soundstage()</h2>

<section class="grid-2">
<h3 class="text-4">Properties</h3>
<article template-fn="docs:'./modules/sequence.js?name','./modules/soundstage.js','./modules/graph.js?plugins,connections','./modules/sequence.js?events,sequences' each append:body" class="toggle-block block" toggleable id="{[id]}">
<h3 class="text-5 {[prefix|is:'.'|yesno:'dot-indent','']}">
<a href="#{[id]}">
<code template-fn="html:title" class="language-js"></code>
</a>
</h3>
</article>
</section>

<section class="grid-3">
<h3 class="text-4">Methods</h3>
<article template-fn="docs:'./modules/graph.js?create,get','./modules/sequencer.js','./modules/location.js','./modules/meter.js','./modules/soundstage.js?timeAtDomTime' each append:body" class="toggle-block block" toggleable id="{[id]}">
<h3 class="text-5 {[prefix|is:'.'|yesno:'dot-indent','']}">
<a href="#{[id]}">
<code template-fn="html:title" class="language-js"></code>
</a>
</h3>
</article>
</section>
</section>




<!--div class="grid-block block">
<select class="grid-1/6 block" id="meter-select">
<option value="2/4">2/4</option>
Expand Down Expand Up @@ -367,6 +405,7 @@ <h1 class="grid-0 midi-icon">{[title]} <span class="text-6">{[version]}</span></
<!-- Tests -->
<script type="module">
import './test/controls.test.js';
import './test/location.test.js';
import './test/soundstage.test.js';
</script>
</body>
12 changes: 6 additions & 6 deletions js/cue-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@

buffer.forEach(release);

// Because length might be immutable...
// Because length might be immutable...
if (buffer.length) { buffer.length = 0; }
}

Expand Down Expand Up @@ -499,7 +499,7 @@ var w = 0;
var cue = this.cue;
var timer = this.timer;
var startTime = this.startTime;
var now = timer.now();
var now = timer.now();

cue.t2 = startTime > now ? startTime : now ;

Expand All @@ -511,7 +511,7 @@ var w = 0;
// Update cue
cue.t1 = cue.t2;
cue.t2 = time >= stopTime ? stopTime : time;

return cue;
},

Expand Down Expand Up @@ -581,11 +581,11 @@ var z = 'stream-' + (++w); //Fn.postpad(' ', 12, (generate[0] && generate[0].joi
// Time

function beatAtTime(time) {
return location && location.beatAtLoc(clock.beatAtTime(time) - startLoc);
return location && location.beatAtLocation(clock.beatAtTime(time) - startLoc);
}

function timeAtBeat(beat) {
return location && clock.timeAtBeat(location.locAtBeat(beat) + startLoc);
return location && clock.timeAtBeat(location.locationAtBeat(beat) + startLoc);
}

// Events
Expand Down Expand Up @@ -655,7 +655,7 @@ var z = 'stream-' + (++w); //Fn.postpad(' ', 12, (generate[0] && generate[0].joi
Stream.from(generate.filter(isRateEvent)) ;

location = new Location(source.rates);

// TODO: Rates is not populated yet, how do you expect
// to get anything useful out of this?
startLoc = clock.beatAtTime(time) - (beat ? location.locAtBeat(beat) : 0);
Expand Down
2 changes: 1 addition & 1 deletion modules/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Clock(audio) {
this.beatAtTime = function(time) { return time - startTime; };
this.timeAtBeat = function(beat) { return startTime + beat; };

this.start = function(time, beat) {
this.start = function(time) {
startTime = time || audio.currentTime ;
return this;
};
Expand Down
9 changes: 7 additions & 2 deletions modules/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const types = {
};

export const transforms = {
'pass': function linear(min, max, c, n) {
return n;
},

'linear': function linear(min, max, c, n) {
return n * (max - min) + min;
},
Expand Down Expand Up @@ -115,9 +119,10 @@ export default function Control(controls, source, target, setting) {
// Catch keys with no name
if (!name && !data.name) { return; }

target.fire(
// time in audioContext timeframe
target.control(
// time in audioContext timeframe - support Audio Nodes
target.object.context ? timeAtDomTime(target.object.context, timeStamp) :
// and Audio Objects, for just now at least
target.object.audio ? timeAtDomTime(target.object.audio, timeStamp) :
0,

Expand Down
26 changes: 12 additions & 14 deletions modules/controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

/*
Controls()
Constructor for an array-like of Control objects. Has the methods:
- learnMIDI
- learnKey
*/

import { get, map, nothing } from '../../fn/fn.js';
import push from '../../fn/modules/lists/push.js';
import { toKeyString, toKeyCode } from '../../../dom/dom.js';
Expand All @@ -20,18 +30,6 @@ function toEvent(audio, time, type, value) {
this.recordable = true;
}



/*
Controls()
Constructor for an array-like of Control objects. Has the methods:
- learnMIDI
- learnKey
*/

function toMIDISelector(e) {
const type = toType(e.data);

Expand All @@ -50,7 +48,7 @@ function toKeySelector(e) {
};
}

function createRoute(controls, getTarget, setting) {
function createControl(controls, getTarget, setting) {
// Detect type of source - do we need to add a type field? Probably. To the
// route or to the source? Hmmm. Maybe to the route. Maybe to the source.
// Definitely the source. I think.
Expand All @@ -74,7 +72,7 @@ export default function Controls(getTarget, settings) {
// Set up routes from data
if (settings) {
settings.reduce(function(routes, setting) {
const route = createRoute(controls, getTarget, setting);
const route = createControl(controls, getTarget, setting);

// Add route to routes
push(routes, route);
Expand Down
41 changes: 17 additions & 24 deletions modules/cue-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,31 +501,23 @@ assign(CueSource.prototype, {

cue.t2 = startTime > now ? startTime : now ;

var fn = pipe(
function toCue(time) {
var stopTime = source.stopTime;
source.id = undefined;

// Update cue
cue.t1 = cue.t2;
cue.t2 = time >= stopTime ? stopTime : time;

return cue;
},

source.frame,
function fn(time) {
var stopTime = source.stopTime;
source.id = undefined;

function until(cue) {
var stopTime = source.stopTime;
// Update cue
cue.t1 = cue.t2;
cue.t2 = time >= stopTime ? stopTime : time;

if (cue.t2 >= stopTime) {
source.stop(stopTime);
return;
}
source.frame(cue);

source.id = timer.request(fn);
if (cue.t2 >= stopTime) {
source.stop(stopTime);
return;
}
);

source.id = timer.request(fn);
}

source.status = 'playing';
fn(time);
Expand Down Expand Up @@ -579,11 +571,11 @@ var z = 'stream-' + (++w); //Fn.postpad(' ', 12, (generate[0] && generate[0].joi
// Time

function beatAtTime(time) {
return location && location.beatAtLoc(clock.beatAtTime(time) - startLoc);
return location && location.beatAtLocation(clock.beatAtTime(time) - startLoc);
}

function timeAtBeat(beat) {
return location && clock.timeAtBeat(location.locAtBeat(beat) + startLoc);
return location && clock.timeAtBeat(location.locationAtBeat(beat) + startLoc);
}

// Events
Expand All @@ -603,7 +595,8 @@ var z = 'stream-' + (++w); //Fn.postpad(' ', 12, (generate[0] && generate[0].joi

function frame(cue) {
// Cue generated events
source.generate(cue)
source
.generate(cue)
.map(Event.from)
.map(transform)
.map(assignTime)
Expand Down
55 changes: 55 additions & 0 deletions modules/distribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { overload } from '../../fn/fn.js';
import { noteToNumber } from '../../midi/midi.js';
import { automate } from './params.js';

function arg2() {
return arguments[2];
}

export const distributors = {

// Event types
//
// [time, "rate", number, curve]
// [time, "meter", numerator, denominator]
// [time, "note", number, velocity, duration]
// [time, "noteon", number, velocity]
// [time, "noteoff", number]
// [time, "param", name, value, curve]
// [time, "pitch", semitones]
// [time, "chord", root, mode, duration]
// [time, "sequence", name || events, target, duration, transforms...]

'note': function(object, time, type, name, value) {
const number = typeof name === 'number' ? name : noteToNumber(name) ;
return object.start(time, number, value) || object;
},

'noteon': function(object, time, type, name, value) {
const number = typeof name === 'number' ? name : noteToNumber(name) ;
return object.start(time, number, value) || object;
},

'noteoff': function(object, time, type, name, value) {
const number = typeof name === 'number' ? name : noteToNumber(name) ;
object.stop(time, number, value);
return object;
},

'param': function(object, time, type, name, value) {
const param = object[name];
automate(param, time, value);
return object;
},

'default': function(object, time, type) {
print('Cannot cue unrecognised type "' + type + '". (Possible types: noteon, noteoff, noteparam, param).' )
}
};

export const distribute = overload(arg2, distributors);

export function distributeEvent(object, event) {
// How long is our longest event going to be? Hmm.
return distribute(object, event[0], event[1], event[2], event[3], event[4], event[5]);
};
Loading

0 comments on commit 9d0a1c3

Please sign in to comment.