Skip to content

Commit

Permalink
airbnb removed again
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Mar 25, 2021
1 parent 1d01aa8 commit 909c082
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"files": [ "**/*.ts" ],
"extends": [
"eslint-config-airbnb-typescript/base",
"eslint:recommended",
"prettier"
],
"rules": {
Expand Down
43 changes: 24 additions & 19 deletions releases/vexflow-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -19647,7 +19647,6 @@ exports.MultiMeasureRest = MultiMeasureRest;
// This class implements some standard music theory routines.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Music = void 0;
/* eslint-disable class-methods-use-this */
var vex_1 = __webpack_require__(/*! ./vex */ "./src/vex.js");
var Music = /** @class */ (function () {
function Music() {
Expand Down Expand Up @@ -19861,10 +19860,10 @@ var Music = /** @class */ (function () {
};
Music.prototype.getNoteParts = function (noteString) {
if (!noteString || noteString.length < 1) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid note name: " + noteString);
throw new vex_1.Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}
if (noteString.length > 3) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid note name: " + noteString);
throw new vex_1.Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}
var note = noteString.toLowerCase();
var regex = /^([cdefgab])(b|bb|n|#|##)?$/;
Expand All @@ -19877,11 +19876,13 @@ var Music = /** @class */ (function () {
accidental: accidental,
};
}
throw new vex_1.Vex.RERR('BadArguments', "Invalid note name: " + noteString);
else {
throw new vex_1.Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}
};
Music.prototype.getKeyParts = function (keyString) {
if (!keyString || keyString.length < 1) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid key: " + keyString);
throw new vex_1.Vex.RERR('BadArguments', 'Invalid key: ' + keyString);
}
var key = keyString.toLowerCase();
// Support Major, Minor, Melodic Minor, and Harmonic Minor key types.
Expand All @@ -19900,7 +19901,9 @@ var Music = /** @class */ (function () {
type: type,
};
}
throw new vex_1.Vex.RERR('BadArguments', "Invalid key: " + keyString);
else {
throw new vex_1.Vex.RERR('BadArguments', "Invalid key: " + keyString);
}
};
Music.prototype.getNoteValue = function (noteString) {
var value = Music.noteValues[noteString];
Expand Down Expand Up @@ -19932,11 +19935,12 @@ var Music = /** @class */ (function () {
* relative note.
*/
Music.prototype.getRelativeNoteValue = function (noteValue, intervalValue, direction) {
var dir = direction == null ? 1 : direction;
if (dir !== 1 && dir !== -1) {
if (direction == null)
direction = 1;
if (direction !== 1 && direction !== -1) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid direction: " + direction);
}
var sum = (noteValue + dir * intervalValue) % Music.NUM_TONES;
var sum = (noteValue + direction * intervalValue) % Music.NUM_TONES;
if (sum < 0)
sum += Music.NUM_TONES;
return sum;
Expand All @@ -19950,25 +19954,25 @@ var Music = /** @class */ (function () {
if (interval > 0)
multiplier = -1;
// Possibly wrap around. (Add +1 for modulo operator)
var reverseInterval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;
if (Math.abs(reverseInterval) > 2) {
var reverse_interval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;
if (Math.abs(reverse_interval) > 2) {
throw new vex_1.Vex.RERR('BadArguments', "Notes not related: " + root + ", " + noteValue + ")");
}
else {
interval = reverseInterval;
interval = reverse_interval;
}
}
if (Math.abs(interval) > 2) {
throw new vex_1.Vex.RERR('BadArguments', "Notes not related: " + root + ", " + noteValue + ")");
}
var relativeNoteName = parts.root;
if (interval > 0) {
for (var i = 1; i <= interval; i += 1) {
for (var i = 1; i <= interval; ++i) {
relativeNoteName += '#';
}
}
else if (interval < 0) {
for (var i = -1; i >= interval; i -= 1) {
for (var i = -1; i >= interval; --i) {
relativeNoteName += 'b';
}
}
Expand Down Expand Up @@ -19997,14 +20001,15 @@ var Music = /** @class */ (function () {
* E.g., Given the scale C, and the note E, returns M3
*/
Music.prototype.getIntervalBetween = function (note1, note2, direction) {
var dir = direction == null ? 1 : direction;
if (dir !== 1 && dir !== -1) {
if (direction == null)
direction = 1;
if (direction !== 1 && direction !== -1) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid direction: " + direction);
}
if (!this.isValidNoteValue(note1) || !this.isValidNoteValue(note2)) {
throw new vex_1.Vex.RERR('BadArguments', "Invalid notes: " + note1 + ", " + note2);
}
var difference = dir === 1 ? note2 - note1 : note1 - note2;
var difference = direction === 1 ? note2 - note1 : note1 - note2;
if (difference < 0)
difference += Music.NUM_TONES;
return difference;
Expand All @@ -20022,11 +20027,11 @@ var Music = /** @class */ (function () {
if (keySigParts.accidental)
keySigString += keySigParts.accidental;
if (!scaleName)
throw new vex_1.Vex.RERR('BadArguments', "Unsupported key type: " + keySignature);
throw new vex_1.Vex.RERR('BadArguments', 'Unsupported key type: ' + keySignature);
var scale = this.getScaleTones(this.getNoteValue(keySigString), scaleName);
var noteLocation = Music.root_indices[keySigParts.root];
var scaleMap = {};
for (var i = 0; i < Music.roots.length; i += 1) {
for (var i = 0; i < Music.roots.length; ++i) {
var index = (noteLocation + i) % Music.roots.length;
var rootName = Music.roots[index];
var noteName = this.getRelativeNoteName(rootName, scale[i]);
Expand Down
2 changes: 1 addition & 1 deletion releases/vexflow-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion releases/vexflow-min.js.map

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions src/music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
// ## Description
// This class implements some standard music theory routines.

/* eslint-disable class-methods-use-this */

import { Vex } from './vex';

export type KeyValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;

export type RootValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;

export type AccidentalValue = -2 | -1 | 0 | 1 | 2;

export interface NoteAccidental {
note: number;
accidental: AccidentalValue;
Expand All @@ -24,6 +16,12 @@ export interface NoteParts {
type?: string;
}

export type KeyValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;

export type RootValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;

export type AccidentalValue = -2 | -1 | 0 | 1 | 2;

export interface Key {
root_index: RootValue;
int_val: KeyValue;
Expand Down Expand Up @@ -204,11 +202,11 @@ export class Music {

getNoteParts(noteString: string): NoteParts {
if (!noteString || noteString.length < 1) {
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}

if (noteString.length > 3) {
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}

const note = noteString.toLowerCase();
Expand All @@ -224,13 +222,14 @@ export class Music {
root,
accidental,
};
} else {
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
}

getKeyParts(keyString: string): NoteParts {
if (!keyString || keyString.length < 1) {
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
throw new Vex.RERR('BadArguments', 'Invalid key: ' + keyString);
}

const key = keyString.toLowerCase();
Expand All @@ -252,8 +251,9 @@ export class Music {
accidental,
type,
};
} else {
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
}
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
}

getNoteValue(noteString: string): number {
Expand Down Expand Up @@ -294,13 +294,13 @@ export class Music {
* relative note.
*/
getRelativeNoteValue(noteValue: number, intervalValue: number, direction?: number): number {
const dir = direction == null ? 1 : direction;
if (direction == null) direction = 1;

if (dir !== 1 && dir !== -1) {
if (direction !== 1 && direction !== -1) {
throw new Vex.RERR('BadArguments', `Invalid direction: ${direction}`);
}

let sum = (noteValue + dir * intervalValue) % Music.NUM_TONES;
let sum = (noteValue + direction * intervalValue) % Music.NUM_TONES;
if (sum < 0) sum += Music.NUM_TONES;

return sum;
Expand All @@ -316,12 +316,12 @@ export class Music {
if (interval > 0) multiplier = -1;

// Possibly wrap around. (Add +1 for modulo operator)
const reverseInterval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;
const reverse_interval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;

if (Math.abs(reverseInterval) > 2) {
if (Math.abs(reverse_interval) > 2) {
throw new Vex.RERR('BadArguments', `Notes not related: ${root}, ${noteValue})`);
} else {
interval = reverseInterval;
interval = reverse_interval;
}
}

Expand All @@ -331,11 +331,11 @@ export class Music {

let relativeNoteName = parts.root;
if (interval > 0) {
for (let i = 1; i <= interval; i += 1) {
for (let i = 1; i <= interval; ++i) {
relativeNoteName += '#';
}
} else if (interval < 0) {
for (let i = -1; i >= interval; i -= 1) {
for (let i = -1; i >= interval; --i) {
relativeNoteName += 'b';
}
}
Expand Down Expand Up @@ -368,16 +368,17 @@ export class Music {
* E.g., Given the scale C, and the note E, returns M3
*/
getIntervalBetween(note1: number, note2: number, direction?: number): number {
const dir = direction == null ? 1 : direction;
if (direction == null) direction = 1;

if (dir !== 1 && dir !== -1) {
if (direction !== 1 && direction !== -1) {
throw new Vex.RERR('BadArguments', `Invalid direction: ${direction}`);
}

if (!this.isValidNoteValue(note1) || !this.isValidNoteValue(note2)) {
throw new Vex.RERR('BadArguments', `Invalid notes: ${note1}, ${note2}`);
}

let difference = dir === 1 ? note2 - note1 : note1 - note2;
let difference = direction === 1 ? note2 - note1 : note1 - note2;

if (difference < 0) difference += Music.NUM_TONES;

Expand All @@ -396,13 +397,13 @@ export class Music {
let keySigString = keySigParts.root;
if (keySigParts.accidental) keySigString += keySigParts.accidental;

if (!scaleName) throw new Vex.RERR('BadArguments', `Unsupported key type: ${keySignature}`);
if (!scaleName) throw new Vex.RERR('BadArguments', 'Unsupported key type: ' + keySignature);

const scale = this.getScaleTones(this.getNoteValue(keySigString), scaleName);
const noteLocation = Music.root_indices[keySigParts.root];

const scaleMap = {} as Record<string, string>;
for (let i = 0; i < Music.roots.length; i += 1) {
for (let i = 0; i < Music.roots.length; ++i) {
const index = (noteLocation + i) % Music.roots.length;
const rootName = Music.roots[index];
let noteName = this.getRelativeNoteName(rootName, scale[i]);
Expand Down

0 comments on commit 909c082

Please sign in to comment.