fixed ts type issue

This commit is contained in:
Clément Le Bihan
2023-09-05 15:08:56 +02:00
parent 85473ae492
commit a81d3ee34d
3 changed files with 14 additions and 6 deletions
+5 -1
View File
@@ -103,7 +103,11 @@ const PartitionView = (props: PartitionViewProps) => {
// console.log('timestamp cursor', _osmd.cursor.iterator.CurrentSourceTimestamp); // console.log('timestamp cursor', _osmd.cursor.iterator.CurrentSourceTimestamp);
// console.log('timestamp cursor', _osmd.cursor.iterator.CurrentVoiceEntries); // console.log('timestamp cursor', _osmd.cursor.iterator.CurrentVoiceEntries);
// console.log('current measure index', _osmd.cursor.iterator.CurrentMeasureIndex); // console.log('current measure index', _osmd.cursor.iterator.CurrentMeasureIndex);
const osmdCanvas = document.querySelector('#' + OSMD_DIV_ID + ' canvas'); const osmdCanvas = document.querySelector<HTMLCanvasElement>('#' + OSMD_DIV_ID + ' canvas');
if (!osmdCanvas) {
// this should never happen this is done to silent ts linter about maybe null
throw new Error('No canvas found');
}
// Ty https://github.com/jimutt/osmd-audio-player/blob/ec205a6e46ee50002c1fa8f5999389447bba7bbf/src/PlaybackEngine.ts#LL77C12-L77C63 // Ty https://github.com/jimutt/osmd-audio-player/blob/ec205a6e46ee50002c1fa8f5999389447bba7bbf/src/PlaybackEngine.ts#LL77C12-L77C63
props.onPartitionReady( props.onPartitionReady(
osmdCanvas.toDataURL(), osmdCanvas.toDataURL(),
@@ -8,9 +8,10 @@ import { RootState, useSelector } from '../../state/Store';
import { setSoundPlayer as setSPStore } from '../../state/SoundPlayerSlice'; import { setSoundPlayer as setSPStore } from '../../state/SoundPlayerSlice';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { SplendidGrandPiano, CacheStorage } from 'smplr'; import { SplendidGrandPiano, CacheStorage } from 'smplr';
import { Note } from 'opensheetmusicdisplay';
let globalTimestamp = 0; let globalTimestamp = 0;
let globalStatus: 'playing' | 'paused' | 'stopped' = 'playing'; const globalStatus: 'playing' | 'paused' | 'stopped' = 'playing';
const isValidSoundPlayer = (soundPlayer: SplendidGrandPiano | undefined) => { const isValidSoundPlayer = (soundPlayer: SplendidGrandPiano | undefined) => {
return soundPlayer && soundPlayer.loaded; return soundPlayer && soundPlayer.loaded;
@@ -35,7 +36,9 @@ const getPianoScene = (
) => { ) => {
class PianoScene extends Phaser.Scene { class PianoScene extends Phaser.Scene {
async preload() {} async preload() {}
private cursorPositionsIdx = -1;
private partition!: Phaser.GameObjects.Image;
private cursor!: Phaser.GameObjects.Rectangle;
create() { create() {
this.textures.addBase64('partition', partitionB64); this.textures.addBase64('partition', partitionB64);
this.cursorPositionsIdx = -1; this.cursorPositionsIdx = -1;
@@ -56,7 +59,7 @@ const getPianoScene = (
if (status === 'playing') { if (status === 'playing') {
const transitionTime = 75; const transitionTime = 75;
const cP = cursorPositions.findLast((cP, idx) => { const cP = cursorPositions.findLast((cP: { timestamp: number; }, idx: number) => {
if ( if (
cP.timestamp < currentTimestamp + transitionTime && cP.timestamp < currentTimestamp + transitionTime &&
idx > this.cursorPositionsIdx idx > this.cursorPositionsIdx
@@ -73,6 +76,7 @@ const getPianoScene = (
x: cP!.x, x: cP!.x,
duration: transitionTime, duration: transitionTime,
ease: 'Sine.easeInOut', ease: 'Sine.easeInOut',
onComplete: undefined as (() => void) | undefined,
}; };
if (this.cursorPositionsIdx === cursorPositions.length - 1) { if (this.cursorPositionsIdx === cursorPositions.length - 1) {
tw.onComplete = () => { tw.onComplete = () => {
@@ -93,7 +97,7 @@ export type PianoCursorPosition = {
// timestamp in ms // timestamp in ms
timing: number; timing: number;
timestamp: number; timestamp: number;
notes: any[]; notes: Note[];
}; };
export type UpdateInfo = { export type UpdateInfo = {
+1 -1
View File
@@ -14,7 +14,7 @@
/* Language and Environment */ /* Language and Environment */
"target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [ "lib": [
"es2019", "es2023",
"DOM" "DOM"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */, ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react-native" /* Specify what JSX code is generated. */, "jsx": "react-native" /* Specify what JSX code is generated. */,