// Copyright (c) 2022 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 ArrowBackIcon from '@mui/icons-material/ArrowBack'; import { Theme } from '@mui/material/styles'; import WithStyles from './WithStyles'; import { createStyles } from './WithStyles'; import { withStyles } from "tss-react/mui"; import Button from '@mui/material/Button'; import DialogEx from './DialogEx'; import MuiDialogTitle from '@mui/material/DialogTitle'; import MuiDialogContent from '@mui/material/DialogContent'; import MuiDialogActions from '@mui/material/DialogActions'; import IconButtonEx from './IconButtonEx'; import Typography from '@mui/material/Typography'; import Grid from '@mui/material/Grid'; import { PiPedalModelFactory } from "./PiPedalModel"; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import { UiPlugin, PortGroup } from './Lv2Plugin'; import PluginIcon from './PluginIcon'; import { Remark } from 'react-remark'; import { css } from '@emotion/react'; const styles = (theme: Theme) => { return createStyles({ root: { margin: 0, padding: theme.spacing(2), }, closeButton: css({ position: 'absolute', right: theme.spacing(1), top: theme.spacing(1), color: theme.palette.grey[500], }), icon: { fill: theme.palette.text.primary, opacity: 0.6 }, controlHeader: { borderBottom: "1px solid " + theme.palette.divider, } }); }; export interface PluginInfoDialogTitleProps extends WithStyles { id: string; children: React.ReactNode; onClose: () => void; } const PluginInfoDialogContent = withStyles( MuiDialogContent, (theme: Theme) => ({ root: { padding: theme.spacing(2), } }) ); const PluginInfoDialogActions = withStyles(MuiDialogActions, (theme: Theme) => ({ root: { margin: 0, padding: theme.spacing(1), }, }) ); 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(plugin: UiPlugin, controlHeadeClass: string) { let controls = plugin.controls; let hasComments = false; for (let i = 0; i < controls.length; ++i) { if (controls[i].comment !== "") { hasComments = true; break; } } hasComments = true; let lastPortGroup: PortGroup | null = null; if (hasComments) { let trs: React.ReactElement[] = []; for (let i = 0; i < controls.length; ++i) { let control = controls[i]; if (!(control.not_on_gui) && control.is_input) { let portGroup = plugin.getPortGroupBySymbol(control.port_group); if (portGroup !== lastPortGroup) { if (portGroup !== null) { trs.push(( {portGroup?.name ?? ""} )); } lastPortGroup = portGroup; } trs.push(( {control.name} {control.comment} )); } } return ( { trs }
); } else { return ( { controls.map((control) => ( {control.name} )) } ); } } const PluginInfoDialog = withStyles((props: PluginInfoProps) => { let model = PiPedalModelFactory.getInstance(); const [open, setOpen] = React.useState(false); let { plugin_uri } = props; let classes = withStyles.getClasses(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 && (
{ handleClose()}} >
{plugin.name}
Author:  {(plugin.author_homepage !== "") ? ( {plugin.author_name} ) : ( {plugin.author_name} ) }
{ioDescription(plugin)}
Controls: { makeControls(plugin, classes.controlHeader) } {plugin.description.length > 0 && (
Description:
{ // return ( //

// ); return ( ); }, code: (props: any) => { return (); }, a: (props: any) => { return ( ); } }, }} > {plugin.description}

)}
)}
); }, styles); export default PluginInfoDialog;