Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to tone 14, fix record #165

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b0fff30
Bump path-parse from 1.0.6 to 1.0.7
dependabot[bot] Aug 10, 2021
de75f84
Bump tar from 4.4.13 to 4.4.19
dependabot[bot] Sep 1, 2021
8f1660b
Bump tmpl from 1.0.4 to 1.0.5
dependabot[bot] Sep 21, 2021
1c64e13
Bump object-path from 0.11.4 to 0.11.8
dependabot[bot] Sep 21, 2021
a78b19f
Bump follow-redirects from 1.13.0 to 1.14.8
dependabot[bot] Feb 12, 2022
05f22e0
Bump url-parse from 1.5.1 to 1.5.10
dependabot[bot] Feb 26, 2022
4ed2a9d
Bump async from 2.6.3 to 2.6.4
dependabot[bot] Apr 28, 2022
68ccd88
Bump eventsource from 1.0.7 to 1.1.1
dependabot[bot] Jun 1, 2022
1e7cf14
Bump moment from 2.24.0 to 2.29.4
dependabot[bot] Jul 8, 2022
2d277eb
Bump terser from 4.3.9 to 4.8.1
dependabot[bot] Jul 20, 2022
51919a4
Bump jszip from 3.1.5 to 3.7.0
dependabot[bot] Sep 8, 2022
ac26512
Bump decode-uri-component from 0.2.0 to 0.2.2
dependabot[bot] Dec 3, 2022
12c2f87
Bump qs from 6.5.2 to 6.5.3
dependabot[bot] Dec 8, 2022
6ba8aaf
Bump json5 from 1.0.1 to 1.0.2
dependabot[bot] Jan 5, 2023
cdf45dc
update
ejarzo Mar 3, 2023
fee43f4
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/path-par…
ejarzo Mar 3, 2023
5019d96
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/tar-4.4.…
ejarzo Mar 3, 2023
ba47f1c
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/tmpl-1.0…
ejarzo Mar 3, 2023
a3787dc
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/object-p…
ejarzo Mar 3, 2023
3e37217
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/follow-r…
ejarzo Mar 3, 2023
49bc41b
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/url-pars…
ejarzo Mar 3, 2023
fd5e145
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/async-2.…
ejarzo Mar 3, 2023
41b6d2f
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/eventsou…
ejarzo Mar 3, 2023
eb2b87c
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/moment-2…
ejarzo Mar 3, 2023
15e558f
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/terser-4…
ejarzo Mar 3, 2023
6e0c136
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/jszip-3.…
ejarzo Mar 3, 2023
019ddfa
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/decode-u…
ejarzo Mar 3, 2023
a5438b3
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/qs-6.5.3…
ejarzo Mar 3, 2023
90e443f
Merge remote-tracking branch 'origin/dependabot/npm_and_yarn/json5-1.…
ejarzo Mar 3, 2023
ff56d90
upgrade to tone 14 [BROKEN]
ejarzo Mar 3, 2023
89957fb
Merge branch 'master' into upgrade-to-tone-14
ejarzo Mar 3, 2023
92de7b0
upgrade to tone 14, STILL BUGGY
ejarzo Mar 6, 2023
1328131
Merge branch 'master' into upgrade-to-tone-14
ejarzo Mar 8, 2023
693550c
fix record
ejarzo Mar 8, 2023
21ab1ad
update SW
ejarzo Mar 8, 2023
609296d
fix build
ejarzo Mar 8, 2023
b78372b
test SW deploy
ejarzo Mar 8, 2023
2dc80e1
test deploy
ejarzo Mar 8, 2023
e6f0de0
test sw
ejarzo Mar 8, 2023
449c62c
test sw
ejarzo Mar 8, 2023
0f8467e
test sw
ejarzo Mar 8, 2023
c17eed8
test sw
ejarzo Mar 8, 2023
f3e049d
test sw
ejarzo Mar 8, 2023
b58c402
test sw
ejarzo Mar 9, 2023
47d5898
test new sw
ejarzo Mar 9, 2023
d67371c
fix keys
ejarzo Mar 9, 2023
c4cd49d
upgrade to tone 14 [BROKEN]
ejarzo Mar 3, 2023
cd8edbf
upgrade to tone 14, STILL BUGGY
ejarzo Mar 6, 2023
34ec57d
fix record
ejarzo Mar 8, 2023
9ff6ca0
update SW
ejarzo Mar 8, 2023
0ea7d6e
fix build
ejarzo Mar 8, 2023
689a830
test SW deploy
ejarzo Mar 8, 2023
5ca8bd4
test deploy
ejarzo Mar 8, 2023
252728b
test sw
ejarzo Mar 8, 2023
6055f64
test sw
ejarzo Mar 8, 2023
9a2c741
test sw
ejarzo Mar 8, 2023
b84a7c9
test sw
ejarzo Mar 8, 2023
6146f04
test sw
ejarzo Mar 8, 2023
bbf0be8
test sw
ejarzo Mar 9, 2023
2ef6214
test new sw
ejarzo Mar 9, 2023
f3dd893
fix keys
ejarzo Mar 9, 2023
dcbc49d
Merge branch 'upgrade-to-tone-14' of github.com:ejarzo/Shape-Your-Mus…
ejarzo Mar 14, 2023
96ec0d5
add conversion to WAV
ejarzo Mar 31, 2023
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
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"antd": "^4.8.4",
"apollo-boost": "^0.4.7",
"apollo-server-lambda": "^2.9.16",
"audiobuffer-to-wav": "^1.0.0",
"bufferutil": "^4.0.1",
"chalk": "^2.4.2",
"classnames": "^2.2.5",
Expand Down Expand Up @@ -51,10 +52,10 @@
"react-portal": "^3.2.0",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-scripts": "^3.1.1",
"react-scripts": "^3.2.0",
"react-select": "^3.0.8",
"teoria": "^2.5.0",
"tone": "13.8.25",
"tone": "14.8.49",
"utf-8-validate": "^5.0.2"
},
"scripts": {
Expand All @@ -64,9 +65,10 @@
"upload-schema": "yarn checkForFaunaKey && curl -u $FAUNADB_SERVER_SECRET: https://graphql.fauna.com/import --data-binary \"@schema.gql\"",
"start:server": "yarn upload-schema && netlify-lambda serve functions -c ./webpack.config.js",
"start:devserver": "NODE_ENV=development yarn start:server",
"build": "npm-run-all --parallel build:**",
"build": "npm-run-all --parallel build:** && npm run-script append-sw",
"build:app": "craco build",
"build:functions": "netlify-lambda build functions -c ./webpack.config.js",
"append-sw": "cat src/sw-epilog.js >> build/service-worker.js",
"test": "craco test --env=jsdom",
"eject": "react-scripts eject"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { string, array } from 'prop-types';
import Tone from 'tone';
import * as Tone from 'tone';
import ColorControllerComponent from './Component';
import { SYNTH_PRESETS } from 'instrumentPresets';
import { SEND_CHANNELS } from 'utils/music';
Expand Down Expand Up @@ -28,10 +28,10 @@ class ColorController extends Component {
const { effects } = SYNTH_PRESETS[synthType];

this.fxList = [];
this.fxBus = new Tone.Gain(0.8);
this.fxBus = new Tone.Channel(0, 0);
this.fxBus.receive(receiveChannel);

this.output = new Tone.Gain(1);
this.output = new Tone.Channel();
this.output.send(SEND_CHANNELS.MASTER_OUTPUT, 0);
this.connectEffects(effects);

Expand Down Expand Up @@ -98,13 +98,13 @@ class ColorController extends Component {
// called by the callbacks in the synth object
// TODO figure out better way?
setEffectAmount(effectIndex, val, parameter) {
this.fxList[effectIndex].set(parameter, val);
this.fxList[effectIndex].set({ [parameter]: val });
}

connectEffects(fxConstructors) {
this.disposeEffects();

this.fxBus = new Tone.Gain(0.8);
this.fxBus = new Tone.Channel(0, 0);
this.fxBus.receive(this.props.receiveChannel);

fxConstructors.forEach(fxObj => {
Expand Down
28 changes: 20 additions & 8 deletions src/components/Project/useAudioOutput.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { useState, useEffect } from 'react';
import Tone from 'tone';
import * as Tone from 'tone';
import { SEND_CHANNELS } from 'utils/music';

export const useAudioOutput = () => {
const [isPlaying, setIsPlaying] = useState(false);

useEffect(() => {
/* master output */
const masterCompressor = new Tone.Compressor({
const destinationCompressor = new Tone.Compressor({
ratio: 16,
threshold: -30,
release: 0.25,
attack: 0.003,
knee: 30,
});

const masterLimiter = new Tone.Limiter(-2);
const masterOutput = new Tone.Gain(0.9).receive(
const destinationLimiter = new Tone.Limiter(-2);

/* TODO set gain */
const destinationOutput = new Tone.Channel(-2, 0).receive(
SEND_CHANNELS.MASTER_OUTPUT
);
masterOutput.chain(masterCompressor, masterLimiter, Tone.Master);

const recordOut = new Tone.Channel(0, 0).send(SEND_CHANNELS.RECORDER, 0);
const finalNode = new Tone.Gain();

finalNode.fan(recordOut, Tone.Destination);

destinationOutput.chain(
destinationCompressor,
destinationLimiter,
finalNode
);
return () => {
Tone.Transport.stop();
masterCompressor.dispose();
masterLimiter.dispose();
masterOutput.dispose();
destinationCompressor.dispose();
destinationLimiter.dispose();
destinationOutput.dispose();
};
}, []);

Expand Down
53 changes: 36 additions & 17 deletions src/components/Project/useRecorder.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
import { useRef, useState, useEffect } from 'react';
import moment from 'moment';
import Tone from 'tone';
import Recorder from 'utils/Recorder';
import * as Tone from 'tone';
import { SEND_CHANNELS } from 'utils/music';
import audiobufferToWav from 'audiobuffer-to-wav';

async function convertWebMToWAV(webmBlob) {
// Read the WebM data as an ArrayBuffer
const arrayBuffer = await webmBlob.arrayBuffer();

// Decode the WebM data using the Web Audio API
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);

// Encode the AudioBuffer as WAV using the 'audiobuffer-to-wav' library
const wavBlob = new Blob([audiobufferToWav(audioBuffer)], {
type: 'audio/wav',
});

return wavBlob;
}

export const useRecorder = () => {
const recorder = useRef(null);
useEffect(() => {
recorder.current = new Recorder(Tone.Master);
const recorderChannel = new Tone.Channel();
recorderChannel.receive(SEND_CHANNELS.RECORDER);
recorder.current = new Tone.Recorder();
recorderChannel.connect(recorder.current);
}, []);

const [isRecording, setIsRecording] = useState(false);
const [isArmed, setIsArmed] = useState(false);
const [downloadUrls, setDownloadUrls] = useState([]);

const beginRecording = () => {
setIsArmed(false);
setIsRecording(true);
recorder.current.record();
recorder.current.start();
};

const stopRecording = (fileName = 'My project') => {
recorder.current.exportWAV(blob => {
const url = URL.createObjectURL(blob);
const newDownloadUrls = downloadUrls.slice();
const createdAt = moment();
newDownloadUrls.push({
url,
fileName: `${fileName}[shapeyourmusic].wav`,
createdAt,
});
setDownloadUrls(newDownloadUrls);
recorder.current.stop();
recorder.current.clear();
const stopRecording = async (fileName = 'My project') => {
const webmBlob = await recorder.current.stop();
const wavBlob = await convertWebMToWAV(webmBlob);
const url = URL.createObjectURL(wavBlob);
const newDownloadUrls = downloadUrls.slice();
const createdAt = moment();
newDownloadUrls.push({
url,
fileName: `${fileName}[shapeyourmusic].wav`,
createdAt,
});
setDownloadUrls(newDownloadUrls);
setIsRecording(false);
};

Expand Down
24 changes: 17 additions & 7 deletions src/components/Shape/Synth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tone from 'tone';
import * as Tone from 'tone';
import { SYNTH_PRESETS } from 'instrumentPresets';
import { SEND_CHANNELS } from 'utils/music';
import { forEachPoint, getNoteInfo } from 'utils/shape';
Expand Down Expand Up @@ -49,7 +49,7 @@ export function Synth({ onStartLoading, onEndLoading }) {
panner.disconnect();
panner.dispose();
panner3d.disconnect();
panner3d.dispose();
// panner3d.dispose();
solo.disconnect();
solo.dispose();
gain.disconnect();
Expand All @@ -69,11 +69,17 @@ export function Synth({ onStartLoading, onEndLoading }) {
if (synth) {
disposeSynth();
}

synth = new synthObj.baseSynth(synthObj.params, () => {
const { isSampler } = synthObj;
console.log('base synth', synthObj.baseSynth);
const onLoaded = () => {
onEndLoading();
isBuffering = false;
});
};
synth = new synthObj.baseSynth(
synthObj.params,
...(isSampler ? [onLoaded] : [])
);

if (synth instanceof Tone.Sampler) {
onStartLoading();
isBuffering = true;
Expand Down Expand Up @@ -110,8 +116,12 @@ export function Synth({ onStartLoading, onEndLoading }) {
}

solo = new Tone.Solo();

// NOTE: this is where we connect to the output channel for this color
gain = new Tone.Gain().send(`${SEND_CHANNELS.FX_PREFIX}${colorIndex}`, 0);
gain = new Tone.Channel().send(
`${SEND_CHANNELS.FX_PREFIX}${colorIndex}`,
0
);

synth.chain(pannerNode, solo, gain);
},
Expand All @@ -124,7 +134,7 @@ export function Synth({ onStartLoading, onEndLoading }) {
});
},
setNoteEvents: (scaleObj, points) => {
part.removeAll();
part.clear();

let delay = 0;
let prevNoteIndex = firstNoteIndex;
Expand Down
1 change: 1 addition & 0 deletions src/components/Shape/useShapeSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const useShapeSynth = ({
}, [firstNoteIndex]);

useEffect(() => {
console.log('calling set synth', selectedSynth, colorIndex);
synthContainer.current.setSynth(selectedSynth, colorIndex);
}, [selectedSynth, colorIndex]);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ShapeCanvas/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ShapeCanvasComponent from './Component';
import { TOOL_TYPES } from 'utils/project';

import withProjectContext from 'components/Project/withProjectContext';
import Tone from 'tone';
import * as Tone from 'tone';

export const DRAWING_STATES = {
PENDING: 'pending', // not currently drawing
Expand Down
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
// import registerServiceWorker from './registerServiceWorker';
import * as serviceWorker from './serviceWorker';

import { initSentry } from 'utils/errorTracking';

Expand All @@ -13,4 +14,12 @@ import './static/css/main.css';
initSentry();

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
serviceWorker.register({
onUpdate: registration => {
alert('New version available! Ready to update?');
if (registration && registration.waiting) {
registration.waiting.postMessage({ type: 'SKIP_WAITING' });
}
window.location.reload();
},
});
2 changes: 1 addition & 1 deletion src/instrumentPresets/blip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tone from 'tone';
import * as Tone from 'tone';
import { setSynthParam, setSynthEnvelopeParam } from './utils';

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentPresets/cello.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tone from 'tone';
import * as Tone from 'tone';
import { setSynthEnvelopeParam, setEffectWet } from './utils';

export default {
Expand Down
48 changes: 46 additions & 2 deletions src/instrumentPresets/duo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import Tone from 'tone';
import * as Tone from 'tone';
import { setSynthParam, setEffectWet } from './utils';

export default {
name: 'Duo',
baseSynth: Tone.DuoSynth,
params: {},
params: {
vibratoAmount: 0.5,
vibratoRate: 5,
harmonicity: 1.5,
voice0: {
volume: -10,
portamento: 0,
oscillator: {
type: 'custom',
partials: [3],
},
filterEnvelope: {
attack: 0.01,
decay: 0,
sustain: 1,
release: 0.5,
},
envelope: {
attack: 0.01,
decay: 0,
sustain: 1,
release: 0.5,
},
},
voice1: {
volume: -10,
portamento: 0,
oscillator: {
type: 'custom',
partials: [3],
},
filterEnvelope: {
attack: 0.01,
decay: 0,
sustain: 1,
release: 0.5,
},
envelope: {
attack: 0.01,
decay: 0,
sustain: 1,
release: 0.5,
},
},
},
effects: [
{
type: Tone.Chorus,
Expand Down
Loading