Skip to content

Commit

Permalink
Upgrade Redux-VCR, ensure silence after stopping/ejecting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwcomeau committed Oct 1, 2016
1 parent dcb6ef8 commit 22945c3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -39,7 +39,7 @@
"redux": "^3.5.2",
"redux-saga": "^0.11.0",
"redux-thunk": "^2.1.0",
"redux-vcr": "0.1.12",
"redux-vcr": "0.3.1",
"reselect": "^2.5.3",
"soundbank-reverb": "^1.1.2",
"svg-inline-loader": "^0.6.1",
Expand Down
5 changes: 5 additions & 0 deletions src/actions/index.js
Expand Up @@ -8,6 +8,7 @@ export const TWEAK_AXIS_PARAMETER = 'EFFECTS/TWEAK_AXIS_PARAMETER';

export const ADD_NOTE = 'NOTES/ADD_NOTE';
export const REMOVE_NOTE = 'NOTES/REMOVE_NOTE';
export const REMOVE_ALL_NOTES = 'NOTES/REMOVE_ALL_NOTES';

export const UPDATE_OSCILLATOR = 'OSCILLATORS/UPDATE_OSCILLATOR';

Expand Down Expand Up @@ -63,6 +64,10 @@ export const removeNote = ({ value }) => ({
value,
});

export const removeAllNotes = () => ({
type: REMOVE_ALL_NOTES,
});

export const updateStage = ({ stage }) => ({
type: UPDATE_STAGE,
stage,
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/effects.reducer.js
@@ -1,5 +1,5 @@
import { createSelector } from 'reselect';
import effectDefaultOptions from '../data/effect-default-options.js';
import effectDefaultOptions from '../data/effect-default-options';

import {
DEACTIVATE_EFFECTS,
Expand Down Expand Up @@ -104,5 +104,5 @@ export const axisControlSelector = createSelector(

export const otherAxisNameSelector = createSelector(
otherAxisName,
(name) => name
name => name
);
6 changes: 5 additions & 1 deletion src/reducers/notes.reducer.js
@@ -1,4 +1,4 @@
import { ADD_NOTE, REMOVE_NOTE } from '../actions';
import { ADD_NOTE, REMOVE_NOTE, REMOVE_ALL_NOTES } from '../actions';

const initialState = [];

Expand All @@ -13,6 +13,10 @@ export default function notesReducer(state = initialState, action) {
return state.filter(note => note.value !== action.value);
}

case REMOVE_ALL_NOTES: {
return [];
}

default:
return state;
}
Expand Down
15 changes: 14 additions & 1 deletion src/utils/build-middleware-array.js
Expand Up @@ -4,23 +4,34 @@ import {
createRetrieveHandler,
createRetrieveMiddleware,
createReplayMiddleware,
getQueryParam,
} from 'redux-vcr';

import { firebaseAuth } from '../data/firebase';

import {
COMPLETE_ONBOARDING,
removeAllNotes,
} from '../actions';


function silence(dispatch) {
dispatch(removeAllNotes());
}

export default function buildMiddlewareArray({ adminMode = false } = {}) {
const middlewares = [];

if (adminMode) {
const retrieveHandler = createRetrieveHandler({ firebaseAuth });


middlewares.push(
createRetrieveMiddleware({ retrieveHandler, requiresAuth: false }),
createRetrieveMiddleware({
retrieveHandler,
requiresAuth: false,
initialCassetteId: getQueryParam({ param: 'cassetteId' }),
}),
createReplayMiddleware({
maximumDelay: 2000,
// The cassette was not recorded in admin mode, but we need to replay
Expand All @@ -29,6 +40,8 @@ export default function buildMiddlewareArray({ adminMode = false } = {}) {
overwriteCassetteState: {
isAdmin: true,
},
onStop: silence,
onEject: silence,
})
);
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/utils/web-audio-manager.js
Expand Up @@ -14,7 +14,7 @@ import {
getLogarithmicFrequencyValue,
getOctaveMultiplier,
} from './web-audio-helpers';
import effectDefaultOptions from '../data/effect-default-options.js';
import effectDefaultOptions from '../data/effect-default-options';


// eslint-disable-next-line no-undef
Expand Down Expand Up @@ -45,7 +45,7 @@ In the above example, the signal routes through a filter and a delay,
avoiding the other effects (distortion and reverb).
*/

export const webAudioManagerFactory = context => {
export const webAudioManagerFactory = (context) => {
/*
Store all currently-playing oscillators here.
Shape is:
Expand Down Expand Up @@ -139,8 +139,7 @@ export const webAudioManagerFactory = context => {
// return the WebAudioManager itself.
return {
stopAllOscillators() {
// TODO: Look into whether I need to kill the gains created for each osc.
activeOscillators.forEach(oscillatorArray => {
activeOscillators.forEach((oscillatorArray) => {
oscillatorArray.forEach(({ oscillator, output }) => {
// Add a brief release, to avoid clipping
fade({
Expand Down

0 comments on commit 22945c3

Please sign in to comment.