Skip to content

Commit 7b1cdde

Browse files
committed
CueSDK support: updating APIs to that of the latest SDK.
1 parent d961909 commit 7b1cdde

File tree

6 files changed

+309
-72
lines changed

6 files changed

+309
-72
lines changed

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/SystemClipboardDemo.h"
3536

3637
#include "components/SettingsComponent.h"
3738
#include "main/DemoLookAndFeel.h"

demo/source/demos/CueSDKDemo.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,46 @@ class CueSDKDemo final : public DemoBase
88
CueSDKDemo (SharedObjects& sharedObjs) :
99
DemoBase (sharedObjs, NEEDS_TRANS ("CueSDK Demo"))
1010
{
11+
auto setupButton = [&] (TextButton& tb, StringRef text, Colour c)
12+
{
13+
constexpr auto id = TextButton::ColourIds::buttonColourId;
14+
15+
tb.setButtonText (text);
16+
tb.setColour (id, c);
17+
tb.onClick = [c]()
18+
{
19+
sp::corsair::updateAllLEDsWithColour (c);
20+
};
21+
22+
addAndMakeVisible (tb);
23+
};
24+
25+
setupButton (redButton, TRANS ("Red"), Colours::red);
26+
setupButton (greenButton, TRANS ("Green"), Colours::green);
27+
setupButton (blueButton, TRANS ("Blue"), Colours::blue);
28+
}
29+
30+
void resized() override
31+
{
32+
constexpr auto marginPx = 4;
33+
constexpr auto barSizePx = marginPx * 8;
34+
35+
auto b = getLocalBounds().reduced (4);
36+
b = b.withHeight (jmin (b.getHeight(), barSizePx));
37+
auto w = (b.getWidth() / 3) - (marginPx * 2);
38+
39+
redButton.setBounds (b.removeFromLeft (w));
40+
b.removeFromLeft (marginPx);
41+
42+
blueButton.setBounds (b.removeFromRight (w));
43+
b.removeFromRight (marginPx);
44+
45+
greenButton.setBounds (b);
1146
}
1247

1348
private:
49+
TextButton redButton, greenButton, blueButton;
50+
1451
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CueSDKDemo)
1552
};
1653

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the JUCE framework examples.
5+
Copyright (c) Raw Material Software Limited
6+
7+
The code included in this file is provided under the terms of the ISC license
8+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
9+
to use, copy, modify, and/or distribute this software for any purpose with or
10+
without fee is hereby granted provided that the above copyright notice and
11+
this permission notice appear in all copies.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19+
PERFORMANCE OF THIS SOFTWARE.
20+
21+
==============================================================================
22+
*/
23+
24+
/*******************************************************************************
25+
The block below describes the properties of this PIP. A PIP is a short snippet
26+
of code that can be read by the Projucer and used to generate a JUCE project.
27+
28+
BEGIN_JUCE_PIP_METADATA
29+
30+
name: SystemClipboardDemo
31+
version: 1.0.0
32+
vendor: JUCE
33+
website: http://juce.com
34+
description: Edit and display the contents of the system's clipboard.
35+
36+
dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
37+
juce_gui_basics
38+
exporters: xcode_mac, vs2022, linux_make, androidstudio, xcode_iphone
39+
40+
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
41+
42+
type: Component
43+
mainClass: SystemClipboardDemo
44+
45+
useLocalCopy: 1
46+
47+
END_JUCE_PIP_METADATA
48+
49+
*******************************************************************************/
50+
51+
#pragma once
52+
53+
#include "../Assets/DemoUtilities.h"
54+
55+
//==============================================================================
56+
class SystemClipboardDemo final : public Component,
57+
private Timer
58+
{
59+
public:
60+
SystemClipboardDemo()
61+
{
62+
typeDetails.setColour (Label::ColourIds::textColourId,
63+
getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText,
64+
Colours::white));
65+
updateText();
66+
addAndMakeVisible (typeDetails);
67+
68+
setOpaque (true);
69+
setSize (750, 650);
70+
startTimer (2000);
71+
}
72+
73+
void paint (Graphics& g) override
74+
{
75+
g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
76+
Colour::greyLevel (0.8f)));
77+
}
78+
79+
void resized() override
80+
{
81+
const auto marginPx = 8;
82+
83+
auto b = getLocalBounds().reduced (marginPx);
84+
85+
typeDetails.setBounds (b.removeFromTop (64));
86+
87+
if (dataViewer != nullptr)
88+
{
89+
b.removeFromTop (marginPx);
90+
dataViewer->setBounds (b);
91+
}
92+
}
93+
94+
void timerCallback() override
95+
{
96+
if (const auto type = SystemClipboard::getDataType(); lastKnownType != type)
97+
{
98+
lastKnownType = type;
99+
updateText();
100+
}
101+
}
102+
103+
private:
104+
Label typeDetails;
105+
std::unique_ptr<Component> dataViewer;
106+
SystemClipboard::Type lastKnownType = SystemClipboard::Type::unknown;
107+
108+
static String toString (SystemClipboard::Type type)
109+
{
110+
switch (type)
111+
{
112+
case SystemClipboard::Type::empty: return TRANS ("(empty)");
113+
case SystemClipboard::Type::unknown: return TRANS ("(unknown)");
114+
case SystemClipboard::Type::text: return TRANS ("Text");
115+
case SystemClipboard::Type::image: return TRANS ("Image");
116+
case SystemClipboard::Type::audioPCM: return TRANS ("Audio (PCM)");
117+
118+
default:
119+
break;
120+
};
121+
122+
jassertfalse; // New type?
123+
return {};
124+
}
125+
126+
void updateText()
127+
{
128+
const auto typeString = TRANS ("Type: {}")
129+
.replace ("{}", toString (lastKnownType));
130+
typeDetails.setText (typeString, sendNotification);
131+
132+
switch (lastKnownType)
133+
{
134+
case SystemClipboard::Type::text:
135+
{
136+
auto te = std::make_unique<TextEditor>();
137+
te->setMultiLine (true);
138+
te->setText (SystemClipboard::getTextFromClipboard());
139+
dataViewer = std::move (te);
140+
}
141+
break;
142+
143+
case SystemClipboard::Type::image:
144+
{
145+
auto ic = std::make_unique<ImageComponent>();
146+
ic->setImage (SystemClipboard::getImageFromClipboard(),
147+
RectanglePlacement::onlyReduceInSize);
148+
dataViewer = std::move (ic);
149+
}
150+
break;
151+
152+
case SystemClipboard::Type::audioPCM:
153+
{
154+
auto te = std::make_unique<TextEditor>();
155+
te->setText ("audio");
156+
dataViewer = std::move (te);
157+
}
158+
break;
159+
160+
default:
161+
dataViewer.reset();
162+
break;
163+
};
164+
165+
if (dataViewer != nullptr)
166+
{
167+
addAndMakeVisible (dataViewer.get());
168+
resized();
169+
}
170+
}
171+
172+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SystemClipboardDemo)
173+
};

demo/source/main/Main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class MainWindow final : public DocumentWindow
100100
centreWithSize (getWidth(), getHeight());
101101
#endif
102102

103+
corsair::logInfo();
104+
103105
setVisible (true);
104106
}
105107

0 commit comments

Comments
 (0)