summaryrefslogtreecommitdiff
path: root/deck-controls.js
diff options
context:
space:
mode:
Diffstat (limited to 'deck-controls.js')
-rw-r--r--deck-controls.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/deck-controls.js b/deck-controls.js
new file mode 100644
index 0000000..91d4494
--- /dev/null
+++ b/deck-controls.js
@@ -0,0 +1,51 @@
+import { DeckButton } from './deck-button.js';
+const pressSound = new Audio("audio/button-press.mp3");
+
+export function DeckControls(params) {
+ const { deck } = params;
+
+ return {
+ go: function () {
+ deck.elem.src = deck.images.go;
+ deck.isPlaying = true;
+ deck.playButton.toggle();
+ },
+ start: function () {
+ deck.hasStarted = true;
+ this.playButton.initSound.onended = (event) => { deck.cassette.play(); };
+ this.playButton.initSound.play();
+ this.go();
+ },
+ pause: function () {
+ this.playButton.toggle();
+ this.playButton.pressSound.play();
+ deck.cassette.pause();
+ deck.elem.src = deck.images.stop;
+ deck.isPlaying = false;
+ },
+ resume: function () {
+ this.playButton.pressSound.play();
+ this.go();
+ deck.cassette.play();
+ },
+ playButton: {
+ elem: document.getElementById("play-button"),
+ state: "off",
+ up: "images/play-button-up.jpg",
+ down: "images/play-button-down.jpg",
+ initSound: new Audio("audio/tape-start.mp3"),
+ pressSound: pressSound,
+ toggle: function () {
+ if (this.state === "off") {
+ this.elem.src = this.down;
+ this.state = "on";
+ } else {
+ this.elem.src = this.up;
+ this.state = "off";
+ }
+ }
+ },
+ ffButton: DeckButton("ff"),
+ rewindButton: DeckButton("rewind"),
+ };
+}