Skip to content

Commit 99b4afe

Browse files
committed
Harp barcode decoding mostly working
1 parent 72892f5 commit 99b4afe

2 files changed

Lines changed: 18 additions & 107 deletions

File tree

Source/Processors/Parameter/ParameterEditor.cpp

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -909,37 +909,17 @@ void SyncControlButton::paintButton (Graphics& g, bool isMouseOver, bool isButto
909909
}
910910
break;
911911
}
912-
case SyncStatus::HARP_DETECTING:
913-
{
914-
if (isMouseOver)
915-
{
916-
//LIGHT PURPLE - analyzing for Harp barcodes
917-
g.setColour (Colour (200, 150, 255));
918-
}
919-
else
920-
{
921-
//DARK PURPLE - analyzing for Harp barcodes
922-
g.setColour (Colour (147, 112, 219));
923-
}
924-
break;
925-
}
926912
case SyncStatus::HARP_CLOCK:
927913
{
928-
Colour harpClockColour = Colour (255, 20, 147); // Deep pink/magenta for Harp synchronization
929-
930-
// If the acquisition is not running, use a muted colour
931-
if (! CoreServices::getAcquisitionStatus())
932-
harpClockColour = harpClockColour.withAlpha (0.4f);
914+
Colour harpClockColour = Colour (200, 150, 255); // Light purplse
933915

934916
if (isMouseOver)
935917
{
936-
// HARP PINK - slightly contrasting
937-
g.setColour (harpClockColour.contrasting (0.1f));
918+
g.setColour (harpClockColour);
938919
}
939920
else
940921
{
941-
// HARP PINK
942-
g.setColour (harpClockColour);
922+
g.setColour (harpClockColour.darker (0.5f));
943923
}
944924
break;
945925
}
@@ -953,21 +933,7 @@ void SyncControlButton::paintButton (Graphics& g, bool isMouseOver, bool isButto
953933

954934
if (node->isMainDataStream (streamKey))
955935
{
956-
if (node->synchronizer.isHarpStream (streamKey))
957-
{
958-
// Main Harp stream - show both indicators
959-
g.drawText ("MH", getLocalBounds().reduced (3), juce::Justification::centred);
960-
}
961-
else
962-
{
963-
// Main stream
964-
g.drawText ("M", getLocalBounds().reduced (3), juce::Justification::centred);
965-
}
966-
}
967-
else if (node->synchronizer.isHarpStream (streamKey))
968-
{
969-
// Harp stream (not main)
970-
g.drawText ("H", getLocalBounds().reduced (3), juce::Justification::centred);
936+
g.drawText ("M", getLocalBounds().reduced (3), juce::Justification::centred);
971937
}
972938
}
973939

Source/Processors/Synchronizer/Synchronizer.cpp

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,19 @@ double SyncStream::getSyncAccuracy()
275275
if (pulses.size() > 0)
276276
{
277277

278-
//LOGD ("Sync accuracy for stream ", streamKey);
278+
LOGD ("Sync accuracy for stream ", streamKey);
279279

280-
//LOGD ("latestSyncSampleNumber: ", latestSyncSampleNumber);
281-
//LOGD ("latestGlobalSyncTime: ", latestGlobalSyncTime);
282-
//LOGD ("globalStartTime: ", globalStartTime);
283-
//LOGD ("actualSampleRate: ", actualSampleRate);
284-
// ORIGINAL CALCULATION:
285-
//double estimatedGlobalTime = latestSyncSampleNumber / actualSampleRate + globalStartTime;
280+
LOGD ("latestSyncSampleNumber: ", latestSyncSampleNumber);
281+
LOGD ("latestGlobalSyncTime: ", latestGlobalSyncTime);
282+
LOGD ("globalStartTime: ", globalStartTime);
283+
LOGD ("actualSampleRate: ", actualSampleRate);
286284

287285
// NEW CALCULATION:
288286
double estimatedGlobalTime = double(latestSyncSampleNumber - baselineMatchingPulse.localSampleNumber)
289287
/ actualSampleRate
290288
+ (baselineMatchingPulse.globalTimestamp);
291-
//LOGD ("estimatedGlobalTime: ", estimatedGlobalTime);
292-
//LOGD ("difference: ", latestGlobalSyncTime - estimatedGlobalTime);
289+
LOGD ("estimatedGlobalTime: ", estimatedGlobalTime);
290+
LOGD ("difference: ", latestGlobalSyncTime - estimatedGlobalTime);
293291

294292
return (estimatedGlobalTime - latestGlobalSyncTime) * 1000;
295293
}
@@ -301,8 +299,8 @@ double SyncStream::getSyncAccuracy()
301299

