Make the crash detection work more nicely across multiple instances of osci-render

pull/300/head
James H Ball 2025-04-25 19:04:15 +01:00
rodzic 9a10347870
commit b88269825c
3 zmienionych plików z 39 dodań i 15 usunięć

Wyświetl plik

@ -62,6 +62,7 @@ CommonAudioProcessor::CommonAudioProcessor(const BusesProperties& busesPropertie
effects.push_back(thresholdEffect); effects.push_back(thresholdEffect);
wavParser.setLooping(false); wavParser.setLooping(false);
startHeartbeat();
} }
void CommonAudioProcessor::addAllParameters() { void CommonAudioProcessor::addAllParameters() {
@ -87,10 +88,31 @@ void CommonAudioProcessor::addAllParameters() {
} }
} }
void CommonAudioProcessor::startHeartbeat() {
if (!heartbeatActive) {
startTimer(2000); // 2 seconds
heartbeatActive = true;
}
}
void CommonAudioProcessor::stopHeartbeat() {
if (heartbeatActive) {
stopTimer();
heartbeatActive = false;
}
}
void CommonAudioProcessor::timerCallback() {
setGlobalValue("lastHeartbeatTime", juce::Time::getCurrentTime().toISO8601(true));
saveGlobalSettings();
}
CommonAudioProcessor::~CommonAudioProcessor() CommonAudioProcessor::~CommonAudioProcessor()
{ {
setGlobalValue("endTime", juce::Time::getCurrentTime().toISO8601(true)); setGlobalValue("endTime", juce::Time::getCurrentTime().toISO8601(true));
saveGlobalSettings(); saveGlobalSettings();
stopHeartbeat();
} }
const juce::String CommonAudioProcessor::getName() const { const juce::String CommonAudioProcessor::getName() const {
@ -394,21 +416,18 @@ void CommonAudioProcessor::setLastOpenedDirectory(const juce::File& directory)
bool CommonAudioProcessor::programCrashedAndUserWantsToReset() { bool CommonAudioProcessor::programCrashedAndUserWantsToReset() {
bool userWantsToReset = false; bool userWantsToReset = false;
if (!hasSetSessionStartTime) { if (!hasSetSessionStartTime) {
// check that the previous end time is later than the start time.
// if not, the program did not close properly.
juce::String startTime = getGlobalStringValue("startTime"); juce::String startTime = getGlobalStringValue("startTime");
juce::String endTime = getGlobalStringValue("endTime"); juce::String endTime = getGlobalStringValue("endTime");
juce::String lastHeartbeat = getGlobalStringValue("lastHeartbeatTime");
if ((startTime.isNotEmpty() && endTime.isNotEmpty()) || (startTime.isNotEmpty() && endTime.isEmpty())) {
juce::Time start = juce::Time::fromISO8601(startTime); juce::Time start = juce::Time::fromISO8601(startTime);
juce::Time end = juce::Time::fromISO8601(endTime); juce::Time end = juce::Time::fromISO8601(endTime);
juce::Time heartbeat = juce::Time::fromISO8601(lastHeartbeat);
if ((start > end || end == juce::Time()) && juce::MessageManager::getInstance()->isThisTheMessageThread()) { juce::Time now = juce::Time::getCurrentTime();
bool heartbeatStale = (now.toMilliseconds() - heartbeat.toMilliseconds()) > 3000;
if ((startTime.isNotEmpty() && endTime.isNotEmpty()) || (startTime.isNotEmpty() && endTime.isEmpty())) {
if (((start > end || end == juce::Time()) && heartbeatStale) && juce::MessageManager::getInstance()->isThisTheMessageThread()) {
juce::String message = "It appears that " + juce::String(ProjectInfo::projectName) + " did not close properly during your last session. This may indicate a problem with your project or session."; juce::String message = "It appears that " + juce::String(ProjectInfo::projectName) + " did not close properly during your last session. This may indicate a problem with your project or session.";
// Use a synchronous dialog to ensure user makes a choice before proceeding
bool userPressedReset = juce::AlertWindow::showOkCancelBox( bool userPressedReset = juce::AlertWindow::showOkCancelBox(
juce::AlertWindow::WarningIcon, juce::AlertWindow::WarningIcon,
"Possible Crash Detected", "Possible Crash Detected",
@ -418,18 +437,15 @@ bool CommonAudioProcessor::programCrashedAndUserWantsToReset() {
nullptr, nullptr,
nullptr nullptr
); );
if (userPressedReset) { if (userPressedReset) {
userWantsToReset = true; userWantsToReset = true;
} }
} }
} }
setGlobalValue("startTime", juce::Time::getCurrentTime().toISO8601(true)); setGlobalValue("startTime", juce::Time::getCurrentTime().toISO8601(true));
saveGlobalSettings(); saveGlobalSettings();
hasSetSessionStartTime = true; hasSetSessionStartTime = true;
} }
return userWantsToReset; return userWantsToReset;
} }

Wyświetl plik

@ -21,7 +21,7 @@ public:
virtual void parserChanged() = 0; virtual void parserChanged() = 0;
}; };
class CommonAudioProcessor : public juce::AudioProcessor, public SampleRateManager class CommonAudioProcessor : public juce::AudioProcessor, public SampleRateManager, public juce::Timer
#if JucePlugin_Enable_ARA #if JucePlugin_Enable_ARA
, public juce::AudioProcessorARAExtension , public juce::AudioProcessorARAExtension
#endif #endif
@ -180,4 +180,11 @@ protected:
//============================================================================== //==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CommonAudioProcessor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CommonAudioProcessor)
private:
void startHeartbeat();
void stopHeartbeat();
void timerCallback() override;
bool heartbeatActive = false;
}; };

Wyświetl plik

@ -122,7 +122,8 @@ VisualiserComponent::VisualiserComponent(
}; };
} }
addAndMakeVisible(audioPlayer); addChildComponent(audioPlayer);
audioPlayer.setVisible(visualiserOnly);
audioPlayer.addMouseListener(static_cast<juce::Component*>(this), true); audioPlayer.addMouseListener(static_cast<juce::Component*>(this), true);
openGLContext.setRenderer(this); openGLContext.setRenderer(this);