Initial tests for embedding outside widgets, working in X11
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
f262e6661c
commit
975e722a10
8 changed files with 550 additions and 0 deletions
|
@ -112,6 +112,15 @@
|
|||
"Utility"
|
||||
]
|
||||
},
|
||||
{
|
||||
"slug": "MPV",
|
||||
"disabled": false,
|
||||
"name": "MPV",
|
||||
"description": "An embed video player inside Cardinal",
|
||||
"tags": [
|
||||
"Visual"
|
||||
]
|
||||
},
|
||||
{
|
||||
"slug": "TextEditor",
|
||||
"disabled": false,
|
||||
|
|
147
plugins/Cardinal/res/MPV.svg
Normal file
147
plugins/Cardinal/res/MPV.svg
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="233.67999mm"
|
||||
height="128.5mm"
|
||||
viewBox="0 0 233.68 128.5"
|
||||
version="1.1"
|
||||
id="svg4620"
|
||||
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
|
||||
sodipodi:docname="MPV.svg">
|
||||
<defs
|
||||
id="defs4614">
|
||||
<style
|
||||
id="style6"
|
||||
type="text/css">
|
||||
|
||||
.str0 {stroke:#565656;stroke-width:0.0966867}
|
||||
.str1 {stroke:#4F4F4F;stroke-width:0.193345}
|
||||
.fil0 {fill:none}
|
||||
.fil2 {fill:#2B2A29}
|
||||
.fil1 {fill:#6B6B6B}
|
||||
|
||||
</style>
|
||||
<clipPath
|
||||
clipPathUnits="userSpaceOnUse"
|
||||
id="clipPath847">
|
||||
<g
|
||||
id="use849"
|
||||
inkscape:label="Clip">
|
||||
<g
|
||||
style="fill-rule:evenodd"
|
||||
id="g855"
|
||||
transform="matrix(6.342689,0,0,6.342689,5.4472535,175.6457)">
|
||||
<g
|
||||
transform="translate(-1.6191379e-5,-0.08553947)"
|
||||
id="g853">
|
||||
<metadata
|
||||
id="metadata847" />
|
||||
<circle
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.0966867;stroke-opacity:1"
|
||||
id="circle849"
|
||||
r="0.15916"
|
||||
cy="0.61075097"
|
||||
cx="0.525226"
|
||||
class="fil0 str0" />
|
||||
<circle
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.193345;stroke-opacity:1"
|
||||
id="circle851"
|
||||
r="0.42853901"
|
||||
cy="0.61075097"
|
||||
cx="0.525226"
|
||||
class="fil0 str1" />
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
aria-label="Cardinal"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10.58333302px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
|
||||
id="g873"
|
||||
transform="translate(-0.09449404,0.14174107)">
|
||||
<path
|
||||
d="m 17.923601,176.99103 v 0.66043 q -0.31626,-0.29456 -0.675928,-0.44028 -0.356567,-0.14573 -0.759643,-0.14573 -0.79375,0 -1.21543,0.48679 -0.42168,0.48369 -0.42168,1.40146 0,0.91468 0.42168,1.40147 0.42168,0.48369 1.21543,0.48369 0.403076,0 0.759643,-0.14573 0.359668,-0.14572 0.675928,-0.44028 v 0.65422 q -0.328662,0.22325 -0.697632,0.33487 -0.365869,0.11162 -0.775146,0.11162 -1.051099,0 -1.655713,-0.64182 -0.604615,-0.64492 -0.604615,-1.75804 0,-1.11621 0.604615,-1.75803 0.604614,-0.64492 1.655713,-0.64492 0.415478,0 0.781347,0.11162 0.36897,0.10852 0.691431,0.32866 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path857"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 20.444377,179.51801 q -0.69143,0 -0.958081,0.15813 -0.26665,0.15813 -0.26665,0.5395 0,0.30386 0.198437,0.48369 0.201538,0.17674 0.545703,0.17674 0.47439,0 0.759644,-0.33487 0.288355,-0.33796 0.288355,-0.89606 v -0.12713 z m 1.137915,-0.23564 v 1.98127 h -0.570507 v -0.5271 q -0.195337,0.31626 -0.486792,0.46819 -0.291456,0.14883 -0.713135,0.14883 -0.533301,0 -0.849561,-0.29766 -0.313159,-0.30075 -0.313159,-0.80305 0,-0.58601 0.390674,-0.88367 0.393774,-0.29765 1.172021,-0.29765 h 0.799952 v -0.0558 q 0,-0.39378 -0.26045,-0.60772 -0.257348,-0.21704 -0.725537,-0.21704 -0.297656,0 -0.579809,0.0713 -0.282154,0.0713 -0.542603,0.21394 v -0.52709 q 0.313159,-0.12093 0.607715,-0.17984 0.294556,-0.062 0.573608,-0.062 0.753443,0 1.125513,0.39067 0.37207,0.39068 0.37207,1.18443 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path859"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 24.769695,178.32429 q -0.09612,-0.0558 -0.21084,-0.0806 -0.111621,-0.0279 -0.248047,-0.0279 -0.483691,0 -0.744141,0.31626 -0.257348,0.31315 -0.257348,0.90227 v 1.82934 H 22.73571 v -3.47265 h 0.573609 v 0.5395 q 0.179834,-0.31626 0.468188,-0.46819 0.288355,-0.15503 0.700733,-0.15503 0.05891,0 0.130224,0.009 0.07131,0.006 0.15813,0.0217 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path861"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 27.541618,178.31808 v -1.87895 h 0.570508 v 4.82451 h -0.570508 v -0.5209 q -0.179834,0.31006 -0.455786,0.46199 -0.272851,0.14883 -0.657324,0.14883 -0.629419,0 -1.026294,-0.5023 -0.393774,-0.50229 -0.393774,-1.32085 0,-0.81855 0.393774,-1.32085 0.396875,-0.50229 1.026294,-0.50229 0.384473,0 0.657324,0.15193 0.275952,0.14883 0.455786,0.45888 z m -1.944067,1.21233 q 0,0.62942 0.257349,0.98909 0.260449,0.35657 0.713134,0.35657 0.452686,0 0.713135,-0.35657 0.260449,-0.35967 0.260449,-0.98909 0,-0.62942 -0.260449,-0.98598 -0.260449,-0.35967 -0.713135,-0.35967 -0.452685,0 -0.713134,0.35967 -0.257349,0.35656 -0.257349,0.98598 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path863"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 29.287248,177.79099 h 0.570508 v 3.47265 h -0.570508 z m 0,-1.35186 h 0.570508 v 0.72244 h -0.570508 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path865"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 33.938127,179.16765 v 2.09599 h -0.570508 v -2.07739 q 0,-0.49299 -0.192236,-0.73794 -0.192236,-0.24495 -0.576709,-0.24495 -0.461987,0 -0.728638,0.29456 -0.26665,0.29455 -0.26665,0.80305 v 1.96267 h -0.573608 v -3.47265 h 0.573608 v 0.5395 q 0.204639,-0.31316 0.480591,-0.46819 0.279053,-0.15503 0.641821,-0.15503 0.598413,0 0.905371,0.37207 0.306958,0.36897 0.306958,1.08831 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path867"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 36.654241,179.51801 q -0.691431,0 -0.958081,0.15813 -0.26665,0.15813 -0.26665,0.5395 0,0.30386 0.198437,0.48369 0.201538,0.17674 0.545703,0.17674 0.47439,0 0.759644,-0.33487 0.288354,-0.33796 0.288354,-0.89606 v -0.12713 z m 1.137915,-0.23564 v 1.98127 h -0.570508 v -0.5271 q -0.195337,0.31626 -0.486792,0.46819 -0.291455,0.14883 -0.713135,0.14883 -0.5333,0 -0.84956,-0.29766 -0.313159,-0.30075 -0.313159,-0.80305 0,-0.58601 0.390674,-0.88367 0.393774,-0.29765 1.172021,-0.29765 h 0.799951 v -0.0558 q 0,-0.39378 -0.260449,-0.60772 -0.257349,-0.21704 -0.725537,-0.21704 -0.297656,0 -0.57981,0.0713 -0.282153,0.0713 -0.542602,0.21394 v -0.52709 q 0.313159,-0.12093 0.607715,-0.17984 0.294555,-0.062 0.573608,-0.062 0.753442,0 1.125513,0.39067 0.37207,0.39068 0.37207,1.18443 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path869"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 38.967278,176.43913 h 0.570508 v 4.82451 h -0.570508 z"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332"
|
||||
id="path871"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:cx="34.29705"
|
||||
inkscape:cy="201.2366"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1026"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata4617">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-168.5)" />
|
||||
</svg>
|
After Width: | Height: | Size: 11 KiB |
219
plugins/Cardinal/src/EmbedWidget.cpp
Normal file
219
plugins/Cardinal/src/EmbedWidget.cpp
Normal file
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* DISTRHO Cardinal Plugin
|
||||
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of
|
||||
* the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
#if defined(ARCH_LIN) && !defined(HEADLESS)
|
||||
# define HAVE_X11
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_X11
|
||||
# include <sys/types.h>
|
||||
# include <X11/Xatom.h>
|
||||
# include <X11/Xlib.h>
|
||||
# include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
#include "EmbedWidget.hpp"
|
||||
|
||||
static void offsetToXY(const Vec offset, int& x, int& y)
|
||||
{
|
||||
if (offset.x > 0.0f)
|
||||
x = static_cast<int>(offset.x + 0.5f);
|
||||
else if (offset.x < 0.0f)
|
||||
x = static_cast<int>(offset.x - 0.5f);
|
||||
else
|
||||
x = 0;
|
||||
|
||||
if (offset.y > 0.0f)
|
||||
y = static_cast<int>(offset.y + 0.5f);
|
||||
else if (offset.y < 0.0f)
|
||||
y = static_cast<int>(offset.y - 0.5f);
|
||||
else
|
||||
y = 0;
|
||||
}
|
||||
|
||||
struct EmbedWidget::PrivateData {
|
||||
#ifdef HAVE_X11
|
||||
::Display* display = nullptr;
|
||||
::Window window = 0;
|
||||
#endif
|
||||
|
||||
int lastX = 0;
|
||||
int lastY = 0;
|
||||
uint lastWidth = 0;
|
||||
uint lastHeight = 0;
|
||||
|
||||
PrivateData(const Vec size)
|
||||
{
|
||||
const uint width = size.x;
|
||||
const uint height = size.y;
|
||||
|
||||
#ifdef HAVE_X11
|
||||
display = XOpenDisplay(nullptr);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(display != nullptr,);
|
||||
|
||||
const ::Window rootWindow = RootWindow(display, DefaultScreen(display));
|
||||
|
||||
window = XCreateSimpleWindow(display, rootWindow, 0, 0, width, height, 0, 0, 0);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(window != 0,);
|
||||
|
||||
XSizeHints sizeHints = {};
|
||||
sizeHints.flags = PMinSize | PMaxSize;
|
||||
sizeHints.min_width = width;
|
||||
sizeHints.max_width = width;
|
||||
sizeHints.min_height = height;
|
||||
sizeHints.max_height = height;
|
||||
XSetNormalHints(display, window, &sizeHints);
|
||||
XStoreName(display, window, "EmbedWidget");
|
||||
#endif
|
||||
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
}
|
||||
|
||||
~PrivateData()
|
||||
{
|
||||
#ifdef HAVE_X11
|
||||
if (display == nullptr)
|
||||
return;
|
||||
|
||||
if (window != 0)
|
||||
XDestroyWindow(display, window);
|
||||
|
||||
XCloseDisplay(display);
|
||||
#endif
|
||||
}
|
||||
|
||||
void embedIntoRack(const uintptr_t nativeWindowId, const Rect rect)
|
||||
{
|
||||
int x, y;
|
||||
offsetToXY(rect.pos, x, y);
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
|
||||
const uint width = rect.size.x;
|
||||
const uint height = rect.size.y;
|
||||
|
||||
if (lastWidth != width || lastHeight != height)
|
||||
{
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
#ifdef HAVE_X11
|
||||
XResizeWindow(display, window, width, height);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_X11
|
||||
DISTRHO_SAFE_ASSERT_RETURN(window != 0,);
|
||||
|
||||
XReparentWindow(display, window, nativeWindowId, x, y);
|
||||
XMapRaised(display, window);
|
||||
XSync(display, False);
|
||||
|
||||
d_stdout("this window is %lu", window);
|
||||
#endif
|
||||
}
|
||||
|
||||
void hide()
|
||||
{
|
||||
#ifdef HAVE_X11
|
||||
DISTRHO_SAFE_ASSERT_RETURN(window != 0,);
|
||||
|
||||
const ::Window rootWindow = RootWindow(display, DefaultScreen(display));
|
||||
|
||||
XUnmapWindow(display, window);
|
||||
XReparentWindow(display, window, rootWindow, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void step(const Rect rect)
|
||||
{
|
||||
int x, y;
|
||||
offsetToXY(rect.pos, x, y);
|
||||
|
||||
const uint width = rect.size.x;
|
||||
const uint height = rect.size.y;
|
||||
|
||||
const bool diffPos = (lastX != x || lastY != y);
|
||||
const bool diffSize = (lastWidth != width || lastHeight != height);
|
||||
|
||||
if (diffPos && diffSize)
|
||||
{
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
#ifdef HAVE_X11
|
||||
XMoveResizeWindow(display, window, x, y, width, height);
|
||||
#endif
|
||||
}
|
||||
else if (diffPos)
|
||||
{
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
#ifdef HAVE_X11
|
||||
XMoveWindow(display, window, x, y);
|
||||
#endif
|
||||
}
|
||||
else if (diffSize)
|
||||
{
|
||||
lastWidth = width;
|
||||
lastHeight = height;
|
||||
#ifdef HAVE_X11
|
||||
XResizeWindow(display, window, width, height);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_X11
|
||||
if (window == 0)
|
||||
return;
|
||||
|
||||
for (XEvent event; XPending(display) > 0;)
|
||||
XNextEvent(display, &event);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
EmbedWidget::EmbedWidget(const Vec size)
|
||||
: pData(new PrivateData(size))
|
||||
{
|
||||
box.size = size;
|
||||
}
|
||||
|
||||
EmbedWidget::~EmbedWidget()
|
||||
{
|
||||
delete pData;
|
||||
}
|
||||
|
||||
void EmbedWidget::embedIntoRack(const uintptr_t nativeWindowId)
|
||||
{
|
||||
pData->embedIntoRack(nativeWindowId, getAbsoluteRect());
|
||||
}
|
||||
|
||||
void EmbedWidget::hide()
|
||||
{
|
||||
pData->hide();
|
||||
}
|
||||
|
||||
void EmbedWidget::step()
|
||||
{
|
||||
pData->step(getAbsoluteRect());
|
||||
}
|
||||
|
||||
Rect EmbedWidget::getAbsoluteRect()
|
||||
{
|
||||
return Rect(getAbsoluteOffset({}), box.size.mult(getAbsoluteZoom()));
|
||||
}
|
37
plugins/Cardinal/src/EmbedWidget.hpp
Normal file
37
plugins/Cardinal/src/EmbedWidget.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* DISTRHO Cardinal Plugin
|
||||
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of
|
||||
* the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "plugin.hpp"
|
||||
|
||||
struct EmbedWidget : Widget {
|
||||
struct PrivateData;
|
||||
PrivateData* const pData;
|
||||
|
||||
EmbedWidget(Vec size);
|
||||
~EmbedWidget() override;
|
||||
|
||||
void embedIntoRack(uintptr_t nativeWindowId);
|
||||
void hide();
|
||||
|
||||
private:
|
||||
void draw(const DrawArgs&) override {}
|
||||
void step() override;
|
||||
|
||||
Rect getAbsoluteRect();
|
||||
};
|
133
plugins/Cardinal/src/MPV.cpp
Normal file
133
plugins/Cardinal/src/MPV.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* DISTRHO Cardinal Plugin
|
||||
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of
|
||||
* the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* For a full copy of the GNU General Public License see the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "plugincontext.hpp"
|
||||
|
||||
#ifndef HEADLESS
|
||||
# include "EmbedWidget.hpp"
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
struct CardinalEmbedModule : Module {
|
||||
enum ParamIds {
|
||||
NUM_PARAMS
|
||||
};
|
||||
enum InputIds {
|
||||
NUM_INPUTS
|
||||
};
|
||||
enum OutputIds {
|
||||
AUDIO_OUTPUT1,
|
||||
AUDIO_OUTPUT2,
|
||||
NUM_OUTPUTS
|
||||
};
|
||||
enum LightIds {
|
||||
NUM_LIGHTS
|
||||
};
|
||||
|
||||
CardinalPluginContext* const pcontext;
|
||||
|
||||
CardinalEmbedModule()
|
||||
: pcontext(static_cast<CardinalPluginContext*>(APP))
|
||||
{
|
||||
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
|
||||
|
||||
configOutput(0, "Audio Left");
|
||||
configOutput(1, "Audio Right");
|
||||
}
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef HEADLESS
|
||||
struct CardinalEmbedWidget : ModuleWidget {
|
||||
CardinalEmbedModule* const module;
|
||||
CardinalPluginContext* const pcontext;
|
||||
EmbedWidget* embedWidget = nullptr;
|
||||
bool isEmbed = false;
|
||||
|
||||
CardinalEmbedWidget(CardinalEmbedModule* const m)
|
||||
: ModuleWidget(),
|
||||
module(m),
|
||||
pcontext(m != nullptr ? m->pcontext : nullptr)
|
||||
{
|
||||
setModule(module);
|
||||
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/MPV.svg")));
|
||||
|
||||
if (m != nullptr)
|
||||
{
|
||||
embedWidget = new EmbedWidget(box.size);
|
||||
addChild(embedWidget);
|
||||
}
|
||||
}
|
||||
|
||||
void onContextCreate(const ContextCreateEvent& e) override
|
||||
{
|
||||
ModuleWidget::onContextCreate(e);
|
||||
widgetCreated();
|
||||
}
|
||||
|
||||
void onContextDestroy(const ContextDestroyEvent& e) override
|
||||
{
|
||||
widgetDestroyed();
|
||||
ModuleWidget::onContextDestroy(e);
|
||||
}
|
||||
|
||||
void onAdd(const AddEvent& e) override
|
||||
{
|
||||
ModuleWidget::onAdd(e);
|
||||
widgetCreated();
|
||||
}
|
||||
|
||||
void onRemove(const RemoveEvent& e) override
|
||||
{
|
||||
widgetDestroyed();
|
||||
ModuleWidget::onRemove(e);
|
||||
}
|
||||
|
||||
void widgetCreated()
|
||||
{
|
||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr,);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext->nativeWindowId != 0,);
|
||||
|
||||
if (isEmbed)
|
||||
return;
|
||||
|
||||
isEmbed = true;
|
||||
embedWidget->embedIntoRack(pcontext->nativeWindowId);
|
||||
}
|
||||
|
||||
void widgetDestroyed()
|
||||
{
|
||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr,);
|
||||
|
||||
if (! isEmbed)
|
||||
return;
|
||||
|
||||
isEmbed = false;
|
||||
embedWidget->hide();
|
||||
}
|
||||
};
|
||||
#else
|
||||
typedef ModuleWidget CardinalEmbedWidget;
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Model* modelMPV = createModel<CardinalEmbedModule, CardinalEmbedWidget>("MPV");
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
|
@ -38,4 +38,5 @@ extern Model* modelHostMIDI;
|
|||
extern Model* modelHostParameters;
|
||||
extern Model* modelHostTime;
|
||||
extern Model* modelIldaeil;
|
||||
extern Model* modelMPV;
|
||||
extern Model* modelTextEditor;
|
||||
|
|
|
@ -199,9 +199,11 @@ ifneq ($(STATIC_BUILD),true)
|
|||
PLUGIN_FILES += Cardinal/src/AudioFile.cpp
|
||||
PLUGIN_FILES += Cardinal/src/Carla.cpp
|
||||
PLUGIN_FILES += Cardinal/src/Ildaeil.cpp
|
||||
PLUGIN_FILES += Cardinal/src/MPV.cpp
|
||||
endif
|
||||
|
||||
ifneq ($(HEADLESS),true)
|
||||
PLUGIN_FILES += Cardinal/src/EmbedWidget.cpp
|
||||
PLUGIN_FILES += Cardinal/src/ImGuiWidget.cpp
|
||||
PLUGIN_FILES += Cardinal/src/ImGuiTextEditor.cpp
|
||||
PLUGIN_FILES += $(wildcard Cardinal/src/DearImGui/*.cpp)
|
||||
|
|
|
@ -728,10 +728,12 @@ static void initStatic__Cardinal()
|
|||
p->addModel(modelAudioFile);
|
||||
p->addModel(modelCarla);
|
||||
p->addModel(modelIldaeil);
|
||||
p->addModel(modelMPV);
|
||||
#else
|
||||
spl.removeModule("AudioFile");
|
||||
spl.removeModule("Carla");
|
||||
spl.removeModule("Ildaeil");
|
||||
spl.removeModule("MPV");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue