Skip to content

Commit

Permalink
eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
LilaShiba committed May 7, 2020
1 parent 70aa23c commit 91a87b8
Show file tree
Hide file tree
Showing 63 changed files with 2,190 additions and 1,844 deletions.
68 changes: 12 additions & 56 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,23 @@
"Float32Array": true,
"Uint8Array": true
},
"extends": ["eslint:recommended", "prettier"],
"plugins": ["prettier"],
"rules": {
"block-scoped-var": 0,
"camelcase": 0,
"comma-style": [
2,
"last"
],
"dot-notation": [
"prettier/prettier": ["error"],
"no-cond-assign": [2, "except-parens"],
"eqeqeq": ["error", "smart"],
"no-use-before-define": [
2,
{
"allowKeywords": true
"functions": false
}
],
"eqeqeq": [
2,
"allow-null"
],
"eol-last": ["error", "always"],
"guard-for-in": 2,
"indent": ["error", 2, { "SwitchCase": 1 }],
"max-len": [1, 120, 2, { "ignoreComments": true }],
"new-cap": 2,
"new-cap": 0,
"no-caller": 2,
"no-cond-assign": [
2,
"except-parens"
],
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 2,
"no-extra-semi": 2,
"no-irregular-whitespace": 2,
"no-trailing-spaces": 2,
"no-iterator": 2,
"no-loop-func": 0,
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-undef": 2,
"no-unused-vars": 2,
"no-with": 2,
"quotes": [
2,
"single"
],
"semi": [
2
],
"space-before-blocks": "error",
"strict": 2,
"valid-typeof": 2,
"wrap-iife": [
2,
"inside"
]
"no-undef": 0,
"no-unused-vars": ["error", { "args": "none" }],
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-console": "off"
}
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Gruntfile.js
test/test.js
webpack.config.js
lib/
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
9 changes: 6 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ module.exports = function(grunt) {
// Configure style consistency
eslint: {
source: {
options: {configFile: './.eslintrc'},
options: {
configFile: './.eslintrc',
fix: true
},
src: ['src/**/*.js', 'test/tests/**/*.js']
}
},
Expand Down Expand Up @@ -56,7 +59,7 @@ module.exports = function(grunt) {
}
});


grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-connect');
Expand All @@ -65,7 +68,7 @@ module.exports = function(grunt) {

grunt.registerTask('lint', ['eslint:source']);
grunt.registerTask('default', ['webpack:prod', 'decomment']);
grunt.registerTask('dev', ['connect','webpack:dev', 'decomment']);
grunt.registerTask('dev', ['eslint','connect','webpack:dev', 'decomment']);
grunt.registerTask('serve', 'connect:server:keepalive');
grunt.registerTask('run-tests', ['serve', 'open']);
};
50 changes: 50 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"amdclean": "~2.0",
"babel-loader": "^8.0.6",
"babel-plugin-preval": "^3.0.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"grunt": "~0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-connect": "^1.0.2",
Expand All @@ -21,6 +23,7 @@
"grunt-mocha": "^1.0.4",
"grunt-open": "^0.2.3",
"grunt-webpack": "^3.1.3",
"prettier": "2.0.5",
"raw-loader": "^3.0.0",
"uglify-loader": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.1.3",
Expand All @@ -30,7 +33,8 @@
"dependencies": {
"audioworklet-polyfill": "^1.1.2",
"startaudiocontext": "^1.2.1",
"tone": "0.10.0"
"tone": "0.10.0",
"tslint-config-prettier": "^1.18.0"
},
"scripts": {
"build": "grunt",
Expand Down
61 changes: 32 additions & 29 deletions src/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,29 @@ define(function (require) {
*
* </code></div>
*/
p5.Amplitude = function(smoothing) {

p5.Amplitude = function (smoothing) {
// Set to 2048 for now. In future iterations, this should be inherited or parsed from p5sound's default
this.bufferSize = safeBufferSize(2048);

// set audio context
this.audiocontext = p5sound.audiocontext;
this._workletNode = new AudioWorkletNode(this.audiocontext, processorNames.amplitudeProcessor, {
outputChannelCount: [1],
this._workletNode = new AudioWorkletNode(
this.audiocontext,
processorNames.amplitudeProcessor,
{
outputChannelCount: [1],

parameterData: { smoothing: smoothing || 0 },
processorOptions: {
normalize: false,
smoothing: smoothing || 0,
numInputChannels: 2,
bufferSize: this.bufferSize
parameterData: { smoothing: smoothing || 0 },
processorOptions: {
normalize: false,
smoothing: smoothing || 0,
numInputChannels: 2,
bufferSize: this.bufferSize,
},
}
});
);

this._workletNode.port.onmessage = function(event) {
this._workletNode.port.onmessage = function (event) {
if (event.data.name === 'amplitude') {
this.volume = event.data.volume;
this.volNorm = event.data.volNorm;
Expand Down Expand Up @@ -146,8 +149,7 @@ define(function (require) {
* }
* </code></div>
*/
p5.Amplitude.prototype.setInput = function(source, smoothing) {

p5.Amplitude.prototype.setInput = function (source, smoothing) {
p5sound.meter.disconnect();

if (smoothing) {
Expand All @@ -156,7 +158,9 @@ define(function (require) {

// connect to the master out of p5s instance if no snd is provided
if (source == null) {
console.log('Amplitude input source is not ready! Connecting to master output instead');
console.log(
'Amplitude input source is not ready! Connecting to master output instead'
);
p5sound.meter.connect(this._workletNode);
}

Expand All @@ -177,7 +181,7 @@ define(function (require) {
}
};

p5.Amplitude.prototype.connect = function(unit) {
p5.Amplitude.prototype.connect = function (unit) {
if (unit) {
if (unit.hasOwnProperty('input')) {
this.output.connect(unit.input);
Expand All @@ -189,7 +193,7 @@ define(function (require) {
}
};

p5.Amplitude.prototype.disconnect = function() {
p5.Amplitude.prototype.disconnect = function () {
if (this.output) {
this.output.disconnect();
}
Expand Down Expand Up @@ -234,18 +238,16 @@ define(function (require) {
* }
* </code></div>
*/
p5.Amplitude.prototype.getLevel = function(channel) {
p5.Amplitude.prototype.getLevel = function (channel) {
if (typeof channel !== 'undefined') {
if (this.normalize) {
return this.stereoVolNorm[channel];
} else {
return this.stereoVol[channel];
}
}
else if (this.normalize) {
} else if (this.normalize) {
return this.volNorm;
}
else {
} else {
return this.volume;
}
};
Expand All @@ -264,14 +266,16 @@ define(function (require) {
* @for p5.Amplitude
* @param {boolean} [boolean] set normalize to true (1) or false (0)
*/
p5.Amplitude.prototype.toggleNormalize = function(bool) {
p5.Amplitude.prototype.toggleNormalize = function (bool) {
if (typeof bool === 'boolean') {
this.normalize = bool;
}
else {
} else {
this.normalize = !this.normalize;
}
this._workletNode.port.postMessage({ name: 'toggleNormalize', normalize: this.normalize });
this._workletNode.port.postMessage({
name: 'toggleNormalize',
normalize: this.normalize,
});
};

/**
Expand All @@ -282,15 +286,15 @@ define(function (require) {
* @for p5.Amplitude
* @param {Number} set smoothing from 0.0 <= 1
*/
p5.Amplitude.prototype.smooth = function(s) {
p5.Amplitude.prototype.smooth = function (s) {
if (s >= 0 && s < 1) {
this._workletNode.port.postMessage({ name: 'smoothing', smoothing: s });
} else {
console.log('Error: smoothing must be between 0 and 1');
}
};

p5.Amplitude.prototype.dispose = function() {
p5.Amplitude.prototype.dispose = function () {
// remove reference from soundArray
var index = p5sound.soundArray.indexOf(this);
p5sound.soundArray.splice(index, 1);
Expand All @@ -307,5 +311,4 @@ define(function (require) {
this._workletNode.disconnect();
delete this._workletNode;
};

});
2 changes: 0 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

define(function (require) {

require('audioworklet-polyfill');
require('shims');
require('audiocontext');
Expand Down Expand Up @@ -40,5 +39,4 @@ define(function (require) {
require('polysynth');

return p5SOUND;

});
Loading

0 comments on commit 91a87b8

Please sign in to comment.