Skip to content

Commit 16b596b

Browse files
committed
iCUESDK: Fully supporting the latest SDK and APIs.
The support for the previous SDK has been removed.
1 parent aac8218 commit 16b596b

File tree

12 files changed

+559
-244
lines changed

12 files changed

+559
-244
lines changed

demo/JuceLibraryCode/AppConfig.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// [END_USER_CODE_SECTION]
2222

23-
#define JUCE_PROJUCER_VERSION 0x80001
23+
#define JUCE_PROJUCER_VERSION 0x80002
2424

2525
//==============================================================================
2626
#define JUCE_MODULE_AVAILABLE_juce_analytics 1
@@ -325,7 +325,7 @@
325325
#endif
326326

327327
#ifndef SQUAREPINE_USE_REX_AUDIO_FORMAT
328-
//#define SQUAREPINE_USE_REX_AUDIO_FORMAT 0
328+
#define SQUAREPINE_USE_REX_AUDIO_FORMAT 1
329329
#endif
330330

331331
//==============================================================================
@@ -360,7 +360,7 @@
360360
#endif
361361

362362
#ifndef SQUAREPINE_LOG_GOOGLE_ANALYTICS
363-
//#define SQUAREPINE_LOG_GOOGLE_ANALYTICS 0
363+
#define SQUAREPINE_LOG_GOOGLE_ANALYTICS 1
364364
#endif
365365

366366
#ifndef SQUAREPINE_ONLY_LOG_GOOGLE_ANALYTICS
@@ -374,12 +374,12 @@
374374
//#define SQUAREPINE_USE_AVIR_RESIZER 1
375375
#endif
376376

377-
#ifndef SQUAREPINE_USE_CUESDK
378-
//#define SQUAREPINE_USE_CUESDK 0
377+
#ifndef SQUAREPINE_USE_ICUESDK
378+
#define SQUAREPINE_USE_ICUESDK 1
379379
#endif
380380

381381
#ifndef SQUAREPINE_LOG_OPENGL_INFO
382-
//#define SQUAREPINE_LOG_OPENGL_INFO 0
382+
#define SQUAREPINE_LOG_OPENGL_INFO 1
383383
#endif
384384

385385
//==============================================================================

demo/SquarePineDemo.jucer

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
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="CueSDKDemo.h" compile="0" resource="0" file="source/demos/CueSDKDemo.h"/>
53+
<FILE id="brHreQ" name="iCUESDKDemo.h" compile="0" resource="0" file="source/demos/iCUESDKDemo.h"/>
5454
<FILE id="mUqbF6" name="DemoBase.h" compile="0" resource="0" file="source/demos/DemoBase.h"/>
5555
<FILE id="IZHnpO" name="EasingsDemo.h" compile="0" resource="0" file="source/demos/EasingsDemo.h"/>
5656
<FILE id="MTl6Wo" name="EffectChainDemo.cpp" compile="0" resource="0"
@@ -80,7 +80,9 @@
8080
<JUCEOPTIONS JUCE_STRICT_REFCOUNTEDPOINTER="1" JUCE_USE_CAMERA="1" JUCE_USE_WINRT_MIDI="1"
8181
JUCE_USE_MP3AUDIOFORMAT="1" JUCE_USE_LAME_AUDIO_FORMAT="1" JUCE_PLUGINHOST_VST3="1"
8282
JUCE_PLUGINHOST_AU="1" JUCE_PLUGINHOST_LADSPA="1" JUCE_USE_WIN_WEBVIEW2="1"
83-
SQUAREPINE_COMPILE_UNIT_TESTS="1"/>
83+
SQUAREPINE_COMPILE_UNIT_TESTS="1" SQUAREPINE_LOG_GOOGLE_ANALYTICS="1"
84+
SQUAREPINE_USE_REX_AUDIO_FORMAT="1" SQUAREPINE_USE_ICUESDK="1"
85+
SQUAREPINE_LOG_OPENGL_INFO="1"/>
8486
<EXPORTFORMATS>
8587
<ANDROIDSTUDIO targetFolder="builds/android" smallIcon="jqPxuh" bigIcon="jqPxuh"
8688
androidAdditionalResourceFolders="assets/Android/res" androidTheme="@style/ActivityTheme"
@@ -160,9 +162,11 @@
160162
</LINUX_MAKE>
161163
<VS2022 targetFolder="builds/vs2022" smallIcon="jqPxuh" bigIcon="jqPxuh">
162164
<CONFIGURATIONS>
163-
<CONFIGURATION isDebug="1" name="Debug" targetName="SquarePine Demo"/>
165+
<CONFIGURATION isDebug="1" name="Debug" targetName="SquarePine Demo" headerPath="C:\Users\joelr\Downloads\iCUESDK_4.0.84\"
166+
libraryPath="C:\Users\joelr\Downloads\iCUESDK_4.0.84\"/>
164167
<CONFIGURATION isDebug="0" name="Release" targetName="SquarePine Demo" characterSet="Unicode"
165-
useRuntimeLibDLL="0" linkTimeOptimisation="1"/>
168+
useRuntimeLibDLL="0" linkTimeOptimisation="1" headerPath="C:\Users\joelr\Downloads\iCUESDK_4.0.84\"
169+
libraryPath="C:\Users\joelr\Downloads\iCUESDK_4.0.84\"/>
166170
<CONFIGURATION isDebug="1" name="Debug" targetName="SquarePine Demo" winArchitecture="ARM64"/>
167171
<CONFIGURATION isDebug="0" name="Release" targetName="SquarePine Demo" characterSet="Unicode"
168172
useRuntimeLibDLL="0" winArchitecture="ARM64" linkTimeOptimisation="1"/>

