Skip to content

Commit

Permalink
Keep track of music playback position now that uge player is reset ev…
Browse files Browse the repository at this point in the history
…ery time play button is pressed
  • Loading branch information
chrismaltby committed Mar 18, 2024
1 parent 03af18f commit 5ed7e70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/app/music/MusicRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import player from "components/music/helpers/player";
import player, { PlaybackPosition } from "components/music/helpers/player";
import { playNotePreview } from "components/music/helpers/notePreview";
import API from "renderer/lib/api";

Expand All @@ -24,12 +24,15 @@ player.initPlayer(onPlayerInit, sfx);

player.setOnIntervalCallback((playbackUpdate) => {
log(playbackUpdate);
position = playbackUpdate;
API.music.sendToProjectWindow({
action: "update",
update: playbackUpdate,
});
});

let position: PlaybackPosition = [0, 0];

API.events.music.data.subscribe((_event, d) => {
log(d);
switch (d.action) {
Expand All @@ -45,8 +48,11 @@ API.events.music.data.subscribe((_event, d) => {
});
break;
case "play":
if (d.position) {
position = d.position;
}
player.reset();
player.play(d.song, d.position);
player.play(d.song, position);
API.music.sendToProjectWindow({
action: "log",
message: "playing",
Expand All @@ -60,13 +66,19 @@ API.events.music.data.subscribe((_event, d) => {
});
break;
case "stop":
if (d.position) {
position = d.position;
}
player.stop(d.position);
API.music.sendToProjectWindow({
action: "log",
message: "stop",
});
break;
case "position":
if (d.position) {
position = d.position;
}
player.setStartPosition(d.position);
API.music.sendToProjectWindow({
action: "log",
Expand Down
2 changes: 1 addition & 1 deletion src/components/music/helpers/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Song } from "shared/lib/uge/song/Song";
import { lo, hi } from "shared/lib/helpers/8bit";
import { SubPatternCell } from "shared/lib/uge/song/SubPatternCell";

type PlaybackPosition = [number, number];
export type PlaybackPosition = [number, number];

let currentSong: Song | null = null;

Expand Down

0 comments on commit 5ed7e70

Please sign in to comment.