302300
void SyncStream::syncWith (const SyncStream* mainStream)
303301
{
304-
//LOGD ("Synchronizing ", streamKey, " with ", mainStream->streamKey, "...");
305-
//LOGD ("Expected sample rate: ", expectedSampleRate);
302+
LOGD ("Synchronizing ", streamKey, " with ", mainStream->streamKey, "...");
303+
LOGD ("Expected sample rate: ", expectedSampleRate);
306304

307305
if (mainStream->pulses.size() < 2 || pulses.size() < 2)
308306
{
@@ -591,61 +589,13 @@ void SyncStream::attemptBarcodeDecoding()
591589
{
592590
LOGD ("Successful decoding...setting isHarpStream to true.");
593591
isHarpStream = true;
592+
isSynchronized = true;
594593
}
595594
else
596595
{
597596
LOGD ("Unsuccessful decoding...setting harpDetectionActive to false.")
598597
harpDetectionActive = false;
599598
}
600-
601-
/*// Check if enough time has elapsed to consider the barcode potentially complete
602-
int64 currentTime = Time::currentTimeMillis();
603-
double elapsedTimeMs = double(currentTime - barcodeStartTime);
604-
605-
// If we've been collecting for more than the expected barcode duration, try to decode
606-
if (elapsedTimeMs >= HarpDecoder::EXPECTED_BARCODE_DURATION_MS * 0.8) // Allow some tolerance
607-
{
608-
// Try to decode with current events
609-
HarpBarcode barcode;
610-
611-
if (harpDecoder.decodeBarcode(currentBarcodeEvents, barcode, expectedSampleRate))
612-
{
613-
if (validateBarcodeStructure(barcode) && validateBarcodeTimestamp(barcode))
614-
{
615-
completedBarcodes.push_back(barcode);
616-
consecutiveValidBarcodes++;
617-
618-
LOGD("Valid Harp barcode decoded via timer: timestamp=", barcode.encodedTime, ", consecutive=", consecutiveValidBarcodes);
619-
620-
// Check if we have enough valid barcodes to confirm Harp mode
621-
if (consecutiveValidBarcodes >= MIN_VALID_BARCODES_FOR_HARP)
622-
{
623-
harpState = HarpDetectionState::HARP_CONFIRMED;
624-
isHarpStream = true;
625-
harpDetectionActive = false; // Stop dual detection
626-
627-
LOGD("Stream ", streamKey, " confirmed as Harp stream via timer");
628-
629-
// Set baseline for synchronization
630-
if (!baselineMatchingBarcode.isComplete)
631-
{
632-
baselineMatchingBarcode = barcode;
633-
}
634-
}
635-
636-
predictNextBarcodeStart(barcode);
637-
}
638-
else
639-
{
640-
consecutiveValidBarcodes = 0; // Reset count on invalid barcode
641-
}
642-
}
643-
644-
// Reset for next barcode regardless of decode success
645-
harpState = HarpDetectionState::IDLE;
646-
currentBarcodeEvents.clear();
647-
barcodeStartTime = -1;
648-
}*/
649599
}
650600

651601

@@ -669,9 +619,11 @@ void SyncStream::syncWithHarp()
669619

670620
// Calculate global start time
671621
LOGD ("Estimated global start time: ", double (firstBarcode.encodedTime) - firstBarcode.localStartTimestamp);
672-
globalStartTime = double (firstBarcode.encodedTime) - firstBarcode.localStartTimestamp;
622+
globalStartTime = (double (firstBarcode.encodedTime) - firstBarcode.localStartTimestamp) / 1000;
673623
baselineMatchingPulse.globalTimestamp = double (firstBarcode.encodedTime);
674624
baselineMatchingPulse.localSampleNumber = firstBarcode.localStartSample;
625+
latestSyncSampleNumber = lastBarcode.barcodeEvents.front().first;
626+
latestGlobalSyncTime = double(lastBarcode.encodedTime);
675627

676628
isSynchronized = true;
677629

@@ -853,7 +805,7 @@ double Synchronizer::getAccuracy (String streamKey)
853805
return 0.0;
854806
else
855807
{
856-
if(streamKey == mainStreamKey)
808+
if (streamKey == mainStreamKey && !streams[streamKey]->isHarpStream)
857809
return 0.0;
858810
else
859811
{
@@ -894,15 +846,8 @@ SyncStatus Synchronizer::getStatus (String streamKey)
894846
if (streamGeneratesTimestamps (streamKey))
895847
return SyncStatus::HARDWARE_SYNCED;
896848

897-
// Check for Harp-specific states
898849
if (streams[streamKey]->isHarpStream)
899-
{
900850
return SyncStatus::HARP_CLOCK;
901-
}
902-
else if (streams[streamKey]->harpDetectionActive)
903-
{
904-
return SyncStatus::HARP_DETECTING;
905-
}
906851

907852
if (isStreamSynced (streamKey))
908853
return SyncStatus::SYNCED;

0 commit comments

Comments
 (0)