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

Support single beat time signatures #666

Merged
merged 2 commits into from
Sep 18, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading