Skip to content

Commit

Permalink
Reorganise files, param, node-graph
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Feb 28, 2024
1 parent ff07b81 commit 47c284e
Show file tree
Hide file tree
Showing 36 changed files with 303 additions and 293 deletions.
7 changes: 3 additions & 4 deletions modules/assign-settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import { log, logGroup, logGroupEnd } from './print.js';
import { automato__ } from './automate__.js';
import { getAutomation } from './param.js';
import { automate, getAutomation } from './param.js';

const DEBUG = false;

Expand All @@ -20,8 +19,8 @@ function assignSetting(node, key, value, notify) {
// purge old automation events. Keep an eye, might be a bit aggressive
getAutomation(node[key]).length = 0;

// node, name, time, curve, value, duration, notify, context
automato__(node, key, node.context.currentTime, 'step', value, null, notify);
// param, time, curve, value, duration
automate(node[key], node.context.currentTime, 'step', value);
}

// Or an AudioNode?
Expand Down
87 changes: 0 additions & 87 deletions modules/automate.js

This file was deleted.

68 changes: 20 additions & 48 deletions modules/automate__.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import id from '../../fn/modules/id.js';
import last from '../../fn/modules/last.js';
import overload from '../../fn/modules/overload.js';

import Event from './event.js';
import { getAutomation } from './param.js';
import { isAudioContext, timeAtDomTime } from './context.js';
import config from '../config.js';
Expand Down Expand Up @@ -78,69 +79,40 @@ const curves = {
};

