Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: no-chris/chord-mark
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.17.0
Choose a base ref
...
head repository: no-chris/chord-mark
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 7 files changed
  • 2 contributors

Commits on Sep 18, 2024

  1. add 1 beat time signatures

    no-chris committed Sep 18, 2024
    Copy the full SHA
    4f4a9ab View commit details
  2. rename isTimeSignatureString to isTimeSignature

    no-chris committed Sep 18, 2024
    Copy the full SHA
    fd114c8 View commit details
  3. Merge pull request #666 from no-chris/add-one-beat-time-signatures

    Support single beat time signatures
    no-chris authored Sep 18, 2024
    Copy the full SHA
    4f2254b View commit details

Commits on Sep 20, 2024

  1. add test case for pickup measure with sub-beat

    no-chris committed Sep 20, 2024
    Copy the full SHA
    acc576e View commit details
5 changes: 2 additions & 3 deletions packages/chord-mark/src/parser/matchers/isChordLine.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import clearSpaces from '../helper/clearSpaces';

import syntax from '../syntax';
import isChord from './isChord';
import isTimeSignatureString from './isTimeSignatureString';
import isTimeSignature from './isTimeSignature';

const chordBeatCountSymbols = new RegExp(
_escapeRegExp(syntax.chordBeatCount) + '*$',
@@ -30,8 +30,7 @@ export default function isChordLine(line = '') {
isChord(clean) ||
(potentialChordToken.match(barRepeatSymbols) && index > 0) ||
clean === syntax.noChord ||
(isTimeSignatureString(potentialChordToken) &&
allTokens.length > 1)
(isTimeSignature(potentialChordToken) && allTokens.length > 1)
);
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const allowedTimeSignatures = [
'1/2',
'2/2',
'3/2',
'4/2',
'1/4',
'2/4',
'3/4',
'4/4',
@@ -19,6 +21,6 @@ const allowedTimeSignatures = [
'12/8',
];

export default function isTimeSignatureString(string) {
export default function isTimeSignature(string) {
return allowedTimeSignatures.includes(string);
}
4 changes: 2 additions & 2 deletions packages/chord-mark/src/parser/parseChordLine.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import _cloneDeep from 'lodash/cloneDeep';
import syntax, { defaultTimeSignature } from './syntax';
import clearSpaces from './helper/clearSpaces';

import isTimeSignatureString from './matchers/isTimeSignatureString';
import isTimeSignature from './matchers/isTimeSignature';
import parseChord from './parseChord';
import parseTimeSignature from './parseTimeSignature';

@@ -90,7 +90,7 @@ export default function parseChordLine(
allTokens.forEach((token, tokenIndex) => {
if (token.match(barRepeatSymbols)) {
repeatPreviousBars(token);
} else if (isTimeSignatureString(token)) {
} else if (isTimeSignature(token)) {
changeTimeSignature(token);
} else {
parseChordToken(token);
4 changes: 2 additions & 2 deletions packages/chord-mark/src/parser/parseTimeSignature.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isTimeSignatureString from './matchers/isTimeSignatureString';
import isTimeSignature from './matchers/isTimeSignature';

/**
* @typedef {Object} TimeSignature
@@ -14,7 +14,7 @@ import isTimeSignatureString from './matchers/isTimeSignatureString';
* @returns {TimeSignature}
*/
export default function parseTimeSignature(string) {
if (!isTimeSignatureString(string)) {
if (!isTimeSignature(string)) {
throw new TypeError(
'Expected time signature string, received: ' + string
);
2 changes: 1 addition & 1 deletion packages/chord-mark/src/parser/songLinesFactory.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import isChordLine from './matchers/isChordLine';
import isChordLineRepeater from './matchers/isChordLineRepeater';
import isEmptyLine from './matchers/isEmptyLine';
import isSectionLabel from './matchers/isSectionLabel';
import isTimeSignature from './matchers/isTimeSignatureString';
import isTimeSignature from './matchers/isTimeSignature';

import parseChordLine from './parseChordLine';
import parseKeyDeclaration from './parseKeyDeclaration';
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import isTimeSignatureString from '../../../../src/parser/matchers/isTimeSignatureString';
import isTimeSignature from '../../../../src/parser/matchers/isTimeSignature';

describe('isTimeSignatureString', () => {
describe('isTimeSignatureS', () => {
test('Module', () => {
expect(isTimeSignatureString).toBeInstanceOf(Function);
expect(isTimeSignature).toBeInstanceOf(Function);
});
});

describe.each([
['1/2', true],
['2/2', true],
['3/2', true],
['4/2', true],

['1/4', true],
['2/4', true],
['3/4', true],
['4/4', true],
@@ -35,6 +37,6 @@ describe.each([
['13/8', false],
])('Time signature string %s', (tsString, result) => {
test('Correctly detect time signature', () => {
expect(isTimeSignatureString(tsString)).toEqual(result);
expect(isTimeSignature(tsString)).toEqual(result);
});
});
62 changes: 19 additions & 43 deletions packages/chord-mark/tests/unit/parser/parseChordLine.spec.js
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ describe('parseChordLine', () => {
});
});

const ts1_4 = parseTimeSignature('1/4');
const ts2_4 = parseTimeSignature('2/4');
const ts3_4 = parseTimeSignature('3/4');
const ts4_4 = parseTimeSignature('4/4');
@@ -1100,76 +1101,51 @@ describe.each([
},
],
[
'2 sub-beat groups over 2 bars of 2/4',
'C. [F G] [F G] C.',
ts2_4,
'sub-beat group in a single beat measure',
'1/4 [NC A] 4/4 E',
ts4_4,
{
allBars: [
{
allChords: [
{
string: 'C.',
model: { symbol: 'C' },
duration: 1,
beat: 1,
isInSubBeatGroup: false,
},
{
string: '[F',
model: { symbol: 'F' },
string: '[NC',
model: 'NC',
duration: 0.5,
beat: 2,
beat: 1,
isInSubBeatGroup: true,
isFirstOfSubBeat: true,
isLastOfSubBeat: false,
},
{
string: 'G]',
model: { symbol: 'G' },
string: 'A]',
model: { symbol: 'A' },
duration: 0.5,
beat: 2,
beat: 1,
isInSubBeatGroup: true,
isFirstOfSubBeat: false,
isLastOfSubBeat: true,
},
],
timeSignature: ts2_4,
timeSignature: ts1_4,
isRepeated: false,
hasUnevenChordsDurations: true,
lineHadTimeSignatureChange: false,
hasUnevenChordsDurations: false,
lineHadTimeSignatureChange: true,
},
{
allChords: [
{
string: '[F',
model: { symbol: 'F' },
duration: 0.5,
beat: 1,
isInSubBeatGroup: true,
isFirstOfSubBeat: true,
isLastOfSubBeat: false,
},
{
string: 'G]',
model: { symbol: 'G' },
duration: 0.5,
string: 'E',
model: { symbol: 'E' },
duration: 4,
beat: 1,
isInSubBeatGroup: true,
isFirstOfSubBeat: false,
isLastOfSubBeat: true,
},
{
string: 'C.',
model: { symbol: 'C' },
duration: 1,
beat: 2,
isInSubBeatGroup: false,
},
],
timeSignature: ts2_4,
timeSignature: ts4_4,
isRepeated: false,
hasUnevenChordsDurations: true,
lineHadTimeSignatureChange: false,
hasUnevenChordsDurations: false,
lineHadTimeSignatureChange: true,
},
],
originalKey: {},