Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D tuning / Soprano Ukulele #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This project is using *yarn* as package manager, so all the basic command relate
the project lifecycle are bound to it. Three basic commands

```
yarn install
yarn build
```
Generates a new version of the library when new chords are added.
Expand Down
170 changes: 170 additions & 0 deletions src/db/soprano-ukulele.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/* global it, describe, expect */

import ukulele from './soprano-ukulele';
import {
strChord2array,
chord2midi,
processString,
numberOfBarres,
unique,
getNoteFromMidiNumber,
} from '../tools';

describe('ukulele Chords', () => {
describe('Strings', () => {
it('Should have 4 strings', () => expect(ukulele.main.strings).toEqual(4));
});

describe('Types', () => {
ukulele.suffixes.map((suffix) =>
it(`Type suffix ${suffix} should have a description`, () =>
expect(suffix).toBeDefined())
);
});

describe(`Test Cmajor midi notes`, () => {
it(`Should match [ 72, 64, 67, 72 ]`, () => {
const Cmajor = ukulele.chords.C.find((chord) => chord.suffix === 'major');
const midiNotes = chord2midi(
processString(Cmajor.positions[0].frets),
ukulele.tunings['standard']
);
const CmajorNotes = [72, 64, 67, 72];
expect(JSON.stringify(midiNotes)).toEqual(JSON.stringify(CmajorNotes));
});
});

Object.keys(ukulele.chords).map((key) =>
describe(`Key ${key} chords`, () => {
const chords = ukulele.chords[key];

it(`Should not have duplicated suffixes`, () => {
let seen = new Set();
const duplicates = chords.some(
(chord) => seen.size === seen.add(chord.suffix).size
);
expect(duplicates).toBe(false);
});

chords.map((chord) =>
describe(`Chord ${chord.key}${chord.suffix}`, () => {
describe('General properties', () => {
it(`The chord ${key}${chord.suffix} should have a defined key property`, () =>
expect(chord.key).toEqual(key.replace('sharp', '#')));
it(`The chord ${key}${chord.suffix} should have a defined suffix property`, () =>
expect(chord.suffix).toBeDefined());
it(`The chord ${key}${chord.suffix} should have a list of positions`, () =>
expect(chord.positions).toBeInstanceOf(Array));
});

describe(`Positions`, () => {
chord.positions.map((position, index) => {
const frets = Array.isArray(position.frets)
? position.frets
: strChord2array(position.frets);
const effectiveFrets = frets.filter((f) => f > 0);
describe(`Frets`, () => {
it(`The ${
index + 1
} position frets array should have 4 values`, () =>
expect(frets.length).toEqual(4));
it(`The ${
index + 1
} position frets array should have values lower than 16`, () =>
expect(Math.max(...frets)).toBeLessThan(16));
it(`The ${
index + 1
} position frets array should have at most 4 fingers of distance`, () =>
expect(
Math.max(...effectiveFrets) - Math.min(...effectiveFrets)
).toBeLessThan(ukulele.main.fretsOnChord));
});

if (position.fingers) {
describe(`Fingers`, () => {
const fingers = Array.isArray(position.fingers)
? position.fingers
: strChord2array(position.fingers);
it(`The ${
index + 1
} position fingers array should have 4 values`, () =>
expect(fingers.length).toEqual(4));
it(`The ${
index + 1
} position fingers array should have values lower than 5`, () =>
expect(Math.max(...fingers)).toBeLessThan(5));
it(`The ${
index + 1
} position fingers array should have values higher or equal to 0`, () =>
expect(Math.min(...fingers)).toBeGreaterThanOrEqual(0));
});
}

describe(`Barres`, () => {
if (position.fingers && !position.barres) {
it(`The ${index + 1} position needs a barres property`, () =>
expect(numberOfBarres(position.fingers)).toEqual(0));
}

if (!position.barres) {
it(`The ${
index + 1
} position doesn't need a capo property`, () =>
expect(position.capo).not.toEqual(true));
}

if (position.barres) {
const barres = Array.isArray(position.barres)
? position.barres
: [position.barres];

if (position.fingers) {
it(`The ${
index + 1
} position needs a barres property`, () =>
expect(numberOfBarres(position.fingers)).toEqual(
barres.length
));
}

barres.map((barre) => {
it(`The barre at position ${
index + 1
} should have frets`, () =>
expect(frets.indexOf(barre)).not.toEqual(-1));
it(`The barre at position ${
index + 1
} should have two strings at least`, () =>
expect(frets.indexOf(barre)).not.toEqual(
frets.lastIndexOf(barre)
));
});
}
});
});

describe('MIDI checks', () => {
var initialNotes = chord2midi(
processString(chord.positions[0].frets),
ukulele.tunings['standard']
).map((n) => getNoteFromMidiNumber(n));
chord.positions.map((position, index) => {
it(`The MIDI notes should be homogeneous at position ${
index + 1
}`, () => {
const notes = chord2midi(
processString(position.frets),
ukulele.tunings['standard']
).map((n) => getNoteFromMidiNumber(n));
expect(unique(notes.sort())).toEqual(
unique(initialNotes.sort())
);
});
});
});
});
})
);
})
);
});
18 changes: 18 additions & 0 deletions src/db/soprano-ukulele/chords/A/11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
key: 'A',
suffix: '11',
positions: [
{
frets: '2012',
fingers: '2013',
},
{
frets: '5552',
fingers: '2341',
},
{
frets: '4553',
fingers: '2341',
},
],
};
24 changes: 24 additions & 0 deletions src/db/soprano-ukulele/chords/A/13.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
key: 'A',
suffix: '13',
positions: [
{
frets: '2412',
fingers: '2413',
},
{
frets: '4557',
fingers: '1234',
},
{
frets: '9978',
fingers: '3412',
},
{
frets: 'a977',
fingers: '4311',
barres: 7,
capo: true,
},
],
};
24 changes: 24 additions & 0 deletions src/db/soprano-ukulele/chords/A/13b5b9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
key: 'A',
suffix: '13b5b9',
positions: [
{
frets: '1414',
fingers: '1314',
barres: 1,
capo: true,
},
{
frets: '6547',
fingers: '3214',
},
{
frets: 'a897',
fingers: '4231',
},
{
frets: '9898',
fingers: '3142',
},
],
};
28 changes: 28 additions & 0 deletions src/db/soprano-ukulele/chords/A/13b9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default {
key: 'A',
suffix: '13b9',
positions: [
{
frets: '1412',
fingers: '1412',
barres: 1,
capo: true,
},
{
frets: '4547',
fingers: '1214',
barres: 4,
capo: true,
},
{
frets: 'a877',
fingers: '4211',
barres: 7,
capo: true,
},
{
frets: 'abcb',
fingers: '1243',
},
],
};
24 changes: 24 additions & 0 deletions src/db/soprano-ukulele/chords/A/6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
key: 'A',
suffix: '6',
positions: [
{
frets: '0202',
fingers: '0102',
},
{
frets: '4435',
fingers: '2314',
},
{
frets: '7777',
fingers: '1111',
barres: 7,
capo: true,
},
{
frets: '9baa',
fingers: '1423',
},
],
};
26 changes: 26 additions & 0 deletions src/db/soprano-ukulele/chords/A/69.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
key: 'A',
suffix: '69',
positions: [
{
frets: '2202',
fingers: '1203',
},
{
frets: '4455',
fingers: '1122',
barres: [4, 5],
capo: true,
},
{
frets: '7977',
fingers: '1311',
barres: 7,
capo: true,
},
{
frets: '9bac',
fingers: '1324',
},
],
};
26 changes: 26 additions & 0 deletions src/db/soprano-ukulele/chords/A/7#9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
key: 'A',
suffix: '7#9',
positions: [
{
frets: '3212',
fingers: '4213',
},
{
frets: '4211',
fingers: '4211',
barres: 1,
capo: true,
},
{
frets: '4565',
fingers: '1243',
},
{
frets: '7a78',
fingers: '1412',
barres: 7,
capo: true,
},
],
};
26 changes: 26 additions & 0 deletions src/db/soprano-ukulele/chords/A/7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
key: 'A',
suffix: '7',
positions: [
{
frets: '0212',
fingers: '0213',
},
{
frets: '4535',
fingers: '2314',
},
{
frets: '7778',
fingers: '1112',
barres: 7,
capo: true,
},
{
frets: 'abaa',
fingers: '1211',
barres: 10,
capo: true,
},
],
};
Loading