Skip to content

Commit

Permalink
Add "Last empty" row to Queue tab
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Oct 26, 2024
1 parent 392e775 commit e262672
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
@@ -97,6 +97,7 @@ AdvSceneSwitcher.actionQueueTab.queueAddButton.tooltip="Add new action queue"
AdvSceneSwitcher.actionQueueTab.queueRemoveButton.tooltip="Remove selected action queues"
AdvSceneSwitcher.actionQueueTab.name.header="Name"
AdvSceneSwitcher.actionQueueTab.size.header="Size"
AdvSceneSwitcher.actionQueueTab.lastEmpty.header="Last empty"
AdvSceneSwitcher.actionQueueTab.isRunning.header="Is running"
AdvSceneSwitcher.actionQueueTab.runOnStartup.header="Run on startup"
AdvSceneSwitcher.actionQueueTab.yes="Yes"
11 changes: 11 additions & 0 deletions lib/queue/action-queue-tab.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
#include "plugin-state-helpers.hpp"
#include "sync-helpers.hpp"
#include "tab-helpers.hpp"
#include "time-helpers.hpp"
#include "ui-helpers.hpp"

#include <QTimer>
@@ -55,6 +56,13 @@ void ActionQueueTable::Add()
QString::fromStdString(newQueue->Name()));
}

static double getSecondsSinceLastEmpty(ActionQueue *queue)
{
const auto time = std::chrono::high_resolution_clock::now() -
queue->GetLastEmptyTime();
return std::chrono::duration_cast<std::chrono::seconds>(time).count();
}

static QStringList getCellLabels(ActionQueue *queue, bool addName = true)
{
assert(queue);
@@ -64,6 +72,7 @@ static QStringList getCellLabels(ActionQueue *queue, bool addName = true)
result << QString::fromStdString(queue->Name());
}
result << QString::number(queue->Size())
<< FormatRelativeTime(getSecondsSinceLastEmpty(queue))
<< QString::fromStdString(obs_module_text(
queue->IsRunning()
? "AdvSceneSwitcher.actionQueueTab.yes"
@@ -199,6 +208,8 @@ ActionQueueTable::ActionQueueTable(QTabWidget *parent)
"AdvSceneSwitcher.actionQueueTab.name.header")
<< obs_module_text(
"AdvSceneSwitcher.actionQueueTab.size.header")
<< obs_module_text(
"AdvSceneSwitcher.actionQueueTab.lastEmpty.header")
<< obs_module_text(
"AdvSceneSwitcher.actionQueueTab.isRunning.header")
<< obs_module_text(
15 changes: 14 additions & 1 deletion lib/queue/action-queue.cpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,10 @@ void SetupActionQueues()
done = true;
}

ActionQueue::ActionQueue() : Item() {}
ActionQueue::ActionQueue() : Item()
{
_lastEmpty = std::chrono::high_resolution_clock::now();
}

ActionQueue::~ActionQueue()
{
@@ -124,6 +127,14 @@ bool ActionQueue::IsEmpty()
return _actions.empty();
}

ActionQueue::TimePoint ActionQueue::GetLastEmptyTime()
{
if (IsEmpty()) {
_lastEmpty = std::chrono::high_resolution_clock::now();
}
return _lastEmpty;
}

size_t ActionQueue::Size()
{
std::lock_guard<std::mutex> lock(_mutex);
@@ -137,6 +148,8 @@ void ActionQueue::RunActions()
{ // Grab next action to run
std::unique_lock<std::mutex> lock(_mutex);
while (_actions.empty() && !_stop) {
_lastEmpty =
std::chrono::high_resolution_clock::now();
_cv.wait(lock);
}

7 changes: 6 additions & 1 deletion lib/queue/action-queue.hpp
Original file line number Diff line number Diff line change
@@ -2,18 +2,21 @@
#include "item-selection-helpers.hpp"
#include "macro-action.hpp"

#include <chrono>
#include <condition_variable>
#include <deque>
#include <obs-data.h>
#include <QCheckBox>
#include <thread>
#include <condition_variable>

namespace advss {

class ActionQueueSelection;
class ActionQueueSettingsDialog;

class ActionQueue : public Item {
using TimePoint = std::chrono::high_resolution_clock::time_point;

public:
ActionQueue();
~ActionQueue();
@@ -30,6 +33,7 @@ class ActionQueue : public Item {

void Clear();
bool IsEmpty();
TimePoint GetLastEmptyTime();

void Add(const std::shared_ptr<MacroAction> &);
size_t Size();
@@ -44,6 +48,7 @@ class ActionQueue : public Item {
std::condition_variable _cv;
std::thread _thread;
std::deque<std::shared_ptr<MacroAction>> _actions;
TimePoint _lastEmpty;

friend ActionQueueSelection;
friend ActionQueueSettingsDialog;

0 comments on commit e262672

Please sign in to comment.