Skip to content

Commit 54b71b0

Browse files
committed
Make iniChartModifiers optional
1 parent 0f3bb31 commit 54b71b0

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,14 @@ const noteFlags = {
450450
accent: 1024,
451451
} as const
452452

453+
interface IniChartModifiers {
454+
song_length: number // Default: 0
455+
hopo_frequency: number // Default: 0
456+
eighthnote_hopo: boolean // Default: false
457+
multiplier_note: number // Default: 0
458+
sustain_cutoff_threshold: number // Default: -1
459+
chord_snap_threshold: number // Default: 0
460+
five_lane_drums: boolean // Default: false
461+
pro_drums: boolean // Default: false
462+
}
453463
```

src/chart/note-parsing-interfaces.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export interface IniChartModifiers {
1212
pro_drums: boolean
1313
}
1414

15+
export const defaultIniChartModifiers = {
16+
song_length: 0,
17+
hopo_frequency: 0,
18+
eighthnote_hopo: false,
19+
multiplier_note: 0,
20+
sustain_cutoff_threshold: -1,
21+
chord_snap_threshold: 0,
22+
five_lane_drums: false,
23+
pro_drums: false,
24+
}
25+
1526
/**
1627
* This is the common format that both .mid and .chart parsers target, and is used by `parseChart()` to generate `ChartData`.
1728
*

src/chart/notes-parser.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import * as _ from 'lodash'
33
import { DrumType, drumTypes, Instrument } from 'src/interfaces'
44
import { parseNotesFromChart } from './chart-parser'
55
import { parseNotesFromMidi } from './midi-parser'
6-
import { EventType, eventTypes, IniChartModifiers, NoteEvent, noteFlags, NoteType, noteTypes, RawChartData } from './note-parsing-interfaces'
6+
import {
7+
defaultIniChartModifiers,
8+
EventType,
9+
eventTypes,
10+
IniChartModifiers,
11+
NoteEvent,
12+
noteFlags,
13+
NoteType,
14+
noteTypes,
15+
RawChartData,
16+
} from './note-parsing-interfaces'
717

818
type TrackEvent = RawChartData['trackData'][number]['trackEvents'][number]
919
type UntimedNoteEvent = Omit<NoteEvent, 'msTime' | 'msLength'>
@@ -15,7 +25,8 @@ export type ParsedChart = ReturnType<typeof parseChartFile>
1525
*
1626
* Throws an exception if `buffer` could not be parsed as a chart in the .chart or .mid format.
1727
*/
18-
export function parseChartFile(data: Uint8Array, format: 'chart' | 'mid', iniChartModifiers: IniChartModifiers) {
28+
export function parseChartFile(data: Uint8Array, format: 'chart' | 'mid', partialIniChartModifiers: Partial<IniChartModifiers> = {}) {
29+
const iniChartModifiers = Object.assign({}, defaultIniChartModifiers, partialIniChartModifiers) as IniChartModifiers
1930
const rawChartData = format === 'mid' ? parseNotesFromMidi(data, iniChartModifiers) : parseNotesFromChart(data)
2031
const timedTempos = getTimedTempos(rawChartData.tempos, rawChartData.chartTicksPerBeat)
2132
const drumTracks = rawChartData.trackData.filter(track => track.instrument === 'drums')

0 commit comments

Comments
 (0)