-
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.
Allow choosing from all the mGB built-in waves
- Loading branch information
Showing
10 changed files
with
325 additions
and
121 deletions.
There are no files selected for viewing
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,15 @@ | ||
import { useId } from "react"; | ||
import { Flex } from "./Flex"; | ||
|
||
export const Field: React.FC<{ | ||
label: string; | ||
children: (id: string) => React.ReactNode; | ||
}> = ({ label, children }) => { | ||
const id = useId(); | ||
return ( | ||
<Flex row align="center" gap={8} style={{ alignContent: "center" }}> | ||
<label htmlFor={id}>{label}</label> | ||
{children(id)} | ||
</Flex> | ||
); | ||
}; |
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,41 @@ | ||
import { Waveform } from "../types"; | ||
import { sysexWaveformMessage } from "../lib/sysex"; | ||
import { useMemo } from "react"; | ||
import { Button } from "primereact/button"; | ||
import { PrimeIcons } from "primereact/api"; | ||
|
||
export const SysexDownloadButton: React.FC<{ waveform: Waveform }> = ({ | ||
waveform, | ||
}) => { | ||
const blobUrl = useMemo(() => { | ||
// Convert object to Blob | ||
const blobConfig = new Blob( | ||
[Uint8Array.from(sysexWaveformMessage(waveform))], | ||
{ type: "application/octet-stream" } | ||
); | ||
return URL.createObjectURL(blobConfig); | ||
}, [waveform]); | ||
|
||
const handleDownload = () => { | ||
const fileName = "mGB-patch.syx"; | ||
downloadFile(blobUrl, fileName); | ||
}; | ||
|
||
return ( | ||
<Button | ||
text | ||
icon={PrimeIcons.DOWNLOAD} | ||
onClick={handleDownload} | ||
label="Download .syx file" | ||
/> | ||
); | ||
}; | ||
|
||
function downloadFile(blobUrl: string, fileName: string) { | ||
const link = document.createElement("a"); | ||
link.href = blobUrl; | ||
link.download = fileName; | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
} |
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
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,44 @@ | ||
import { InputText } from "primereact/inputtext"; | ||
import { Slider } from "primereact/slider"; | ||
import { memo } from "react"; | ||
import { WAVEFORM_SLOTS } from "../lib/globals"; | ||
import { Callback } from "../types"; | ||
import { Field } from "./Field"; | ||
import { Flex } from "./Flex"; | ||
|
||
export const WaveformSelector: React.FC<{ | ||
value: number; | ||
onChange: Callback<number>; | ||
}> = ({ value, onChange }) => { | ||
if (value >= WAVEFORM_SLOTS) | ||
throw new Error( | ||
`Invalid waveform index ${value}. Only 0-${WAVEFORM_SLOTS - 1} are valid` | ||
); | ||
|
||
return ( | ||
<Field label="Waveform index"> | ||
{(id) => <SliderWithDisplay id={id} value={value} onChange={onChange} />} | ||
</Field> | ||
); | ||
}; | ||
|
||
const SliderWithDisplay: React.FC<{ | ||
id: string; | ||
value: number; | ||
onChange: Callback<number>; | ||
}> = memo(({ id, value, onChange }) => { | ||
return ( | ||
<Flex row gap={16} align="center" grow="1" style={{ padding: "0 8px" }}> | ||
<Slider | ||
id={id} | ||
style={{ flex: 1 }} | ||
max={WAVEFORM_SLOTS - 1} | ||
value={value} | ||
onChange={(e) => { | ||
if (typeof e.value === "number") onChange(e.value); | ||
}} | ||
/> | ||
<InputText value={value.toString()} readOnly style={{ width: "48px" }} /> | ||
</Flex> | ||
); | ||
}); |
Oops, something went wrong.