Skip to content

Commit

Permalink
fix handling of stop events
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Oct 8, 2024
1 parent 4261d56 commit e548a1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"node": "./dist/punkomatic.node.js",
"browser": "./dist/punkomatic.browser.js"
},
"version": "0.1.0",
"version": "0.5.2",
"description": "a tool to parse and render Punk-O-Matic 2 song data",
"scripts": {
"build": "./scripts/build.sh",
Expand Down
20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ export function parseSong(data: string): Song {
};

for (let [channel, data] of channels) {
data = data.replace(/\s/g, '');
let events = song.events[channel];
data = data.replace(/\s/g, "");

let time = 0;
let hasSound = false;

for (let i = 0; i < data.length; i += 2) {
if (hasSound && time >= song.events[channel].at(-1)!.endTime) hasSound = false;
if (hasSound && time >= events.at(-1)!.endTime + events.at(-1)!.release) {
hasSound = false;
}

const atom = data.slice(i, i + 2);

Expand All @@ -59,16 +62,17 @@ export function parseSong(data: string): Song {
time += length * 31129;
} else if (atom === "!!") {
if (hasSound) {
song.events[channel].at(-1)!.endTime = time;
song.events[channel].at(-1)!.release = 882;
events.at(-1)!.endTime = time;
events.at(-1)!.release = 882;
hasSound = false;
}
time += 31129;
} else {
const sound = SOUNDS[channel][parseBase52(atom)];
if (hasSound) {
song.events[channel].at(-1)!.endTime = time;
song.events[channel].at(-1)!.release = 0;
song.events[channel].push({
events.at(-1)!.endTime = time;
events.at(-1)!.release = 0;
events.push({
startTime: time,
endTime: time + sound.samples,
sound,
Expand All @@ -77,7 +81,7 @@ export function parseSong(data: string): Song {
});
time += 31129;
} else {
song.events[channel].push({
events.push({
startTime: time - (channel === "guitarB" ? 1700 : 1300),
endTime: time + sound.samples - (channel === "guitarB" ? 1700 : 1300),
sound,
Expand Down

0 comments on commit e548a1b

Please sign in to comment.