Skip to content

Commit f95e883

Browse files
committed
Added barebones WinRTRGB.
The idea is that the Win10+ APIs will be wrapped using JUCE.
1 parent 63af719 commit f95e883

File tree

11 files changed

+294
-23
lines changed

11 files changed

+294
-23
lines changed

demo/JuceLibraryCode/AppConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@
382382
#define SQUAREPINE_LOG_OPENGL_INFO 1
383383
#endif
384384

385+
#ifndef SQUAREPINE_USE_WINRTRGB
386+
//#define SQUAREPINE_USE_WINRTRGB 1
387+
#endif
388+
385389
//==============================================================================
386390
#ifndef JUCE_STANDALONE_APPLICATION
387391
#if defined(JucePlugin_Name) && defined(JucePlugin_Build_Standalone)

demo/SquarePineDemo.jucer

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@
5050
<GROUP id="{775B98BE-1BF2-5AF2-2E31-B17D3A9219DD}" name="demos">
5151
<FILE id="o8ngkO" name="CodeEditorDemo.h" compile="0" resource="0"
5252
file="source/demos/CodeEditorDemo.h"/>
53-
<FILE id="brHreQ" name="iCUESDKDemo.h" compile="0" resource="0" file="source/demos/iCUESDKDemo.h"/>
5453
<FILE id="mUqbF6" name="DemoBase.h" compile="0" resource="0" file="source/demos/DemoBase.h"/>
5554
<FILE id="IZHnpO" name="EasingsDemo.h" compile="0" resource="0" file="source/demos/EasingsDemo.h"/>
5655
<FILE id="MTl6Wo" name="EffectChainDemo.cpp" compile="0" resource="0"
5756
file="source/demos/EffectChainDemo.cpp"/>
5857
<FILE id="KagqFb" name="EffectChainDemo.h" compile="0" resource="0"
5958
file="source/demos/EffectChainDemo.h"/>
59+
<FILE id="brHreQ" name="iCUESDKDemo.h" compile="0" resource="0" file="source/demos/iCUESDKDemo.h"/>
6060
<FILE id="vSHEQC" name="ImageDemo.h" compile="0" resource="0" file="source/demos/ImageDemo.h"/>
6161
<FILE id="S1SGkR" name="MediaDeviceListerDemo.h" compile="0" resource="0"
6262
file="source/demos/MediaDeviceListerDemo.h"/>
6363
<FILE id="hoUe5P" name="OpenGLDetailsDemo.h" compile="0" resource="0"
6464
file="source/demos/OpenGLDetailsDemo.h"/>
65+
<FILE id="SVoVfA" name="WinRTRGBDemo.h" compile="0" resource="0" file="source/demos/WinRTRGBDemo.h"/>
6566
</GROUP>
6667
<GROUP id="{B136827C-443D-9F46-D62C-F9F22179369A}" name="main">
6768
<FILE id="rbIntd" name="DemoLookAndFeel.cpp" compile="0" resource="0"

demo/source/MainModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace
3232
#include "demos/ImageDemo.h"
3333
#include "demos/MediaDeviceListerDemo.h"
3434
#include "demos/OpenGLDetailsDemo.h"
35+
#include "demos/WinRTRGBDemo.h"
3536
// #include "demos/SystemClipboardDemo.h"
3637

3738
#include "components/SettingsComponent.h"

