Compare commits
6 commits
develop
...
gh-b77c025
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
229ceb66ba | ||
|
|
f58f0eaf92 | ||
|
|
8702c1dd24 | ||
|
|
d03ad221a1 | ||
|
|
af3065f315 | ||
|
|
6cc81b6a9a |
15 changed files with 1176 additions and 699 deletions
|
|
@ -121,6 +121,7 @@ pinnedNote: "Pinned note"
|
||||||
pinned: "Pin to profile"
|
pinned: "Pin to profile"
|
||||||
you: "You"
|
you: "You"
|
||||||
clickToShow: "Click to show"
|
clickToShow: "Click to show"
|
||||||
|
patternHidden: "Pattern hidden"
|
||||||
sensitive: "Sensitive"
|
sensitive: "Sensitive"
|
||||||
add: "Add"
|
add: "Add"
|
||||||
reaction: "Reactions"
|
reaction: "Reactions"
|
||||||
|
|
@ -1084,6 +1085,7 @@ showClipButtonInNoteFooter: "Add \"Clip\" to note action menu"
|
||||||
reactionsDisplaySize: "Reaction display size"
|
reactionsDisplaySize: "Reaction display size"
|
||||||
limitWidthOfReaction: "Limits the maximum width of reactions and display them in reduced size."
|
limitWidthOfReaction: "Limits the maximum width of reactions and display them in reduced size."
|
||||||
noteIdOrUrl: "Note ID or URL"
|
noteIdOrUrl: "Note ID or URL"
|
||||||
|
module: "Module"
|
||||||
video: "Video"
|
video: "Video"
|
||||||
videos: "Videos"
|
videos: "Videos"
|
||||||
dataSaver: "Data Saver"
|
dataSaver: "Data Saver"
|
||||||
|
|
|
||||||
2
locales/index.d.ts
vendored
2
locales/index.d.ts
vendored
|
|
@ -124,6 +124,7 @@ export interface Locale {
|
||||||
"pinned": string;
|
"pinned": string;
|
||||||
"you": string;
|
"you": string;
|
||||||
"clickToShow": string;
|
"clickToShow": string;
|
||||||
|
"patternHidden": string;
|
||||||
"sensitive": string;
|
"sensitive": string;
|
||||||
"add": string;
|
"add": string;
|
||||||
"reaction": string;
|
"reaction": string;
|
||||||
|
|
@ -1094,6 +1095,7 @@ export interface Locale {
|
||||||
"reactionsDisplaySize": string;
|
"reactionsDisplaySize": string;
|
||||||
"limitWidthOfReaction": string;
|
"limitWidthOfReaction": string;
|
||||||
"noteIdOrUrl": string;
|
"noteIdOrUrl": string;
|
||||||
|
"module": string;
|
||||||
"video": string;
|
"video": string;
|
||||||
"videos": string;
|
"videos": string;
|
||||||
"audio": string;
|
"audio": string;
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ pinnedNote: "ピン留めされたノート"
|
||||||
pinned: "ピン留め"
|
pinned: "ピン留め"
|
||||||
you: "あなた"
|
you: "あなた"
|
||||||
clickToShow: "クリックして表示"
|
clickToShow: "クリックして表示"
|
||||||
|
patternHidden: "パターン非表示"
|
||||||
sensitive: "センシティブ"
|
sensitive: "センシティブ"
|
||||||
add: "追加"
|
add: "追加"
|
||||||
reaction: "リアクション"
|
reaction: "リアクション"
|
||||||
|
|
@ -1091,6 +1092,7 @@ showClipButtonInNoteFooter: "ノートのアクションにクリップを追加
|
||||||
reactionsDisplaySize: "リアクションの表示サイズ"
|
reactionsDisplaySize: "リアクションの表示サイズ"
|
||||||
limitWidthOfReaction: "リアクションの最大横幅を制限し、縮小して表示する"
|
limitWidthOfReaction: "リアクションの最大横幅を制限し、縮小して表示する"
|
||||||
noteIdOrUrl: "ノートIDまたはURL"
|
noteIdOrUrl: "ノートIDまたはURL"
|
||||||
|
module: "Module" # TODO: translate
|
||||||
video: "動画"
|
video: "動画"
|
||||||
videos: "動画"
|
videos: "動画"
|
||||||
audio: "音声"
|
audio: "音声"
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ html
|
||||||
link(rel='stylesheet' href='/assets/phosphor-icons/bold/style.css')
|
link(rel='stylesheet' href='/assets/phosphor-icons/bold/style.css')
|
||||||
link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css')
|
link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css')
|
||||||
link(rel='modulepreload' href=`/vite/${clientEntry.file}`)
|
link(rel='modulepreload' href=`/vite/${clientEntry.file}`)
|
||||||
script(src='/client-assets/libopenmpt.js')
|
|
||||||
|
|
||||||
if !config.clientManifestExists
|
if !config.clientManifestExists
|
||||||
script(type="module" src="/vite/@vite/client")
|
script(type="module" src="/vite/@vite/client")
|
||||||
|
|
@ -73,7 +72,6 @@ html
|
||||||
script.
|
script.
|
||||||
var VERSION = "#{version}";
|
var VERSION = "#{version}";
|
||||||
var CLIENT_ENTRY = "#{clientEntry.file}";
|
var CLIENT_ENTRY = "#{clientEntry.file}";
|
||||||
window.libopenmpt = window.Module;
|
|
||||||
|
|
||||||
script
|
script
|
||||||
include ../boot.js
|
include ../boot.js
|
||||||
|
|
|
||||||
1
packages/frontend/@types/global.d.ts
vendored
1
packages/frontend/@types/global.d.ts
vendored
|
|
@ -16,3 +16,4 @@ declare const _DATA_TRANSFER_DECK_COLUMN_: string;
|
||||||
|
|
||||||
// for dev-mode
|
// for dev-mode
|
||||||
declare const _LANGS_FULL_: string[][];
|
declare const _LANGS_FULL_: string[][];
|
||||||
|
declare const __DIRNAME__: string;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -52,6 +52,7 @@
|
||||||
"is-file-animated": "1.0.2",
|
"is-file-animated": "1.0.2",
|
||||||
"json5": "2.2.3",
|
"json5": "2.2.3",
|
||||||
"katex": "0.16.9",
|
"katex": "0.16.9",
|
||||||
|
"libopenmpt-wasm": "github:TheEssem/libopenmpt-packaging#build",
|
||||||
"matter-js": "0.19.0",
|
"matter-js": "0.19.0",
|
||||||
"misskey-js": "workspace:*",
|
"misskey-js": "workspace:*",
|
||||||
"photoswipe": "5.4.3",
|
"photoswipe": "5.4.3",
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<template v-for="media in mediaList.filter(media => previewable(media))">
|
<template v-for="media in mediaList.filter(media => previewable(media))">
|
||||||
<XVideo v-if="media.type.startsWith('video')" :key="`video:${media.id}`" :class="$style.media" :video="media"/>
|
<XVideo v-if="media.type.startsWith('video')" :key="`video:${media.id}`" :class="$style.media" :video="media"/>
|
||||||
<XImage v-else-if="media.type.startsWith('image')" :key="`image:${media.id}`" :class="$style.media" class="image" :data-id="media.id" :image="media" :raw="raw"/>
|
<XImage v-else-if="media.type.startsWith('image')" :key="`image:${media.id}`" :class="$style.media" class="image" :data-id="media.id" :image="media" :raw="raw"/>
|
||||||
<XModPlayer v-else-if="isModule(media)" :key="media.id" :module="media"/>
|
<XModule v-else-if="isModule(media)" :key="`module:${media.id}`" :class="$style.media" :module="media"/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -37,7 +37,7 @@ import 'photoswipe/style.css';
|
||||||
import XBanner from '@/components/MkMediaBanner.vue';
|
import XBanner from '@/components/MkMediaBanner.vue';
|
||||||
import XImage from '@/components/MkMediaImage.vue';
|
import XImage from '@/components/MkMediaImage.vue';
|
||||||
import XVideo from '@/components/MkMediaVideo.vue';
|
import XVideo from '@/components/MkMediaVideo.vue';
|
||||||
import XModPlayer from '@/components/MkModPlayer.vue';
|
import XModule from '@/components/SkMediaModule.vue';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { FILE_TYPE_BROWSERSAFE, FILE_EXT_TRACKER_MODULES, FILE_TYPE_TRACKER_MODULES } from '@/const.js';
|
import { FILE_TYPE_BROWSERSAFE, FILE_EXT_TRACKER_MODULES, FILE_TYPE_TRACKER_MODULES } from '@/const.js';
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
|
|
|
||||||
|
|
@ -1,475 +0,0 @@
|
||||||
<template>
|
|
||||||
<div v-if="hide" class="mod-player-disabled" @click="toggleVisible()">
|
|
||||||
<div>
|
|
||||||
<b><i class="ph-eye ph-bold ph-lg"></i> {{ i18n.ts.sensitive }}</b>
|
|
||||||
<span>{{ i18n.ts.clickToShow }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="mod-player-enabled">
|
|
||||||
<div class="pattern-display" @click="togglePattern()">
|
|
||||||
<div v-if="patternHide" class="pattern-hide">
|
|
||||||
<b><i class="ph-eye ph-bold ph-lg"></i> Pattern Hidden</b>
|
|
||||||
<span>{{ i18n.ts.clickToShow }}</span>
|
|
||||||
</div>
|
|
||||||
<canvas ref="displayCanvas" class="pattern-canvas"></canvas>
|
|
||||||
</div>
|
|
||||||
<div class="controls">
|
|
||||||
<button class="play" @click="playPause()">
|
|
||||||
<i v-if="playing" class="ph-pause ph-bold ph-lg"></i>
|
|
||||||
<i v-else class="ph-play ph-bold ph-lg"></i>
|
|
||||||
</button>
|
|
||||||
<button class="stop" @click="stop()">
|
|
||||||
<i class="ph-stop ph-bold ph-lg"></i>
|
|
||||||
</button>
|
|
||||||
<input ref="progress" v-model="position" class="progress" type="range" min="0" max="1" step="0.1" @mousedown="initSeek()" @mouseup="performSeek()"/>
|
|
||||||
<input v-model="player.context.gain.value" type="range" min="0" max="1" step="0.1"/>
|
|
||||||
<a class="download" :title="i18n.ts.download" :href="module.url" target="_blank">
|
|
||||||
<i class="ph-download ph-bold ph-lg"></i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<i class="hide ph-eye-slash ph-bold ph-lg" @click="toggleVisible()"></i>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { ref, nextTick, computed } from 'vue';
|
|
||||||
import * as Misskey from 'misskey-js';
|
|
||||||
import { i18n } from '@/i18n.js';
|
|
||||||
import { defaultStore } from '@/store.js';
|
|
||||||
import { ChiptuneJsPlayer, ChiptuneJsConfig } from '@/scripts/chiptune2.js';
|
|
||||||
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
module: Misskey.entities.DriveFile
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const isSensitive = computed(() => { return props.module.isSensitive; });
|
|
||||||
const url = computed(() => { return props.module.url; });
|
|
||||||
let hide = ref((defaultStore.state.nsfw === 'force') ? true : isSensitive.value && (defaultStore.state.nsfw !== 'ignore'));
|
|
||||||
let patternHide = ref(false);
|
|
||||||
let firstFrame = ref(true);
|
|
||||||
let playing = ref(false);
|
|
||||||
let displayCanvas = ref<HTMLCanvasElement>();
|
|
||||||
let progress = ref<HTMLProgressElement>();
|
|
||||||
let position = ref(0);
|
|
||||||
const player = ref(new ChiptuneJsPlayer(new ChiptuneJsConfig()));
|
|
||||||
|
|
||||||
const rowBuffer = 24;
|
|
||||||
let buffer = null;
|
|
||||||
let isSeeking = false;
|
|
||||||
|
|
||||||
player.value.load(url.value).then((result) => {
|
|
||||||
buffer = result;
|
|
||||||
try {
|
|
||||||
player.value.play(buffer);
|
|
||||||
progress.value!.max = player.value.duration();
|
|
||||||
display();
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(err);
|
|
||||||
}
|
|
||||||
player.value.stop();
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
function playPause() {
|
|
||||||
player.value.addHandler('onRowChange', () => {
|
|
||||||
progress.value!.max = player.value.duration();
|
|
||||||
if (!isSeeking) {
|
|
||||||
position.value = player.value.position() % player.value.duration();
|
|
||||||
}
|
|
||||||
display();
|
|
||||||
});
|
|
||||||
|
|
||||||
player.value.addHandler('onEnded', () => {
|
|
||||||
stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (player.value.currentPlayingNode === null) {
|
|
||||||
player.value.play(buffer);
|
|
||||||
player.value.seek(position.value);
|
|
||||||
playing.value = true;
|
|
||||||
} else {
|
|
||||||
player.value.togglePause();
|
|
||||||
playing.value = !player.value.currentPlayingNode.paused;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop(noDisplayUpdate = false) {
|
|
||||||
player.value.stop();
|
|
||||||
playing.value = false;
|
|
||||||
if (!noDisplayUpdate) {
|
|
||||||
try {
|
|
||||||
player.value.play(buffer);
|
|
||||||
display();
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.value.stop();
|
|
||||||
position.value = 0;
|
|
||||||
player.value.handlers = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function initSeek() {
|
|
||||||
isSeeking = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function performSeek() {
|
|
||||||
const noNode = !player.value.currentPlayingNode;
|
|
||||||
if (noNode) {
|
|
||||||
player.value.play(buffer);
|
|
||||||
}
|
|
||||||
player.value.seek(position.value);
|
|
||||||
display();
|
|
||||||
if (noNode) {
|
|
||||||
player.value.stop();
|
|
||||||
}
|
|
||||||
isSeeking = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleVisible() {
|
|
||||||
hide.value = !hide.value;
|
|
||||||
if (!hide.value && patternHide.value) {
|
|
||||||
firstFrame.value = true;
|
|
||||||
patternHide.value = false;
|
|
||||||
}
|
|
||||||
nextTick(() => { stop(hide.value); });
|
|
||||||
}
|
|
||||||
|
|
||||||
function togglePattern() {
|
|
||||||
patternHide.value = !patternHide.value;
|
|
||||||
if (!patternHide.value) {
|
|
||||||
if (player.value.getRow() === 0) {
|
|
||||||
try {
|
|
||||||
player.value.play(buffer);
|
|
||||||
display();
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(err);
|
|
||||||
}
|
|
||||||
player.value.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function display() {
|
|
||||||
if (!displayCanvas.value) {
|
|
||||||
stop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (patternHide.value) return;
|
|
||||||
|
|
||||||
if (firstFrame.value) {
|
|
||||||
firstFrame.value = false;
|
|
||||||
patternHide.value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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') as CanvasRenderingContext2D;
|
|
||||||
ctx.font = '10px monospace';
|
|
||||||
ctx.fillStyle = colours.background;
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
ctx.fillStyle = colours.default.inactive;
|
|
||||||
for (let rowOffset = 0; rowOffset < rowBuffer; rowOffset++) {
|
|
||||||
const rowToDraw = row - rowBuffer / 2 + rowOffset;
|
|
||||||
if (rowToDraw >= 0 && rowToDraw < nbRows) {
|
|
||||||
const active = (rowToDraw === row) ? 'active' : 'inactive';
|
|
||||||
let rowText = parseInt(rowToDraw).toString(16);
|
|
||||||
if (rowText.length === 1) {
|
|
||||||
rowText = '0' + rowText;
|
|
||||||
}
|
|
||||||
ctx.fillStyle = colours.default[active];
|
|
||||||
if (rowToDraw % 4 === 0) {
|
|
||||||
ctx.fillStyle = colours.quarter[active];
|
|
||||||
}
|
|
||||||
ctx.fillText(rowText, 0, 10 + rowOffset * 12);
|
|
||||||
for (let channel = 0; channel < nbChannels; channel++) {
|
|
||||||
const part = player.value.getPatternRowChannel(pattern, rowToDraw, channel);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
.hide {
|
|
||||||
border-radius: var(--radius-sm) !important;
|
|
||||||
background-color: black !important;
|
|
||||||
color: var(--accentLighten) !important;
|
|
||||||
font-size: 12px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mod-player-enabled {
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
|
|
||||||
> i {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
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%;
|
|
||||||
}
|
|
||||||
.pattern-hide {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
background: rgba(64, 64, 64, 0.3);
|
|
||||||
backdrop-filter: blur(2em);
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
|
|
||||||
position: absolute;
|
|
||||||
z-index: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
> span {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .controls {
|
|
||||||
display: flex;
|
|
||||||
width: 100%;
|
|
||||||
background-color: var(--bg);
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
> * {
|
|
||||||
padding: 4px 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
> button, a {
|
|
||||||
border: none;
|
|
||||||
background-color: transparent;
|
|
||||||
color: var(--accent);
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--fg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> input[type=range] {
|
|
||||||
height: 21px;
|
|
||||||
-webkit-appearance: none;
|
|
||||||
width: 90px;
|
|
||||||
padding: 0;
|
|
||||||
margin: 4px 8px;
|
|
||||||
overflow-x: hidden;
|
|
||||||
|
|
||||||
&: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);
|
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-webkit-slider-thumb {
|
|
||||||
border: none;
|
|
||||||
height: 100%;
|
|
||||||
width: 14px;
|
|
||||||
border-radius: 0;
|
|
||||||
background: var(--accentLighten);
|
|
||||||
cursor: pointer;
|
|
||||||
-webkit-appearance: none;
|
|
||||||
box-shadow: calc(-100vw - 14px) 0 0 100vw var(--accent);
|
|
||||||
clip-path: polygon(1px 0, 100% 0, 100% 100%, 1px 100%, 1px calc(50% + 10.5px), -100vw calc(50% + 10.5px), -100vw calc(50% - 10.5px), 0 calc(50% - 10.5px));
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-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-progress {
|
|
||||||
cursor: pointer;
|
|
||||||
height: 100%;
|
|
||||||
background: var(--accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-moz-range-thumb {
|
|
||||||
border: none;
|
|
||||||
height: 100%;
|
|
||||||
border-radius: 0;
|
|
||||||
width: 14px;
|
|
||||||
background: var(--accentLighten);
|
|
||||||
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 {
|
|
||||||
background: var(--accent);
|
|
||||||
border: 1px solid var(--fg);
|
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::-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(--accentLighten);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.progress {
|
|
||||||
flex-grow: 1;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.mod-player-disabled {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
490
packages/frontend/src/components/SkMediaModule.vue
Normal file
490
packages/frontend/src/components/SkMediaModule.vue
Normal file
|
|
@ -0,0 +1,490 @@
|
||||||
|
<!--
|
||||||
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
-->
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="playerEl"
|
||||||
|
:class="[
|
||||||
|
$style.moduleContainer,
|
||||||
|
controlsShowing && $style.active,
|
||||||
|
(module.isSensitive && defaultStore.state.highlightSensitiveMedia) && $style.sensitive,
|
||||||
|
]"
|
||||||
|
@mouseover="onMouseOver"
|
||||||
|
@mouseleave="onMouseLeave"
|
||||||
|
@contextmenu.stop
|
||||||
|
>
|
||||||
|
<button v-if="hide" :class="$style.hidden" @click="hide = false">
|
||||||
|
<div :class="$style.hiddenTextWrapper">
|
||||||
|
<b v-if="module.isSensitive" style="display: block;"><i class="ph-warning ph-bold ph-lg"></i> {{ i18n.ts.sensitive }}{{ defaultStore.state.dataSaver.media ? ` (${i18n.ts.module}${module.size ? ' ' + bytes(module.size) : ''})` : '' }}</b>
|
||||||
|
<b v-else style="display: block;"><i class="ph-film-strip ph-bold ph-lg"></i> {{ defaultStore.state.dataSaver.media && module.size ? bytes(module.size) : i18n.ts.module }}</b>
|
||||||
|
<span style="display: block;">{{ i18n.ts.clickToShow }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
<div v-else :class="$style.moduleRoot" @click.self="showPattern">
|
||||||
|
<SkModPlayer
|
||||||
|
ref="moduleEl"
|
||||||
|
:class="$style.module"
|
||||||
|
:src="module.url"
|
||||||
|
:alt="module.comment"
|
||||||
|
/>
|
||||||
|
<button v-if="isReady && !isPlaying" class="_button" :class="$style.moduleOverlayPlayButton" @click="togglePlayPause"><i class="ph-play ph-bold ph-lg"></i></button>
|
||||||
|
<i class="ti ti-eye-off" :class="$style.hide" @click="hide = true"></i>
|
||||||
|
<div :class="$style.indicators">
|
||||||
|
<div v-if="module.comment" :class="$style.indicator">ALT</div>
|
||||||
|
<div v-if="module.isSensitive" :class="$style.indicator" style="color: var(--warn);" :title="i18n.ts.sensitive"><i class="ph-warning ph-bold ph-lg"></i></div>
|
||||||
|
</div>
|
||||||
|
<div :class="$style.moduleControls" @click.self="showPattern">
|
||||||
|
<div :class="[$style.controlsChild, $style.controlsLeft]">
|
||||||
|
<button class="_button" :class="$style.controlButton" @click="togglePlayPause">
|
||||||
|
<i v-if="isPlaying" class="ph-pause ph-bold ph-lg"></i>
|
||||||
|
<i v-else class="ph-play ph-bold ph-lg"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div :class="[$style.controlsChild, $style.controlsRight]">
|
||||||
|
<button class="_button" :class="$style.controlButton" @click="showMenu">
|
||||||
|
<i class="ph-settings ph-bold ph-lg"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div :class="[$style.controlsChild, $style.controlsTime]">{{ hms(elapsedTimeMs, {}) }}</div>
|
||||||
|
<div :class="[$style.controlsChild, $style.controlsVolume]">
|
||||||
|
<button class="_button" :class="$style.controlButton" @click="toggleMute">
|
||||||
|
<i v-if="volume === 0" class="ph-speaker-x ph-bold ph-lg"></i>
|
||||||
|
<i v-else class="ph-speaker-high ph-bold ph-lg"></i>
|
||||||
|
</button>
|
||||||
|
<MkMediaRange
|
||||||
|
v-model="volume"
|
||||||
|
:sliderBgWhite="true"
|
||||||
|
:class="$style.volumeSeekbar"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<MkMediaRange
|
||||||
|
v-model="rangePercent"
|
||||||
|
:sliderBgWhite="true"
|
||||||
|
:class="$style.seekbarRoot"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, shallowRef, computed, watch, onDeactivated, onActivated, onMounted } from 'vue';
|
||||||
|
import * as Misskey from 'misskey-js';
|
||||||
|
import type { MenuItem } from '@/types/menu.js';
|
||||||
|
import bytes from '@/filters/bytes.js';
|
||||||
|
import { hms } from '@/filters/hms.js';
|
||||||
|
import { defaultStore } from '@/store.js';
|
||||||
|
import { i18n } from '@/i18n.js';
|
||||||
|
import * as os from '@/os.js';
|
||||||
|
import MkMediaRange from '@/components/MkMediaRange.vue';
|
||||||
|
import SkModPlayer from '@/components/SkModPlayer.vue';
|
||||||
|
import { iAmModerator } from '@/account.js';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
module: Misskey.entities.DriveFile;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
||||||
|
const hide = ref((defaultStore.state.nsfw === 'force' || defaultStore.state.dataSaver.media) ? true : (props.module.isSensitive && defaultStore.state.nsfw !== 'ignore'));
|
||||||
|
|
||||||
|
// Menu
|
||||||
|
const menuShowing = ref(false);
|
||||||
|
|
||||||
|
function showMenu(ev: MouseEvent) {
|
||||||
|
let menu: MenuItem[] = [];
|
||||||
|
|
||||||
|
menu = [
|
||||||
|
// TODO: 再生キューに追加
|
||||||
|
{
|
||||||
|
text: i18n.ts.hide,
|
||||||
|
icon: 'ti ti-eye-off',
|
||||||
|
action: () => {
|
||||||
|
hide.value = true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (iAmModerator) {
|
||||||
|
menu.push({
|
||||||
|
type: 'divider',
|
||||||
|
}, {
|
||||||
|
text: props.module.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
||||||
|
icon: props.module.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation',
|
||||||
|
danger: true,
|
||||||
|
action: () => toggleSensitive(props.module),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
menuShowing.value = true;
|
||||||
|
os.popupMenu(menu, ev.currentTarget ?? ev.target, {
|
||||||
|
align: 'right',
|
||||||
|
onClosing: () => {
|
||||||
|
menuShowing.value = false;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSensitive(file: Misskey.entities.DriveFile) {
|
||||||
|
os.apiWithDialog('drive/files/update', {
|
||||||
|
fileId: file.id,
|
||||||
|
isSensitive: !file.isSensitive,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// MediaControl: Module State
|
||||||
|
const moduleEl = shallowRef<typeof SkModPlayer>();
|
||||||
|
const playerEl = shallowRef<HTMLDivElement>();
|
||||||
|
const isHoverring = ref(false);
|
||||||
|
const controlsShowing = computed(() => {
|
||||||
|
if (!oncePlayed.value) return true;
|
||||||
|
if (isHoverring.value) return true;
|
||||||
|
if (menuShowing.value) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
let controlStateTimer: string | number;
|
||||||
|
|
||||||
|
// MediaControl: Common State
|
||||||
|
const oncePlayed = ref(false);
|
||||||
|
const isReady = ref(false);
|
||||||
|
const isPlaying = computed(() => moduleEl.value?.playing ?? false);
|
||||||
|
const elapsedTimeMs = ref(0);
|
||||||
|
const rangePercent = computed({
|
||||||
|
get: () => {
|
||||||
|
if (!moduleEl.value) return 0;
|
||||||
|
return moduleEl.value.position / moduleEl.value.duration;
|
||||||
|
},
|
||||||
|
set: (to) => {
|
||||||
|
if (!moduleEl.value) return;
|
||||||
|
moduleEl.value.position = to * moduleEl.value.duration;
|
||||||
|
moduleEl.value.performSeek();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const volume = ref(.5);
|
||||||
|
|
||||||
|
// MediaControl Events
|
||||||
|
function onMouseOver() {
|
||||||
|
if (controlStateTimer) {
|
||||||
|
clearTimeout(controlStateTimer);
|
||||||
|
}
|
||||||
|
isHoverring.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseLeave() {
|
||||||
|
controlStateTimer = window.setTimeout(() => {
|
||||||
|
isHoverring.value = false;
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPattern() {
|
||||||
|
if (!isReady.value || !moduleEl.value) return;
|
||||||
|
|
||||||
|
if (moduleEl.value.patternVisible) {
|
||||||
|
togglePlayPause();
|
||||||
|
} else {
|
||||||
|
moduleEl.value.showPattern();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function togglePlayPause() {
|
||||||
|
if (!isReady.value || !moduleEl.value) return;
|
||||||
|
|
||||||
|
moduleEl.value.playPause();
|
||||||
|
if (!isPlaying.value) {
|
||||||
|
oncePlayed.value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleMute() {
|
||||||
|
if (volume.value === 0) {
|
||||||
|
volume.value = .5;
|
||||||
|
} else {
|
||||||
|
volume.value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let onceInit = false;
|
||||||
|
let stopModuleElWatch: () => void;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
if (onceInit) return;
|
||||||
|
onceInit = true;
|
||||||
|
|
||||||
|
stopModuleElWatch = watch(moduleEl, () => {
|
||||||
|
if (moduleEl.value) {
|
||||||
|
isReady.value = true;
|
||||||
|
|
||||||
|
function updateMediaTick() {
|
||||||
|
if (moduleEl.value) {
|
||||||
|
elapsedTimeMs.value = moduleEl.value.position * 1000;
|
||||||
|
}
|
||||||
|
window.requestAnimationFrame(updateMediaTick);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMediaTick();
|
||||||
|
|
||||||
|
moduleEl.value.volume = volume.value;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
immediate: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(volume, (to) => {
|
||||||
|
if (moduleEl.value) moduleEl.value.volume = to;
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
|
||||||
|
onActivated(() => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
|
||||||
|
onDeactivated(() => {
|
||||||
|
isReady.value = false;
|
||||||
|
elapsedTimeMs.value = 0;
|
||||||
|
hide.value = (defaultStore.state.nsfw === 'force' || defaultStore.state.dataSaver.media) ? true : (props.module.isSensitive && defaultStore.state.nsfw !== 'ignore');
|
||||||
|
stopModuleElWatch();
|
||||||
|
onceInit = false;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" module>
|
||||||
|
.moduleContainer {
|
||||||
|
container-type: inline-size;
|
||||||
|
position: relative;
|
||||||
|
overflow: clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sensitive {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
pointer-events: none;
|
||||||
|
border-radius: inherit;
|
||||||
|
box-shadow: inset 0 0 0 4px var(--warn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.indicators {
|
||||||
|
display: inline-flex;
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: .5;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.indicator {
|
||||||
|
/* Hardcode to black because either --bg or --fg makes it hard to read in dark/light mode */
|
||||||
|
background-color: black;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--accentLighten);
|
||||||
|
display: inline-block;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.8em;
|
||||||
|
padding: 2px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background-color: black;
|
||||||
|
color: var(--accentLighten);
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: .5;
|
||||||
|
padding: 5px 8px;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
top: 12px;
|
||||||
|
right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
width: 100%;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
font: inherit;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 120px 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hiddenTextWrapper {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.8em;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moduleRoot {
|
||||||
|
background: #000;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.module {
|
||||||
|
display: block;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moduleOverlayPlayButton {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%,-50%);
|
||||||
|
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity .4s ease-in-out;
|
||||||
|
|
||||||
|
background: var(--accent);
|
||||||
|
color: #fff;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 99rem;
|
||||||
|
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moduleLoading {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moduleControls {
|
||||||
|
display: grid;
|
||||||
|
grid-template-areas:
|
||||||
|
"left time . volume right"
|
||||||
|
"seekbar seekbar seekbar seekbar seekbar";
|
||||||
|
grid-template-columns: auto auto 1fr auto auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px 8px;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
padding: 35px 10px 10px 10px;
|
||||||
|
background: linear-gradient(rgba(0, 0, 0, 0),rgba(0, 0, 0, .75));
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
|
||||||
|
transform: translateY(100%);
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity .4s ease-in-out, transform .4s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
.moduleControls {
|
||||||
|
transform: translateY(0);
|
||||||
|
opacity: 1;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moduleOverlayPlayButton {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsChild {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
color: #fff;
|
||||||
|
|
||||||
|
.controlButton {
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: calc(var(--radius) / 2);
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--accent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsLeft {
|
||||||
|
grid-area: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsRight {
|
||||||
|
grid-area: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsTime {
|
||||||
|
grid-area: time;
|
||||||
|
font-size: .9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsVolume {
|
||||||
|
grid-area: volume;
|
||||||
|
|
||||||
|
.volumeSeekbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.seekbarRoot {
|
||||||
|
grid-area: seekbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@container (min-width: 500px) {
|
||||||
|
.moduleControls {
|
||||||
|
grid-template-areas: "left seekbar time volume right";
|
||||||
|
grid-template-columns: auto 1fr auto auto auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlsVolume {
|
||||||
|
.volumeSeekbar {
|
||||||
|
max-width: 90px;
|
||||||
|
display: block;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.indicators {
|
||||||
|
display: inline-flex;
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: .5;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.indicator {
|
||||||
|
/* Hardcode to black because either --bg or --fg makes it hard to read in dark/light mode */
|
||||||
|
background-color: black;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
color: var(--accentLighten);
|
||||||
|
display: inline-block;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.8em;
|
||||||
|
padding: 2px 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
313
packages/frontend/src/components/SkModPlayer.vue
Normal file
313
packages/frontend/src/components/SkModPlayer.vue
Normal file
|
|
@ -0,0 +1,313 @@
|
||||||
|
<template>
|
||||||
|
<div :class="$style.root">
|
||||||
|
<div v-if="patternVisible">
|
||||||
|
<div v-if="patData.length !== 0" ref="modPattern" :class="$style.pattern">
|
||||||
|
<span
|
||||||
|
v-for="(row, i) in patData[currentPattern]"
|
||||||
|
ref="initRow"
|
||||||
|
:key="i"
|
||||||
|
:class="[$style.row, { [$style.active]: isRowActive(i) }]"
|
||||||
|
>
|
||||||
|
<span :class="{ [$style.quarter]: i % 4 === 0 }">{{ indexText(i) }}</span>
|
||||||
|
<span :class="$style.column">{{ getRowText(row) }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<MkLoading v-else/>
|
||||||
|
</div>
|
||||||
|
<div v-else :class="$style.pattern">
|
||||||
|
<p>{{ i18n.ts.patternHidden }}</p>
|
||||||
|
<p v-if="alt">{{ alt }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, ref, shallowRef, onDeactivated, onMounted, nextTick, watch } from 'vue';
|
||||||
|
import { i18n } from '@/i18n.js';
|
||||||
|
import { ChiptuneJsPlayer } from '@/scripts/chiptune2.js';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
src: string,
|
||||||
|
alt: string | null,
|
||||||
|
}>();
|
||||||
|
|
||||||
|
interface ModRow {
|
||||||
|
notes: string[];
|
||||||
|
insts: string[];
|
||||||
|
vols: string[];
|
||||||
|
fxs: string[];
|
||||||
|
ops: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const available = ref(false);
|
||||||
|
const initRow = shallowRef<HTMLSpanElement>();
|
||||||
|
const patternVisible = ref(false);
|
||||||
|
const playing = ref(false);
|
||||||
|
const modPattern = ref<HTMLDivElement>();
|
||||||
|
const position = ref(0);
|
||||||
|
const player = shallowRef(new ChiptuneJsPlayer());
|
||||||
|
const patData = shallowRef<readonly ModRow[][]>([]);
|
||||||
|
const currentPattern = ref(0);
|
||||||
|
const nbChannels = ref(0);
|
||||||
|
const duration = ref(1);
|
||||||
|
const loop = ref(false);
|
||||||
|
const fetching = ref(true);
|
||||||
|
const error = ref(false);
|
||||||
|
const loading = ref(false);
|
||||||
|
const currentRow = ref(0);
|
||||||
|
|
||||||
|
const volume = computed({
|
||||||
|
get() {
|
||||||
|
return player.value.context.gain.value;
|
||||||
|
},
|
||||||
|
|
||||||
|
set(value) {
|
||||||
|
player.value.context.gain.value = value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let buffer: ArrayBuffer|null = null;
|
||||||
|
let rowHeight = 0;
|
||||||
|
|
||||||
|
watch(currentRow, (row) => {
|
||||||
|
if (!modPattern.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowHeight === 0 && initRow.value) rowHeight = initRow.value[0].getBoundingClientRect().height;
|
||||||
|
modPattern.value.scrollTop = row * rowHeight;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
buffer = await player.value.load(props.src);
|
||||||
|
available.value = true;
|
||||||
|
error.value = false;
|
||||||
|
fetching.value = false;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
error.value = true;
|
||||||
|
fetching.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.value.addHandler('onRowChange', (i: { index: number }) => {
|
||||||
|
currentRow.value = i.index;
|
||||||
|
currentPattern.value = player.value.getPattern();
|
||||||
|
duration.value = player.value.duration();
|
||||||
|
position.value = player.value.position() % duration.value;
|
||||||
|
requestAnimationFrame(() => display());
|
||||||
|
});
|
||||||
|
|
||||||
|
player.value.addHandler('onEnded', () => {
|
||||||
|
stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(load);
|
||||||
|
|
||||||
|
function showPattern() {
|
||||||
|
patternVisible.value = !patternVisible.value;
|
||||||
|
nextTick(() => {
|
||||||
|
if (playing.value) display();
|
||||||
|
else stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRowText(row: ModRow) {
|
||||||
|
let text = '';
|
||||||
|
for (let i = 0; i < row.notes.length; i++) {
|
||||||
|
text = text.concat(
|
||||||
|
'|',
|
||||||
|
row.notes[i],
|
||||||
|
row.insts[i],
|
||||||
|
row.vols[i],
|
||||||
|
row.fxs[i],
|
||||||
|
row.ops[i],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function playPause() {
|
||||||
|
if (buffer === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.value.currentPlayingNode === null) {
|
||||||
|
loading.value = true;
|
||||||
|
player.value.play(buffer).then(() => {
|
||||||
|
player.value.seek(position.value);
|
||||||
|
player.value.repeat(loop.value ? -1 : 0);
|
||||||
|
playing.value = true;
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
player.value.togglePause();
|
||||||
|
playing.value = !player.value.currentPlayingNode.paused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stop(noDisplayUpdate = false) {
|
||||||
|
if (buffer === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.value.stop();
|
||||||
|
playing.value = false;
|
||||||
|
if (!noDisplayUpdate) {
|
||||||
|
try {
|
||||||
|
await player.value.play(buffer);
|
||||||
|
display(true);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.value.stop();
|
||||||
|
position.value = 0;
|
||||||
|
currentRow.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleLoop() {
|
||||||
|
loop.value = !loop.value;
|
||||||
|
player.value.repeat(loop.value ? -1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function performSeek() {
|
||||||
|
player.value.seek(position.value);
|
||||||
|
display();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRowActive(i: number) {
|
||||||
|
return i === currentRow.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function indexText(i: number) {
|
||||||
|
return i.toString(16).padStart(2, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRow(pattern: number, rowOffset: number): ModRow {
|
||||||
|
const notes: string[] = [];
|
||||||
|
const insts: string[] = [];
|
||||||
|
const vols: string[] = [];
|
||||||
|
const fxs: string[] = [];
|
||||||
|
const ops: string[] = [];
|
||||||
|
|
||||||
|
for (let channel = 0; channel < nbChannels.value; channel++) {
|
||||||
|
const part = player.value.getPatternRowChannel(
|
||||||
|
pattern,
|
||||||
|
rowOffset,
|
||||||
|
channel,
|
||||||
|
);
|
||||||
|
|
||||||
|
notes.push(part.substring(0, 3));
|
||||||
|
insts.push(part.substring(4, 6));
|
||||||
|
vols.push(part.substring(6, 9));
|
||||||
|
fxs.push(part.substring(10, 11));
|
||||||
|
ops.push(part.substring(11, 13));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
notes,
|
||||||
|
insts,
|
||||||
|
vols,
|
||||||
|
fxs,
|
||||||
|
ops,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function display(reset = false) {
|
||||||
|
if (reset) {
|
||||||
|
currentPattern.value = player.value.getPattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (patData.value.length === 0) {
|
||||||
|
const nbPatterns = player.value.getNumPatterns();
|
||||||
|
currentPattern.value = player.value.getPattern();
|
||||||
|
|
||||||
|
if (player.value.currentPlayingNode) {
|
||||||
|
nbChannels.value = player.value.currentPlayingNode.nbChannels;
|
||||||
|
}
|
||||||
|
|
||||||
|
const patternsArray: ModRow[][] = [];
|
||||||
|
|
||||||
|
for (let patOffset = 0; patOffset < nbPatterns; patOffset++) {
|
||||||
|
const rowsArray: ModRow[] = [];
|
||||||
|
const nbRows = player.value.getPatternNumRows(patOffset);
|
||||||
|
for (let rowOffset = 0; rowOffset < nbRows; rowOffset++) {
|
||||||
|
rowsArray.push(getRow(patOffset, rowOffset));
|
||||||
|
}
|
||||||
|
patternsArray.push(rowsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
patData.value = Object.freeze(patternsArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onDeactivated(() => {
|
||||||
|
stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
performSeek,
|
||||||
|
playPause,
|
||||||
|
stop,
|
||||||
|
toggleLoop,
|
||||||
|
showPattern,
|
||||||
|
duration,
|
||||||
|
loading,
|
||||||
|
loop,
|
||||||
|
playing,
|
||||||
|
position,
|
||||||
|
volume,
|
||||||
|
patternVisible,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" module>
|
||||||
|
.root {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
color: white;
|
||||||
|
background-color: black;
|
||||||
|
text-align: center;
|
||||||
|
font: 12px monospace;
|
||||||
|
white-space: pre;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pattern {
|
||||||
|
display: grid;
|
||||||
|
overflow-y: hidden;
|
||||||
|
height: 0;
|
||||||
|
padding-top: calc((56.25% - 48px) / 2);
|
||||||
|
padding-bottom: calc((56.25% - 48px) / 2);
|
||||||
|
content-visibility: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.quarter {
|
||||||
|
color: var(--badge);
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
background: repeating-linear-gradient(
|
||||||
|
to right,
|
||||||
|
var(--fg) 0 4ch,
|
||||||
|
var(--codeBoolean) 4ch 6ch,
|
||||||
|
var(--codeNumber) 6ch 9ch,
|
||||||
|
var(--codeString) 9ch 10ch,
|
||||||
|
var(--error) 10ch 12ch
|
||||||
|
);
|
||||||
|
background-clip: text;
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -1,220 +1,300 @@
|
||||||
/* global libopenmpt UTF8ToString writeAsciiToMemory */
|
type HandlerFunction = Function;
|
||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
const ChiptuneAudioContext = window.AudioContext || window.webkitAudioContext;
|
interface Handler {
|
||||||
|
eventName: string,
|
||||||
export function ChiptuneJsConfig (repeatCount: number, context: AudioContext) {
|
handler: HandlerFunction,
|
||||||
this.repeatCount = repeatCount;
|
|
||||||
this.context = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChiptuneJsConfig.prototype.constructor = ChiptuneJsConfig;
|
export class ChiptuneJsPlayer {
|
||||||
|
libopenmpt;
|
||||||
|
audioContext: AudioContext;
|
||||||
|
context: GainNode;
|
||||||
|
currentPlayingNode: ChiptuneProcessorNode | null;
|
||||||
|
private handlers: Handler[];
|
||||||
|
private touchLocked: boolean;
|
||||||
|
|
||||||
export function ChiptuneJsPlayer (config: object) {
|
constructor() {
|
||||||
this.config = config;
|
this.libopenmpt = null;
|
||||||
this.audioContext = config.context || new ChiptuneAudioContext();
|
this.audioContext = new AudioContext();
|
||||||
this.context = this.audioContext.createGain();
|
this.context = this.audioContext.createGain();
|
||||||
this.currentPlayingNode = null;
|
this.currentPlayingNode = null;
|
||||||
this.handlers = [];
|
this.handlers = [];
|
||||||
this.touchLocked = true;
|
this.touchLocked = true;
|
||||||
this.volume = 1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.constructor = ChiptuneJsPlayer;
|
fireEvent(eventName: string, response) {
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.fireEvent = function (eventName: string, response) {
|
|
||||||
const handlers = this.handlers;
|
const handlers = this.handlers;
|
||||||
if (handlers.length > 0) {
|
if (handlers.length > 0) {
|
||||||
for(const handler of handlers) {
|
for (const handler of handlers) {
|
||||||
if (handler.eventName === eventName) {
|
if (handler.eventName === eventName) {
|
||||||
handler.handler(response);
|
handler.handler(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.addHandler = function (eventName: string, handler: Function) {
|
addHandler(
|
||||||
|
eventName: string,
|
||||||
|
handler: HandlerFunction,
|
||||||
|
) {
|
||||||
this.handlers.push({ eventName, handler });
|
this.handlers.push({ eventName, handler });
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.onEnded = function (handler: Function) {
|
clearHandlers() {
|
||||||
|
this.handlers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
onEnded(handler: HandlerFunction) {
|
||||||
this.addHandler('onEnded', handler);
|
this.addHandler('onEnded', handler);
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.onError = function (handler: Function) {
|
onError(handler: HandlerFunction) {
|
||||||
this.addHandler('onError', handler);
|
this.addHandler('onError', handler);
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.duration = function () {
|
|
||||||
return libopenmpt._openmpt_module_get_duration_seconds(this.currentPlayingNode.modulePtr);
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.position = function () {
|
|
||||||
return libopenmpt._openmpt_module_get_position_seconds(this.currentPlayingNode.modulePtr);
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.seek = function (position: number) {
|
|
||||||
if (this.currentPlayingNode) {
|
|
||||||
libopenmpt._openmpt_module_set_position_seconds(this.currentPlayingNode.modulePtr, position);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.metadata = function () {
|
duration(): number {
|
||||||
const data = {};
|
if (!this.currentPlayingNode) {
|
||||||
const keys = UTF8ToString(libopenmpt._openmpt_module_get_metadata_keys(this.currentPlayingNode.modulePtr)).split(';');
|
return 0;
|
||||||
let keyNameBuffer = 0;
|
|
||||||
for (const key of keys) {
|
|
||||||
keyNameBuffer = libopenmpt._malloc(key.length + 1);
|
|
||||||
writeAsciiToMemory(key, keyNameBuffer);
|
|
||||||
data[key] = UTF8ToString(libopenmpt._openmpt_module_get_metadata(this.currentPlayingNode.modulePtr, keyNameBuffer));
|
|
||||||
libopenmpt._free(keyNameBuffer);
|
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.unlock = function () {
|
return this.libopenmpt._openmpt_module_get_duration_seconds(
|
||||||
const context = this.audioContext;
|
this.currentPlayingNode.modulePtr,
|
||||||
const buffer = context.createBuffer(1, 1, 22050);
|
);
|
||||||
const unlockSource = context.createBufferSource();
|
|
||||||
unlockSource.buffer = buffer;
|
|
||||||
unlockSource.connect(this.context);
|
|
||||||
this.context.connect(context.destination);
|
|
||||||
unlockSource.start(0);
|
|
||||||
this.touchLocked = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.load = function (input) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if(this.touchLocked) {
|
|
||||||
this.unlock();
|
|
||||||
}
|
}
|
||||||
const player = this;
|
|
||||||
if (input instanceof File) {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = () => {
|
|
||||||
resolve(reader.result);
|
|
||||||
};
|
|
||||||
reader.readAsArrayBuffer(input);
|
|
||||||
} else {
|
|
||||||
window.fetch(input).then((response) => {
|
|
||||||
response.arrayBuffer().then((arrayBuffer) => {
|
|
||||||
resolve(arrayBuffer);
|
|
||||||
}).catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
}).catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.play = function (buffer: ArrayBuffer) {
|
position(): number {
|
||||||
this.unlock();
|
if (!this.currentPlayingNode) {
|
||||||
this.stop();
|
return 0;
|
||||||
const processNode = this.createLibopenmptNode(buffer, this.buffer);
|
}
|
||||||
if (processNode === null) {
|
|
||||||
|
return this.libopenmpt._openmpt_module_get_position_seconds(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(repeatCount: number) {
|
||||||
|
if (!this.currentPlayingNode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
libopenmpt._openmpt_module_set_repeat_count(processNode.modulePtr, this.config.repeatCount || 0);
|
|
||||||
this.currentPlayingNode = processNode;
|
|
||||||
processNode.connect(this.context);
|
|
||||||
this.context.connect(this.audioContext.destination);
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.stop = function () {
|
this.libopenmpt._openmpt_module_set_repeat_count(
|
||||||
if (this.currentPlayingNode != null) {
|
this.currentPlayingNode.modulePtr,
|
||||||
this.currentPlayingNode.disconnect();
|
repeatCount,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
seek(position: number) {
|
||||||
|
if (!this.currentPlayingNode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.libopenmpt._openmpt_module_set_position_seconds(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
position,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata() {
|
||||||
|
if (this.currentPlayingNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: {[key: string]: string} = {};
|
||||||
|
const keys = this.libopenmpt
|
||||||
|
.UTF8ToString(
|
||||||
|
this.libopenmpt._openmpt_module_get_metadata_keys(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.split(';');
|
||||||
|
let keyNameBuffer = 0;
|
||||||
|
for (const key of keys) {
|
||||||
|
keyNameBuffer = this.libopenmpt._malloc(key.length + 1);
|
||||||
|
this.libopenmpt.stringToUTF8(key, keyNameBuffer);
|
||||||
|
data[key] = this.libopenmpt.UTF8ToString(
|
||||||
|
this.libopenmpt._openmpt_module_get_metadata(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
keyNameBuffer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
this.libopenmpt._free(keyNameBuffer);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock() {
|
||||||
|
const buffer = this.audioContext.createBuffer(1, 1, 22050);
|
||||||
|
const unlockSource = this.audioContext.createBufferSource();
|
||||||
|
unlockSource.buffer = buffer;
|
||||||
|
unlockSource.connect(this.context);
|
||||||
|
this.context.connect(this.audioContext.destination);
|
||||||
|
unlockSource.start(0);
|
||||||
|
this.touchLocked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async load(input: string): Promise<ArrayBuffer> {
|
||||||
|
if (this.touchLocked) {
|
||||||
|
this.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(input);
|
||||||
|
const arrayBuffer = await response.arrayBuffer();
|
||||||
|
return arrayBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
async play(buffer: ArrayBuffer) {
|
||||||
|
this.unlock();
|
||||||
|
this.stop();
|
||||||
|
const processNode = await this.createLibopenmptNode(buffer);
|
||||||
|
this.libopenmpt._openmpt_module_set_repeat_count(
|
||||||
|
processNode.modulePtr,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
this.currentPlayingNode = processNode;
|
||||||
|
processNode.processNode.connect(this.context);
|
||||||
|
this.context.connect(this.audioContext.destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
if (this.currentPlayingNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentPlayingNode.processNode.disconnect();
|
||||||
this.currentPlayingNode.cleanup();
|
this.currentPlayingNode.cleanup();
|
||||||
this.currentPlayingNode = null;
|
this.currentPlayingNode = null;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.togglePause = function () {
|
togglePause() {
|
||||||
if (this.currentPlayingNode != null) {
|
if (this.currentPlayingNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.currentPlayingNode.togglePause();
|
this.currentPlayingNode.togglePause();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getPattern = function () {
|
getPattern() {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode?.modulePtr) {
|
||||||
return libopenmpt._openmpt_module_get_current_pattern(this.currentPlayingNode.modulePtr);
|
return this.libopenmpt._openmpt_module_get_current_pattern(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getRow = function () {
|
getRow() {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode?.modulePtr) {
|
||||||
return libopenmpt._openmpt_module_get_current_row(this.currentPlayingNode.modulePtr);
|
return this.libopenmpt._openmpt_module_get_current_row(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getPatternNumRows = function (pattern: number) {
|
getNumPatterns() {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode?.modulePtr) {
|
||||||
return libopenmpt._openmpt_module_get_pattern_num_rows(this.currentPlayingNode.modulePtr, pattern);
|
return this.libopenmpt._openmpt_module_get_num_patterns(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getPatternRowChannel = function (pattern: number, row: number, channel: number) {
|
getPatternNumRows(pattern: number) {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode?.modulePtr) {
|
||||||
return UTF8ToString(libopenmpt._openmpt_module_format_pattern_row_channel(this.currentPlayingNode.modulePtr, pattern, row, channel, 0, true));
|
return this.libopenmpt._openmpt_module_get_pattern_num_rows(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
pattern,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPatternRowChannel(
|
||||||
|
pattern: number,
|
||||||
|
row: number,
|
||||||
|
channel: number,
|
||||||
|
) {
|
||||||
|
if (this.currentPlayingNode?.modulePtr) {
|
||||||
|
return this.libopenmpt.UTF8ToString(
|
||||||
|
this.libopenmpt._openmpt_module_format_pattern_row_channel(
|
||||||
|
this.currentPlayingNode.modulePtr,
|
||||||
|
pattern,
|
||||||
|
row,
|
||||||
|
channel,
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
}
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: object) {
|
async createLibopenmptNode(buffer: ArrayBuffer) {
|
||||||
|
if (!this.libopenmpt) {
|
||||||
|
const libopenmpt = await import('libopenmpt-wasm');
|
||||||
|
this.libopenmpt = await libopenmpt.default( _DEV_ ? {
|
||||||
|
// hack to make libopenmpt load in dev mode
|
||||||
|
locateFile(file) {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.pathname = `/@fs/${__DIRNAME__}/node_modules/libopenmpt-wasm/${file}`;
|
||||||
|
return url.href;
|
||||||
|
},
|
||||||
|
} : {});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ChiptuneProcessorNode(this, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChiptuneProcessorNode {
|
||||||
|
player: ChiptuneJsPlayer;
|
||||||
|
processNode: ScriptProcessorNode;
|
||||||
|
paused: boolean;
|
||||||
|
|
||||||
|
nbChannels: number;
|
||||||
|
patternIndex: number;
|
||||||
|
|
||||||
|
modulePtr: number;
|
||||||
|
leftBufferPtr: number;
|
||||||
|
rightBufferPtr: number;
|
||||||
|
|
||||||
|
constructor(player: ChiptuneJsPlayer, buffer: ArrayBuffer) {
|
||||||
const maxFramesPerChunk = 4096;
|
const maxFramesPerChunk = 4096;
|
||||||
const processNode = this.audioContext.createScriptProcessor(2048, 0, 2);
|
|
||||||
processNode.config = config;
|
this.player = player;
|
||||||
processNode.player = this;
|
this.processNode = this.player.audioContext.createScriptProcessor(2048, 0, 2);
|
||||||
|
|
||||||
|
const libopenmpt = player.libopenmpt;
|
||||||
const byteArray = new Int8Array(buffer);
|
const byteArray = new Int8Array(buffer);
|
||||||
const ptrToFile = libopenmpt._malloc(byteArray.byteLength);
|
const ptrToFile = libopenmpt._malloc(byteArray.byteLength);
|
||||||
libopenmpt.HEAPU8.set(byteArray, ptrToFile);
|
libopenmpt.HEAPU8.set(byteArray, ptrToFile);
|
||||||
processNode.modulePtr = libopenmpt._openmpt_module_create_from_memory(ptrToFile, byteArray.byteLength, 0, 0, 0);
|
|
||||||
processNode.nbChannels = libopenmpt._openmpt_module_get_num_channels(processNode.modulePtr);
|
this.modulePtr = libopenmpt._openmpt_module_create_from_memory(
|
||||||
processNode.patternIndex = -1;
|
ptrToFile,
|
||||||
processNode.paused = false;
|
byteArray.byteLength,
|
||||||
processNode.leftBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
0,
|
||||||
processNode.rightBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
0,
|
||||||
processNode.cleanup = function () {
|
0,
|
||||||
if (this.modulePtr !== 0) {
|
);
|
||||||
libopenmpt._openmpt_module_destroy(this.modulePtr);
|
this.nbChannels = libopenmpt._openmpt_module_get_num_channels(
|
||||||
this.modulePtr = 0;
|
this.modulePtr,
|
||||||
}
|
);
|
||||||
if (this.leftBufferPtr !== 0) {
|
this.patternIndex = -1;
|
||||||
libopenmpt._free(this.leftBufferPtr);
|
|
||||||
this.leftBufferPtr = 0;
|
|
||||||
}
|
|
||||||
if (this.rightBufferPtr !== 0) {
|
|
||||||
libopenmpt._free(this.rightBufferPtr);
|
|
||||||
this.rightBufferPtr = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
processNode.stop = function () {
|
|
||||||
this.disconnect();
|
|
||||||
this.cleanup();
|
|
||||||
};
|
|
||||||
processNode.pause = function () {
|
|
||||||
this.paused = true;
|
|
||||||
};
|
|
||||||
processNode.unpause = function () {
|
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
};
|
this.leftBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
||||||
processNode.togglePause = function () {
|
this.rightBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
||||||
this.paused = !this.paused;
|
|
||||||
};
|
this.processNode.addEventListener('audioprocess', (ev) => {
|
||||||
processNode.onaudioprocess = function (e) {
|
const outputL = ev.outputBuffer.getChannelData(0);
|
||||||
const outputL = e.outputBuffer.getChannelData(0);
|
const outputR = ev.outputBuffer.getChannelData(1);
|
||||||
const outputR = e.outputBuffer.getChannelData(1);
|
|
||||||
let framesToRender = outputL.length;
|
let framesToRender = outputL.length;
|
||||||
if (this.ModulePtr === 0) {
|
if (this.modulePtr === 0) {
|
||||||
for (let i = 0; i < framesToRender; ++i) {
|
for (let i = 0; i < framesToRender; ++i) {
|
||||||
outputL[i] = 0;
|
outputL[i] = 0;
|
||||||
outputR[i] = 0;
|
outputR[i] = 0;
|
||||||
}
|
}
|
||||||
this.disconnect();
|
this.processNode.disconnect();
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -229,23 +309,42 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
let ended = false;
|
let ended = false;
|
||||||
let error = false;
|
let error = false;
|
||||||
|
|
||||||
const currentPattern = libopenmpt._openmpt_module_get_current_pattern(this.modulePtr);
|
const currentPattern =
|
||||||
const currentRow = libopenmpt._openmpt_module_get_current_row(this.modulePtr);
|
this.player.libopenmpt._openmpt_module_get_current_pattern(
|
||||||
|
this.modulePtr,
|
||||||
|
);
|
||||||
|
const currentRow =
|
||||||
|
this.player.libopenmpt._openmpt_module_get_current_row(
|
||||||
|
this.modulePtr,
|
||||||
|
);
|
||||||
if (currentPattern !== this.patternIndex) {
|
if (currentPattern !== this.patternIndex) {
|
||||||
processNode.player.fireEvent('onPatternChange');
|
this.player.fireEvent('onPatternChange');
|
||||||
}
|
}
|
||||||
processNode.player.fireEvent('onRowChange', { index: currentRow });
|
this.player.fireEvent('onRowChange', { index: currentRow });
|
||||||
|
|
||||||
while (framesToRender > 0) {
|
while (framesToRender > 0) {
|
||||||
const framesPerChunk = Math.min(framesToRender, maxFramesPerChunk);
|
const framesPerChunk = Math.min(framesToRender, maxFramesPerChunk);
|
||||||
const actualFramesPerChunk = libopenmpt._openmpt_module_read_float_stereo(this.modulePtr, this.context.sampleRate, framesPerChunk, this.leftBufferPtr, this.rightBufferPtr);
|
const actualFramesPerChunk =
|
||||||
|
this.player.libopenmpt._openmpt_module_read_float_stereo(
|
||||||
|
this.modulePtr,
|
||||||
|
this.processNode.context.sampleRate,
|
||||||
|
framesPerChunk,
|
||||||
|
this.leftBufferPtr,
|
||||||
|
this.rightBufferPtr,
|
||||||
|
);
|
||||||
if (actualFramesPerChunk === 0) {
|
if (actualFramesPerChunk === 0) {
|
||||||
ended = true;
|
ended = true;
|
||||||
// modulePtr will be 0 on openmpt: error: openmpt_module_read_float_stereo: ERROR: module * not valid or other openmpt error
|
// modulePtr will be 0 on openmpt: error: openmpt_module_read_float_stereo: ERROR: module * not valid or other openmpt error
|
||||||
error = !this.modulePtr;
|
error = !this.modulePtr;
|
||||||
}
|
}
|
||||||
const rawAudioLeft = libopenmpt.HEAPF32.subarray(this.leftBufferPtr / 4, this.leftBufferPtr / 4 + actualFramesPerChunk);
|
const rawAudioLeft = this.player.libopenmpt.HEAPF32.subarray(
|
||||||
const rawAudioRight = libopenmpt.HEAPF32.subarray(this.rightBufferPtr / 4, this.rightBufferPtr / 4 + actualFramesPerChunk);
|
this.leftBufferPtr / 4,
|
||||||
|
this.leftBufferPtr / 4 + actualFramesPerChunk,
|
||||||
|
);
|
||||||
|
const rawAudioRight = this.player.libopenmpt.HEAPF32.subarray(
|
||||||
|
this.rightBufferPtr / 4,
|
||||||
|
this.rightBufferPtr / 4 + actualFramesPerChunk,
|
||||||
|
);
|
||||||
for (let i = 0; i < actualFramesPerChunk; ++i) {
|
for (let i = 0; i < actualFramesPerChunk; ++i) {
|
||||||
outputL[framesRendered + i] = rawAudioLeft[i];
|
outputL[framesRendered + i] = rawAudioLeft[i];
|
||||||
outputR[framesRendered + i] = rawAudioRight[i];
|
outputR[framesRendered + i] = rawAudioRight[i];
|
||||||
|
|
@ -258,10 +357,45 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
framesRendered += framesPerChunk;
|
framesRendered += framesPerChunk;
|
||||||
}
|
}
|
||||||
if (ended) {
|
if (ended) {
|
||||||
this.disconnect();
|
this.processNode.disconnect();
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
error ? processNode.player.fireEvent('onError', { type: 'openmpt' }) : processNode.player.fireEvent('onEnded');
|
error
|
||||||
|
? this.player.fireEvent('onError', { type: 'openmpt' })
|
||||||
|
: this.player.fireEvent('onEnded');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
return processNode;
|
}
|
||||||
};
|
|
||||||
|
cleanup() {
|
||||||
|
if (this.modulePtr !== 0) {
|
||||||
|
this.player.libopenmpt._openmpt_module_destroy(this.modulePtr);
|
||||||
|
this.modulePtr = 0;
|
||||||
|
}
|
||||||
|
if (this.leftBufferPtr !== 0) {
|
||||||
|
this.player.libopenmpt._free(this.leftBufferPtr);
|
||||||
|
this.leftBufferPtr = 0;
|
||||||
|
}
|
||||||
|
if (this.rightBufferPtr !== 0) {
|
||||||
|
this.player.libopenmpt._free(this.rightBufferPtr);
|
||||||
|
this.rightBufferPtr = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
this.processNode.disconnect();
|
||||||
|
this.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
pause() {
|
||||||
|
this.paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
unpause() {
|
||||||
|
this.paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
togglePause() {
|
||||||
|
this.paused = !this.paused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ const devConfig = {
|
||||||
define: {
|
define: {
|
||||||
...defaultConfig.define,
|
...defaultConfig.define,
|
||||||
_LANGS_FULL_: JSON.stringify(Object.entries(locales)),
|
_LANGS_FULL_: JSON.stringify(Object.entries(locales)),
|
||||||
|
__DIRNAME__: JSON.stringify(__dirname),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
|
|
@ -774,6 +774,9 @@ importers:
|
||||||
katex:
|
katex:
|
||||||
specifier: 0.16.9
|
specifier: 0.16.9
|
||||||
version: 0.16.9
|
version: 0.16.9
|
||||||
|
libopenmpt-wasm:
|
||||||
|
specifier: github:TheEssem/libopenmpt-packaging#build
|
||||||
|
version: github.com/TheEssem/libopenmpt-packaging/d05d151a72b638c6312227af0417aca69521172c
|
||||||
matter-js:
|
matter-js:
|
||||||
specifier: 0.19.0
|
specifier: 0.19.0
|
||||||
version: 0.19.0
|
version: 0.19.0
|
||||||
|
|
@ -20493,6 +20496,12 @@ packages:
|
||||||
readable-stream: 3.6.0
|
readable-stream: 3.6.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
github.com/TheEssem/libopenmpt-packaging/d05d151a72b638c6312227af0417aca69521172c:
|
||||||
|
resolution: {tarball: https://codeload.github.com/TheEssem/libopenmpt-packaging/tar.gz/d05d151a72b638c6312227af0417aca69521172c}
|
||||||
|
name: libopenmpt-wasm
|
||||||
|
version: 0.7.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
github.com/aiscript-dev/aiscript-vscode/b5a8aa0ad927831a0b867d1c183460a14e6c48cd:
|
github.com/aiscript-dev/aiscript-vscode/b5a8aa0ad927831a0b867d1c183460a14e6c48cd:
|
||||||
resolution: {tarball: https://codeload.github.com/aiscript-dev/aiscript-vscode/tar.gz/b5a8aa0ad927831a0b867d1c183460a14e6c48cd}
|
resolution: {tarball: https://codeload.github.com/aiscript-dev/aiscript-vscode/tar.gz/b5a8aa0ad927831a0b867d1c183460a14e6c48cd}
|
||||||
name: aiscript-vscode
|
name: aiscript-vscode
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue