Skip to content

Commit

Permalink
Add GH tracks support
Browse files Browse the repository at this point in the history
  • Loading branch information
tonygoldcrest committed Feb 16, 2024
1 parent cefff39 commit 8339e50
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
80 changes: 63 additions & 17 deletions src/midi-parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,66 @@ export class MidiParser {
95: 'e/4', // kick
96: 'f/4', // kick
97: 'c/5', // snare
98: 'g/5/x2', // yellow tom
99: 'f/5/x2', // blue tom
100: 'a/5/x2', // green tom
98: 'g/5/x2', // yellow cymbal
99: 'f/5/x2', // blue cymbal
100: 'a/5/x2', // green cymbal
},
hard: {
84: 'f/4', // kick
85: 'c/5', // snare
86: 'g/5/x2', // yellow tom
87: 'f/5/x2', // blue tom
88: 'a/5/x2', // green tom
86: 'g/5/x2', // yellow cymbal
87: 'f/5/x2', // blue cymbal
88: 'a/5/x2', // green cymbal
},
medium: {
72: 'f/4', // kick
73: 'c/5', // snare
74: 'g/5/x2', // yellow tom
75: 'f/5/x2', // blue tom
76: 'a/5/x2', // green tom
74: 'g/5/x2', // yellow cymbal
75: 'f/5/x2', // blue cymbal
76: 'a/5/x2', // green cymbal
},
easy: {
60: 'f/4', // kick
61: 'c/5', // snare
62: 'g/5/x2', // yellow tom
63: 'f/5/x2', // blue tom
64: 'a/5/x2', // green tom
62: 'g/5/x2', // yellow cymbal
63: 'f/5/x2', // blue cymbal
64: 'a/5/x2', // green cymbal
},
};

mappingFiveLane: { [key in Difficulty]: MidiMapping } = {
expert: {
95: 'e/4', // kick
96: 'f/4', // kick
97: 'c/5', // snare
98: 'g/5/x2', // yellow cymbal
99: 'd/5', // blue tom
100: 'a/5/x2', // green cymbal
101: 'a/4', // green tom
},
hard: {
84: 'f/4', // kick
85: 'c/5', // snare
86: 'g/5/x2', // yellow cymbal
87: 'd/5', // blue tom
88: 'a/5/x2', // green cymbal
89: 'a/4', // green tom
},
medium: {
72: 'f/4', // kick
73: 'c/5', // snare
74: 'g/5/x2', // yellow cymbal
75: 'd/5', // blue tom
76: 'a/5/x2', // green cymbal
77: 'a/4', // green tom
},
easy: {
60: 'f/4', // kick
61: 'c/5', // snare
62: 'g/5/x2', // yellow cymbal
63: 'd/5', // blue tom
64: 'a/5/x2', // green cymbal
65: 'a/4', // green tom
},
};

Expand Down Expand Up @@ -120,7 +156,11 @@ export class MidiParser {

durationMap: { [key: number]: Duration };

constructor(data: MidiJSON, difficulty: Difficulty = Difficulty.expert) {
constructor(
data: MidiJSON,
isFiveLane: boolean,
difficulty: Difficulty = Difficulty.expert,
) {
const drumPart = data.tracks.find((track) => track.name === 'PART DRUMS');

if (!drumPart) {
Expand All @@ -133,21 +173,27 @@ export class MidiParser {

this.durationMap = this.constructDurationMap();

this.processNotes(drumPart, difficulty);
this.processNotes(drumPart, isFiveLane, difficulty);
this.createMeasures();
this.fillBeats();
this.extendNoteDuration();
this.processCompositeDuration();
this.flattenMeasures();
}

processNotes(trackData: TrackJSON, difficulty: Difficulty) {
processNotes(
trackData: TrackJSON,
isFiveLane: boolean,
difficulty: Difficulty,
) {
const mapping = isFiveLane ? this.mappingFiveLane : this.mapping;

trackData.notes.forEach((note) => {
if (this.mapping[difficulty][note.midi]) {
if (mapping[difficulty][note.midi]) {
const tickData = this.rawMidiNotes.get(note.ticks) ?? [];
tickData.push({
note,
key: this.mapping[difficulty][note.midi],
key: mapping[difficulty][note.midi],
});
this.rawMidiNotes.set(note.ticks, tickData);
} else if (this.tomModifiers[note.midi]) {
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/components/SheetMusic/SheetMusic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface SheetMusicProps {
currentTime: number;
onSelectMeasure: (time: number) => void;
difficulty: Difficulty;
isFiveLane: boolean;
}

export function SheetMusic({
Expand All @@ -20,6 +21,7 @@ export function SheetMusic({
currentTime,
onSelectMeasure,
difficulty,
isFiveLane,
}: SheetMusicProps) {
const containerRef = useRef<HTMLDivElement | null>(null);
const highlightsRef = useRef<RefObject<HTMLButtonElement>[]>([]);
Expand All @@ -44,8 +46,8 @@ export function SheetMusic({
return;
}

setParsedMidi(new MidiParser(midi.toJSON(), difficulty));
}, [midi, difficulty]);
setParsedMidi(new MidiParser(midi.toJSON(), isFiveLane, difficulty));
}, [midi, isFiveLane, difficulty]);

useEffect(() => {
if (!vexflowContainerRef.current || !parsedMidi) {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/SongView/SongView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export function SongView() {
difficulty={difficulty}
showBarNumbers={showBarNumbers}
enableColors={enableColors}
isFiveLane={songData.five_lane_drums === 'True'}
onSelectMeasure={(time) => {
if (!audioPlayer) {
return;
Expand Down

0 comments on commit 8339e50

Please sign in to comment.