fix ts issues 2
This commit is contained in:
@@ -103,9 +103,11 @@ const PartitionView = (props: PartitionViewProps) => {
|
||||
// console.log('timestamp cursor', _osmd.cursor.iterator.CurrentSourceTimestamp);
|
||||
// console.log('timestamp cursor', _osmd.cursor.iterator.CurrentVoiceEntries);
|
||||
// console.log('current measure index', _osmd.cursor.iterator.CurrentMeasureIndex);
|
||||
const osmdCanvas = document.querySelector<HTMLCanvasElement>('#' + OSMD_DIV_ID + ' canvas');
|
||||
const osmdCanvas = document.querySelector<HTMLCanvasElement>(
|
||||
'#' + OSMD_DIV_ID + ' canvas'
|
||||
);
|
||||
// this should never happen this is done to silent ts linter about maybe null
|
||||
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
|
||||
|
||||
@@ -17,7 +17,16 @@ const isValidSoundPlayer = (soundPlayer: SplendidGrandPiano | undefined) => {
|
||||
return soundPlayer && soundPlayer.loaded;
|
||||
};
|
||||
|
||||
const playNotes = (notes: any[], soundPlayer: SplendidGrandPiano) => {
|
||||
const myFindLast = <T,>(a: T[], p: (_: T, _2: number) => boolean) => {
|
||||
for (let i = a.length - 1; i >= 0; i--) {
|
||||
if (p(a[i]!, i)) {
|
||||
return a[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const playNotes = (notes: PianoCursorNote[], soundPlayer: SplendidGrandPiano) => {
|
||||
notes.forEach(({ note, duration }) => {
|
||||
const fixedKey =
|
||||
note.ParentVoiceEntry.ParentVoice.Parent.SubInstruments.at(0)?.fixedKey ?? 0;
|
||||
@@ -59,7 +68,7 @@ const getPianoScene = (
|
||||
|
||||
if (status === 'playing') {
|
||||
const transitionTime = 75;
|
||||
const cP = cursorPositions.findLast((cP: { timestamp: number; }, idx: number) => {
|
||||
const cP = myFindLast(cursorPositions, (cP: { timestamp: number; }, idx: number) => {
|
||||
if (
|
||||
cP.timestamp < currentTimestamp + transitionTime &&
|
||||
idx > this.cursorPositionsIdx
|
||||
@@ -91,13 +100,18 @@ const getPianoScene = (
|
||||
return PianoScene;
|
||||
};
|
||||
|
||||
type PianoCursorNote = {
|
||||
note: Note;
|
||||
duration: number;
|
||||
};
|
||||
|
||||
export type PianoCursorPosition = {
|
||||
// offset in pixels
|
||||
x: number;
|
||||
// timestamp in ms
|
||||
timing: number;
|
||||
timestamp: number;
|
||||
notes: Note[];
|
||||
notes: PianoCursorNote[];
|
||||
};
|
||||
|
||||
export type UpdateInfo = {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
/* Language and Environment */
|
||||
"target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
"lib": [
|
||||
"es2023",
|
||||
"es2022",
|
||||
"DOM"
|
||||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||
"jsx": "react-native" /* Specify what JSX code is generated. */,
|
||||
|
||||
Reference in New Issue
Block a user