demo/source/demos/WinRTRGBDemo.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#if SQUAREPINE_USE_WINRTRGB
2+
3+
/** */
4+
class WinRTRGBDemo final : public DemoBase,
5+
public ListBoxModel,
6+
private Timer
7+
{
8+
public:
9+
/** */
10+
WinRTRGBDemo (SharedObjects& sharedObjs) :
11+
DemoBase (sharedObjs, NEEDS_TRANS ("WinRT RGB Demo"))
12+
{
13+
auto setupButton = [&] (TextButton& tb, StringRef text, Colour c)
14+
{
15+
constexpr auto id = TextButton::ColourIds::buttonColourId;
16+
17+
tb.setButtonText (text);
18+
tb.setColour (id, c);
19+
tb.onClick = [c]()
20+
{
21+
};
22+
23+
addAndMakeVisible (tb);
24+
};
25+
26+
setupButton (redButton, TRANS ("Red"), Colours::red);
27+
setupButton (greenButton, TRANS ("Green"), Colours::green);
28+
setupButton (blueButton, TRANS ("Blue"), Colours::blue);
29+
30+
listbox.setRowHeight (barSizePx);
31+
listbox.setModel (this);
32+
addAndMakeVisible (listbox);
33+
34+
startTimerHz (60);
35+
}
36+
37+
void resized() override
38+
{
39+
auto b = getLocalBounds().reduced (marginPx);
40+
41+
{
42+
auto lb = b.removeFromTop (jmin (b.getHeight(), (int) barSizePx));
43+
auto w = (lb.getWidth() / 3) - (marginPx * 2);
44+
45+
redButton.setBounds (lb.removeFromLeft (w));
46+
lb.removeFromLeft (marginPx);
47+
48+
blueButton.setBounds (lb.removeFromRight (w));
49+
lb.removeFromRight (marginPx);
50+
51+
greenButton.setBounds (lb);
52+
}
53+
54+
b.removeFromTop (marginPx);
55+
listbox.setBounds (b);
56+
}
57+
58+
void timerCallback() override
59+
{
60+
bool changed = false;
61+
62+
auto newDevices = sp::WinRTRGB().getConnectedDevices();
63+
// if (connectedDevices != newDevices)
64+
{
65+
connectedDevices.swapWithArray (newDevices);
66+
changed = true;
67+
}
68+
69+
if (changed)
70+
listbox.updateContent();
71+
72+
repaint(); // For the LEDs.
73+
}
74+
75+
int getNumRows() override { return 0; }
76+
77+
void paintListBoxItem (int rowIndex, Graphics& g, int width, int height, bool) override
78+
{
79+
}
80+
81+
private:
82+
enum
83+
{
84+
pxW = 2,
85+
pxH = 2,
86+
marginPx = 4,
87+
barSizePx = marginPx * 12
88+
};
89+
90+
TextButton redButton, greenButton, blueButton;
91+
ListBox listbox;
92+
Array<WinRTRGB::Device> connectedDevices;
93+
94+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WinRTRGBDemo)
95+
};
96+
97+
#endif // SQUAREPINE_USE_WINRTRGB

