diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs
index a4db48cb..899e57e9 100644
--- a/packages/core/controls.mjs
+++ b/packages/core/controls.mjs
@@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see .
*/
-import { Pattern, register, sequence } from './pattern.mjs';
+import { Pattern, register, reify, sequence } from './pattern.mjs';
import { zipWith } from './util.mjs';
const controls = {};
@@ -381,18 +381,18 @@ const generic_params = [
*/
['coarse'],
- /**
- * Allows you to set the output channels on the interface
- *
- * @name channels
- * @synonyms ch
- *
- * @param {!Float32Array} channels Array
- * @example
- * note("e a d b g").channels([2, 3]).room(1)
- *
- */
- ['channels', 'ch'],
+ // /**
+ // * Allows you to set the output channels on the interface
+ // *
+ // * @name channels
+ // * @synonyms ch
+ // *
+ // * @param {!Float32Array} channels Array
+ // * @example
+ // * note("e a d b g").channels([2, 3]).room(1)
+ // *
+ // */
+ // ['channels', 'ch'],
['phaserrate', 'phasr'], // superdirt only
@@ -1390,4 +1390,13 @@ controls.ds = register('ds', (ds, pat) => {
return pat.set({ decay, sustain });
});
+controls.ch = register(['channels', 'ch'], (channels, pat) => {
+ channels = !Array.isArray(channels) ? [channels] : channels;
+
+ // channels = channels.map(reify).map((channelPat) => {
+ // // How do I return the current value of the channel pattern here?
+ // });
+ return pat.set({ channels });
+});
+
export default controls;
diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs
index ef77db8a..3cccfc96 100644
--- a/packages/superdough/superdough.mjs
+++ b/packages/superdough/superdough.mjs
@@ -31,38 +31,33 @@ let audioContext;
export const getAudioContext = () => {
if (!audioContext) {
audioContext = new AudioContext();
- var maxChannelCount = audioContext.destination.maxChannelCount;
+ const maxChannelCount = audioContext.destination.maxChannelCount;
audioContext.destination.channelCount = maxChannelCount;
}
- //console.log(audioContext.destination.maxChannelCount);
-
return audioContext;
};
-// outputs: Map
+// outputs: Map
const outputs = new Map();
let channelMerger;
// channels: Array
const getDestinations = (channels) => {
const ctx = getAudioContext();
if (channelMerger == null) {
- channelMerger = ctx.createChannelMerger(ctx.destination.channelCount);
+ channelMerger = new ChannelMergerNode(ctx, { numberOfInputs: ctx.destination.channelCount });
channelMerger.connect(ctx.destination);
}
channels.forEach((ch) => {
if (!outputs.has(ch)) {
- const gain = ctx.createGain();
- gain.channelInterpretation = 'discrete';
+ const gain = new GainNode(ctx, {
+ channelInterpretation: 'discrete',
+ channelCount: 1,
+ channelCountMode: 'explicit',
+ });
gain.connect(channelMerger, 0, ch);
outputs.set(ch, gain);
}
});
- // if (!destination) {
- // destination = ctx.createGain();
- // channelMerger = ctx.createChannelMerger(ctx.destination.channelCount);
- // channelMerger.connect(ctx.destination);
- // destination.connect(channelMerger, 0, 4);
- // destination.connect(channelMerger, 0, 5);
- // }
+
return channels.map((ch) => outputs.get(ch));
};
@@ -121,10 +116,15 @@ const maxfeedback = 0.98;
//input: audioNode, channels: Array
const connectToOutputs = (input, channels = [0, 1]) => {
const outputs = getDestinations(channels);
- console.log(input);
-
+ const ctx = getAudioContext();
+ const center = new StereoPannerNode(ctx);
+ input.connect(center);
+ const splitter = new ChannelSplitterNode(ctx, {
+ numberOfOutputs: input.channelCount,
+ });
+ center.connect(splitter);
outputs.forEach((output, i) => {
- input.connect(output, 0);
+ splitter.connect(output, i % input.channelCount, 0);
});
};
@@ -333,6 +333,7 @@ export const superdough = async (value, deadline, hapDuration) => {
compressorAttack,
compressorRelease,
} = value;
+
gain *= velocity; // legacy fix for velocity
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
const onended = () => {
@@ -466,11 +467,9 @@ export const superdough = async (value, deadline, hapDuration) => {
}
// last gain
- const post = gainNode(postgain);
+ const post = new GainNode(ac, { gain: postgain });
chain.push(post);
- console.log(channels);
- // this should be an array but is getting interpreted as an int for some reason...
- connectToOutputs(post, [channels]);
+ connectToOutputs(post, channels);
// delay
let delaySend;