mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-02 11:43:07 +02:00
Compare commits
No commits in common. "8197148209713d28439526f1ab0ba949e02961a6" and "78975ddcc83d2c1c6ac4b7738a2266142e26f098" have entirely different histories.
8197148209
...
78975ddcc8
4 changed files with 140 additions and 409 deletions
|
@ -1,20 +1,20 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import * as Redis from 'ioredis';
|
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
|
import * as Redis from 'ioredis';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['meta'],
|
tags: ["meta"],
|
||||||
description: 'Get Sharkey GH Sponsors',
|
description: "Get Sharkey GH Sponsors",
|
||||||
|
|
||||||
requireCredential: false,
|
requireCredential: false,
|
||||||
requireCredentialPrivateMode: false,
|
requireCredentialPrivateMode: false,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const paramDef = {
|
export const paramDef = {
|
||||||
type: 'object',
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
forceUpdate: { type: 'boolean', default: false },
|
forceUpdate: { type: "boolean", default: false },
|
||||||
},
|
},
|
||||||
required: [],
|
required: [],
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -26,7 +26,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
let sponsors;
|
let sponsors;
|
||||||
const cachedSponsors = await this.redisClient.get('sponsors');
|
const cachedSponsors = await this.redisClient.get("sponsors");
|
||||||
if (!ps.forceUpdate && cachedSponsors) {
|
if (!ps.forceUpdate && cachedSponsors) {
|
||||||
sponsors = JSON.parse(cachedSponsors);
|
sponsors = JSON.parse(cachedSponsors);
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,16 +36,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
return ctrl.signal;
|
return ctrl.signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
sponsors = await fetch("https://kaifa.ch/transfem-sponsors.json", { signal: AbortSignal.timeout(2000) })
|
||||||
sponsors = await fetch('https://kaifa.ch/transfem-sponsors.json', { signal: AbortSignal.timeout(2000) })
|
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
|
await this.redisClient.set("sponsors", JSON.stringify(sponsors), "EX", 3600);
|
||||||
await this.redisClient.set('sponsors', JSON.stringify(sponsors), 'EX', 3600);
|
|
||||||
} catch (error) {
|
|
||||||
sponsors = {
|
|
||||||
sponsors: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return { sponsor_data: sponsors['sponsors'] };
|
return { sponsor_data: sponsors['sponsors'] };
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,17 +7,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="mod-player-enabled">
|
<div v-else class="mod-player-enabled">
|
||||||
<div class="pattern-display" @click="togglePattern()" @scroll="scrollHandler" @scrollend="scrollEndHandle">
|
<div class="pattern-display" @click="togglePattern()">
|
||||||
<div v-if="patternHide" class="pattern-hide">
|
<div v-if="patternHide" class="pattern-hide">
|
||||||
<b><i class="ph-eye ph-bold ph-lg"></i> Pattern Hidden</b>
|
<b><i class="ph-eye ph-bold ph-lg"></i> Pattern Hidden</b>
|
||||||
<span>{{ i18n.ts.clickToShow }}</span>
|
<span>{{ i18n.ts.clickToShow }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class="patternShadowTop"></span>
|
|
||||||
<span class="patternShadowBottom"></span>
|
|
||||||
<canvas ref="displayCanvas" class="pattern-canvas"></canvas>
|
<canvas ref="displayCanvas" class="pattern-canvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input v-if="patternScrollSliderShow" ref="patternScrollSlider" v-model="patternScrollSliderPos" class="pattern-slider" type="range" min="0" max="100" step="0.01" style=""/>
|
|
||||||
<button class="play" @click="playPause()">
|
<button class="play" @click="playPause()">
|
||||||
<i v-if="playing" class="ph-pause ph-bold ph-lg"></i>
|
<i v-if="playing" class="ph-pause ph-bold ph-lg"></i>
|
||||||
<i v-else class="ph-play ph-bold ph-lg"></i>
|
<i v-else class="ph-play ph-bold ph-lg"></i>
|
||||||
|
@ -36,30 +33,43 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, nextTick, computed, watch, onDeactivated, onMounted } from 'vue';
|
import { ref, nextTick, computed } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
import { ChiptuneJsPlayer, ChiptuneJsConfig } from '@/scripts/chiptune2.js';
|
import { ChiptuneJsPlayer, ChiptuneJsConfig } from '@/scripts/chiptune2.js';
|
||||||
import { isTouchUsing } from '@/scripts/touch.js';
|
|
||||||
|
|
||||||
const colours = {
|
|
||||||
background: '#000000',
|
|
||||||
foreground: {
|
|
||||||
default: '#ffffff',
|
|
||||||
quarter: '#ffff00',
|
|
||||||
instr: '#80e0ff',
|
|
||||||
volume: '#80ff80',
|
|
||||||
fx: '#ff80e0',
|
|
||||||
operant: '#ffe080',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const CHAR_WIDTH = 6;
|
const CHAR_WIDTH = 6;
|
||||||
const CHAR_HEIGHT = 12;
|
const CHAR_HEIGHT = 12;
|
||||||
const ROW_OFFSET_Y = 10;
|
const ROW_OFFSET_Y = 10;
|
||||||
const MAX_TIME_SPENT = 50;
|
|
||||||
const MAX_TIME_PER_ROW = 15;
|
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<{
|
const props = defineProps<{
|
||||||
module: Misskey.entities.DriveFile
|
module: Misskey.entities.DriveFile
|
||||||
|
@ -69,49 +79,22 @@ const isSensitive = computed(() => { return props.module.isSensitive; });
|
||||||
const url = computed(() => { return props.module.url; });
|
const url = computed(() => { return props.module.url; });
|
||||||
let hide = ref((defaultStore.state.nsfw === 'force') ? true : isSensitive.value && (defaultStore.state.nsfw !== 'ignore'));
|
let hide = ref((defaultStore.state.nsfw === 'force') ? true : isSensitive.value && (defaultStore.state.nsfw !== 'ignore'));
|
||||||
let patternHide = ref(false);
|
let patternHide = ref(false);
|
||||||
|
let firstFrame = ref(true);
|
||||||
let playing = ref(false);
|
let playing = ref(false);
|
||||||
let displayCanvas = ref<HTMLCanvasElement>();
|
let displayCanvas = ref<HTMLCanvasElement>();
|
||||||
let progress = ref<HTMLProgressElement>();
|
let progress = ref<HTMLProgressElement>();
|
||||||
let position = ref(0);
|
let position = ref(0);
|
||||||
let patternScrollSlider = ref<HTMLProgressElement>();
|
|
||||||
let patternScrollSliderShow = ref(false);
|
|
||||||
let patternScrollSliderPos = ref(0);
|
|
||||||
const player = ref(new ChiptuneJsPlayer(new ChiptuneJsConfig()));
|
const player = ref(new ChiptuneJsPlayer(new ChiptuneJsConfig()));
|
||||||
|
|
||||||
const maxRowNumbers = 0xFF;
|
const rowBuffer = 24;
|
||||||
const rowBuffer = 26;
|
|
||||||
let buffer = null;
|
let buffer = null;
|
||||||
let isSeeking = false;
|
let isSeeking = false;
|
||||||
let firstFrame = true;
|
|
||||||
let lastPattern = -1;
|
|
||||||
let lastDrawnRow = -1;
|
|
||||||
let numberRowCanvas = new OffscreenCanvas(2 * CHAR_WIDTH + 1, maxRowNumbers * CHAR_HEIGHT + 1);
|
|
||||||
let alreadyHiddenOnce = false;
|
|
||||||
let alreadyDrawn = [false];
|
|
||||||
let patternTime = { 'current': 0, 'max': 0, 'initial': 0 };
|
|
||||||
|
|
||||||
function bakeNumberRow() {
|
|
||||||
let ctx = numberRowCanvas.getContext('2d', { alpha: false }) as OffscreenCanvasRenderingContext2D;
|
|
||||||
ctx.font = '10px monospace';
|
|
||||||
|
|
||||||
for (let i = 0; i < maxRowNumbers; i++) {
|
|
||||||
let rowText = i.toString(16);
|
|
||||||
if (rowText.length === 1) rowText = '0' + rowText;
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.default;
|
|
||||||
if (i % 4 === 0) ctx.fillStyle = colours.foreground.quarter;
|
|
||||||
|
|
||||||
ctx.fillText(rowText, 0, 10 + i * 12);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
player.value.load(url.value).then((result) => {
|
player.value.load(url.value).then((result) => {
|
||||||
buffer = result;
|
buffer = result;
|
||||||
try {
|
try {
|
||||||
player.value.play(buffer);
|
player.value.play(buffer);
|
||||||
progress.value!.max = player.value.duration();
|
progress.value!.max = player.value.duration();
|
||||||
bakeNumberRow();
|
|
||||||
display();
|
display();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
|
@ -120,7 +103,6 @@ onMounted(() => {
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
function playPause() {
|
function playPause() {
|
||||||
player.value.addHandler('onRowChange', () => {
|
player.value.addHandler('onRowChange', () => {
|
||||||
|
@ -151,7 +133,7 @@ function stop(noDisplayUpdate = false) {
|
||||||
if (!noDisplayUpdate) {
|
if (!noDisplayUpdate) {
|
||||||
try {
|
try {
|
||||||
player.value.play(buffer);
|
player.value.play(buffer);
|
||||||
display(true);
|
display();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
|
@ -180,255 +162,103 @@ function performSeek() {
|
||||||
|
|
||||||
function toggleVisible() {
|
function toggleVisible() {
|
||||||
hide.value = !hide.value;
|
hide.value = !hide.value;
|
||||||
if (!hide.value) {
|
if (!hide.value && patternHide.value) {
|
||||||
lastPattern = -1;
|
firstFrame.value = true;
|
||||||
lastDrawnRow = -1;
|
patternHide.value = false;
|
||||||
}
|
}
|
||||||
nextTick(() => { stop(hide.value); });
|
nextTick(() => { stop(hide.value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
function togglePattern() {
|
function togglePattern() {
|
||||||
patternHide.value = !patternHide.value;
|
patternHide.value = !patternHide.value;
|
||||||
handleScrollBarEnable();
|
if (!patternHide.value) {
|
||||||
|
if (player.value.getRow() === 0) {
|
||||||
if (player.value.getRow() === 0 && player.value.getPattern() === 0) {
|
|
||||||
try {
|
try {
|
||||||
player.value.play(buffer);
|
player.value.play(buffer);
|
||||||
display(true);
|
display();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
player.value.stop();
|
player.value.stop();
|
||||||
} else {
|
}
|
||||||
display(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPattern() {
|
function display() {
|
||||||
if (!displayCanvas.value) return;
|
if (!displayCanvas.value) {
|
||||||
const canvas = displayCanvas.value;
|
|
||||||
|
|
||||||
const startTime = performance.now();
|
|
||||||
const pattern = player.value.getPattern();
|
|
||||||
const nbRows = player.value.getPatternNumRows(pattern);
|
|
||||||
const row = player.value.getRow();
|
|
||||||
const halfbuf = rowBuffer / 2;
|
|
||||||
const minRow = row - halfbuf;
|
|
||||||
const maxRow = row + halfbuf;
|
|
||||||
|
|
||||||
let rowDif = 0;
|
|
||||||
|
|
||||||
let nbChannels = 0;
|
|
||||||
if (player.value.currentPlayingNode) {
|
|
||||||
nbChannels = player.value.currentPlayingNode.nbChannels;
|
|
||||||
}
|
|
||||||
if (pattern === lastPattern) {
|
|
||||||
rowDif = row - lastDrawnRow;
|
|
||||||
} else {
|
|
||||||
if (patternTime.initial !== 0 && !alreadyHiddenOnce) {
|
|
||||||
const trackerTime = player.value.currentPlayingNode.getProcessTime();
|
|
||||||
|
|
||||||
if (patternTime.initial + trackerTime.max > MAX_TIME_SPENT && trackerTime.max + patternTime.max > MAX_TIME_PER_ROW) {
|
|
||||||
alreadyHiddenOnce = true;
|
|
||||||
togglePattern();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
patternTime = { 'current': 0, 'max': 0, 'initial': 0 };
|
|
||||||
alreadyDrawn = [];
|
|
||||||
if (canvas.width !== (12 + 84 * nbChannels + 2)) canvas.width = 12 + 84 * nbChannels + 2;
|
|
||||||
if (canvas.height !== (12 * nbRows)) canvas.height = 12 * nbRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d', { alpha: false, desynchronized: true }) as CanvasRenderingContext2D;
|
|
||||||
if (ctx.font !== '10px monospace') ctx.font = '10px monospace';
|
|
||||||
ctx.imageSmoothingEnabled = false;
|
|
||||||
if (pattern !== lastPattern) {
|
|
||||||
ctx.fillStyle = colours.background;
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
ctx.drawImage( numberRowCanvas, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.default;
|
|
||||||
for (let rowOffset = minRow + rowDif; rowOffset < maxRow + rowDif; rowOffset++) {
|
|
||||||
const rowToDraw = rowOffset - rowDif;
|
|
||||||
|
|
||||||
if (alreadyDrawn[rowToDraw] === true) continue;
|
|
||||||
|
|
||||||
if (rowToDraw >= 0 && rowToDraw < nbRows) {
|
|
||||||
const baseOffset = 2 * CHAR_WIDTH;
|
|
||||||
const baseRowOffset = ROW_OFFSET_Y + rowToDraw * CHAR_HEIGHT;
|
|
||||||
let done = drawRow(ctx, rowToDraw, nbChannels, pattern, baseOffset, baseRowOffset);
|
|
||||||
|
|
||||||
alreadyDrawn[rowToDraw] = done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastDrawnRow = row;
|
|
||||||
lastPattern = pattern;
|
|
||||||
|
|
||||||
patternTime.current = performance.now() - startTime;
|
|
||||||
if (patternTime.initial !== 0 && patternTime.current > patternTime.max) patternTime.max = patternTime.current;
|
|
||||||
else if (patternTime.initial === 0) patternTime.initial = patternTime.current;
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawPetternPreview() {
|
|
||||||
if (!displayCanvas.value) return;
|
|
||||||
const canvas = displayCanvas.value;
|
|
||||||
|
|
||||||
const pattern = player.value.getPattern();
|
|
||||||
const nbRows = player.value.getPatternNumRows(pattern);
|
|
||||||
const row = player.value.getRow();
|
|
||||||
const halfbuf = rowBuffer / 2;
|
|
||||||
alreadyDrawn = [];
|
|
||||||
|
|
||||||
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;
|
|
||||||
if (canvas.height !== (12 * rowBuffer)) canvas.height = 12 * rowBuffer;
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d', { alpha: false }) as CanvasRenderingContext2D;
|
|
||||||
ctx.font = '10px monospace';
|
|
||||||
ctx.imageSmoothingEnabled = false;
|
|
||||||
ctx.fillStyle = colours.background;
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
ctx.drawImage( numberRowCanvas, 0, (halfbuf - row) * CHAR_HEIGHT );
|
|
||||||
|
|
||||||
for (let rowOffset = 0; rowOffset < rowBuffer; rowOffset++) {
|
|
||||||
const rowToDraw = rowOffset + row - halfbuf;
|
|
||||||
|
|
||||||
if (rowToDraw >= 0 && rowToDraw < nbRows) {
|
|
||||||
const baseOffset = 2 * CHAR_WIDTH;
|
|
||||||
const baseRowOffset = ROW_OFFSET_Y + rowOffset * CHAR_HEIGHT;
|
|
||||||
drawRow(ctx, rowToDraw, nbChannels, pattern, baseOffset, baseRowOffset);
|
|
||||||
} else if (rowToDraw >= 0) {
|
|
||||||
const baseRowOffset = ROW_OFFSET_Y + rowOffset * CHAR_HEIGHT;
|
|
||||||
ctx.fillStyle = colours.background;
|
|
||||||
ctx.fillRect(0, baseRowOffset - CHAR_HEIGHT, CHAR_WIDTH * 2, baseRowOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastPattern = -1;
|
|
||||||
lastDrawnRow = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawRow(ctx: CanvasRenderingContext2D, row: number, channels: number, pattern: number, drawX = (2 * CHAR_WIDTH), drawY = ROW_OFFSET_Y) {
|
|
||||||
if (!player.value.currentPlayingNode) return false;
|
|
||||||
if (alreadyDrawn[row]) return true;
|
|
||||||
const spacer = 11;
|
|
||||||
const space = ' ';
|
|
||||||
let seperators = '';
|
|
||||||
let note = '';
|
|
||||||
let instr = '';
|
|
||||||
let volume = '';
|
|
||||||
let fx = '';
|
|
||||||
let op = '';
|
|
||||||
for (let channel = 0; channel < channels; channel++) {
|
|
||||||
const part = player.value.getPatternRowChannel(pattern, row, channel);
|
|
||||||
|
|
||||||
seperators += '|' + space.repeat( spacer + 2 );
|
|
||||||
note += part.substring(0, 3) + space.repeat( spacer );
|
|
||||||
instr += part.substring(4, 6) + space.repeat( spacer + 1 );
|
|
||||||
volume += part.substring(6, 9) + space.repeat( spacer );
|
|
||||||
fx += part.substring(10, 11) + space.repeat( spacer + 2 );
|
|
||||||
op += part.substring(11, 13) + space.repeat( spacer + 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.default;
|
|
||||||
ctx.fillText(seperators, drawX, drawY);
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.default;
|
|
||||||
ctx.fillText(note, drawX + CHAR_WIDTH, drawY);
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.instr;
|
|
||||||
ctx.fillText(instr, drawX + CHAR_WIDTH * 5, drawY);
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.volume;
|
|
||||||
ctx.fillText(volume, drawX + CHAR_WIDTH * 7, drawY);
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.fx;
|
|
||||||
ctx.fillText(fx, drawX + CHAR_WIDTH * 11, drawY);
|
|
||||||
|
|
||||||
ctx.fillStyle = colours.foreground.operant;
|
|
||||||
ctx.fillText(op, drawX + CHAR_WIDTH * 12, drawY);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function display(skipOptimizationChecks = false) {
|
|
||||||
if (!displayCanvas.value || !displayCanvas.value.parentElement) {
|
|
||||||
stop();
|
stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patternHide.value && !skipOptimizationChecks) return;
|
if (patternHide.value) return;
|
||||||
|
|
||||||
if (firstFrame) {
|
if (firstFrame.value) {
|
||||||
// Changing it to false should enable pattern display by default.
|
firstFrame.value = false;
|
||||||
patternHide.value = true;
|
patternHide.value = true;
|
||||||
handleScrollBarEnable();
|
|
||||||
firstFrame = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const row = player.value.getRow();
|
const canvas = displayCanvas.value;
|
||||||
|
|
||||||
const pattern = player.value.getPattern();
|
const pattern = player.value.getPattern();
|
||||||
|
const row = player.value.getRow();
|
||||||
if ( row === lastDrawnRow && pattern === lastPattern && !skipOptimizationChecks) return;
|
let nbChannels = 0;
|
||||||
|
if (player.value.currentPlayingNode) {
|
||||||
// Size vs speed
|
nbChannels = player.value.currentPlayingNode.nbChannels;
|
||||||
if (patternHide.value) drawPetternPreview();
|
|
||||||
else drawPattern();
|
|
||||||
|
|
||||||
displayCanvas.value.style.top = !patternHide.value ? 'calc( 50% - ' + (row * CHAR_HEIGHT) + 'px )' : '0%';
|
|
||||||
}
|
}
|
||||||
|
if (canvas.width !== 12 + 84 * nbChannels + 2) {
|
||||||
let suppressScrollSliderWatcher = false;
|
canvas.width = 12 + 84 * nbChannels + 2;
|
||||||
|
canvas.height = 12 * rowBuffer;
|
||||||
function scrollHandler() {
|
|
||||||
suppressScrollSliderWatcher = true;
|
|
||||||
|
|
||||||
if (!patternScrollSlider.value) return;
|
|
||||||
if (!displayCanvas.value) return;
|
|
||||||
if (!displayCanvas.value.parentElement) return;
|
|
||||||
|
|
||||||
patternScrollSliderPos.value = (displayCanvas.value.parentElement.scrollLeft) / (displayCanvas.value.width - displayCanvas.value.parentElement.offsetWidth) * 100;
|
|
||||||
patternScrollSlider.value.style.opacity = '1';
|
|
||||||
}
|
}
|
||||||
|
const nbRows = player.value.getPatternNumRows(pattern);
|
||||||
function scrollEndHandle() {
|
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
||||||
suppressScrollSliderWatcher = false;
|
ctx.font = '10px monospace';
|
||||||
|
ctx.fillStyle = colours.background;
|
||||||
if (!patternScrollSlider.value) return;
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
patternScrollSlider.value.style.opacity = '';
|
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;
|
||||||
|
|
||||||
function handleScrollBarEnable() {
|
ctx.fillStyle = colours.default[active];
|
||||||
patternScrollSliderShow.value = (!patternHide.value && !isTouchUsing);
|
ctx.fillText('|', baseOffset, baseRowOffset);
|
||||||
if (patternScrollSliderShow.value !== true) return;
|
|
||||||
|
|
||||||
if (!displayCanvas.value) return;
|
const note = part.substring(0, 3);
|
||||||
if (!displayCanvas.value.parentElement) return;
|
ctx.fillStyle = colours.default[active];
|
||||||
if (firstFrame) {
|
ctx.fillText(note, baseOffset + CHAR_WIDTH, baseRowOffset);
|
||||||
patternScrollSliderShow.value = (12 + 84 * player.value.getPatternNumRows(player.value.getPattern()) + 2 > displayCanvas.value.parentElement.offsetWidth);
|
|
||||||
} else {
|
const instr = part.substring(4, 6);
|
||||||
patternScrollSliderShow.value = (displayCanvas.value.width > displayCanvas.value.parentElement.offsetWidth);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(patternScrollSliderPos, () => {
|
|
||||||
if (suppressScrollSliderWatcher) return;
|
|
||||||
if (!displayCanvas.value) return;
|
|
||||||
if (!displayCanvas.value.parentElement) return;
|
|
||||||
|
|
||||||
displayCanvas.value.parentElement.scrollLeft = (displayCanvas.value.width - displayCanvas.value.parentElement.offsetWidth) * patternScrollSliderPos.value / 100;
|
|
||||||
});
|
|
||||||
|
|
||||||
onDeactivated(() => {
|
|
||||||
stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -460,7 +290,6 @@ onDeactivated(() => {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
top: 12px;
|
top: 12px;
|
||||||
right: 12px;
|
right: 12px;
|
||||||
z-index: 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
> .pattern-display {
|
> .pattern-display {
|
||||||
|
@ -470,55 +299,22 @@ onDeactivated(() => {
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
max-height: 312px; /* magic_number = CHAR_HEIGHT * rowBuffer, needs to be in px */
|
|
||||||
|
|
||||||
scrollbar-width: none;
|
|
||||||
|
|
||||||
&::-webkit-scrollbar {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pattern-canvas {
|
.pattern-canvas {
|
||||||
position: relative;
|
|
||||||
background-color: black;
|
background-color: black;
|
||||||
image-rendering: pixelated;
|
height: 100%;
|
||||||
pointer-events: none;
|
|
||||||
z-index: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.patternShadowTop {
|
|
||||||
background: #00000080;
|
|
||||||
width: 100%;
|
|
||||||
height: calc( 50% - 14px );
|
|
||||||
translate: 0 -100%;
|
|
||||||
top: calc( 50% - 14px );
|
|
||||||
position: absolute;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.patternShadowBottom {
|
|
||||||
background: #00000080;
|
|
||||||
width: 100%;
|
|
||||||
height: calc( 50% - 12px );
|
|
||||||
top: calc( 50% - 1px );
|
|
||||||
position: absolute;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pattern-hide {
|
.pattern-hide {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: rgba(64, 64, 64, 0.3);
|
background: rgba(64, 64, 64, 0.3);
|
||||||
backdrop-filter: var(--modalBgFilter);
|
backdrop-filter: blur(2em);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 4;
|
z-index: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
@ -532,7 +328,7 @@ onDeactivated(() => {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--bg);
|
background-color: var(--bg);
|
||||||
z-index: 5;
|
z-index: 1;
|
||||||
|
|
||||||
> * {
|
> * {
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
|
@ -557,18 +353,6 @@ onDeactivated(() => {
|
||||||
margin: 4px 8px;
|
margin: 4px 8px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
|
||||||
&.pattern-slider {
|
|
||||||
position: absolute;
|
|
||||||
width: calc( 100% - 8px * 2 );
|
|
||||||
top: calc( 100% - 21px * 3 );
|
|
||||||
opacity: 0%;
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
opacity: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
<FormSection v-if="sponsors[0].length > 0">
|
<FormSection>
|
||||||
<template #label>Our lovely Sponsors</template>
|
<template #label>Our lovely Sponsors</template>
|
||||||
<div :class="$style.contributors">
|
<div :class="$style.contributors">
|
||||||
<span
|
<span
|
||||||
|
|
|
@ -150,27 +150,6 @@ ChiptuneJsPlayer.prototype.getRow = function () {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getNumPatterns = function () {
|
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
|
||||||
return libopenmpt._openmpt_module_get_num_patterns(this.currentPlayingNode.modulePtr);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getCurrentSpeed = function () {
|
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
|
||||||
return libopenmpt._openmpt_module_get_current_speed(this.currentPlayingNode.modulePtr);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getCurrentTempo = function () {
|
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
|
||||||
return libopenmpt._openmpt_module_get_current_tempo(this.currentPlayingNode.modulePtr);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getPatternNumRows = function (pattern: number) {
|
ChiptuneJsPlayer.prototype.getPatternNumRows = function (pattern: number) {
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
||||||
return libopenmpt._openmpt_module_get_pattern_num_rows(this.currentPlayingNode.modulePtr, pattern);
|
return libopenmpt._openmpt_module_get_pattern_num_rows(this.currentPlayingNode.modulePtr, pattern);
|
||||||
|
@ -185,20 +164,6 @@ ChiptuneJsPlayer.prototype.getPatternRowChannel = function (pattern: number, row
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.getCtls = function () {
|
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
|
||||||
return libopenmpt._openmpt_module_get_ctls(this.currentPlayingNode.modulePtr);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.version = function () {
|
|
||||||
if (this.currentPlayingNode && this.currentPlayingNode.modulePtr) {
|
|
||||||
return libopenmpt._openmpt_get_library_version();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: object) {
|
ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: object) {
|
||||||
const maxFramesPerChunk = 4096;
|
const maxFramesPerChunk = 4096;
|
||||||
const processNode = this.audioContext.createScriptProcessor(2048, 0, 2);
|
const processNode = this.audioContext.createScriptProcessor(2048, 0, 2);
|
||||||
|
@ -213,7 +178,6 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
processNode.paused = false;
|
processNode.paused = false;
|
||||||
processNode.leftBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
processNode.leftBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
||||||
processNode.rightBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
processNode.rightBufferPtr = libopenmpt._malloc(4 * maxFramesPerChunk);
|
||||||
processNode.perf = { 'current': 0, 'max': 0 };
|
|
||||||
processNode.cleanup = function () {
|
processNode.cleanup = function () {
|
||||||
if (this.modulePtr !== 0) {
|
if (this.modulePtr !== 0) {
|
||||||
libopenmpt._openmpt_module_destroy(this.modulePtr);
|
libopenmpt._openmpt_module_destroy(this.modulePtr);
|
||||||
|
@ -241,13 +205,7 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
processNode.togglePause = function () {
|
processNode.togglePause = function () {
|
||||||
this.paused = !this.paused;
|
this.paused = !this.paused;
|
||||||
};
|
};
|
||||||
processNode.getProcessTime = function() {
|
|
||||||
const max = this.perf.max;
|
|
||||||
this.perf.max = 0;
|
|
||||||
return { 'current': this.perf.current, 'max': max };
|
|
||||||
};
|
|
||||||
processNode.onaudioprocess = function (e) {
|
processNode.onaudioprocess = function (e) {
|
||||||
let startTimeP1 = performance.now();
|
|
||||||
const outputL = e.outputBuffer.getChannelData(0);
|
const outputL = e.outputBuffer.getChannelData(0);
|
||||||
const outputR = e.outputBuffer.getChannelData(1);
|
const outputR = e.outputBuffer.getChannelData(1);
|
||||||
let framesToRender = outputL.length;
|
let framesToRender = outputL.length;
|
||||||
|
@ -273,13 +231,11 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
|
|
||||||
const currentPattern = libopenmpt._openmpt_module_get_current_pattern(this.modulePtr);
|
const currentPattern = libopenmpt._openmpt_module_get_current_pattern(this.modulePtr);
|
||||||
const currentRow = libopenmpt._openmpt_module_get_current_row(this.modulePtr);
|
const currentRow = libopenmpt._openmpt_module_get_current_row(this.modulePtr);
|
||||||
startTimeP1 = startTimeP1 - performance.now();
|
|
||||||
if (currentPattern !== this.patternIndex) {
|
if (currentPattern !== this.patternIndex) {
|
||||||
processNode.player.fireEvent('onPatternChange');
|
processNode.player.fireEvent('onPatternChange');
|
||||||
}
|
}
|
||||||
processNode.player.fireEvent('onRowChange', { index: currentRow });
|
processNode.player.fireEvent('onRowChange', { index: currentRow });
|
||||||
|
|
||||||
const startTimeP2 = performance.now();
|
|
||||||
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 = libopenmpt._openmpt_module_read_float_stereo(this.modulePtr, this.context.sampleRate, framesPerChunk, this.leftBufferPtr, this.rightBufferPtr);
|
||||||
|
@ -306,8 +262,6 @@ ChiptuneJsPlayer.prototype.createLibopenmptNode = function (buffer, config: obje
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
error ? processNode.player.fireEvent('onError', { type: 'openmpt' }) : processNode.player.fireEvent('onEnded');
|
error ? processNode.player.fireEvent('onError', { type: 'openmpt' }) : processNode.player.fireEvent('onEnded');
|
||||||
}
|
}
|
||||||
this.perf.current = performance.now() - startTimeP2 + startTimeP1;
|
|
||||||
if (this.perf.current > this.perf.max) this.perf.max = this.perf.current;
|
|
||||||
};
|
};
|
||||||
return processNode;
|
return processNode;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue