Skip to content

writeChartFile: [Song] / [SyncTrack] / [Events] / unrecognized sections#101

Open
elicwhite wants to merge 3 commits into
Geomitron:masterfrom
elicwhite:chart-writer-core
Open

writeChartFile: [Song] / [SyncTrack] / [Events] / unrecognized sections#101
elicwhite wants to merge 3 commits into
Geomitron:masterfrom
elicwhite:chart-writer-core

Conversation

@elicwhite
Copy link
Copy Markdown
Contributor

Context

Adds `.chart` file serialization (non-instrument half). Follow-up PR handles instrument track sections.

```ts
export function writeChartFile(chart: ParsedChart): string
```

Sections emitted

  • `[Song]` — the subset of metadata the chart body supports: `Name`, `Artist`, `Charter`, `Album`, `Genre`, `Year` (with the GHTCP-convention leading `, ` separator), `Resolution`, `Offset` (seconds, from `metadata.chart_offset`), `PreviewStart`, `Difficulty`. Other ini fields live exclusively in `song.ini`.
  • `[SyncTrack]` — tempos as `B millibeats` and time signatures as `TS numerator [denominator-exponent]`, sorted by tick with TS before B at the same tick.
  • `[Events]` — section markers wrapped as `[section name]` (survives the parser's greedy trailing-\`]\` regex), `end` events, unrecognized global events (with bracket-stripping when source is `.mid`), vocal `phrase_start`/`phrase_end`/`lyric` events from normalized `vocalTracks.parts.vocals`, `coda` events synthesized from `drumFreestyleSections[].isCoda` when not already in `unrecognizedEvents`.
  • Unrecognized chart sections — re-emitted verbatim.

CRLF line endings throughout. All output round-trips cleanly through `parseChartAndIni`.

Depends on

PRs #97 + #98 + #99 + #100 — stacked above.

Builds a minimal valid ParsedChart from scratch: default 480 resolution,
120 BPM at tick 0, 4/4 time signature at tick 0, empty tracks/sections/
metadata/vocal parts/unrecognized events. chartBytes defaults to an empty
Uint8Array (no source bytes), format defaults to 'chart', iniChartModifiers
to the library defaults.

Options let callers override resolution, bpm, timeSignature, and format.

Useful for programmatic chart generation (e.g. downstream code that builds
charts up from scratch rather than parsing source bytes).
Serializes IniMetadata (Partial<typeof defaultMetadata> + extraIniFields)
back to song.ini text with:
- [song] header
- Known fields emitted in the canonical defaultMetadata order
- Undefined values skipped
- Booleans as True/False (Clone Hero convention)
- extraIniFields appended in insertion order
- CRLF line endings

Derives its field order from Object.keys(defaultMetadata) rather than
hardcoding a separate FIELD_ORDER list, so new fields added to
defaultMetadata automatically participate in writing.

Tests exercise writeIniFile only via round-trip through parseChartAndIni,
per reviewer feedback: build a metadata object, write it, re-parse, and
assert on parsedChart.metadata. No assertions about the serialized ini
text itself (CRLF, field order, True/False formatting, quoting) — those
are implementation details.
…emission

Port of the non-instrument-track half of the chart writer into scan-chart:
- [Song] emits the subset of metadata the chart body supports (Name,
  Artist, Charter, Album, Genre, Year, Resolution, Offset, PreviewStart,
  Difficulty). Other fields live exclusively in song.ini.
- [SyncTrack] emits tempos as `B millibeats` and time signatures as
  `TS numerator [denominator-exponent]`, sorted by tick with TS before B
  at the same tick.
- [Events] emits section markers (wrapped as [section name] to survive
  the parser's greedy trailing-\] regex), end events, unrecognized global
  events (with bracket-stripping when source is .mid so round-trip to
  .chart emits naked text), and vocal phrase_start/phrase_end/lyric
  events from the normalized vocalTracks.parts.vocals.
- Unrecognized chart sections are re-emitted verbatim.

Instrument tracks ([ExpertSingle] etc.) land in a follow-up PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant