-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProDJLinkInput.h
More file actions
2777 lines (2497 loc) · 124 KB
/
ProDJLinkInput.h
File metadata and controls
2777 lines (2497 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Super Timecode Converter
// Copyright (c) 2026 Fiverecords -- MIT License
// https://github.com/fiverecords/SuperTimecodeConverter
//
// ProDJLinkInput -- Direct Pro DJ Link protocol implementation.
//
// Connects natively to Pioneer CDJ/XDJ/DJM hardware without requiring
// PRO DJ LINK Bridge or third-party software. Creates a Virtual CDJ on the
// network and receives player state, beat, and position data directly
// from the players.
//
// Position sources:
// CDJ-3000: Absolute Position packets (type 0x0b, 30Hz, ms precision)
// NXS2/older: Beat-derived from status (beatCount x 60000/BPM, ~5Hz)
//
// Phase 1: UDP monitoring + Dual-keepalive bridge
// - Bridge join sequence: hello 0x0A (player=5) -> IP claim 0x02 (player=0xC0)
// - Two keepalives sent in parallel:
// 1) 54B BROADCAST (player=0xC1) -- DJM discovers bridge, activates fader delivery
// 2) 95B UNICAST to each CDJ (player=5, PIONEER DJ CORP strings) -- CDJ registers
// us as a valid peer and sends AbsPos/Status unicast data
// - The DJM NEVER receives the 95B (it's unicast to CDJ IPs only)
// -> DJM sees single identity (0xC1) -> faders work
// - The CDJ sees both, but both are from the same bridge -> no conflict
// - Sends type-0x57 subscribe to each DJM (port 50001)
// -> triggers DJM to send type-0x39 mixer fader packets
// - Sends type-0x55 bridge notify to each CDJ (port 50002)
// - Player discovery via keepalive packets (port 50000)
// - Beat packets with BPM/pitch/beat info (port 50001)
// - Absolute Position from CDJ-3000 (port 50001, type 0x0b)
// - CDJ status: track ID, play state, pitch (port 50002)
// - DJM on-air broadcast (port 50001, type 0x03)
// - DJM on-air unicast (type 0x29, handled on both 50001 & 50002)
// - DJM mixer fader data (type 0x39, handled on both 50001 & 50002)
// - Timecode derived from playhead position in ms
//
// Protocol analysis: Deep Symmetry "DJ Link Ecosystem Analysis"
// https://djl-analysis.deepsymmetry.org/djl-analysis/
// Reference impl: python-prodj-link (flesniak, Apache-2.0)
// https://github.com/flesniak/python-prodj-link
#pragma once
#include <JuceHeader.h>
#include "TimecodeCore.h"
#include "NetworkUtils.h"
#include <atomic>
#include <array>
#include <cstring>
#ifdef _WIN32
// Windows includes pulled in by JuceHeader (iphlpapi etc.)
#elif defined(__APPLE__)
#include <ifaddrs.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <sys/socket.h> // SO_BROADCAST setsockopt
#elif defined(__linux__)
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <sys/socket.h> // SO_BROADCAST setsockopt
#endif
//==============================================================================
// Protocol constants
//==============================================================================
namespace ProDJLink
{
// Magic header for all Pro DJ Link UDP packets
static constexpr char kMagic[11] = "Qspt1WmJOL"; // 10 bytes + null
static constexpr int kMagicLen = 10;
// UDP ports
static constexpr int kKeepalivePort = 50000;
static constexpr int kBeatPort = 50001;
static constexpr int kStatusPort = 50002;
// Keepalive packet types (byte 10)
static constexpr uint8_t kKeepAliveTypeHello = 0x0a;
static constexpr uint8_t kKeepAliveTypeIP = 0x02;
static constexpr uint8_t kKeepAliveTypeStatus = 0x06;
// Beat packet types (byte 10)
static constexpr uint8_t kBeatTypeBeat = 0x28;
static constexpr uint8_t kBeatTypeAbsPosition = 0x0b;
static constexpr uint8_t kBeatTypeMixer = 0x03;
// Status packet types (byte 10)
static constexpr uint8_t kStatusTypeCDJ = 0x0a;
static constexpr uint8_t kStatusTypeMixer = 0x39; // DJM fader status (unicast, bridge-triggered)
static constexpr uint8_t kStatusTypeDJM = 0x29; // DJM channel on-air status (unicast, bridge-triggered)
static constexpr uint8_t kStatusTypeVU = 0x58; // DJM VU meter data (unicast, 524B, port 50001)
// Play states (from status packet, bytes 120-123)
static constexpr uint32_t kPlayNoTrack = 0x00;
static constexpr uint32_t kPlayLoading = 0x02;
static constexpr uint32_t kPlayPlaying = 0x03;
static constexpr uint32_t kPlayLooping = 0x04;
static constexpr uint32_t kPlayPaused = 0x05;
static constexpr uint32_t kPlayCued = 0x06;
static constexpr uint32_t kPlayCueing = 0x07;
static constexpr uint32_t kPlaySeeking = 0x09;
static constexpr uint32_t kPlayEndTrack = 0x11;
static constexpr uint32_t kPlayEmergency = 0x12;
// Maximum supported players (CDJ-3000 supports channels 1-6)
static constexpr int kMaxPlayers = 6;
// Maximum mixer channels (DJM-V10 has 6, DJM-900NXS2 has 4)
static constexpr int kMaxMixerChannels = 6;
// VU meter indices: channels first, then master L/R
static constexpr int kVuMasterL = kMaxMixerChannels; // index 6
static constexpr int kVuMasterR = kMaxMixerChannels + 1; // index 7
static constexpr int kVuSlots = kMaxMixerChannels + 2; // 8 total
// Device type bytes (byte [33] in keepalive packets) -- confirmed from captures:
// 0x01 = bridge / lighting controller
// 0x02 = DJM mixer (player_number >= 0x21)
// 0x03 = CDJ / XDJ player (player_number 1-6)
static constexpr uint8_t kDeviceTypeBridge = 0x01;
static constexpr uint8_t kDeviceTypeMixer = 0x02; // DJM: device_type=0x02, pn >= 0x21
static constexpr uint8_t kMixerPlayerNumMin = 0x21; // DJM player numbers start at 33
// Virtual CDJ defaults
// Player 5 is used as bridge slot -- does NOT occupy CDJ slots 1-4.
// The CDJ-3000 grants dbserver access to player 5 when the 95-byte
// keepalive includes the Pioneer bridge identification strings.
static constexpr int kDefaultVCDJNumber = 5;
static constexpr double kKeepaliveInterval = 1.5; // seconds
static constexpr double kBridgeSubInterval = 2.0; // seconds between 0x57 re-subscriptions (DJM requires ~2s keepalive)
// Bridge subscription
static constexpr uint8_t kBridgeSubType = 0x57; // mixer subscribe packet type
//==========================================================================
// Byte-level helpers (big-endian)
//==========================================================================
inline uint16_t readU16BE(const uint8_t* p) { return (uint16_t(p[0]) << 8) | p[1]; }
inline uint32_t readU32BE(const uint8_t* p) { return (uint32_t(p[0]) << 24) | (uint32_t(p[1]) << 16)
| (uint32_t(p[2]) << 8) | p[3]; }
inline void writeU16BE(uint8_t* p, uint16_t v) { p[0] = uint8_t(v >> 8); p[1] = uint8_t(v); }
inline void writeU32BE(uint8_t* p, uint32_t v) { p[0] = uint8_t(v >> 24); p[1] = uint8_t(v >> 16);
p[2] = uint8_t(v >> 8); p[3] = uint8_t(v); }
//==========================================================================
// Convert pitch field from protocol value to multiplier
// Status packets: pitch / 0x100000 (e.g. 0x100000 = 1.0 = 0%)
// Abs position: pitch / 100 (e.g. 100 = 1.0 = 0%)
//==========================================================================
inline double pitchFromStatus(uint32_t raw) { return double(raw) / double(0x100000); }
//==========================================================================
// Convert playhead position (ms) to SMPTE Timecode
//==========================================================================
inline Timecode playheadToTimecode(uint32_t playheadMs, FrameRate fps)
{
return wallClockToTimecode(double(playheadMs), fps);
}
//==========================================================================
// Play state to human-readable string
//==========================================================================
inline const char* playStateToString(uint32_t ps)
{
switch (ps)
{
case kPlayNoTrack: return "NO TRACK";
case kPlayLoading: return "LOADING";
case kPlayPlaying: return "PLAYING";
case kPlayLooping: return "LOOPING";
case kPlayPaused: return "PAUSED";
case kPlayCued: return "CUE";
case kPlayCueing: return "CUE PLAY";
case kPlaySeeking: return "SEEKING";
case kPlayEndTrack: return "END";
case kPlayEmergency: return "EMERGENCY";
default: return "UNKNOWN";
}
}
}
//==============================================================================
// Per-player state -- atomics for cross-thread access
//==============================================================================
struct ProDJLinkPlayerState
{
// Identity (set once on discovery, read-only after)
std::atomic<bool> discovered { false };
std::atomic<uint8_t> playerNumber { 0 };
char model[21] {}; // null-terminated, written once
char ipStr[16] {}; // "x.x.x.x", written once
uint8_t macAddr[6] {}; // written once
// Timing -- from Absolute Position packets (CDJ-3000, every 30ms)
// or beat-derived (NXS2: beatCount * 60000 / BPM, from status packets ~5Hz)
std::atomic<uint32_t> playheadMs { 0 }; // position in track (ms)
std::atomic<uint32_t> trackLenSec { 0 }; // track length (seconds)
std::atomic<bool> hasAbsolutePosition { false }; // CDJ-3000: native ms playhead
std::atomic<bool> hasBeatDerivedPosition { false }; // NXS2: computed from beatCount+BPM
// From beat packets
std::atomic<uint32_t> bpmRaw { 0 }; // BPM x 100 (from beat) or x10 (from abs pos)
std::atomic<uint32_t> pitchRaw { 0x100000 }; // fader pitch multiplier raw (offset 140)
std::atomic<uint32_t> actualSpeedRaw { 0 }; // real playback speed raw (offset 152)
// Includes motor ramp -- 0 when stopped,
// ramps 0->0x100000 during play start,
// ramps 0x100000->0 during pause.
std::atomic<uint8_t> beatInBar { 1 }; // 1-4
// From status packets
std::atomic<uint32_t> trackId { 0 }; // rekordbox database ID
std::atomic<uint32_t> playState { 0 }; // ProDJLink::kPlay* enum
std::atomic<uint32_t> beatCount { 0 }; // beat counter
std::atomic<uint8_t> loadedPlayer { 0 }; // player where track was loaded from
std::atomic<uint8_t> loadedSlot { 0 }; // 0=empty, 2=SD, 3=USB
std::atomic<bool> isMaster { false };
std::atomic<bool> isOnAir { false };
std::atomic<bool> isPlaying { false }; // derived from state flags
// Track change detection
std::atomic<uint32_t> trackVersion { 0 }; // incremented on track change
// Timing
std::atomic<double> lastPacketTime { 0.0 }; // juce::Time::getMillisecondCounterHiRes()
std::atomic<double> absPositionTs { 0.0 }; // timestamp of last abs position (for interpolation)
void reset()
{
// Store discovered=false FIRST with release ordering.
// UI-thread getters check discovered with acquire ordering --
// release guarantees they see discovered=false before we zero
// the non-atomic fields (model, ipStr, macAddr).
discovered.store(false, std::memory_order_release);
playerNumber.store(0, std::memory_order_relaxed);
std::memset(model, 0, sizeof(model));
std::memset(ipStr, 0, sizeof(ipStr));
std::memset(macAddr, 0, sizeof(macAddr));
playheadMs.store(0, std::memory_order_relaxed);
trackLenSec.store(0, std::memory_order_relaxed);
hasAbsolutePosition.store(false, std::memory_order_relaxed);
hasBeatDerivedPosition.store(false, std::memory_order_relaxed);
bpmRaw.store(0, std::memory_order_relaxed);
pitchRaw.store(0x100000, std::memory_order_relaxed);
actualSpeedRaw.store(0, std::memory_order_relaxed);
beatInBar.store(1, std::memory_order_relaxed);
trackId.store(0, std::memory_order_relaxed);
playState.store(0, std::memory_order_relaxed);
beatCount.store(0, std::memory_order_relaxed);
loadedPlayer.store(0, std::memory_order_relaxed);
loadedSlot.store(0, std::memory_order_relaxed);
isMaster.store(false, std::memory_order_relaxed);
isOnAir.store(false, std::memory_order_relaxed);
isPlaying.store(false, std::memory_order_relaxed);
trackVersion.store(0, std::memory_order_relaxed);
lastPacketTime.store(0.0, std::memory_order_relaxed);
absPositionTs.store(0.0, std::memory_order_relaxed);
}
};
//==============================================================================
// ProDJLinkInput -- main network handler
//==============================================================================
class ProDJLinkInput : public juce::Thread
{
public:
//--------------------------------------------------------------------------
// TrackInfo -- per-player track metadata
//--------------------------------------------------------------------------
struct TrackInfo
{
juce::String artist;
juce::String title;
};
//--------------------------------------------------------------------------
ProDJLinkInput()
: Thread("ProDJLink Input")
{
for (auto& p : players) p.reset();
}
~ProDJLinkInput() override
{
stop();
}
//==========================================================================
// Network interface management
//==========================================================================
void refreshNetworkInterfaces()
{
availableInterfaces = ::getNetworkInterfaces();
}
juce::StringArray getInterfaceNames() const
{
juce::StringArray names;
for (auto& ni : availableInterfaces)
names.add(ni.name + " (" + ni.ip + ")");
return names;
}
int getInterfaceCount() const { return availableInterfaces.size(); }
juce::String getBindInfo() const
{
return bindIp;
}
//==========================================================================
// Start / Stop
//==========================================================================
bool start(int interfaceIndex = 0)
{
if (isRunningFlag.load(std::memory_order_relaxed))
return true;
refreshNetworkInterfaces();
if (availableInterfaces.isEmpty())
{
DBG("ProDJLink: No network interfaces available");
return false;
}
int idx = juce::jlimit(0, availableInterfaces.size() - 1, interfaceIndex);
selectedInterface = idx;
const auto& iface = availableInterfaces[idx];
bindIp = iface.ip;
broadcastIp = iface.broadcast;
subnetMask = iface.subnet;
// Parse our own IP and MAC for keepalive packets
parseIpString(iface.ip, ownIpBytes);
// Get MAC address for this interface
if (!getMacAddress(iface.name, ownMacBytes, iface.ip))
{
// Fallback: use a plausible MAC
std::memset(ownMacBytes, 0, 6);
ownMacBytes[0] = 0x02; // locally administered
ownMacBytes[5] = uint8_t(vCDJPlayerNumber);
}
// --- Create sockets ---
// IMPORTANT: beatSock and statusSock must NOT use setEnablePortReuse().
// On macOS, JUCE's setEnablePortReuse(true) enables SO_REUSEPORT, which
// tells the kernel to distribute incoming packets among ALL sockets bound
// to the same port. If a previous STC instance didn't close cleanly, or
// another Pro DJ Link app (Bridge, rekordbox) has a socket on port 50001,
// the kernel splits packets between them -- causing packet reordering and
// stale playhead values that appear as timecode fluctuation.
//
// beatSock, statusSock, and bridgeSock bind to bindIp to ensure packets
// go out the correct NIC and to receive only from the selected interface.
//
// keepaliveSock binding is PLATFORM-SPECIFIC:
// Windows: bind to bindIp. On multi-adapter systems (two NICs on the
// same subnet), INADDR_ANY lets the OS routing table pick the outgoing
// interface for broadcasts -- which may be the wrong one. The DJM sees
// the keepalive arriving from a different MAC than the payload and
// rejects the bridge identity.
// macOS: bind to INADDR_ANY. macOS does NOT deliver broadcast packets
// to sockets bound to a specific IP -- only to INADDR_ANY. Without
// broadcast reception on port 50000, no CDJ or DJM keepalives arrive
// and device discovery fails completely.
// keepaliveSock keeps SO_REUSEPORT for coexistence with other Pro DJ Link
// software on port 50000.
keepaliveSock = std::make_unique<juce::DatagramSocket>(true);
keepaliveSock->setEnablePortReuse(true);
#ifdef _WIN32
// Windows: bind to specific interface to force correct outgoing NIC
if (!keepaliveSock->bindToPort(ProDJLink::kKeepalivePort, bindIp)
&& !keepaliveSock->bindToPort(ProDJLink::kKeepalivePort))
#else
// macOS/Linux: INADDR_ANY required for broadcast reception
if (!keepaliveSock->bindToPort(ProDJLink::kKeepalivePort))
#endif
{
DBG("ProDJLink: Failed to bind keepalive socket to port " << ProDJLink::kKeepalivePort);
keepaliveSock = nullptr;
return false;
}
ensureSoBroadcast(keepaliveSock.get(), "keepalive");
beatSock = std::make_unique<juce::DatagramSocket>(true);
// NO setEnablePortReuse -- see comment above
if (!beatSock->bindToPort(ProDJLink::kBeatPort, bindIp)
&& !beatSock->bindToPort(ProDJLink::kBeatPort)) // fallback to INADDR_ANY
{
DBG("ProDJLink: WARNING -- Failed to bind beat socket to port " << ProDJLink::kBeatPort
<< " (beat sync unavailable, but status/keepalive will work)");
beatSock = nullptr; // non-fatal: continue without beat data
}
if (beatSock) ensureSoBroadcast(beatSock.get(), "beat");
statusSock = std::make_unique<juce::DatagramSocket>(false);
// NO setEnablePortReuse -- see comment above
if (!statusSock->bindToPort(ProDJLink::kStatusPort, bindIp)
&& !statusSock->bindToPort(ProDJLink::kStatusPort)) // fallback to INADDR_ANY
{
DBG("ProDJLink: Failed to bind status socket to port " << ProDJLink::kStatusPort);
keepaliveSock = nullptr;
beatSock = nullptr;
statusSock = nullptr;
return false;
}
// Extra send-only socket on ephemeral port for 0x57 subscribe / 0x55 notify.
// Pioneer Bridge uses a separate port (~50006) for these; some DJM firmware
// ignores subscribes whose source port matches a well-known ProDJLink port.
// Non-fatal: if it fails, subscribe/notify still go via beatSock/statusSock.
bridgeSock = std::make_unique<juce::DatagramSocket>(false);
if (!bridgeSock->bindToPort(0, bindIp) && !bridgeSock->bindToPort(0))
{
DBG("ProDJLink: bridgeSock creation failed (non-fatal)");
bridgeSock = nullptr;
}
// Reset player states
for (auto& p : players)
p.reset();
isRunningFlag.store(true, std::memory_order_release);
startThread(juce::Thread::Priority::high);
return true;
}
void stop()
{
isRunningFlag.store(false, std::memory_order_release);
if (keepaliveSock) keepaliveSock->shutdown();
if (beatSock) beatSock->shutdown();
if (statusSock) statusSock->shutdown();
if (bridgeSock) bridgeSock->shutdown();
stopThread(2000);
keepaliveSock = nullptr;
beatSock = nullptr;
statusSock = nullptr;
bridgeSock = nullptr;
vCDJPlayerNumber = ProDJLink::kDefaultVCDJNumber;
joinCompleted.store(false, std::memory_order_release);
{ const juce::ScopedLock sl(djmIpLock); djmIps.clear(); djmModels.clear(); djmLastSeen.clear(); }
// Reset mixer state + packet counters for clean restart
hasMixerData.store(false, std::memory_order_relaxed);
lastMixerPacketTime.store(0.0, std::memory_order_relaxed);
for (auto& f : mixerFader) f.store(255, std::memory_order_relaxed);
mixerCrossfader.store(128, std::memory_order_relaxed);
mixerMasterFader.store(255, std::memory_order_relaxed);
hasVuData.store(false, std::memory_order_relaxed);
lastVuPacketTime.store(0.0, std::memory_order_relaxed);
pktCountKeepalive.store(0, std::memory_order_relaxed);
pktCountBeat.store(0, std::memory_order_relaxed);
pktCountAbsPos.store(0, std::memory_order_relaxed);
pktCountStatus.store(0, std::memory_order_relaxed);
pktCountMixer.store(0, std::memory_order_relaxed);
pktCountVU.store(0, std::memory_order_relaxed);
pktCountDJMStatus.store(0, std::memory_order_relaxed);
}
//==========================================================================
// Virtual CDJ configuration
//==========================================================================
int getVCDJPlayerNumber() const { return vCDJPlayerNumber; }
void setVCDJPlayerNumber(int n) { vCDJPlayerNumber = juce::jlimit(1, 127, n); }
//==========================================================================
// Query API -- per-player state accessors for TimecodeEngine
//==========================================================================
/// Is the network thread running?
bool getIsRunning() const { return isRunningFlag.load(std::memory_order_acquire); }
int getSelectedInterface() const { return selectedInterface; }
/// Are we receiving packets from any player?
bool isReceiving() const
{
double now = juce::Time::getMillisecondCounterHiRes();
for (int i = 0; i < ProDJLink::kMaxPlayers; ++i)
{
if (players[i].discovered.load(std::memory_order_relaxed))
{
double last = players[i].lastPacketTime.load(std::memory_order_relaxed);
if ((now - last) < 5000.0)
return true;
}
}
return false;
}
/// Get timecode for a given player (1-based player number).
/// CDJ-3000: converts absolute playhead (ms) to SMPTE timecode.
/// NXS2/older: converts beat-derived playhead (beatCount x 60000/BPM) to SMPTE.
/// Raw timecode from CDJ playhead (no smoothing -- use engine PLL for output).
Timecode getCurrentTimecode(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers)
return {};
const auto& p = players[idx];
if (!p.discovered.load(std::memory_order_relaxed))
return {};
uint32_t baseMs = p.playheadMs.load(std::memory_order_relaxed);
FrameRate fps = outputFps.load(std::memory_order_relaxed);
return ProDJLink::playheadToTimecode(baseMs, fps);
}
/// Get detected frame rate. ProDJLink doesn't transmit frame rate,
/// so this returns the user-configured output rate.
FrameRate getDetectedFrameRate(int /*playerNum*/) const
{
return outputFps.load(std::memory_order_relaxed);
}
void setOutputFrameRate(FrameRate fps)
{
outputFps.store(fps, std::memory_order_relaxed);
}
/// Name of the master player (if any)
juce::String getMasterNodeName() const
{
for (int i = 0; i < ProDJLink::kMaxPlayers; ++i)
{
if (players[i].discovered.load(std::memory_order_acquire)
&& players[i].isMaster.load(std::memory_order_relaxed))
{
return juce::String(players[i].model) + " #"
+ juce::String((int)players[i].playerNumber.load(std::memory_order_relaxed));
}
}
return {};
}
/// Returns the player number (1-6) of the current master, or 0 if no master.
int getMasterPlayerNumber() const
{
for (int i = 0; i < ProDJLink::kMaxPlayers; ++i)
{
if (players[i].discovered.load(std::memory_order_acquire)
&& players[i].isMaster.load(std::memory_order_relaxed))
return (int)players[i].playerNumber.load(std::memory_order_relaxed);
}
return 0;
}
/// Returns the BPM of the current master player, or 0.0 if no master.
double getMasterBPM() const
{
int master = getMasterPlayerNumber();
return (master > 0) ? getBPM(master) : 0.0;
}
/// Does this player have usable timecode data?
/// CDJ-3000: absolute position packets provide ms playhead directly.
/// NXS2/older: position derived from beatCount x (60000/BPM) in status packets.
bool hasTimecodeData(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return false;
const auto& p = players[idx];
return p.discovered.load(std::memory_order_relaxed)
&& (p.hasAbsolutePosition.load(std::memory_order_relaxed)
|| p.hasBeatDerivedPosition.load(std::memory_order_relaxed))
&& p.trackId.load(std::memory_order_relaxed) != 0;
}
/// Is the player's playhead actively advancing?
bool isPositionMoving(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return false;
uint32_t ps = players[idx].playState.load(std::memory_order_relaxed);
return ps == ProDJLink::kPlayPlaying
|| ps == ProDJLink::kPlayLooping
|| ps == ProDJLink::kPlayCueing;
}
/// Get play state as uint8 (for status display)
uint8_t getLayerPlayState(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0;
uint32_t ps = players[idx].playState.load(std::memory_order_relaxed);
// Map to simplified state for display
switch (ps)
{
case ProDJLink::kPlayPlaying:
case ProDJLink::kPlayLooping:
case ProDJLink::kPlayCueing: return 1; // playing
case ProDJLink::kPlayPaused:
case ProDJLink::kPlayCued: return 2; // paused/cued
default: return 0; // idle
}
}
/// Get the play state string for display
juce::String getPlayStateString(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return "?";
return ProDJLink::playStateToString(
players[idx].playState.load(std::memory_order_relaxed));
}
/// True if player has reached end of track (CDJ reports playState 0x11).
/// In this state, actualSpeed freezes at the last playing value and
/// never ramps to zero -- unlike pause where actualSpeed decelerates.
bool isEndOfTrack(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return false;
return players[idx].playState.load(std::memory_order_relaxed)
== ProDJLink::kPlayEndTrack;
}
/// Track ID (rekordbox database ID)
uint32_t getTrackID(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0;
return players[idx].trackId.load(std::memory_order_relaxed);
}
/// Track version -- incremented each time the track changes
uint32_t getTrackVersion(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0;
return players[idx].trackVersion.load(std::memory_order_relaxed);
}
/// Track info -- Phase 1 only provides what we can extract from status packets.
/// Full metadata (artist/title) requires Phase 2 DB queries.
TrackInfo getTrackInfo(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return {};
// Phase 1: no metadata yet -- return track ID as title placeholder
TrackInfo info;
uint32_t tid = players[idx].trackId.load(std::memory_order_relaxed);
if (tid != 0)
info.title = "Track #" + juce::String(tid);
return info;
}
/// BPM for a player (0.0 if unknown)
double getBPM(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0.0;
const auto& p = players[idx];
if (p.hasAbsolutePosition.load(std::memory_order_relaxed))
{
// Abs position: BPM x 10
return double(p.bpmRaw.load(std::memory_order_relaxed)) / 10.0;
}
// Beat/status packets: BPM x 100
return double(p.bpmRaw.load(std::memory_order_relaxed)) / 100.0;
}
/// Fader pitch multiplier (1.0 = 0%, from status offset 140)
/// This is the DJ's physical fader setting -- does NOT include motor ramp.
double getFaderPitch(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 1.0;
return ProDJLink::pitchFromStatus(
players[idx].pitchRaw.load(std::memory_order_relaxed));
}
/// Actual playback speed (0.0 = stopped, 1.0 = full speed at fader, from status offset 152)
/// Includes motor ramp: ramps 0->target on play, target->0 on pause.
/// This is what the CDJ is ACTUALLY doing right now.
double getActualSpeed(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0.0;
return ProDJLink::pitchFromStatus(
players[idx].actualSpeedRaw.load(std::memory_order_relaxed));
}
/// Legacy alias -- returns fader pitch for backward compatibility
double getActualPitch(int playerNum) const { return getFaderPitch(playerNum); }
/// Returns true if DJM mixer fader data is actively being received.
/// Goes stale after 5 seconds without a 0x39 packet (DJM offline/disconnected).
bool hasMixerFaderData() const
{
if (!hasMixerData.load(std::memory_order_relaxed)) return false;
double last = lastMixerPacketTime.load(std::memory_order_relaxed);
double now = juce::Time::getMillisecondCounterHiRes();
return (now - last) < 5000.0;
}
/// Monotonic counter of received 0x39 mixer packets. Used by forwarding
/// logic to skip iteration when no new data has arrived since last check.
uint32_t getMixerPacketCount() const { return pktCountMixer.load(std::memory_order_relaxed); }
/// Channel fader position (0=closed/bottom, 255=fully open/top).
/// Only valid after hasMixerFaderData() returns true.
uint8_t getChannelFader(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 255;
return mixerFader[idx].load(std::memory_order_relaxed);
}
/// Trim/gain knob (0=min, 128=unity, 255=max).
uint8_t getChannelTrim(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerTrim[idx].load(std::memory_order_relaxed);
}
/// Per-channel Compressor knob (0=off, 255=max). V10 only; always 0 on 900NXS2.
/// Confirmed from Comp__V10.pcapng: per-channel offset +2.
uint8_t getChannelComp(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 0;
return mixerComp[idx].load(std::memory_order_relaxed);
}
/// EQ High knob (0=full cut, 128=center/flat, 255=full boost).
uint8_t getChannelEqHi(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerEqHi[idx].load(std::memory_order_relaxed);
}
/// EQ Mid knob (0=full cut, 128=center/flat, 255=full boost).
/// On V10 this is "Hi Mid" (4-band EQ).
uint8_t getChannelEqMid(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerEqMid[idx].load(std::memory_order_relaxed);
}
/// EQ Low Mid knob (0=full cut, 128=center/flat, 255=full boost).
/// V10 only (4-band EQ); always 0 on 900NXS2.
uint8_t getChannelEqLoMid(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerEqLoMid[idx].load(std::memory_order_relaxed);
}
/// EQ Low knob (0=full cut, 128=center/flat, 255=full boost).
uint8_t getChannelEqLo(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerEqLo[idx].load(std::memory_order_relaxed);
}
/// Color/FX knob (0=min, 128=center/off, 255=max).
uint8_t getChannelColor(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 128;
return mixerColor[idx].load(std::memory_order_relaxed);
}
/// Per-channel Send knob (0=off, 255=max). V10 only; always 0 on 900NXS2.
/// Confirmed from Send_V10.pcapng: per-channel offset +8.
uint8_t getChannelSend(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 0;
return mixerSend[idx].load(std::memory_order_relaxed);
}
/// CUE headphone button (0=off, 1=on).
uint8_t getChannelCue(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 0;
return mixerCueBtn[idx].load(std::memory_order_relaxed);
}
/// CUE B headphone button (0=off, 1=on). A9/V10 dual-cue; always 0 on 900NXS2.
uint8_t getChannelCueB(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 0;
return mixerCueBtnB[idx].load(std::memory_order_relaxed);
}
/// Input source selector per channel.
/// 900NXS2: 0=PC USB A, 1=PC USB B, 2=DIGITAL, 3=LINE, 4=PHONO, 8=RET/AUX
/// A9: 0=PC USB A, 1=PC USB B, 2=DIGITAL, 3=LINE, 4=PHONO, 7=USB, 8=RETURN, 10=BLUETOOTH
/// V10: 0=PC USB A, 1=PC USB B, 2=DIGITAL, 3=LINE, 4=PHONO, 5=BUILT-IN,
/// 6=EXT1, 7=EXT2, 8=MULTI I/O, 9=COMBO
uint8_t getChannelInputSrc(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 3;
return mixerInputSrc[idx].load(std::memory_order_relaxed);
}
/// Crossfader assign (0=THRU, 1=A, 2=B).
uint8_t getChannelXfAssign(int channel) const
{
int idx = channel - 1;
if (idx < 0 || idx >= ProDJLink::kMaxMixerChannels) return 0;
return mixerXfAssign[idx].load(std::memory_order_relaxed);
}
/// Crossfader position (0=fully side-A, 128=center, 255=fully side-B).
uint8_t getCrossfader() const { return mixerCrossfader.load(std::memory_order_relaxed); }
/// Master fader position (0=min, 255=max).
uint8_t getMasterFader() const { return mixerMasterFader.load(std::memory_order_relaxed); }
/// Master CUE button (0=off, 1=on).
uint8_t getMasterCue() const { return mixerMasterCue.load(std::memory_order_relaxed); }
uint8_t getMasterCueB() const { return mixerMasterCueB.load(std::memory_order_relaxed); } // A9/V10 dual-cue
/// Isolator On/Off (0/1). V10 only; always 0 on 900NXS2.
uint8_t getIsolatorOn() const { return mixerIsolatorOn.load(std::memory_order_relaxed); }
/// Isolator Hi (0-255, 128=center). V10 only.
uint8_t getIsolatorHi() const { return mixerIsolatorHi.load(std::memory_order_relaxed); }
/// Isolator Mid (0-255, 128=center). V10 only.
uint8_t getIsolatorMid() const { return mixerIsolatorMid.load(std::memory_order_relaxed); }
/// Isolator Lo (0-255, 128=center). V10 only.
uint8_t getIsolatorLo() const { return mixerIsolatorLo.load(std::memory_order_relaxed); }
/// Fader curve (0/1/2).
uint8_t getFaderCurve() const { return mixerFaderCurve.load(std::memory_order_relaxed); }
/// Crossfader curve (0/1/2).
uint8_t getXfCurve() const { return mixerXfCurve.load(std::memory_order_relaxed); }
/// Booth monitor level (0-255).
uint8_t getBoothLevel() const { return mixerBooth.load(std::memory_order_relaxed); }
uint8_t getBoothEqHi() const { return mixerBoothEqHi.load(std::memory_order_relaxed); } // A9/V10
uint8_t getBoothEqLo() const { return mixerBoothEqLo.load(std::memory_order_relaxed); } // A9/V10
/// Headphone Cue Link (0=off, 1=on).
uint8_t getHpCueLink() const { return mixerHpCueLink.load(std::memory_order_relaxed); }
/// Headphone mixing knob (0=CUE, 255=Master).
uint8_t getHpMixing() const { return mixerHpMixing.load(std::memory_order_relaxed); }
/// Headphone level (0-255).
uint8_t getHpLevel() const { return mixerHpLevel.load(std::memory_order_relaxed); }
/// HP A Pre EQ button (0=off, 1=on). V10 only; always 0 on 900NXS2.
/// Booth EQ button (0=off, 1=on). A9 and V10; always 0 on 900NXS2.
uint8_t getBoothEq() const { return mixerBoothEq.load(std::memory_order_relaxed); }
/// Headphone B Cue Link (0=off, 1=on). A9 and V10; always 0 on 900NXS2.
uint8_t getHpCueLinkB() const { return mixerHpCueLinkB.load(std::memory_order_relaxed); }
/// Headphone B mixing knob (0=CUE, 255=Master). A9 and V10.
uint8_t getHpMixingB() const { return mixerHpMixingB.load(std::memory_order_relaxed); }
/// Headphone B level (0-255). A9 and V10.
uint8_t getHpLevelB() const { return mixerHpLevelB.load(std::memory_order_relaxed); }
/// Beat FX selector (0-13: Delay,Echo,PingPong,Spiral,Reverb,Trans,Filter,Flanger,Phaser,Pitch,SlipRoll,Roll,VinylBrake,Helix).
uint8_t getBeatFxSelect() const { return mixerBeatFxSel.load(std::memory_order_relaxed); }
/// Beat FX level/depth (0-255).
uint8_t getBeatFxLevel() const { return mixerBeatFxLevel.load(std::memory_order_relaxed); }
/// Beat FX on/off (0/1).
uint8_t getBeatFxOn() const { return mixerBeatFxOn.load(std::memory_order_relaxed); }
/// Beat FX channel assign (0=Mic,1=CH1,2=CH2,3=CH3,7=CH4,6=XF-A,8=XF-B,9=Master).
uint8_t getBeatFxAssign() const { return mixerBeatFxAssign.load(std::memory_order_relaxed); }
/// FX frequency band buttons.
uint8_t getFxFreqLo() const { return mixerFxFreqLo.load(std::memory_order_relaxed); }
uint8_t getFxFreqMid() const { return mixerFxFreqMid.load(std::memory_order_relaxed); }
uint8_t getFxFreqHi() const { return mixerFxFreqHi.load(std::memory_order_relaxed); }
/// Send/Return level (0-255).
uint8_t getSendReturnLevel() const { return mixerSendReturn.load(std::memory_order_relaxed); }
/// Multi I/O Select. A9 and V10; 0 on 900NXS2.
/// A9: 0-3=CH1-CH4, 6=MIC, 7=Master, 8=XF-A, 9=XF-B
/// V10: 0=Mic, 1-6=CH1-CH6, 7=Master
uint8_t getMultiIoSelect() const { return mixerMultiIoSelect.load(std::memory_order_relaxed); }
/// Multi I/O Level (0-255). A9 and V10; 0 on 900NXS2.
uint8_t getMultiIoLevel() const { return mixerMultiIoLevel.load(std::memory_order_relaxed); }
/// Color FX selector (255=OFF, 0=Space,1=DubEcho,2=Sweep,3=Noise,4=Crush,5=Filter).
uint8_t getColorFxSelect() const { return mixerColorFxSel.load(std::memory_order_relaxed); }
/// Color FX parameter knob (0-255).
uint8_t getColorFxParam() const { return mixerColorFxParam.load(std::memory_order_relaxed); }
/// Color FX channel assign (same enum as Beat FX assign).
uint8_t getColorFxAssign() const { return mixerColorFxAssign.load(std::memory_order_relaxed); }
/// Send Ext1 On/Off (0/1). V10 only; always 0 on 900NXS2.
uint8_t getSendExt1() const { return mixerSendExt1.load(std::memory_order_relaxed); }
/// Send Ext2 On/Off (0/1). V10 only; always 0 on 900NXS2.
uint8_t getSendExt2() const { return mixerSendExt2.load(std::memory_order_relaxed); }
/// Master Mix On/Off (0/1). V10 only; always 0 on 900NXS2.
uint8_t getMasterMixOn() const { return mixerMasterMixOn.load(std::memory_order_relaxed); }
/// Master Mix Size/Feedback (0-255). V10 only.
uint8_t getMasterMixSize() const { return mixerMasterMixSize.load(std::memory_order_relaxed); }
/// Master Mix Time (0-255). V10 only.
uint8_t getMasterMixTime() const { return mixerMasterMixTime.load(std::memory_order_relaxed); }
/// Master Mix Tone (0-255). V10 only.
uint8_t getMasterMixTone() const { return mixerMasterMixTone.load(std::memory_order_relaxed); }
/// Master Mix Level (0-255). V10 only. Shares offset 0x0e2 with Color FX Param.
uint8_t getMasterMixLevel() const { return mixerMasterMixLevel.load(std::memory_order_relaxed); }
/// Mic EQ High (0-255, 128=center).
uint8_t getMicEqHi() const { return mixerMicEqHi.load(std::memory_order_relaxed); }
/// Mic EQ Low (0-255, 128=center).
uint8_t getMicEqLo() const { return mixerMicEqLo.load(std::memory_order_relaxed); }
/// Filter LPF button (0=off, 1=on). V10 only; always 0 on 900NXS2.
uint8_t getFilterLPF() const { return mixerFilterLPF.load(std::memory_order_relaxed); }
/// Filter HPF button (0=off, 1=on). V10 only; always 0 on 900NXS2.
uint8_t getFilterHPF() const { return mixerFilterHPF.load(std::memory_order_relaxed); }
/// Filter Resonance knob (0-255). V10 only; always 0 on 900NXS2.
uint8_t getFilterResonance() const { return mixerFilterReso.load(std::memory_order_relaxed); }
/// Has VU meter data been received recently?
bool hasVuMeterData() const
{
if (!hasVuData.load(std::memory_order_relaxed)) return false;
double last = lastVuPacketTime.load(std::memory_order_relaxed);
double now = juce::Time::getMillisecondCounterHiRes();
return (now - last) < 5000.0;
}
/// VU peak level for a channel (0=silence, 32767=clip).
/// ch: 0-5=CH1-CH6, kVuMasterL=Master L, kVuMasterR=Master R
uint16_t getVuPeak(int ch) const
{
if (ch < 0 || ch >= ProDJLink::kVuSlots) return 0;
return vuPeak[ch].load(std::memory_order_relaxed);
}
/// VU peak as normalised float 0.0-1.0.
float getVuPeakNorm(int ch) const { return float(getVuPeak(ch)) / 32767.0f; }
/// Copy all 15 VU segments for one channel into dst[15].
/// ch: 0-5=CH1-CH6, kVuMasterL=Master L, kVuMasterR=Master R
void getVuSegments(int ch, uint16_t dst[15]) const
{
if (ch < 0 || ch >= ProDJLink::kVuSlots) { std::memset(dst, 0, 15 * sizeof(uint16_t)); return; }
const juce::SpinLock::ScopedLockType sl(vuDataLock);
std::memcpy(dst, vuSegments[ch], 15 * sizeof(uint16_t));
}
/// Model name of the first known DJM mixer (empty if none discovered yet).
juce::String getDJMModel() const
{
const juce::ScopedLock sl(djmIpLock);
return djmModels.empty() ? juce::String() : juce::String(djmModels[0]);
}
/// Number of mixer channels based on detected DJM model.
/// DJM-V10 / V10-LF = 6 channels; all others (900NXS2, A9) = 4.
int getMixerChannelCount() const
{
juce::String model = getDJMModel();
if (model.containsIgnoreCase("V10")) return 6;
return 4;
}
/// Playhead position in milliseconds
uint32_t getPlayheadMs(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0;
return players[idx].playheadMs.load(std::memory_order_relaxed);
}
/// Timestamp (ms hi-res) of last absolute position packet -- for PLL new-packet detection
double getAbsPositionTs(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0.0;
return players[idx].absPositionTs.load(std::memory_order_relaxed);
}
/// True if player is actively playing (for PLL advance)
bool isPlayerPlaying(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return false;
uint32_t ps = players[idx].playState.load(std::memory_order_relaxed);
return (ps == ProDJLink::kPlayPlaying || ps == ProDJLink::kPlayLooping);
}
/// Track length in seconds
uint32_t getTrackLengthSec(int playerNum) const
{
int idx = playerNum - 1;
if (idx < 0 || idx >= ProDJLink::kMaxPlayers) return 0;
return players[idx].trackLenSec.load(std::memory_order_relaxed);
}
/// Set track length from external source (e.g. dbserver metadata).
/// Used by NXS2/older players that don't report duration in protocol packets.
void setTrackLengthSec(int playerNum, uint32_t sec)
{