Permalink
Browse files

Align naming + some refactor

  • Loading branch information...
duivvv committed Dec 25, 2018
1 parent 93cd8d7 commit 635809b878ebd34cc8c8d4e4e7930869af50faca
Showing with 660 additions and 586 deletions.
  1. +1 −1 __tests__/chords.test.js
  2. +2 −2 __tests__/chromaticc.test.js
  3. +8 −8 __tests__/scales.test.js
  4. +1 −1 package-lock.json
  5. +3 −2 package.json
  6. +2 −2 src/accidentalToLetter/index.js
  7. +2 −2 src/accidentalToSymbol/index.js
  8. +4 −4 src/{areSameNotes → areEqual}/index.js
  9. +10 −10 src/{areSameNotes → areEqual}/test.js
  10. +2 −2 src/{isIntervalArray → areIntervals}/index.js
  11. 0 src/{isIntervalArray → areIntervals}/test.js
  12. +4 −4 src/{isScientificNoteArray → areNotes}/index.js
  13. +9 −9 src/{isScientificNoteArray → areNotes}/test.js
  14. +2 −2 src/createChord/index.js
  15. +23 −0 src/createMelody/index.js
  16. +6 −6 src/{createPattern → createMelody}/test.js
  17. +0 −23 src/createPattern/index.js
  18. +2 −2 src/createScale/index.js
  19. +2 −2 src/flatToSharp/index.js
  20. +2 −2 src/getAccidental/index.js
  21. +2 −2 src/getChromaticCPosition/index.js
  22. +11 −3 src/getDominant/index.js
  23. +4 −4 src/getDominant/test.js
  24. +2 −2 src/getIntervals/index.js
  25. +11 −3 src/getLeadingTone/index.js
  26. +4 −4 src/getLeadingTone/test.js
  27. +11 −3 src/getMediant/index.js
  28. +4 −4 src/getMediant/test.js
  29. +2 −2 src/getNote/index.js
  30. +23 −0 src/getNoteOnDegree/index.js
  31. +93 −0 src/getNoteOnDegree/test.js
  32. +2 −2 src/getOctave/index.js
  33. +2 −2 src/getRoot/index.js
  34. +0 −29 src/getScaleDegree/index.js
  35. +0 −72 src/getScaleDegree/test.js
  36. +11 −3 src/getSubdominant/index.js
  37. +4 −4 src/getSubdominant/test.js
  38. +11 −3 src/getSubmediant/index.js
  39. +4 −4 src/getSubmediant/test.js
  40. +11 −3 src/getSupertonic/index.js
  41. +4 −4 src/getSupertonic/test.js
  42. +11 −3 src/getTonic/index.js
  43. +4 −4 src/getTonic/test.js
  44. +2 −2 src/hasAccidental/index.js
  45. +2 −2 src/hasAccidentalLetter/index.js
  46. +2 −2 src/hasAccidentalSymbol/index.js
  47. +4 −4 src/{isScaleWithIntervalAmount → hasIntervalAmount}/index.js
  48. +12 −12 src/{isScaleWithIntervalAmount → hasIntervalAmount}/test.js
  49. +2 −2 src/hasOctave/index.js
  50. +2 −2 src/haveSameOctave/index.js
  51. +36 −36 src/index.js
  52. +4 −4 src/{isAnhemitonicScale → isAnhemitonic}/index.js
  53. +7 −7 src/{isAnhemitonicScale → isAnhemitonic}/test.js
  54. +2 −2 src/{isAscendingScale → isAscending}/index.js
  55. +10 −10 src/{isAscendingScale → isAscending}/test.js
  56. +6 −6 src/{isCohemitonicScale → isCohemitonic}/index.js
  57. +7 −7 src/{isCohemitonicScale → isCohemitonic}/test.js
  58. +2 −2 src/{isDescendingScale → isDescending}/index.js
  59. 0 src/{isDescendingScale → isDescending}/test.js
  60. +6 −6 src/{isDiatonicScale → isDiatonic}/index.js
  61. +13 −13 src/{isDiatonicScale → isDiatonic}/test.js
  62. +2 −2 src/isFlat/index.js
  63. +4 −4 src/{isHemitonicScale → isHemitonic}/index.js
  64. +6 −6 src/{isHemitonicScale → isHemitonic}/test.js
  65. +14 −0 src/isHeptatonic/index.js
  66. +12 −12 src/{isHeptatonicScale → isHeptatonic}/test.js
  67. +0 −14 src/isHeptatonicScale/index.js
  68. +14 −0 src/isHexatonic/index.js
  69. +10 −10 src/{isHexatonicScale → isHexatonic}/test.js
  70. +0 −14 src/isHexatonicScale/index.js
  71. +4 −4 src/isMode/index.js
  72. +2 −2 src/isNatural/index.js
  73. +2 −2 src/{isScientificNote → isNote}/index.js
  74. +11 −11 src/{isScientificNote → isNote}/test.js
  75. +14 −0 src/isOctatonic/index.js
  76. +14 −14 src/{isOctatonicScale → isOctatonic}/test.js
  77. +0 −14 src/isOctatonicScale/index.js
  78. +14 −0 src/isPentatonic/index.js
  79. +12 −12 src/{isPentatonicScale → isPentatonic}/test.js
  80. +0 −14 src/isPentatonicScale/index.js
  81. +2 −2 src/isScale/index.js
  82. +2 −2 src/isSharp/index.js
  83. +2 −2 src/isTriad/index.js
  84. +7 −10 src/{normalizeScale → normalize}/index.js
  85. +12 −12 src/{normalizeScale → normalize}/test.js
  86. +2 −2 src/noteToFrequency/index.js
  87. +4 −4 src/noteToMidi/index.js
  88. +12 −7 src/noteToMidi/test.js
  89. +2 −2 src/noteToObject/index.js
  90. +2 −2 src/objectToNote/index.js
  91. +2 −2 src/sharpToFlat/index.js
  92. +8 −8 src/transferAccidental/index.js
  93. +8 −8 src/transferAccidentalStyle/index.js
  94. +6 −6 src/transferAccidentalStyle/test.js
  95. +8 −8 src/transferStyle/index.js
  96. +7 −7 src/transferStyle/test.js
  97. +4 −4 src/transpose/index.js
