-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate voices from wasm package to hopefully be able to fix t…
…he github pages issue, either via regular build or uploading a compiled app
- Loading branch information
Showing
11 changed files
with
275 additions
and
114 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import { forEach } from "lodash"; | ||
import { TextField, ToggleButton, ToggleButtonGroup } from "@mui/material"; | ||
import PlayIcon from "@mui/icons-material/PlayArrow"; | ||
import PauseIcon from "@mui/icons-material/Pause"; | ||
import StopIcon from "@mui/icons-material/Stop"; | ||
|
||
export const MediaControls = () => { | ||
const [jumpToTime, setJumpToTime] = React.useState(0); | ||
return ( | ||
<ToggleButtonGroup | ||
size="small" | ||
exclusive | ||
onChange={(_event, action) => { | ||
const allAudios = document.querySelectorAll("audio"); | ||
forEach(allAudios, (audio) => { | ||
if (action === "play") { | ||
audio.play(); | ||
} else if (action === "pause") { | ||
audio.pause(); | ||
} else if (action === "stop") { | ||
audio.pause(); | ||
audio.currentTime = 0; | ||
} else if (action === "jump") { | ||
forEach(allAudios, (audio) => { | ||
audio.currentTime = jumpToTime; | ||
}); | ||
} | ||
}); | ||
}} | ||
aria-label="text formatting" | ||
> | ||
<ToggleButton value="play" aria-label="italic"> | ||
<PlayIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="pause" aria-label="underlined"> | ||
<PauseIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="stop" aria-label="color"> | ||
<StopIcon /> | ||
</ToggleButton> | ||
{/* Jump to */} | ||
<ToggleButton value="jump" aria-label="color"> | ||
Jump to | ||
</ToggleButton> | ||
<TextField | ||
type="number" | ||
value={jumpToTime} | ||
placeholder="Enter time in seconds" | ||
onChange={(e) => { | ||
setJumpToTime(Number(e.target.value)); | ||
}} | ||
inputProps={{ min: 0, step: 1 }} | ||
/> | ||
</ToggleButtonGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react"; | ||
import { forEach } from "lodash"; | ||
import { Button, styled } from "@mui/material"; | ||
import CloudUploadIcon from "@mui/icons-material/CloudUpload"; | ||
|
||
import { SplitParams, createSplitOddVoiceJsonInputsFromMusicXml } from "./oddVoiceJSON"; | ||
import { parseXmlText } from "./musicXmlParsing/xmlHelpers"; | ||
import { OddVoiceJSON } from "./oddVoiceJSON/oddVoiceHelpers"; | ||
|
||
const VisuallyHiddenInput = styled("input")({ | ||
clip: "rect(0 0 0 0)", | ||
clipPath: "inset(50%)", | ||
height: 1, | ||
overflow: "hidden", | ||
position: "absolute", | ||
bottom: 0, | ||
left: 0, | ||
whiteSpace: "nowrap", | ||
width: 1, | ||
}); | ||
|
||
export const UploadButton: React.FC<{ | ||
isLoadingVoice: boolean; | ||
setOddVoiceOutputs: React.Dispatch<React.SetStateAction<Array<{ output: OddVoiceJSON; splitParams: SplitParams }>>>; | ||
setAudioOutputs: React.Dispatch<React.SetStateAction<Uint8Array[]>>; | ||
setRawFile: React.Dispatch<React.SetStateAction<string>>; | ||
setIsGeneratingAudio: React.Dispatch<React.SetStateAction<boolean>>; | ||
generateVoiceFromOddVoiceJson: (oddVoiceJson: OddVoiceJSON) => Uint8Array | undefined; | ||
}> = ({ | ||
isLoadingVoice, | ||
generateVoiceFromOddVoiceJson, | ||
setIsGeneratingAudio, | ||
setOddVoiceOutputs, | ||
setAudioOutputs, | ||
setRawFile, | ||
}) => { | ||
const [, startTransition] = React.useTransition(); | ||
|
||
return ( | ||
<Button | ||
component="label" | ||
role={undefined} | ||
variant="contained" | ||
tabIndex={-1} | ||
startIcon={<CloudUploadIcon />} | ||
disabled={isLoadingVoice} | ||
> | ||
Upload file | ||
<VisuallyHiddenInput | ||
type="file" | ||
onChange={(e) => { | ||
const file = e?.target?.files?.[0]; | ||
if (!file) { | ||
return; | ||
} | ||
const reader = new FileReader(); | ||
reader.onload = (e) => { | ||
if (e?.target?.result) { | ||
setIsGeneratingAudio(true); | ||
const result = e.target.result as string; | ||
startTransition(() => { | ||
const newOddVoiceOutputs = createSplitOddVoiceJsonInputsFromMusicXml( | ||
parseXmlText(result) | ||
); | ||
setOddVoiceOutputs(newOddVoiceOutputs); | ||
setRawFile(result); | ||
forEach(newOddVoiceOutputs, (oddVoiceOutput, i) => { | ||
const outputAudio = generateVoiceFromOddVoiceJson(oddVoiceOutput.output); | ||
if (!outputAudio || outputAudio.length === 0) { | ||
console.error("Failed to generate audio output."); | ||
return; | ||
} | ||
setAudioOutputs((prev) => { | ||
const newOutputs = [...prev]; | ||
newOutputs[i] = outputAudio; | ||
return newOutputs; | ||
}); | ||
}); | ||
setIsGeneratingAudio(false); | ||
}); | ||
} | ||
}; | ||
reader.readAsText(file); | ||
}} | ||
/> | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.