Skip to content

Commit

Permalink
fix: setting the timingchanges wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Nov 12, 2023
1 parent 7317683 commit ab6b07d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/internal/syntacticAnalysis/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Deserializer {

constructor(sequence: Iterable<Token>) {
this.enumerator = new Enumerator<Token>(sequence);
this.timingChanges.push(new TimingChange(0, 4));
this.timingChanges.push(new TimingChange());
this.currentNoteCollection = undefined;
this.currentTime = 0;
this.endOfFile = false;
Expand Down
3 changes: 2 additions & 1 deletion src/internal/syntacticAnalysis/states/noteReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class NoteReader {
const currentNote = new Note(parent.currentNoteCollection!);
currentNote.location = noteLocation;

const overrideTiming = new TimingChange(parent.currentNoteCollection!.time);
const overrideTiming = new TimingChange();
overrideTiming.tempo = parent.timingChanges[parent.timingChanges.length - 1].tempo;

if (noteLocation.group !== NoteGroup.Tap) currentNote.type = NoteType.Touch;

Expand Down
8 changes: 6 additions & 2 deletions src/internal/syntacticAnalysis/states/subdivisionReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export class SubdivisionReader {
let newTimingChange;
{
const oldTimingChange = parent.timingChanges[parent.timingChanges.length - 1];
newTimingChange = new TimingChange(oldTimingChange.tempo, oldTimingChange.subdivisions);
newTimingChange = new TimingChange();
newTimingChange.tempo = oldTimingChange.tempo;
newTimingChange.subdivisions = oldTimingChange.subdivisions;
}

newTimingChange.setSeconds(explicitTempo);
Expand All @@ -40,7 +42,9 @@ export class SubdivisionReader {
let newTimingChange;
{
const oldTimingChange = parent.timingChanges[parent.timingChanges.length - 1];
newTimingChange = new TimingChange(oldTimingChange.tempo, oldTimingChange.subdivisions);
newTimingChange = new TimingChange();
newTimingChange.tempo = oldTimingChange.tempo;
newTimingChange.subdivisions = oldTimingChange.subdivisions;
}

newTimingChange.subdivisions = subdivision;
Expand Down
4 changes: 3 additions & 1 deletion src/internal/syntacticAnalysis/states/tempoReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class TempoReader {
let newTimingChange;
{
const oldTimingChange = parent.timingChanges[parent.timingChanges.length - 1];
newTimingChange = new TimingChange(oldTimingChange.tempo, oldTimingChange.subdivisions);
newTimingChange = new TimingChange();
newTimingChange.tempo = oldTimingChange.tempo;
newTimingChange.subdivisions = oldTimingChange.subdivisions;
}

newTimingChange.tempo = tempo;
Expand Down
9 changes: 2 additions & 7 deletions src/internal/syntacticAnalysis/timingChange.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class TimingChange {
public time: number = 0;
public tempo: number;
public subdivisions: number;
public tempo: number = 0;
public subdivisions: number = 0;

get secondsPerBar(): number {
// could use || here since number is falsy if 0
Expand All @@ -13,11 +13,6 @@ export class TimingChange {
return this.secondsPerBar / ((this.subdivisions === 0 ? 4 : this.subdivisions) / 4);
}

constructor(tempo: number, subdivisions: number = 4) {
this.tempo = tempo;
this.subdivisions = subdivisions;
}

public setSeconds(value: number) {
this.tempo = 60 / value;
this.subdivisions = 4;
Expand Down

0 comments on commit ab6b07d

Please sign in to comment.