From b3f4477dd2c4878ee615694a92fa7466c8f2cd07 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 10 Jul 2022 02:05:53 -0400 Subject: [PATCH] Fix for Vocodes v1 removal Mistakenly deleted files with function still in use --- packages/components/src/utils/GetRandomArrayValue.ts | 6 ++++++ packages/components/src/utils/GetRandomInt.ts | 11 +++++++++++ .../src/v2/view/tts/tts_result_view/SpectrogramFc.tsx | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/components/src/utils/GetRandomArrayValue.ts create mode 100644 packages/components/src/utils/GetRandomInt.ts diff --git a/packages/components/src/utils/GetRandomArrayValue.ts b/packages/components/src/utils/GetRandomArrayValue.ts new file mode 100644 index 0000000000..3b5855120a --- /dev/null +++ b/packages/components/src/utils/GetRandomArrayValue.ts @@ -0,0 +1,6 @@ +import { GetRandomInt } from "./GetRandomInt"; + +export function GetRandomArrayValue(array: Array) : T { + let index = GetRandomInt(0, array.length); + return array[index]; +} diff --git a/packages/components/src/utils/GetRandomInt.ts b/packages/components/src/utils/GetRandomInt.ts new file mode 100644 index 0000000000..922a47003e --- /dev/null +++ b/packages/components/src/utils/GetRandomInt.ts @@ -0,0 +1,11 @@ + +/** + * Generate a random integer in range. + * @param min minimum inclusive + * @param max maximum exclusive + */ +export function GetRandomInt(min: number, max: number) : number { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; +} diff --git a/packages/fakeyou/src/v2/view/tts/tts_result_view/SpectrogramFc.tsx b/packages/fakeyou/src/v2/view/tts/tts_result_view/SpectrogramFc.tsx index b2c7acacf3..a525d6de46 100644 --- a/packages/fakeyou/src/v2/view/tts/tts_result_view/SpectrogramFc.tsx +++ b/packages/fakeyou/src/v2/view/tts/tts_result_view/SpectrogramFc.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useRef } from 'react'; import { VIRIDIS, MAGMA } from "@colormap/presets"; import { createColorMap, linearScale } from "@colormap/core"; -import { getRandomArrayValue } from "../../../../v1/api/Utils"; +import { GetRandomArrayValue } from '@storyteller/components/src/utils/GetRandomArrayValue'; interface Props { spectrogramJsonLink: string @@ -29,7 +29,7 @@ function SpectrogramFc(props: Props) { let bytes = new Uint8ClampedArray(size); let colorMapScale = linearScale([0, 255], [0, 1]); - let colorMapColors = getRandomArrayValue(COLOR_MAP_PRESETS); + let colorMapColors = GetRandomArrayValue(COLOR_MAP_PRESETS); let colorMap = createColorMap(colorMapColors, colorMapScale); let k = 0;