const createEvent = overload(id, {
'exponential': (curve, param, event0, event1, time, value) => {
// Make an event object to be stored in param$automationEvents
const event = {
time: time,
value: Math.fround(value)
};

'exponential': (curve, param, e0, e1, time, value) => {
// Deal with exponential curves starting or ending with value 0. Swap them
// for step curves, which is what they tend towards for low values.
// Todo: deal with -ve values.
if (event.value <= config.minExponentialValue) {
event.time = event0 ? event0.time : 0 ;
event.curve = "step";
if (event[2] <= config.minExponentialValue) {
time = e0 ? e0[0] : 0 ;
curve = "step";
}
else if (event0 && event0.value < config.minExponentialValue) {
event.curve = "step";
else if (e0 && e0[2] < config.minExponentialValue) {
curve = "step";
}
else {
event.curve = "exponential";
curve = "exponential";
}

return event;
return new Event(time, curve, Math.fround(value));
},

'hold': function(curve, param, event0, event1, time) {
// Set a curve of the same type as the next to this time and value
return event1 && event1.curve === 'linear' ? {
time: time,
curve: 'linear',
value: Math.fround(getValueBetweenEvents(event0, event1, time))
} :

event1 && event1.curve === 'exponential' ? {
time: time,
curve: 'exponential',
value: Math.fround(getValueBetweenEvents(event0, event1, time))
} :

event0 && event0.curve === 'target' ? {
time: time,
curve: 'step',
value: getValueAtTime(param, time)
} : {
time: time
} ;
return event1 && event1.curve === 'linear' ?
new Event(time, 'linear', Math.fround(getValueBetweenEvents(event0, event1, time))) :
event1 && event1.curve === 'exponential' ?
new Event(time, 'exponential', Math.fround(getValueBetweenEvents(event0, event1, time))) :
event0 && event0.curve === 'target' ?
new Event(time, 'step', getValueAtTime(param, time)) :
new Event(time) ;
},

'target': (curve, param, event0, event1, time, value, duration) => {
return {
time: time,
curve: 'target',
value: Math.fround(value),
duration: duration
};
},
'target': (curve, param, event0, event1, time, value, duration) =>
new Event(time, 'target', Math.fround(value), duration),

'default': (curve, param, event0, event1, time, value, duration) => {
return {
time: time,
curve: curve,
value: Math.fround(value)
};
}
'default': (curve, param, event0, event1, time, value, duration) =>
new Event(time, curve, Math.fround(value))
});

const mutateEvents = choose({
Expand Down
2 changes: 1 addition & 1 deletion modules/clock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import Privates from '../../fn/modules/privates.js';
import Playable from './playable.js';
import Playable from './mixins/playable.js';

const DEBUG = false;//window.DEBUG;

Expand Down
4 changes: 1 addition & 3 deletions modules/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ const constructEventType = overload(arg(1), {
},

default: function() {
this[0] = parseFloat32(arguments[0]);
this[1] = arguments[1];
this[2] = arguments[2];
assign(this, arguments);
}
});

Expand Down
2 changes: 1 addition & 1 deletion modules/graph/audio-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Privates from '../../../../fn/modules/privates.js';
import remove from '../../../../fn/modules/remove.js';
import { floatToFrequency, toNoteNumber } from '../../../../midi/modules/data.js';

import Node from '../streams/node.js';
import Node from '../mixins/node.js';
import { create } from '../graph/constructors.js';
import { automateParamAtTime, automatePropertyAtTime } from '../automate__.js';
import { isAudioParam } from '../param.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/graph/connectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import overload from '../../../../fn/modules/overload.js';
import Privates from '../../../../fn/modules/privates.js';
import remove from '../../../../fn/modules/remove.js';

import Collection from '../streams/collection.js';
import Collection from '../mixins/collection.js';
import Connector from './connector.js';
import { log } from '../print.js';

Expand Down
1 change: 1 addition & 0 deletions modules/graph/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import SampleNode from '../nodes/sample-set.js';
'sample': SampleNode
*/


const constructors = {
// https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/AnalyserNode
'analyser': AnalyserNode,
Expand Down
22 changes: 5 additions & 17 deletions modules/graph/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import nothing from '../../../../fn/modules/nothing.js';
import overload from '../../../../fn/modules/overload.js';
import Privates from '../../../../fn/modules/privates.js';
import remove from '../../../../fn/modules/remove.js';
import Collection from '../streams/collection.js';
import Tree from '../streams/tree.js';
import Collection from '../mixins/collection.js';
import Tree from '../mixins/tree.js';
import AudioObject from './audio-object.js';

import { log } from '../print.js';
Expand Down Expand Up @@ -61,17 +61,9 @@ assign(Objects, {
}
});

define(Objects.prototype, {
length: {
get: function() {
let n = -1;
while (this[++n]);
return n;
}
}
});
mix(Objects.prototype, Collection.prototype);

assign(Objects.prototype, Collection.prototype, {
assign(Objects.prototype, {
create: overload((object) => typeof object, {
object: function(data) {
const privates = Privates(this);
Expand All @@ -87,9 +79,5 @@ assign(Objects.prototype, Collection.prototype, {
}),

push: Tree.prototype.push,
pipe: Tree.prototype.pipe,

toJSON: function() {
return Array.from(this);
}
pipe: Tree.prototype.pipe
});
2 changes: 1 addition & 1 deletion modules/graph/pipe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { unpipe, removeOutput } from '../streams/node.js';
import { unpipe, removeOutput } from '../mixins/node.js';

const assign = Object.assign;
const define = Object.defineProperties;
Expand Down
2 changes: 1 addition & 1 deletion modules/graph/pipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mix from '../../../../fn/modules/mix.js';
import overload from '../../../../fn/modules/overload.js';
import Privates from '../../../../fn/modules/privates.js';

import Collection from '../streams/collection.js';
import Collection from '../mixins/collection.js';
import Pipe from './pipe.js';
import { log } from '../print.js';

Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions modules/streams/head.js → modules/mixins/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ assign(Head.prototype, {
this.startTime = time;

// Input may not exist yet
if (this.input) {
this.input.start.apply(this.input, arguments);
if (this[-1]) {
this[-1].start.apply(this[-1], arguments);
}

return this;
Expand Down Expand Up @@ -163,8 +163,8 @@ assign(Head.prototype, {

// Use cached rates if we have them
const rates = this.rates || this.events.filter(isRateEvent);
const headTime = this.input.beatAtTime ?
this.input.beatAtTime(time) :
const headTime = this[-1].beatAtTime ?
this[-1].beatAtTime(time) :
time - this.startTime ;

return beatAtLocation(rates, rate0, headTime - this.startTime);
Expand All @@ -179,8 +179,8 @@ assign(Head.prototype, {
const rates = this.rates || this.events.filter(isRateEvent);
const headTime = locationAtBeat(rates, rate0, beat);

return this.input.timeAtBeat ?
this.input.timeAtBeat(this.startTime + headTime) :
return this[-1].timeAtBeat ?
this[-1].timeAtBeat(this.startTime + headTime) :
this.startTime + headTime ;
}
});
3 changes: 1 addition & 2 deletions modules/streams/node.js → modules/mixins/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ function createId() {

/**
pipe(stream)
Connect stream to output. Sets up `stream[0]` and `output.input` (if output is
`.stop()`able).
Connect stream to output.
**/

export function pipe(stream, output) {
Expand Down
2 changes: 1 addition & 1 deletion modules/playable.js → modules/mixins/playable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const json = JSON.stringify(playable); // {}
```
**/

import { logGroup, logGroupEnd } from './print.js';
import { logGroup, logGroupEnd } from '../print.js';

const DEBUG = window.DEBUG;
const assign = Object.assign;
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions modules/streams/tree.js → modules/mixins/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ assign(Tree.prototype, {
while (this[++n]);

// Pipe
if (output.stop) { output.input = this; }
if (output.stop) { output[-1] = this; }
this[n] = output;
return output;
},

remove: function() {
// Don't stop input, unpipe() this from it
if (this.input) {
unpipe(this.input, this);
if (this[-1]) {
unpipe(this[-1], this);
}

return this;
Expand All @@ -91,13 +91,13 @@ assign(Tree.prototype, {
if (this.status === 'done') { return this; }

// Dont propagate stop up to other nodes, just remove
if (this.constructor === this.input.constructor) {
unpipe(this.input, this);
if (this.constructor === this[-1].constructor) {
unpipe(this[-1], this);
return stop(this);
}

// Do propagate up to other inputs (this is to stop Frames)
this.input.stop.apply(this.input, arguments);
this[-1].stop.apply(this[-1], arguments);
return this;
},

Expand Down
Loading

0 comments on commit 47c284e

Please sign in to comment.