@@ -3,7 +3,7 @@ import Chord from '../src/constants/Chord';
import transpose from '../src/transpose';
import getIntervals from '../src/getIntervals';
import objectToNote from '../src/objectToNote';
import normalizeScale from '../src/normalizeScale';
import normalize from '../src/normalize';
import { OCTAVE } from '../src/constants/Interval/Names';
import sharpToFlat from '../src/sharpToFlat';
import accidentalToLetter from '../src/accidentalToLetter';
@@ -5,7 +5,7 @@ import sharpToFlat from '../src/sharpToFlat';
import accidentalToLetter from '../src/accidentalToLetter';
import getChromaticCPosition from '../src/getChromaticCPosition';
import getIntervals from '../src/getIntervals';
import normalizeScale from '../src/normalizeScale';
import normalize from '../src/normalize';

const createScalesForOctave = octave => {
const root = objectToNote({
@@ -37,7 +37,7 @@ describe('scales', () => {
scale.map(getChromaticCPosition)
);
const intervals = scales.map(scale =>
getIntervals(normalizeScale(scale, Scale.CHROMATIC.length))
getIntervals(normalize(scale, Scale.CHROMATIC.length))
);

expect(
@@ -4,13 +4,13 @@ import transpose from '../src/transpose';
import getIntervals from '../src/getIntervals';
import objectToNote from '../src/objectToNote';
import { OCTAVE } from '../src/constants/Interval/Names';
import isHeptatonicScale from '../src/isHeptatonicScale';
import isDiatonicScale from '../src/isDiatonicScale';
import isHemitonicScale from '../src/isHemitonicScale';
import isHeptatonic from '../src/isHeptatonic';
import isDiatonic from '../src/isDiatonic';
import isHemitonic from '../src/isHemitonic';
import isScale from '../src/isScale';
import sharpToFlat from '../src/sharpToFlat';
import accidentalToLetter from '../src/accidentalToLetter';
import normalizeScale from '../src/normalizeScale';
import normalize from '../src/normalize';

const createScalesForOctave = octave => {
const root = objectToNote({
@@ -46,13 +46,13 @@ describe('scales', () => {
.reduce((acc, v) => [...acc, ...v], []);

const intervals = scales.map(s =>
getIntervals(normalizeScale(s, Scale.MAJOR.length))
getIntervals(normalize(s, Scale.MAJOR.length))
);

expect(scales.every(isHeptatonicScale)).toBe(true);
expect(scales.every(isDiatonicScale)).toBe(true);
expect(scales.every(isHeptatonic)).toBe(true);
expect(scales.every(isDiatonic)).toBe(true);
expect(scales.every(isScale)).toBe(true);
expect(scales.every(isHemitonicScale)).toBe(true);
expect(scales.every(isHemitonic)).toBe(true);

expect(
intervals.every(interval => Scale.MAJOR.join(',') === interval.join(','))

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,7 +1,8 @@
{
"name": "music-fns",
"version": "0.1.0-alpha.5",
"description": "JavaScript music utility library",
"version": "0.1.0",
"description":
"JavaScript music utility library that contains small music notation related functions.",
"main": "dist",
"scripts": {
"test": "jest",
@@ -4,10 +4,10 @@ import { LETTER, SYMBOL } from '../constants/Accidental';

import noteToObject from '../noteToObject';
import objectToNote from '../objectToNote';
import isScientificNote from '../isScientificNote';
import isNote from '../isNote';

const accidentalToLetter = (note: ScientificNote): ScientificNote => {
if (!isScientificNote(note)) {
if (!isNote(note)) {
throw new Error(`"${note}" is not a valid note.`);
}

@@ -4,10 +4,10 @@ import { LETTER, SYMBOL } from '../constants/Accidental';

import noteToObject from '../noteToObject';
import objectToNote from '../objectToNote';
import isScientificNote from '../isScientificNote';
import isNote from '../isNote';

const accidentalToSymbol = (note: ScientificNote): ScientificNote => {
if (!isScientificNote(note)) {
if (!isNote(note)) {
throw new Error(`"${note}" is not a valid note.`);
}

@@ -2,10 +2,10 @@

import getChromaticCPosition from '../getChromaticCPosition';
import getOctave from '../getOctave';
import isScientificNoteArray from '../isScientificNoteArray';
import areNotes from '../areNotes';

const areSameNotes = (notes: ScientificNotes) => {
if (!isScientificNoteArray(notes)) {
const areEqual = (notes: ScientificNotes) => {
if (!areNotes(notes)) {
return false;
}

@@ -19,4 +19,4 @@ const areSameNotes = (notes: ScientificNotes) => {
}
};

export default areSameNotes;
export default areEqual;
@@ -1,51 +1,51 @@
import areSameNotes from './';
import areEqual from './';

describe('areSameNotes', () => {
describe('areEqual', () => {
it('should return true when comparing "C" and "B♯"', () => {
const note = 'C';
const note2 = 'B♯';
expect(areSameNotes([note, note2])).toEqual(true);
expect(areEqual([note, note2])).toEqual(true);
});

it('should return false when comparing "C" and "D"', () => {
const note = 'C';
const note2 = 'D';
expect(areSameNotes([note, note2])).toEqual(false);
expect(areEqual([note, note2])).toEqual(false);
});

it('should return true when comparing "G#2" and "Ab2"', () => {
const note = 'G#2';
const note2 = 'Ab2';
expect(areSameNotes([note, note2])).toEqual(true);
expect(areEqual([note, note2])).toEqual(true);
});

it('should return false when comparing "Eb7" and "A♯7"', () => {
const note = 'Eb7';
const note2 = 'A♯7';
expect(areSameNotes([note, note2])).toEqual(false);
expect(areEqual([note, note2])).toEqual(false);
});

it('should return true when comparing "F♯3" and "Gb3"', () => {
const note = 'F♯3';
const note2 = 'Gb3';
expect(areSameNotes([note, note2])).toEqual(true);
expect(areEqual([note, note2])).toEqual(true);
});

it('should return false when comparing invalid scientific notes', () => {
const note = 'Fr';
const note2 = 'G#2';
expect(areSameNotes([note, note2])).toEqual(false);
expect(areEqual([note, note2])).toEqual(false);
});

it('should return false when comparing invalid scientific notes', () => {
const note = 'G#2';
const note2 = 'Fr';
expect(areSameNotes([note, note2])).toEqual(false);
expect(areEqual([note, note2])).toEqual(false);
});

it('should return false when comparing invalid scientific notes', () => {
const note = 'Fr';
const note2 = 'Fr';
expect(areSameNotes([note, note2])).toEqual(false);
expect(areEqual([note, note2])).toEqual(false);
});
});
@@ -1,9 +1,9 @@
// @flow

const isIntervalArray = (intervals: Intervals) =>
const areIntervals = (intervals: Intervals) =>
Array.isArray(intervals) &&
intervals.length > 1 &&
intervals.every(i => typeof i === 'number') &&
(intervals.every(i => i >= 0) || intervals.every(i => i <= 0));

export default isIntervalArray;
export default areIntervals;
File renamed without changes.
@@ -1,20 +1,20 @@
// @flow

import hasOctave from '../hasOctave';
import isScientificNote from '../isScientificNote';
import isNote from '../isNote';

const isScientificNoteArray = (notes: ScientificNotes) => {
const areNotes = (notes: ScientificNotes) => {
if (!Array.isArray(notes)) return false;

try {
const isValid =
notes.filter(n => hasOctave(n)).length === notes.length ||
notes.filter(n => !hasOctave(n)).length === notes.length;

return notes.every(n => isScientificNote(n)) && isValid;
return notes.every(n => isNote(n)) && isValid;
} catch (e) {
return false;
}
};

export default isScientificNoteArray;
export default areNotes;
@@ -1,38 +1,38 @@
import isScientificNoteArray from './';
import areNotes from './';

describe('isScientificNoteArray', () => {
describe('areNotes', () => {
it('should return true on a valid notes array', () => {
const notes = ['A', 'B', 'D'];
expect(isScientificNoteArray(notes)).toBe(true);
expect(areNotes(notes)).toBe(true);
});

it('should return true on a valid notes array', () => {
const notes = ['A', 'B'];
expect(isScientificNoteArray(notes)).toBe(true);
expect(areNotes(notes)).toBe(true);
});

it('should return false when notes is larger then octave', () => {
const notes = ['A#3', 'B7'];
expect(isScientificNoteArray(notes)).toBe(true);
expect(areNotes(notes)).toBe(true);
});

it('should return true on a notes with mixed intervals', () => {
const notes = ['A1', 'B1', 'A1'];
expect(isScientificNoteArray(notes)).toBe(true);
expect(areNotes(notes)).toBe(true);
});

it('should return true on a notes with mixed intervals', () => {
const notes = ['A1', 'B1', 'A1'];
expect(isScientificNoteArray(notes)).toBe(true);
expect(areNotes(notes)).toBe(true);
});

it('should return false on an invalid notes', () => {
const notes = ['A', 'B2'];
expect(isScientificNoteArray(notes)).toBe(false);
expect(areNotes(notes)).toBe(false);
});

it('should return false on invalid notes', () => {
const notes = ['A', 'Fr'];
expect(isScientificNoteArray(notes)).toBe(false);
expect(areNotes(notes)).toBe(false);
});
});
@@ -1,14 +1,14 @@
// @flow

import transpose from '../transpose';
import isIntervalArray from '../isIntervalArray';
import areIntervals from '../areIntervals';
import { ROOT } from '../constants/Interval/Names';

const createChord = (
root: ScientificNote,
chord: Intervals
): ScientificNotes => {
if (!isIntervalArray(chord)) {
if (!areIntervals(chord)) {
throw new Error(
`Provide a valid collection of chord intervals ex: [0, 1, 3]`
);
@@ -0,0 +1,23 @@
// @flow

import areNotes from '../areNotes';

const createMelody = (
notes: ScientificNotes,
pattern: number[]
): ScientificNotes => {
if (!areNotes(notes)) {
throw new Error('Please provide an array of scientific notes');
}

if (!Array.isArray(pattern) || pattern.some(v => v > notes.length - 1)) {
throw new Error(
`Please provide an array with note positions (max position: ${notes.length -
1})`
);
}

return pattern.map(v => notes[v]);
};

export default createMelody;
@@ -1,13 +1,13 @@
import createPattern from './';
import createMelody from './';

describe('createPattern', () => {
describe('createMelody', () => {
it('should create a pattern', () => {
const notes = ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
const positions = [0, 2, 4, 2];

const pattern = ['C', 'E', 'G', 'E'];

expect(createPattern(notes, positions)).toEqual(pattern);
expect(createMelody(notes, positions)).toEqual(pattern);
});

it('should create a correct pattern', () => {
@@ -16,14 +16,14 @@ describe('createPattern', () => {

const pattern = ['C', 'C', 'C', 'E'];

expect(createPattern(notes, positions)).toEqual(pattern);
expect(createMelody(notes, positions)).toEqual(pattern);
});

it('should create a correct pattern', () => {
const notes = ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
const positions = [0, 7, 0, 3];

expect(() => createPattern(notes, positions)).toThrow(
expect(() => createMelody(notes, positions)).toThrow(
`Please provide an array with note positions (max position: 6)`
);
});
@@ -32,7 +32,7 @@ describe('createPattern', () => {
const notes = ['C', 'Fr', 'E', 'F', 'G', 'A', 'B'];
const positions = [0, 2, 0, 2];

expect(() => createPattern(notes, positions)).toThrow(
expect(() => createMelody(notes, positions)).toThrow(
`Please provide an array of scientific notes`
);
});

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 635809b

Please sign in to comment.