diff --git a/src/components/audio-trimmer/audio-trimmer.jsx b/src/components/audio-trimmer/audio-trimmer.jsx index fc216063a89091523735081e9c3ab407739e316a..b7bbe380fe26b0371edd7a03eac205a0aa71b33d 100644 --- a/src/components/audio-trimmer/audio-trimmer.jsx +++ b/src/components/audio-trimmer/audio-trimmer.jsx @@ -10,7 +10,7 @@ const AudioTrimmer = props => ( className={styles.absolute} ref={props.containerRef} > - {props.trimStart !== null ? ( + {props.trimStart === null ? null : ( <Box className={classNames(styles.absolute, styles.trimBackground, styles.startTrimBackground)} style={{ @@ -28,7 +28,7 @@ const AudioTrimmer = props => ( </Box> </Box> </Box> - ) : null} + )} {props.playhead ? ( <Box @@ -39,12 +39,12 @@ const AudioTrimmer = props => ( /> ) : null} - {props.trimEnd !== null ? ( + {props.trimEnd === null ? null : ( <Box className={classNames(styles.absolute, styles.trimBackground, styles.endTrimBackground)} style={{ left: `${100 * props.trimEnd}%`, - width: `${100 - 100 * props.trimEnd}%` + width: `${100 - (100 * props.trimEnd)}%` }} onMouseDown={props.onTrimEndMouseDown} > @@ -58,7 +58,7 @@ const AudioTrimmer = props => ( </Box> </Box> </Box> - ) : null } + )} </div> ); diff --git a/src/components/meter/meter.jsx b/src/components/meter/meter.jsx index b2878a8dda6ae68fa27d19f5960ae4c120e82a43..8c378037c85ae61553af08141b1b52983289317f 100644 --- a/src/components/meter/meter.jsx +++ b/src/components/meter/meter.jsx @@ -17,7 +17,7 @@ const Meter = props => { const barSpacing = 2.5; const barRounding = 3; - const barHeight = (height - barSpacing * (nBars + 1)) / nBars; + const barHeight = (height - (barSpacing * (nBars + 1))) / nBars; const nBarsToMask = nBars - Math.floor(level * nBars); @@ -38,12 +38,12 @@ const Meter = props => { ry={barRounding} width={width - 2} x={1} - y={height - (barSpacing + barHeight) * (index + 1)} + y={height - ((barSpacing + barHeight) * (index + 1))} /> ))} <rect fill="white" - height={nBarsToMask * (barHeight + barSpacing) + barSpacing / 2} + height={(nBarsToMask * (barHeight + barSpacing)) + (barSpacing / 2)} opacity="0.75" width={width} x={0} diff --git a/src/components/record-modal/recording-step.jsx b/src/components/record-modal/recording-step.jsx index 624a2e2b2ae319ad69dbc7a1dc61f7779ee3a498..315696ab6203a55c9e8eef49990064433b6cef6e 100644 --- a/src/components/record-modal/recording-step.jsx +++ b/src/components/record-modal/recording-step.jsx @@ -57,7 +57,7 @@ const RecordingStep = props => ( className={styles.recordButtonCircleOutline} cx="26" cy="26" - r={27 + props.level * 5} + r={27 + (props.level * 5)} /> </svg> )} diff --git a/src/containers/audio-trimmer.jsx b/src/containers/audio-trimmer.jsx index 03e91443eb32f538640ee9a1fd17ac2a66aa2375..db85370b8682f6cf4db9859f2332b957dac54cda 100644 --- a/src/containers/audio-trimmer.jsx +++ b/src/containers/audio-trimmer.jsx @@ -52,7 +52,7 @@ class AudioTrimmer extends React.Component { render () { return ( <AudioTrimmerComponent - containerRef={el => (this.containerElement = el)} + containerRef={el => (this.containerElement = el)} // eslint-disable-line react/jsx-no-bind playhead={this.props.playhead} trimEnd={this.props.trimEnd} trimStart={this.props.trimStart} diff --git a/src/lib/audio/audio-buffer-player.js b/src/lib/audio/audio-buffer-player.js index 39affdfd338d607aaa16ffa5917e5629dc52a8c2..e9e89c787f9fae23eae39c4b3f08e8a6ce601b04 100644 --- a/src/lib/audio/audio-buffer-player.js +++ b/src/lib/audio/audio-buffer-player.js @@ -20,7 +20,7 @@ class AudioBufferPlayer { this.startTime = Date.now(); const trimStartTime = this.buffer.duration * trimStart; - const trimmedDuration = this.buffer.duration * trimEnd - trimStartTime; + const trimmedDuration = (this.buffer.duration * trimEnd) - trimStartTime; this.source = this.audioContext.createBufferSource(); this.source.onended = onEnded; diff --git a/src/lib/audio/audio-effects.js b/src/lib/audio/audio-effects.js index b7ba65cb2384bd3896a607bb5c7ffef185dc84d3..187c6ce6b9be659d404fc72e13bab33bcc413fd3 100644 --- a/src/lib/audio/audio-effects.js +++ b/src/lib/audio/audio-effects.js @@ -24,7 +24,7 @@ class AudioEffects { let playbackRate = 1; switch (name) { case effectTypes.ECHO: - sampleCount = buffer.length + 0.25 * 3 * buffer.sampleRate; + sampleCount = buffer.length + (0.25 * 3 * buffer.sampleRate); break; case effectTypes.FASTER: playbackRate = pitchRatio; diff --git a/src/lib/audio/effects/robot-effect.js b/src/lib/audio/effects/robot-effect.js index d530b9e6e039891f7881f5860de9991684f32b90..472668d531e4344be34a7fcf100d3448f46f090c 100644 --- a/src/lib/audio/effects/robot-effect.js +++ b/src/lib/audio/effects/robot-effect.js @@ -18,15 +18,15 @@ class RobotEffect { // Piecewise function given by (2) in Parker paper const transform = (v, vb = 0.2, vl = 0.4, h = 0.65) => { if (v <= vb) return 0; - if (v <= vl) return h * (Math.pow(v - vb, 2) / (2 * vl - 2 * vb)); - return h * v - h * vl + h * (Math.pow(v - vb, 2) / (2 * vl - 2 * vb)); + if (v <= vl) return h * (Math.pow(v - vb, 2) / ((2 * vl) - (2 * vb))); + return (h * v) - (h * vl) + (h * (Math.pow(v - vb, 2) / ((2 * vl) - (2 * vb)))); }; // Create the waveshaper curve with the voltage transform above const bufferLength = 1024; const curve = new Float32Array(bufferLength); for (let i = 0; i < bufferLength; i++) { - const voltage = 2 * (i / bufferLength) - 1; + const voltage = (2 * (i / bufferLength)) - 1; curve[i] = transform(voltage); } node.curve = curve; diff --git a/src/lib/audio/shared-audio-context.js b/src/lib/audio/shared-audio-context.js index f0b5c3ccf39fffad10de75ac9272eb3156175acc..f125aa722c72fd13682aecbcc24793c484ec53be 100644 --- a/src/lib/audio/shared-audio-context.js +++ b/src/lib/audio/shared-audio-context.js @@ -1,6 +1,9 @@ -// Wrap browser AudioContext because we shouldn't create more than one const AUDIO_CONTEXT = new (window.AudioContext || window.webkitAudioContext)(); +/** + * Wrap browser AudioContext because we shouldn't create more than one + * @return {AudioContext} The singleton AudioContext + */ export default function () { return AUDIO_CONTEXT; } diff --git a/src/lib/blocks.js b/src/lib/blocks.js index 7c6b10b21cafe7e06a0fa9e3e126cb597cb8dc1a..662eb245f354ef9b3a591d20b6b264f16173f60d 100644 --- a/src/lib/blocks.js +++ b/src/lib/blocks.js @@ -1,5 +1,10 @@ import ScratchBlocks from 'scratch-blocks'; +/** + * Connect scratch blocks with the vm + * @param {VirtualMachine} vm - The scratch vm + * @return {ScratchBlocks} ScratchBlocks connected with the vm + */ export default function (vm) { const jsonForMenuBlock = function (name, menuOptionsFn, colors, start) { diff --git a/src/lib/monitor-adapter.js b/src/lib/monitor-adapter.js index 4a05cf3282ba569e2afd96407f8a4a91dd7fac7e..69f362b5c9c9946391f9866204d7d787c89b77de 100644 --- a/src/lib/monitor-adapter.js +++ b/src/lib/monitor-adapter.js @@ -1,8 +1,3 @@ -/** - * Convert monitors from VM format to what the GUI needs to render. - * - Convert opcode to a label and a category - * - Add missing XY position data if needed - */ import OpcodeLabels from './opcode-labels.js'; const PADDING = 5; @@ -10,6 +5,20 @@ const MONITOR_HEIGHT = 23; const isUndefined = a => typeof a === 'undefined'; +/** + * Convert monitors from VM format to what the GUI needs to render. + * - Convert opcode to a label and a category + * - Add missing XY position data if needed + * @param {object} block - The monitor block + * @param {string} block.id - The id of the monitor block + * @param {number} block.index - The index of the monitor + * @param {string} block.opcode - The opcode of the monitor + * @param {object} block.params - Extra params to the monitor block + * @param {string} block.value - The monitor value + * @param {number} x - The monitor x position + * @param {number} y - The monitor y position + * @return {object} The adapted monitor with label and category + */ export default function ({id, index, opcode, params, value, x, y}) { let {label, category, labelFn} = OpcodeLabels(opcode); diff --git a/src/lib/opcode-labels.js b/src/lib/opcode-labels.js index 6acc4109b3ca661cecb3bb2bf51b6d2cc7e01bf9..d36842c682c1c5466d1cb9460983ae42278b5ea6 100644 --- a/src/lib/opcode-labels.js +++ b/src/lib/opcode-labels.js @@ -66,6 +66,11 @@ const opcodeMap = { } }; +/** + * Get the label for an opcode + * @param {string} opcode the opcode you want a label for + * @return {object} object with label and category + */ export default function (opcode) { if (opcode in opcodeMap) return opcodeMap[opcode]; return { diff --git a/test/helpers/selenium-helpers.js b/test/helpers/selenium-helpers.js index 5ee0af01e65a379c5dee5f92f26536e3aa98dab4..909f3a1553eaca14269f494216a1f55140aff87e 100644 --- a/test/helpers/selenium-helpers.js +++ b/test/helpers/selenium-helpers.js @@ -42,8 +42,8 @@ const getLogs = (whitelist) => { console.warn('Ignoring non-SEVERE entry: ' + message); return false; } - return true; } + return true; }); }); }; diff --git a/test/unit/util/audio-util.test.js b/test/unit/util/audio-util.test.js index 714381db64bb61b5ccaa1b37f9265c2ed50c3549..743a5b1c492894ce420b1f6bb66fa977eb2f4522 100644 --- a/test/unit/util/audio-util.test.js +++ b/test/unit/util/audio-util.test.js @@ -9,7 +9,7 @@ describe('computeRMS', () => { const unity = 0.5; const samples = [3, 2, 1]; expect(computeRMS(samples, unity)).toEqual( - Math.sqrt(Math.sqrt((3 * 3 + 2 * 2 + 1 * 1) / 3) / 0.5) + Math.sqrt(Math.sqrt(((3 * 3) + (2 * 2) + (1 * 1)) / 3) / 0.5) ); }); test('uses a default unity value of 0.55', () => { @@ -28,8 +28,8 @@ describe('computeChunkedRMS', () => { // rms scaled with default unity of 0.55 expect(chunkedLevels.length).toEqual(3); expect(chunkedLevels).toEqual([ - Math.sqrt(Math.sqrt((2 * 2 + 1 * 1) / 2) / 0.55), - Math.sqrt(Math.sqrt((3 * 3 + 2 * 2) / 2) / 0.55), + Math.sqrt(Math.sqrt(((2 * 2) + (1 * 1)) / 2) / 0.55), + Math.sqrt(Math.sqrt(((3 * 3) + (2 * 2)) / 2) / 0.55), Math.sqrt(Math.sqrt((5 * 5) / 1) / 0.55) ]); });