Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"dependencies": {
"lodash": "^4.17.21",
"tone": "^15.0.2",
"tone": "^15.1.22",
"yuidocjs": "^0.10.2"
},
"devDependencies": {
Expand Down
25 changes: 25 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';

const toneGlobalShim = path.resolve('src', 'vendor', 'toneGlobal.js');

function aliasToneGlobal() {
return {
name: 'alias-tone-global',
resolveId(source, importer) {
if (source === 'tone/build/esm/core/Global.js') {
return toneGlobalShim;
}

if (
source === '../Global.js' &&
importer &&
importer.includes(`${path.sep}node_modules${path.sep}tone${path.sep}build${path.sep}esm${path.sep}core${path.sep}`)
) {
return toneGlobalShim;
}

return null;
}
};
}

export default [
// Unminified version
{
Expand All @@ -11,6 +34,7 @@ export default [
format: 'iife', // Change to IIFE format
},
plugins: [
aliasToneGlobal(),
resolve(),
terser({
compress: {
Expand Down Expand Up @@ -50,6 +74,7 @@ export default [
format: 'iife', // Change to IIFE format
},
plugins: [
aliasToneGlobal(),
resolve(), // Resolves node_modules
terser(), // Minify the output
],
Expand Down
4 changes: 3 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { toneLoggingSilenced } from './bootstrap';
import { getAudioContext, setAudioContext, userStartAudio, userStopAudio } from './core/Utils';
void toneLoggingSilenced;
p5.prototype.getAudioContext = getAudioContext;
p5.prototype.setAudioContext = setAudioContext;
p5.prototype.userStartAudio = userStartAudio;
Expand Down Expand Up @@ -84,4 +86,4 @@ p5.Score = Score;
p5.SoundLoop = SoundLoop;

//import Recorder from './Recorder';
//p5.prototype.Recorder = Recorder;
//p5.prototype.Recorder = Recorder;
26 changes: 26 additions & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const toneLoggingSilenced = (() => {
const root =
typeof globalThis !== 'undefined'
? globalThis
: typeof window !== 'undefined'
? window
: undefined;

if (root) {
Object.defineProperty(root, 'TONE_SILENCE_LOGGING', {
configurable: true,
value: true,
writable: true
});

if (root.window) {
Object.defineProperty(root.window, 'TONE_SILENCE_LOGGING', {
configurable: true,
value: true,
writable: true
});
}
}

return true;
})();
1 change: 0 additions & 1 deletion src/core/p5soundNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { getAudioContext } from "./Utils";
import { gainToDb as ToneGainToDb } from "tone/build/esm/core/type/Conversions.js";

/**
* This is the primary or "base" class for p5.sound.js nodes.
*
Expand Down
1 change: 0 additions & 1 deletion src/sources/Oscillator.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class Oscillator extends p5soundSource {
type = f;
frequency = t;
}

this.frequency = frequency;
this.type = type;
this.node = new ToneOscillator().connect(this.output);
Expand Down
42 changes: 42 additions & 0 deletions src/vendor/toneGlobal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { hasAudioContext } from "tone/build/esm/core/context/AudioContext.js";
import { Context } from "tone/build/esm/core/context/Context.js";
import { DummyContext } from "tone/build/esm/core/context/DummyContext.js";
import {
isAudioContext,
isOfflineAudioContext
} from "tone/build/esm/core/util/AdvancedTypeCheck.js";

const dummyContext = new DummyContext();
let globalContext = dummyContext;

function wrapContext(context) {
if (context instanceof Context || context instanceof DummyContext) {
return context;
}

if (isAudioContext(context) || isOfflineAudioContext(context)) {
return new Context(context);
}

return context;
}

export function getContext() {
if (globalContext === dummyContext && hasAudioContext) {
setContext(new Context());
}

return globalContext;
}

export function setContext(context, disposeOld = false) {
if (disposeOld && globalContext && typeof globalContext.dispose === "function") {
globalContext.dispose();
}

globalContext = wrapContext(context);
}

export function start() {
return globalContext.resume();
}