demo/source/main/MainComponent.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
inline Rectangle<int> getBoundsAccountingForKeyboard ()
1+
#if SQUAREPINE_IS_MOBILE
2+
3+
inline Rectangle<int> getBoundsAccountingForKeyboard()
24
{
3-
if (auto* display { Desktop::getInstance ().getDisplays ().getPrimaryDisplay () })
5+
if (auto* display = Desktop::getInstance().getDisplays().getPrimaryDisplay())
46
{
5-
auto bounds { display->userArea };
7+
auto bounds = display->userArea;
68

79
// display->safeAreaInsets.subtractFrom (bounds);
810
// display->keyboardInsets.subtractFrom (bounds);
@@ -13,6 +15,8 @@ inline Rectangle<int> getBoundsAccountingForKeyboard ()
1315
return {};
1416
}
1517

18+
#endif
19+
1620
MainComponent::MainComponent (SharedObjects& sharedObjs) :
1721
tabbedComponent (TabbedButtonBar::TabsAtTop)
1822
{
@@ -33,20 +37,30 @@ MainComponent::MainComponent (SharedObjects& sharedObjs) :
3337
addTab (new CueSDKDemo (sharedObjs));
3438
#endif
3539

40+
#if SQUAREPINE_USE_WINRTRGB
41+
addTab (new WinRTRGBDemo (sharedObjs));
42+
#endif
43+
3644
#if SP_DEMO_USE_OPENGL
3745
// Need to call this later on - once JUCE, the GL content, and the OS decide it's cool to talk to each other.
3846
MessageManager::callAsync ([this, ptr = SafePointer (this)]()
3947
{
4048
SQUAREPINE_CRASH_TRACER
4149
if (ptr != nullptr)
42-
rendererConfigurator.configureWithOpenGLIfAvailable (*this, true);
50+
{
51+
rendererConfigurator.configureWithOpenGLIfAvailable (*this);
52+
resized();
53+
}
4354
});
4455

4556
addTab (new OpenGLDetailsDemo (sharedObjs, rendererConfigurator));
4657
#endif // SP_DEMO_USE_OPENGL
4758

4859
tabbedComponent.addTab (TRANS ("Settings"), Colours::grey, new SettingsComponent (sharedObjs), true);
4960

61+
tabbedComponent.setOutline (0);
62+
tabbedComponent.setIndent (0);
63+
5064
addAndMakeVisible (tabbedComponent);
5165

5266
#if SQUAREPINE_IS_DESKTOP
@@ -68,6 +82,8 @@ void MainComponent::paint (Graphics& g)
6882

6983
void MainComponent::resized()
7084
{
85+
SQUAREPINE_CRASH_TRACER
86+
7187
auto b = getLocalBounds();
7288

7389
#if SQUAREPINE_IS_MOBILE
@@ -81,6 +97,8 @@ void MainComponent::resized()
8197

8298
void MainComponent::languageChanged (const IETFLanguageFile&)
8399
{
100+
SQUAREPINE_CRASH_TRACER
101+
84102
for (int i = tabbedComponent.getNumTabs(); --i >= 0;)
85103
if (auto* demoComp = dynamic_cast<DemoBase*> (tabbedComponent.getTabContentComponent (i)))
86104
tabbedComponent.setTabName (i, TRANS (demoComp->getUntranslatedName()));
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#if SQUAREPINE_USE_WINRTRGB
2+
3+
//==============================================================================
4+
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4265)
5+
6+
#include <wrl/wrappers/corewrappers.h>
7+
#include <wrl/client.h>
8+
#include <wrl/event.h>
9+
#include <wrl/async.h>
10+
#include <winrt/Windows.Foundation.h>
11+
#include <winrt/Windows.Foundation.Numerics.h>
12+
#include <winrt/Windows.Foundation.Collections.h>
13+
#include <winrt/Windows.ApplicationModel.Activation.h>
14+
#include <Windows.Devices.Lights.h>
15+
#include <Windows.Devices.Lights.Effects.h>
16+
17+
using namespace Microsoft::WRL;
18+
using namespace Microsoft::WRL::Wrappers;
19+
using namespace ABI::Windows::Foundation;
20+
using namespace ABI::Windows::Devices::Enumeration;
21+
using namespace ABI::Windows::Devices::Lights;
22+
using namespace ABI::Windows::Devices::Lights::Effects;
23+
using namespace ABI::Windows::UI;
24+
25+
#pragma comment (lib, "mincore.lib")
26+
27+
JUCE_END_IGNORE_WARNINGS_MSVC
28+
29+
//==============================================================================
30+
namespace sp
31+
{
32+
using namespace juce;
33+
34+
//==============================================================================
35+
class WinRTRGB::Pimpl
36+
{
37+
public:
38+
Pimpl()
39+
{
40+
findWinRTClass (RuntimeClass_Windows_Devices_Enumeration_DeviceInformation, deviceInfoStatics);
41+
findWinRTClass (RuntimeClass_Windows_Devices_Lights_LampArray, lampArrayStatics);
42+
findWinRTClass (RuntimeClass_Windows_Devices_Lights_Effects_LampArrayCustomEffect, effectFactory);
43+
}
44+
45+
~Pimpl()
46+
{
47+
}
48+
49+
//==============================================================================
50+
51+
private:
52+
//==============================================================================
53+
ComPtr<IDeviceInformationStatics> deviceInfoStatics;
54+
ComPtr<ILampArrayStatics> lampArrayStatics;
55+
ComPtr<ILampArrayCustomEffectFactory> effectFactory;
56+
57+
//==============================================================================
58+
/** Have to set up this circus of a function to gather the various classes
59+
in order to fetch even the most basic details.
60+
61+
WTF MSFT.
62+
*/
63+
template<class ClassName>
64+
bool findWinRTClass (const WCHAR* className, ComPtr<ClassName>& ptrOut)
65+
{
66+
if (const auto hr = GetActivationFactory (HStringReference (className).Get(), &ptrOut); ! SUCCEEDED (hr))
67+
{
68+
jassertfalse;
69+
return false;
70+
}
71+
72+
return true;
73+
}
74+
75+
//==============================================================================
76+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
77+
};
78+
79+
//==============================================================================
80+
WinRTRGB::WinRTRGB() : pimpl (new Pimpl()) {}
81+
WinRTRGB::~WinRTRGB() {}
82+
83+
Array<WinRTRGB::Device> WinRTRGB::getConnectedDevices() const
84+
{
85+
return {};
86+
}
87+
88+
} // namespace sp
89+
90+
#endif // SQUAREPINE_USE_WINRTRGB
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#if SQUAREPINE_USE_WINRTRGB
2+
3+
/** */
4+
class WinRTRGB final
5+
{
6+
public:
7+
/** */
8+
WinRTRGB();
9+
/** */
10+
~WinRTRGB();
11+
12+
//==============================================================================
13+
/** */
14+
struct Device final
15+
{
16+
enum Purpose
17+
{
18+
undefined = 0,
19+
control = 1 << 0,
20+
accent = 1 << 1,
21+
branding = 1 << 2,
22+
status = 1 << 3,
23+
illumination = 1 << 4,
24+
presentation = 1 << 5
25+
};
26+
27+
int index = 0;
28+
Colour colour = Colours::transparentBlack;
29+
Vector3D<float> position;
30+
Purpose purpose = undefined;
31+
};
32+
33+
/** */
34+
[[nodiscard]] Array<Device> getConnectedDevices() const;
35+
36+
private:
37+
//==============================================================================
38+
class Pimpl;
39+
std::unique_ptr<Pimpl> pimpl;
40+
41+
//==============================================================================
42+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WinRTRGB)
43+
};
44+
45+
#endif // SQUAREPINE_USE_WINRTRGB

0 commit comments

Comments
 (0)