// Copyright (c) 2021 Robin Davies // // Permission is hereby granted, free of charge, to any person obtaining a copy of // this software and associated documentation files (the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // the Software, and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import React from 'react'; import { createStyles, Theme, withStyles, WithStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import Dialog from '@material-ui/core/Dialog'; import MuiDialogTitle from '@material-ui/core/DialogTitle'; import MuiDialogContent from '@material-ui/core/DialogContent'; import MuiDialogActions from '@material-ui/core/DialogActions'; import IconButton from '@material-ui/core/IconButton'; import CloseIcon from '@material-ui/icons/Close'; import Typography from '@material-ui/core/Typography'; import Grid from '@material-ui/core/Grid'; import { PiPedalModelFactory } from "./PiPedalModel"; import InfoOutlinedIcon from '@material-ui/icons/InfoOutlined'; import { UiPlugin, UiControl } from './Lv2Plugin'; import PluginIcon from './PluginIcon'; const styles = (theme: Theme) => createStyles({ root: { margin: 0, padding: theme.spacing(2), }, closeButton: { position: 'absolute', right: theme.spacing(1), top: theme.spacing(1), color: theme.palette.grey[500], }, }); export interface PluginInfoDialogTitleProps extends WithStyles { id: string; children: React.ReactNode; onClose: () => void; } // const PluginInfoDialogTitle = withStyles(styles)((props: PluginInfoDialogTitleProps) => { // const { children, classes, onClose, ...other } = props; // return ( // //
// //
//
// {children} //
// handleClose()} // style={{ flex: "0 0 auto" }}> // // //
// ); // }); const PluginInfoDialogContent = withStyles((theme: Theme) => ({ root: { padding: theme.spacing(2), }, }))(MuiDialogContent); const PluginInfoDialogActions = withStyles((theme: Theme) => ({ root: { margin: 0, padding: theme.spacing(1), }, }))(MuiDialogActions); export interface PluginInfoProps extends WithStyles { plugin_uri: string } function displayChannelCount(count: number): string { if (count === 0) return "None"; if (count === 1) return "Mono"; if (count === 2) return "Stereo"; return count + " channels"; } function ioDescription(plugin: UiPlugin): string { let result = "Input: " + displayChannelCount(plugin.audio_inputs) + ". Output: " + displayChannelCount(plugin.audio_outputs) + "."; if (plugin.has_midi_input) { if (plugin.has_midi_output) { result += " Midi in/out."; } else { result += " Midi in."; } } else { if (plugin.has_midi_output) { result += "Midi out."; } } return result; } function makeParagraphs(description: string) { description = description.replaceAll('\r', ''); description = description.replaceAll('\n\n', '\r'); description = description.replaceAll('\n', ' '); let paragraphs: string[] = description.split('\r'); return (
{paragraphs.map((para) => ( {para} ))}
); } function makeControls(controls: UiControl[]) { return ( { controls.map((control) => ( {control.name} )) } ); } const PluginInfoDialog = withStyles(styles)((props: PluginInfoProps) => { let model = PiPedalModelFactory.getInstance(); const [open, setOpen] = React.useState(false); let { classes, plugin_uri } = props; const handleClickOpen = () => { setOpen(true); }; const handleClose = () => { setOpen(false); }; let uri = props.plugin_uri; let visible = true; if (uri === null || uri === "") { visible = false; } if (!visible) { return (
); }; let plugin = model.getUiPlugin(plugin_uri); if (plugin === null) { return (
) } return (
{open && (
{plugin.name}
handleClose()} style={{ flex: "0 0 auto" }}>
Author:  {(plugin.author_homepage !== "") ? {plugin.author_name} : ( plugin.author_name ) } {ioDescription(plugin)} Controls: { makeControls(plugin.controls) } Description: { (plugin.description !== "") && makeParagraphs(plugin.description) }
)}
); }); export default PluginInfoDialog;