demo/source/MainModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace
2626

2727
#include "demos/DemoBase.h"
2828
#include "demos/CodeEditorDemo.h"
29-
#include "demos/CueSDKDemo.h"
29+
#include "demos/iCUESDKDemo.h"
3030
#include "demos/EasingsDemo.h"
3131
#include "demos/EffectChainDemo.h"
3232
#include "demos/ImageDemo.h"

demo/source/demos/CueSDKDemo.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

demo/source/demos/iCUESDKDemo.h

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#if SQUAREPINE_USE_ICUESDK
2+
3+
/** */
4+
class CueSDKDemo final : public DemoBase,
5+
public ListBoxModel,
6+
private Timer
7+
{
8+
public:
9+
/** */
10+
CueSDKDemo (SharedObjects& sharedObjs) :
11+
DemoBase (sharedObjs, NEEDS_TRANS ("iCUESDK 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+
corsair::updateAllLEDsWithColour (c);
22+
};
23+
24+
addAndMakeVisible (tb);
25+
};
26+
27+
setupButton (redButton, TRANS ("Red"), Colours::red);
28+
setupButton (greenButton, TRANS ("Green"), Colours::green);
29+
setupButton (blueButton, TRANS ("Blue"), Colours::blue);
30+
31+
listbox.setRowHeight (barSizePx);
32+
listbox.setModel (this);
33+
addAndMakeVisible (listbox);
34+
35+
startTimerHz (60);
36+
}
37+
38+
void resized() override
39+
{
40+
auto b = getLocalBounds().reduced (marginPx);
41+
42+
{
43+
auto lb = b.removeFromTop (jmin (b.getHeight(), (int) barSizePx));
44+
auto w = (lb.getWidth() / 3) - (marginPx * 2);
45+
46+
redButton.setBounds (lb.removeFromLeft (w));
47+
lb.removeFromLeft (marginPx);
48+
49+
blueButton.setBounds (lb.removeFromRight (w));
50+
lb.removeFromRight (marginPx);
51+
52+
greenButton.setBounds (lb);
53+
}
54+
55+
b.removeFromTop (marginPx);
56+
listbox.setBounds (b);
57+
}
58+
59+
void timerCallback() override
60+
{
61+
const auto newDevs = corsair::getAllAvailableDevices();
62+
63+
bool changed = false;
64+
65+
// Remove disconnected devices:
66+
for (int i = devices.size(); --i >= 0;)
67+
{
68+
auto* device = devices.getUnchecked (i);
69+
const String id (device->deviceInfo.id);
70+
71+
bool found = false;
72+
for (const auto& newDevice : newDevs)
73+
{
74+
if (id == String (newDevice.id))
75+
{
76+
found = true;
77+
break;
78+
}
79+
}
80+
81+
if (! found)
82+
{
83+
device = nullptr;
84+
devices.remove (i);
85+
changed = true;
86+
}
87+
}
88+
89+
// Add new devices:
90+
for (const auto& newDevice : newDevs)
91+
{
92+
const String id (newDevice.id);
93+
94+
bool found = false;
95+
for (const auto& originalDevice : devices)
96+
{
97+
if (id == String (originalDevice->deviceInfo.id))
98+
{
99+
found = true;
100+
break;
101+
}
102+
}
103+
104+
if (! found)
105+
{
106+
auto* ledData = devices.add (new LEDData());
107+
ledData->deviceInfo = newDevice;
108+
ledData->ledPositions = corsair::getLEDIDs (ledData->deviceInfo);
109+
changed = true;
110+
}
111+
}
112+
113+
if (changed)
114+
listbox.updateContent();
115+
116+
repaint(); // For the LEDs.
117+
}
118+
119+
int getNumRows() override { return devices.size(); }
120+
121+
void paintListBoxItem (int rowIndex, Graphics& g, int width, int height, bool) override
122+
{
123+
auto* device = devices[rowIndex];
124+
if (device == nullptr || width <= 1 || height <= 1)
125+
return;
126+
127+
juce::Rectangle<int> area (width, height);
128+
area = area.reduced (marginPx);
129+
130+
g.setColour (Colours::white);
131+
132+
const auto text = [&]()
133+
{
134+
auto s = String (device->deviceInfo.model);
135+
s << newLine << corsair::toString (device->deviceInfo.type);
136+
137+
if (device->isConnected())
138+
s << newLine << "serial: " + String (device->deviceInfo.serial);
139+
140+
return s;
141+
}();
142+
143+
g.drawFittedText (text, area.removeFromLeft (128 * 3), Justification::centredLeft, 3, 1.0f);
144+
145+
if (device->isConnected())
146+
{
147+
device->ledColours = corsair::getLEDColours (device->deviceInfo.id, device->ledPositions);
148+
if (device->ledColours.isEmpty())
149+
return;
150+
151+
const auto numPx = device->ledColours.size();
152+
const auto pxPerRow = area.getWidth() / (pxW * 2); // the *2 is for the tiny margin
153+
const auto numRows = (int) std::ceil ((double) numPx / (double) pxPerRow);
154+
155+
for (int i = 0; i < numPx; ++i)
156+
{
157+
auto column = area.removeFromLeft (pxW);
158+
159+
for (int f = 0; f < numRows; ++f)
160+
{
161+
const auto colourIndex = (i % pxPerRow) + (f * pxPerRow);
162+
163+
if (colourIndex >= numPx)
164+
break;
165+
166+
g.setColour (device->getColourUnchecked (colourIndex));
167+
168+
g.fillRect (column.removeFromTop (pxH));
169+
column.removeFromTop (pxH); // Tiny row margin
170+
}
171+
172+
// Tiny column margin:
173+
area.removeFromLeft (pxW);
174+
}
175+
}
176+
}
177+
178+
private:
179+
enum
180+
{
181+
pxW = 2,
182+
pxH = 2,
183+
marginPx = 4,
184+
barSizePx = marginPx * 12
185+
};
186+
187+
struct LEDData final
188+
{
189+
bool isConnected() const
190+
{
191+
return corsair::isConnected (deviceInfo);
192+
}
193+
194+
Colour getColourUnchecked (int index) const
195+
{
196+
return corsair::toColour (ledColours.getReference (index));
197+
}
198+
199+
corsair::CorsairDeviceInfo deviceInfo;
200+
Array<corsair::CorsairLedPosition> ledPositions;
201+
Array<corsair::CorsairLedColor> ledColours;
202+
};
203+
204+
OwnedArray<LEDData> devices;
205+
TextButton redButton, greenButton, blueButton;
206+
ListBox listbox;
207+
208+
Grid pixelGrid;
209+
210+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CueSDKDemo)
211+
};
212+
213+
#endif // SQUAREPINE_USE_ICUESDK

demo/source/main/MainComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MainComponent::MainComponent (SharedObjects& sharedObjs) :
2929
addTab (new CodeEditorDemo (sharedObjs));
3030
addTab (new MediaDeviceListerDemo (sharedObjs));
3131

32-
#if SQUAREPINE_USE_CUESDK
32+
#if SQUAREPINE_USE_ICUESDK
3333
addTab (new CueSDKDemo (sharedObjs));
3434
#endif
3535

0 commit comments

Comments
 (0)