Skip to content

Commit

Permalink
Merge pull request #666 from no-chris/add-one-beat-time-signatures
Browse files Browse the repository at this point in the history
Support single beat time signatures
  • Loading branch information
no-chris authored Sep 18, 2024
2 parents 4d283de + fd114c8 commit 4f2254b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions packages/chord-mark/src/parser/matchers/isChordLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '*$',
Expand All @@ -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)
);
});
}
Expand Down
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',
Expand All @@ -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
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
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
Expand All @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion packages/chord-mark/src/parser/songLinesFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
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],
Expand All @@ -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);
});
});

0 comments on commit 4f2254b

Please sign in to comment.