forked from Geomitron/scan-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Add createEmptyChart() counterpart to parseChartAndIni #68
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
Open
elicwhite
wants to merge
1
commit into
master
Choose a base branch
from
create-empty-chart
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** | ||
| * Tests for createEmptyChart: the programmatic-build counterpart to parseChartAndIni. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { createEmptyChart } from '../chart/create-chart' | ||
| import { defaultIniChartModifiers } from '../chart/note-parsing-interfaces' | ||
|
|
||
| describe('createEmptyChart', () => { | ||
| it('uses defaults when no options are provided', () => { | ||
| const chart = createEmptyChart() | ||
|
|
||
| expect(chart.resolution).toBe(480) | ||
| expect(chart.tempos).toEqual([{ tick: 0, beatsPerMinute: 120, msTime: 0 }]) | ||
| expect(chart.timeSignatures).toEqual([ | ||
| { tick: 0, numerator: 4, denominator: 4, msTime: 0, msLength: 0 }, | ||
| ]) | ||
| expect(chart.format).toBe('chart') | ||
| }) | ||
|
|
||
| it('honors resolution, bpm, and time signature overrides', () => { | ||
| const chart = createEmptyChart({ | ||
| resolution: 192, | ||
| bpm: 150, | ||
| timeSignature: { numerator: 6, denominator: 8 }, | ||
| }) | ||
|
|
||
| expect(chart.resolution).toBe(192) | ||
| expect(chart.tempos[0].beatsPerMinute).toBe(150) | ||
| expect(chart.timeSignatures[0]).toMatchObject({ numerator: 6, denominator: 8 }) | ||
| }) | ||
|
|
||
| it('honors format override', () => { | ||
| const chart = createEmptyChart({ format: 'mid' }) | ||
| expect(chart.format).toBe('mid') | ||
| }) | ||
|
|
||
| it('produces a chart with empty metadata, tracks, and sections', () => { | ||
| const chart = createEmptyChart() | ||
|
|
||
| expect(chart.metadata).toEqual({}) | ||
| expect(chart.drumType).toBeNull() | ||
| expect(chart.trackData).toEqual([]) | ||
| expect(chart.sections).toEqual([]) | ||
| expect(chart.endEvents).toEqual([]) | ||
| expect(chart.unrecognizedEventsTrackTextEvents).toEqual([]) | ||
| expect(chart.unrecognizedEventsTrackMidiEvents).toEqual([]) | ||
| expect(chart.unrecognizedMidiTracks).toEqual([]) | ||
| expect(chart.unrecognizedChartSections).toEqual([]) | ||
| expect(chart.unrecognizedSyncTrackEvents).toEqual([]) | ||
| expect(chart.parseIssues).toEqual([]) | ||
| }) | ||
|
|
||
| it('produces a chart with empty vocal tracks', () => { | ||
| const chart = createEmptyChart() | ||
| expect(chart.vocalTracks).toEqual({ parts: {}, rangeShifts: [], lyricShifts: [] }) | ||
| }) | ||
|
|
||
| it('produces a chart with empty chartBytes and default ini modifiers', () => { | ||
| const chart = createEmptyChart() | ||
| expect(chart.chartBytes).toBeInstanceOf(Uint8Array) | ||
| expect(chart.chartBytes.length).toBe(0) | ||
| expect(chart.iniChartModifiers).toBe(defaultIniChartModifiers) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { defaultIniChartModifiers } from './note-parsing-interfaces' | ||
| import type { ParsedChart } from './parse-chart-and-ini' | ||
|
|
||
| /** | ||
| * Build a minimal valid {@link ParsedChart} from scratch, without parsing any | ||
| * source bytes. Useful for programmatic chart generation and as the counterpart | ||
| * to `parseChartAndIni`. | ||
| * | ||
| * The returned chart has: | ||
| * - the requested resolution (default 480) | ||
| * - a single tempo event at tick 0 (default 120 BPM) | ||
| * - a single time signature at tick 0 (default 4/4) | ||
| * - empty metadata, tracks, sections, vocal parts, and unrecognized events | ||
| * - `chartBytes` set to an empty `Uint8Array` — there is no source file. | ||
| * `scanChart()` will hash empty bytes (deterministic but not an identity); | ||
| * callers that need a meaningful `chartHash` should serialize via | ||
| * `writeChartFile`/`writeMidiFile` and re-parse. | ||
| * - `format` defaults to `'chart'` — the text format is the simpler target | ||
| * for programmatic construction; pass `format: 'mid'` when the caller | ||
| * needs `.mid` output. | ||
|
elicwhite marked this conversation as resolved.
|
||
| * - `iniChartModifiers` set to the library defaults | ||
| */ | ||
| export function createEmptyChart(options?: { | ||
| format?: 'chart' | 'mid' | ||
| resolution?: number | ||
| bpm?: number | ||
| timeSignature?: { numerator: number; denominator: number } | ||
| }): ParsedChart { | ||
| const resolution = options?.resolution ?? 480 | ||
| const bpm = options?.bpm ?? 120 | ||
| const numerator = options?.timeSignature?.numerator ?? 4 | ||
| const denominator = options?.timeSignature?.denominator ?? 4 | ||
| const format = options?.format ?? 'chart' | ||
|
|
||
| return { | ||
| resolution, | ||
| drumType: null, | ||
| metadata: {}, | ||
| parseIssues: [], | ||
| vocalTracks: { parts: {}, rangeShifts: [], lyricShifts: [] }, | ||
| endEvents: [], | ||
| unrecognizedEventsTrackTextEvents: [], | ||
| unrecognizedEventsTrackMidiEvents: [], | ||
| unrecognizedMidiTracks: [], | ||
| unrecognizedChartSections: [], | ||
| tempos: [{ tick: 0, beatsPerMinute: bpm, msTime: 0 }], | ||
| timeSignatures: [{ tick: 0, numerator, denominator, msTime: 0, msLength: 0 }], | ||
| unrecognizedSyncTrackEvents: [], | ||
| sections: [], | ||
| trackData: [], | ||
| chartBytes: new Uint8Array(0), | ||
|
elicwhite marked this conversation as resolved.
|
||
| format, | ||
| iniChartModifiers: defaultIniChartModifiers, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './chart-scanner' | ||
| export * from './create-chart' | ||
| export * from './parse-chart-and-ini' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.