From c6b49005d2d8d2fca9b462abce61d7d9ddd62163 Mon Sep 17 00:00:00 2001 From: Pavel Kulik Date: Wed, 4 Oct 2023 18:25:36 -0700 Subject: [PATCH] Restore DiskSpaceMonitor --- Source/Processors/Editors/GenericEditor.cpp | 2 +- Source/Processors/RecordNode/RecordNode.cpp | 4 +- .../RecordNode/RecordNodeEditor.cpp | 74 ++++++++++++++++++- .../Processors/RecordNode/RecordNodeEditor.h | 5 +- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Source/Processors/Editors/GenericEditor.cpp b/Source/Processors/Editors/GenericEditor.cpp index 418d53760..10d588f8c 100755 --- a/Source/Processors/Editors/GenericEditor.cpp +++ b/Source/Processors/Editors/GenericEditor.cpp @@ -1428,7 +1428,7 @@ LevelMonitor::LevelMonitor(GenericProcessor *p) : Button("LevelMonitor") processor = p; updateFreq = 60; //10Hz fillPercentage = 0.0; - lastUpdateTime = Time::getMillisecondCounterHiRes(); + lastUpdateTime = 0.0; stateChangeSinceLastUpdate = false; } diff --git a/Source/Processors/RecordNode/RecordNode.cpp b/Source/Processors/RecordNode/RecordNode.cpp index a2a1c9f8e..4fce6575c 100755 --- a/Source/Processors/RecordNode/RecordNode.cpp +++ b/Source/Processors/RecordNode/RecordNode.cpp @@ -156,7 +156,7 @@ void RecordNode::parameterValueChanged(Parameter* p) void RecordNode::checkDiskSpace() { - int diskSpaceWarningThreshold = 5; //GB + float diskSpaceWarningThreshold = 5; //GB File dataDir(dataDirectory); int64 freeSpace = dataDir.getBytesFreeOnVolume(); @@ -165,7 +165,7 @@ void RecordNode::checkDiskSpace() if (availableBytes < diskSpaceWarningThreshold && !isRecording) { - String msg = "Less than " + String(diskSpaceWarningThreshold) + " GB of disk space available in " + String(dataDirectory.getFullPathName()); + String msg = "Less than " + String(int(diskSpaceWarningThreshold)) + " GB of disk space available in " + String(dataDirectory.getFullPathName()); msg += ". Recording may fail. Please free up space or change the recording directory."; AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "WARNING", msg); } diff --git a/Source/Processors/RecordNode/RecordNodeEditor.cpp b/Source/Processors/RecordNode/RecordNodeEditor.cpp index a7c73ccb6..5ab3b2fc3 100644 --- a/Source/Processors/RecordNode/RecordNodeEditor.cpp +++ b/Source/Processors/RecordNode/RecordNodeEditor.cpp @@ -52,20 +52,78 @@ DiskSpaceMonitor::DiskSpaceMonitor(RecordNode* rn) recordingTimeLeftInSeconds(0), dataRate(0.0) { - startTimerHz(10); + startTimerHz(1); } DiskSpaceMonitor::~DiskSpaceMonitor() {} +void DiskSpaceMonitor::reset() +{ + lastUpdateTime = Time::getMillisecondCounterHiRes(); + lastFreeSpace = ((RecordNode*) processor)->getDataDirectory().getBytesFreeOnVolume(); +} + void DiskSpaceMonitor::timerCallback() { RecordNode* recordNode = (RecordNode*) processor; + int64 bytesFree = recordNode->getDataDirectory().getBytesFreeOnVolume(); + int64 volumeSize = recordNode->getDataDirectory().getVolumeTotalSize(); + + float ratio = float(bytesFree) / float(volumeSize); + if (ratio > 0) + setFillPercentage(1.0f - ratio); + + float currentTime = Time::getMillisecondCounterHiRes(); + + if (recordNode->getRecordingStatus()) + { + // Update data rate and recording time left every 30 seconds + if (currentTime - lastUpdateTime > 5000.0f) + { + dataRate = (lastFreeSpace - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms + lastUpdateTime = currentTime; + lastFreeSpace = bytesFree; + + recordingTimeLeftInSeconds = bytesFree / dataRate / 1000.0f; + + // Stop recording and show warning when less than 5 minutes of disk space left + if (dataRate > 0.0f && recordingTimeLeftInSeconds < (60.0f * 5.0f)) + { + CoreServices::setRecordingStatus(false); + String msg = "Recording stopped. Less than 5 minutes of disk space remaining."; + AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "WARNING", msg); + } + + if (dataRate > 0.0f) + { + String msg = String(bytesFree / pow(2, 30)) + " GB available\n"; + msg += String(int(recordingTimeLeftInSeconds / 60.0f)) + " minutes remaining\n"; + msg += "Data rate: " + String(dataRate * 1000 / pow(2, 20), 2) + " MB/s"; + setTooltip(msg); + + LOGD("Data rate: ", dataRate, " bytes/ms"); + } + } + } + else + { + setTooltip(String(bytesFree / pow(2, 30)) + " GB available"); + } + + /* + lastFreeSpace = recordNode->getDataDirectory().getBytesFreeOnVolume(); float bytesFree = (float) recordNode->getDataDirectory().getBytesFreeOnVolume(); float volumeSize = (float) recordNode->getDataDirectory().getVolumeTotalSize(); + printf("Directory: %s\n", recordNode->getDataDirectory().getFullPathName().toRawUTF8()); + printf("lastFreeSpace: %d\n", lastFreeSpace); + printf("Bytes free: %f\n", bytesFree); + printf("Volume size: %f\n", volumeSize); + + float ratio = bytesFree / volumeSize; if (ratio > 0) @@ -77,7 +135,7 @@ void DiskSpaceMonitor::timerCallback() float currentTime = Time::getMillisecondCounterHiRes(); // Update data rate and recording time left every 30 seconds - if (recordNode->getRecordingStatus() && currentTime - lastUpdateTime > 30000) { + if (recordNode->getRecordingStatus()) { if (lastUpdateTime == 0.0) { lastUpdateTime = Time::getMillisecondCounterHiRes(); @@ -85,7 +143,8 @@ void DiskSpaceMonitor::timerCallback() } else { - dataRate = (lastFreeSpace - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms + dataRate = (float(lastFreeSpace) - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms + printf("dataRate = (%d - %f) / (%f - %f)\n", lastFreeSpace, bytesFree, currentTime, lastUpdateTime); lastUpdateTime = currentTime; lastFreeSpace = bytesFree; @@ -105,8 +164,16 @@ void DiskSpaceMonitor::timerCallback() msg += "Data rate: " + String(dataRate * 1000 / pow(2, 20), 2) + " MB/s"; setTooltip(msg); } + + LOGD("lastUpdateTime: ", lastUpdateTime); + LOGD("lastFreeSpace: ", lastFreeSpace); + LOGD("bytesFree: ", bytesFree); + LOGD("volumeSize: ", volumeSize); + LOGD("Free space: ", bytesFree / pow(2, 30), " GB"); } + */ + repaint(); } @@ -456,6 +523,7 @@ void RecordNodeEditor::timerCallback() void RecordNodeEditor::startRecording() { + diskSpaceMonitor->reset(); /* dataPathButton->setEnabled(false); engineSelectCombo->setEnabled(false); diff --git a/Source/Processors/RecordNode/RecordNodeEditor.h b/Source/Processors/RecordNode/RecordNodeEditor.h index 216793533..93a384e9b 100644 --- a/Source/Processors/RecordNode/RecordNodeEditor.h +++ b/Source/Processors/RecordNode/RecordNodeEditor.h @@ -63,9 +63,12 @@ class DiskSpaceMonitor : public LevelMonitor /** Updates the display */ void timerCallback() override; + /** Resets timer */ + void reset(); + private: int64 lastFreeSpace; - int64 recordingTimeLeftInSeconds; + float recordingTimeLeftInSeconds; float dataRate; };