INNER CODE UNIT · TypeScript
fitPatternToNoteCount
scribbletune/scribbletune · src/cli.ts:163
const fitPatternToNoteCount = (pattern: string, noteCount: number): string => {
const stepCount = countPatternSteps(pattern);
if (!stepCount || stepCount >= noteCount) {
return pattern;
}
const reps = Math.ceil(noteCount / stepCount);
return pattern.repeat(reps);
};
const resolvePattern = (
rawPattern: string,
noteCount: number,
fitPattern = false
): string => {
const expanded = expandPatternSyntax(rawPattern);
return fitPattern ? fitPatternToNoteCount(expanded, noteCount) : expanded;
};