2022-12-26 14:19:28 +00:00
|
|
|
<template>
|
|
|
|
<div class="mod-player-disabled" v-if="hide" @click="hide = false">
|
2022-12-26 14:47:10 +00:00
|
|
|
<div>
|
2022-12-27 12:01:06 +00:00
|
|
|
<b><i class="fas fa-exlamation-triangle"></i> {{ i18n.ts.sensitive }}</b>
|
|
|
|
<span>{{ i18n.ts.clickToShow }}</span>
|
2022-12-26 14:47:10 +00:00
|
|
|
</div>
|
2022-12-26 14:19:28 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mod-player-enabled" v-else>
|
2022-12-26 14:47:10 +00:00
|
|
|
<div class="pattern-display">
|
|
|
|
<canvas class="pattern-canvas" ref="displayCanvas"></canvas>
|
|
|
|
</div>
|
|
|
|
<div class="controls">
|
|
|
|
<button class="play" title="play" accesskey="P" @click="playPause()">
|
|
|
|
<i class="fas fa-play" v-if="!playing"></i>
|
|
|
|
<i class="fas fa-pause" v-if="playing"></i>
|
|
|
|
</button>
|
|
|
|
<button class="stop" title="stop" accesskey="X" @click="stop()">
|
|
|
|
<i class="fas fa-stop"></i>
|
|
|
|
</button>
|
|
|
|
<progress min="0" max="100" value="0" ref="progress"></progress>
|
|
|
|
<input type="range" min="0" max="1" v-model="player.context.gain.value" step="0.1" ref="volume" title="volume"/>
|
2022-12-27 13:52:20 +00:00
|
|
|
<a class="download" title="download" :href="module.url" target="_blank">
|
2022-12-26 14:47:10 +00:00
|
|
|
<i class="fas fa-download"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<i class="fas fa-eye-slash" @click="hide = true"></i>
|
2022-12-26 14:19:28 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from 'vue';
|
|
|
|
import * as foundkey from 'foundkey-js';
|
2022-12-27 12:01:06 +00:00
|
|
|
import { i18n } from '@/i18n';
|
2022-12-26 14:19:28 +00:00
|
|
|
import { defaultStore } from '@/store';
|
|
|
|
import { ChiptuneJsPlayer, ChiptuneJsConfig } from '@/scripts/chiptune2';
|
|
|
|
|
2022-12-27 13:45:59 +00:00
|
|
|
const CHAR_WIDTH = 6;
|
|
|
|
const CHAR_HEIGHT = 12;
|
|
|
|
const ROW_OFFSET_Y = 10;
|
|
|
|
|
|
|
|
const colours = {
|
|
|
|
background: '#000000',
|
|
|
|
default: {
|
|
|
|
active: '#ffffff',
|
|
|
|
inactive: '#808080'
|
|
|
|
},
|
|
|
|
quarter: {
|
|
|
|
active: '#ffff00',
|
|
|
|
inactive: '#ffe135'
|
|
|
|
},
|
|
|
|
instr: {
|
|
|
|
active: '#80e0ff',
|
|
|
|
inactive: '#0099cc'
|
|
|
|
},
|
|
|
|
volume: {
|
|
|
|
active: '#80ff80',
|
|
|
|
inactive: '#008000'
|
|
|
|
},
|
|
|
|
fx: {
|
|
|
|
active: '#ff80e0',
|
|
|
|
inactive: '#800060'
|
|
|
|
},
|
|
|
|
operant: {
|
|
|
|
active: '#ffe080',
|
|
|
|
inactive: '#806000'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-26 14:19:28 +00:00
|
|
|
const props = defineProps<{
|
2022-12-26 14:47:10 +00:00
|
|
|
module: foundkey.entities.DriveFile
|
2022-12-26 14:19:28 +00:00
|
|
|
}>();
|
|
|
|
|
|
|
|
let hide = ref((defaultStore.state.nsfw === 'force') ? true : props.module.isSensitive && (defaultStore.state.nsfw !== 'ignore'));
|
|
|
|
let playing = ref(false);
|
|
|
|
let displayCanvas = ref<HTMLCanvasElement>(null);
|
|
|
|
let progress = ref<HTMLProgressElement>(null);
|
2022-12-27 14:23:25 +00:00
|
|
|
const player = ref(new ChiptuneJsPlayer(new ChiptuneJsConfig()));
|
2022-12-26 14:19:28 +00:00
|
|
|
|
|
|
|
const rowBuffer = 24;
|
|
|
|
let buffer = null;
|
|
|
|
player.value.load(props.module.url).then((result) => {
|
2022-12-26 14:47:10 +00:00
|
|
|
buffer = result;
|
|
|
|
try {
|
|
|
|
player.value.play(buffer);
|
|
|
|
display();
|
2022-12-26 14:19:28 +00:00
|
|
|
} catch (e) {
|
2022-12-26 14:47:10 +00:00
|
|
|
console.warn(e);
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
2022-12-26 14:47:10 +00:00
|
|
|
player.value.stop();
|
2022-12-26 14:19:28 +00:00
|
|
|
}).catch((error) => {
|
2022-12-26 14:47:10 +00:00
|
|
|
console.error(error);
|
2022-12-26 14:19:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function playPause() {
|
2022-12-26 14:47:10 +00:00
|
|
|
player.value.addHandler('onRowChange', () => {
|
|
|
|
progress.value.max = player.value.duration();
|
|
|
|
progress.value.value = player.value.position() % player.value.duration();
|
|
|
|
display();
|
2022-12-26 14:19:28 +00:00
|
|
|
});
|
|
|
|
|
2022-12-27 14:23:25 +00:00
|
|
|
player.value.addHandler('onEnded', () => {
|
|
|
|
stop();
|
|
|
|
});
|
|
|
|
|
2022-12-26 14:47:10 +00:00
|
|
|
if (player.value.currentPlayingNode === null) {
|
|
|
|
player.value.play(buffer);
|
|
|
|
playing.value = true;
|
|
|
|
} else {
|
|
|
|
player.value.togglePause();
|
|
|
|
playing.value = !player.value.currentPlayingNode.paused;
|
|
|
|
}
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stop() {
|
2022-12-26 14:47:10 +00:00
|
|
|
player.value.stop();
|
|
|
|
playing.value = false;
|
|
|
|
try {
|
|
|
|
player.value.play(buffer);
|
|
|
|
display();
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
player.value.stop();
|
|
|
|
progress.value.value = 0;
|
|
|
|
player.value.handlers = [];
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function display() {
|
2022-12-26 14:47:10 +00:00
|
|
|
if (!displayCanvas.value) {
|
|
|
|
stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const canvas = displayCanvas.value;
|
|
|
|
|
|
|
|
const pattern = player.value.getPattern();
|
|
|
|
const row = player.value.getRow();
|
|
|
|
let nbChannels = 0;
|
|
|
|
if (player.value.currentPlayingNode) {
|
|
|
|
nbChannels = player.value.currentPlayingNode.nbChannels;
|
|
|
|
}
|
|
|
|
if (canvas.width !== 12 + 84 * nbChannels + 2) {
|
|
|
|
canvas.width = 12 + 84 * nbChannels + 2;
|
|
|
|
canvas.height = 12 * rowBuffer;
|
|
|
|
}
|
|
|
|
const nbRows = player.value.getPatternNumRows(pattern);
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
ctx.font = '10px monospace';
|
2022-12-27 13:45:59 +00:00
|
|
|
ctx.fillStyle = colours.background;
|
2022-12-26 14:47:10 +00:00
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
2022-12-27 13:45:59 +00:00
|
|
|
ctx.fillStyle = colours.default.inactive;
|
2022-12-26 14:47:10 +00:00
|
|
|
for (let rowOffset = 0; rowOffset < rowBuffer; rowOffset++) {
|
|
|
|
const rowToDraw = row - rowBuffer / 2 + rowOffset;
|
|
|
|
if (rowToDraw >= 0 && rowToDraw < nbRows) {
|
2022-12-27 13:45:59 +00:00
|
|
|
const active = (rowToDraw === row) ? 'active' : 'inactive';
|
2022-12-26 14:47:10 +00:00
|
|
|
let rowText = parseInt(rowToDraw).toString(16);
|
|
|
|
if (rowText.length === 1) {
|
|
|
|
rowText = '0' + rowText;
|
|
|
|
}
|
2022-12-27 13:45:59 +00:00
|
|
|
ctx.fillStyle = colours.default[active];
|
2022-12-26 14:47:10 +00:00
|
|
|
if (rowToDraw % 4 === 0) {
|
2022-12-27 13:45:59 +00:00
|
|
|
ctx.fillStyle = colours.quarter[active];
|
2022-12-26 14:47:10 +00:00
|
|
|
}
|
|
|
|
ctx.fillText(rowText, 0, 10 + rowOffset * 12);
|
|
|
|
for (let channel = 0; channel < nbChannels; channel++) {
|
|
|
|
const part = player.value.getPatternRowChannel(pattern, rowToDraw, channel);
|
2022-12-27 13:45:59 +00:00
|
|
|
const baseOffset = (2 + (part.length + 1) * channel) * CHAR_WIDTH;
|
|
|
|
const baseRowOffset = ROW_OFFSET_Y + rowOffset * CHAR_HEIGHT;
|
|
|
|
|
|
|
|
ctx.fillStyle = colours.default[active];
|
|
|
|
ctx.fillText("|", baseOffset, baseRowOffset);
|
|
|
|
|
|
|
|
const note = part.substring(0, 3);
|
|
|
|
ctx.fillStyle = colours.default[active];
|
|
|
|
ctx.fillText(note, baseOffset + CHAR_WIDTH, baseRowOffset);
|
|
|
|
|
|
|
|
const instr = part.substring(4, 6);
|
|
|
|
ctx.fillStyle = colours.instr[active];
|
|
|
|
ctx.fillText(instr, baseOffset + CHAR_WIDTH * 5, baseRowOffset);
|
|
|
|
|
|
|
|
const volume = part.substring(6, 9);
|
|
|
|
ctx.fillStyle = colours.volume[active];
|
|
|
|
ctx.fillText(volume, baseOffset + CHAR_WIDTH * 7, baseRowOffset);
|
|
|
|
|
|
|
|
const fx = part.substring(10, 11);
|
|
|
|
ctx.fillStyle = colours.fx[active];
|
|
|
|
ctx.fillText(fx, baseOffset + CHAR_WIDTH * 11, baseRowOffset);
|
|
|
|
|
|
|
|
const op = part.substring(11, 13);
|
|
|
|
ctx.fillStyle = colours.operant[active];
|
|
|
|
ctx.fillText(op, baseOffset + CHAR_WIDTH * 12, baseRowOffset);
|
2022-12-26 14:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mod-player-enabled {
|
2022-12-26 14:47:10 +00:00
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
> i {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
border-radius: 6px;
|
|
|
|
background-color: var(--fg);
|
|
|
|
color: var(--accentLighten);
|
|
|
|
font-size: 14px;
|
|
|
|
opacity: .5;
|
|
|
|
padding: 3px 6px;
|
|
|
|
text-align: center;
|
|
|
|
cursor: pointer;
|
|
|
|
top: 12px;
|
|
|
|
right: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .pattern-display {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
overflow-x: scroll;
|
|
|
|
overflow-y: hidden;
|
|
|
|
background-color: black;
|
|
|
|
text-align: center;
|
|
|
|
.pattern-canvas {
|
|
|
|
background-color: black;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .controls {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
background-color: var(--bg);
|
|
|
|
|
|
|
|
> * {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> button, a {
|
|
|
|
border: none;
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--accent);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: var(--fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> input[type=range] {
|
|
|
|
height: 21px;
|
|
|
|
-webkit-appearance: none;
|
|
|
|
width: 90px;
|
|
|
|
padding: 0;
|
|
|
|
margin: 4px 8px;
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
|
|
|
|
&::-webkit-slider-runnable-track {
|
|
|
|
background: var(--bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-ms-fill-lower, &::-ms-fill-upper {
|
|
|
|
background: var(--bg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-webkit-slider-runnable-track {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
border-radius: 0;
|
|
|
|
animate: 0.2s;
|
|
|
|
background: var(--bg);
|
|
|
|
border: 1px solid var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-webkit-slider-thumb {
|
|
|
|
border: none;
|
|
|
|
height: 100%;
|
|
|
|
width: 14px;
|
|
|
|
border-radius: 0;
|
|
|
|
background: var(--accent);
|
|
|
|
cursor: pointer;
|
|
|
|
-webkit-appearance: none;
|
|
|
|
margin-top: -0.5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-moz-range-track {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
border-radius: 0;
|
|
|
|
animate: 0.2s;
|
|
|
|
background: var(--bg);
|
|
|
|
border: 1px solid var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-moz-range-thumb {
|
|
|
|
border: none;
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 0;
|
|
|
|
width: 14px;
|
|
|
|
background: var(--accent);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-ms-track {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
border-radius: 0;
|
|
|
|
animate: 0.2s;
|
|
|
|
background: transparent;
|
|
|
|
border-color: transparent;
|
|
|
|
color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-ms-fill-lower, &::-ms-fill-upper {
|
|
|
|
background: var(--bg);
|
|
|
|
border: 1px solid var(--fg);
|
|
|
|
border-radius: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-ms-thumb {
|
|
|
|
margin-top: 1px;
|
|
|
|
border: none;
|
|
|
|
height: 100%;
|
|
|
|
width: 14px;
|
|
|
|
border-radius: 0;
|
|
|
|
background: var(--accent);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> progress {
|
|
|
|
padding: unset;
|
|
|
|
margin: 4px 8px;
|
|
|
|
flex-grow: 1;
|
2022-12-27 13:45:59 +00:00
|
|
|
min-width: 0;
|
2022-12-26 14:47:10 +00:00
|
|
|
background-color: var(--bg);
|
|
|
|
|
|
|
|
&::-moz-progress-bar, &::-webkit-progress-value {
|
|
|
|
background-color: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.mod-player-disabled {
|
2022-12-26 14:47:10 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
background: #111;
|
|
|
|
color: #fff;
|
|
|
|
|
|
|
|
> div {
|
|
|
|
display: table-cell;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
|
|
> b {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
2022-12-26 14:19:28 +00:00
|
|
|
}
|
|
|
|
</style>
|