Skip to content

Commit

Permalink
Merge pull request #14 from OPENSPHERE-Inc/patch-0.9.7
Browse files Browse the repository at this point in the history
Patch 0.9.7
  • Loading branch information
hanatyan128 authored Aug 22, 2024
2 parents 2475239 + d3d932a commit 0468967
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 80 deletions.
4 changes: 2 additions & 2 deletions buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
},
"platformConfig": {
"macos": {
"bundleId": "jp.co.opensphere.source-output"
"bundleId": "jp.co.opensphere.branch-output"
}
},
"name": "osi-branch-output",
"displayName": "Branch Output Plugin",
"version": "0.9.6",
"version": "0.9.7",
"author": "OPENSPHERE Inc.",
"website": "https://opensphere.co.jp/",
"email": "info@opensphere.co.jp",
Expand Down
118 changes: 56 additions & 62 deletions src/dock/output-status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,78 +90,55 @@ BranchOutputStatus::BranchOutputStatus(QWidget *parent) : QFrame(parent), timer(

BranchOutputStatus::~BranchOutputStatus() {}

void BranchOutputStatus::AddOutputLabels(filter_t *filter)
void BranchOutputStatus::AddFilter(filter_t *filter)
{
auto parent = obs_filter_get_parent(filter->source);
auto row = (int)outputLabels.size();

OutputLabels ol;
ol.filter = filter;

ol.filterItem = new FilterItem(QString::fromUtf8(obs_source_get_name(filter->source)), filter->source, this);
ol.parentName = new QTableWidgetItem(QString::fromUtf8(obs_source_get_name(parent)));
ol.filter = filter;
ol.filterCell = new FilterCell(QString::fromUtf8(obs_source_get_name(filter->source)), filter->source, this);
ol.parentCell = new ParentCell(QString::fromUtf8(obs_source_get_name(parent)), parent, this);
ol.status = new QLabel(QTStr("Status.Inactive"), this);
ol.droppedFrames = new QLabel(QString::fromUtf8(""), this);
ol.megabytesSent = new QLabel(QString::fromUtf8(""), this);
ol.bitrate = new QLabel(QString::fromUtf8(""), this);

auto col = 0;
auto row = (int)outputLabels.size();
outputLabels.push_back(ol);

auto col = 0;
outputTable->setRowCount(row + 1);
outputTable->setCellWidget(row, col++, ol.filterItem);
outputTable->setItem(row, col++, ol.parentName);
outputTable->setCellWidget(row, col++, ol.filterCell);
outputTable->setCellWidget(row, col++, ol.parentCell);
outputTable->setCellWidget(row, col++, ol.status);
outputTable->setCellWidget(row, col++, ol.droppedFrames);
outputTable->setCellWidget(row, col++, ol.megabytesSent);
outputTable->setCellWidget(row, col++, ol.bitrate);

outputTable->setRowHeight(row, 32);

outputLabels.push_back(ol);

// Setup reset button
auto resetButtonContainer = new QWidget(this);
auto resetButtonLayout = new QHBoxLayout();
resetButtonLayout->setContentsMargins(0, 0, 0, 0);
resetButtonContainer->setLayout(resetButtonLayout);
auto resetButtonContainerLayout = new QHBoxLayout();
resetButtonContainerLayout->setContentsMargins(0, 0, 0, 0);
resetButtonContainer->setLayout(resetButtonContainerLayout);

auto resetButton = new QPushButton(QTStr("Reset"), this);
connect(resetButton, &QPushButton::clicked, [this, row]() { outputLabels[row].Reset(); });
resetButton->setProperty("toolButton", true);
resetButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

resetButtonLayout->addWidget(resetButton);
resetButtonContainerLayout->addWidget(resetButton);
outputTable->setCellWidget(row, col, resetButtonContainer);

// Listen signal for filter update
signal_handler_connect(
obs_source_get_signal_handler(filter->source), "rename", BranchOutputStatus::OutputLabels::FilterRenamed,
outputLabels[row].filterItem
);

// Listen signal for parent update
signal_handler_connect(
obs_source_get_signal_handler(parent), "rename", BranchOutputStatus::OutputLabels::ParentRenamed,
outputLabels[row].parentName
);
}

void BranchOutputStatus::RemoveOutputLabels(filter_t *filter)
void BranchOutputStatus::RemoveFilter(filter_t *filter)
{
for (int i = 0; i < outputLabels.size(); i++) {
if (outputLabels[i].filter == filter) {
outputLabels.removeAt(i);
outputTable->removeRow(i);

signal_handler_disconnect(
obs_source_get_signal_handler(filter->source), "rename",
BranchOutputStatus::OutputLabels::FilterRenamed, outputLabels[i].filterItem
);

signal_handler_disconnect(
obs_source_get_signal_handler(obs_filter_get_parent(filter->source)), "rename",
BranchOutputStatus::OutputLabels::ParentRenamed, outputLabels[i].parentName
);

break;
}
}
Expand Down Expand Up @@ -314,33 +291,20 @@ void BranchOutputStatus::OutputLabels::Reset()
bitrate->setText(QString("0 kb/s"));
}

void BranchOutputStatus::OutputLabels::FilterRenamed(void *data, calldata_t *cd)
{
auto item = (FilterItem *)data;
auto newName = calldata_string(cd, "new_name");
item->SetText(QString::fromUtf8(newName));
}

void BranchOutputStatus::OutputLabels::ParentRenamed(void *data, calldata_t *cd)
{
auto label = (QTableWidgetItem *)data;
auto newName = calldata_string(cd, "new_name");
label->setText(QString::fromUtf8(newName));
}

// FilterItem class
// FilterCell class

FilterItem::FilterItem(QString text, obs_source_t *_source, QWidget *parent) : QWidget(parent)
FilterCell::FilterCell(QString text, obs_source_t *source, QWidget *parent) : QWidget(parent)
{
setMinimumHeight(27);
source = _source;

visibilityCheckbox = new QCheckBox(this);
visibilityCheckbox->setProperty("visibilityCheckBox", true);
visibilityCheckbox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
visibilityCheckbox->setChecked(obs_source_enabled(source));

connect(visibilityCheckbox, &QCheckBox::clicked, [this](bool visible) { obs_source_set_enabled(source, visible); });
connect(visibilityCheckbox, &QCheckBox::clicked, [source](bool visible) {
obs_source_set_enabled(source, visible);
});

name = new QLabel(text, this);

Expand All @@ -350,23 +314,53 @@ FilterItem::FilterItem(QString text, obs_source_t *_source, QWidget *parent) : Q
checkboxLayout->addWidget(name);
setLayout(checkboxLayout);

// Listen signal for filter update
filterRenamedSignal.Connect(obs_source_get_signal_handler(source), "rename", FilterCell::FilterRenamed, this);

// Listen signal for filter enabled/disabled
signal_handler_connect(obs_source_get_signal_handler(source), "enable", FilterItem::VisibilityChanged, this);
enableSignal.Connect(obs_source_get_signal_handler(source), "enable", FilterCell::VisibilityChanged, this);
}

FilterItem::~FilterItem()
FilterCell::~FilterCell()
{
signal_handler_disconnect(obs_source_get_signal_handler(source), "enable", FilterItem::VisibilityChanged, this);
filterRenamedSignal.Disconnect();
enableSignal.Disconnect();
}

void FilterItem::SetText(QString text)
void FilterCell::SetText(QString text)
{
name->setText(text);
}

void FilterItem::VisibilityChanged(void *data, calldata_t *cd)
void FilterCell::FilterRenamed(void *data, calldata_t *cd)
{
auto item = (FilterItem *)data;
auto item = (FilterCell *)data;
auto newName = calldata_string(cd, "new_name");
item->SetText(QString::fromUtf8(newName));
}

void FilterCell::VisibilityChanged(void *data, calldata_t *cd)
{
auto item = (FilterCell *)data;
auto enabled = calldata_bool(cd, "enabled");
item->visibilityCheckbox->setChecked(enabled);
}

// ParentCell class

ParentCell::ParentCell(QString text, obs_source_t *source, QWidget *parent) : QLabel(text, parent)
{
parentRenamedSignal.Connect(obs_source_get_signal_handler(source), "rename", ParentCell::ParentRenamed, this);
}

ParentCell::~ParentCell()
{
parentRenamedSignal.Disconnect();
}

void ParentCell::ParentRenamed(void *data, calldata_t *cd)
{
auto item = (ParentCell *)data;
auto newName = calldata_string(cd, "new_name");
item->setText(QString::fromUtf8(newName));
}
40 changes: 26 additions & 14 deletions src/dock/output-status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,57 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#pragma once

#include <obs-module.h>
#include <obs.hpp>
#include <QFrame>
#include <QPointer>
#include <QList>
#include <QTimer>
#include <QTableWidgetItem>
#include <QLabel>

class QTableWidget;
class QTableWidgetItem;
class QLabel;
class QString;
class QCheckBox;
struct filter_t;

class FilterItem : public QWidget {
class FilterCell : public QWidget {
Q_OBJECT

obs_source_t *source;

QCheckBox *visibilityCheckbox;
QLabel *name;

OBSSignal enableSignal;
OBSSignal filterRenamedSignal;

public:
FilterItem(QString text, obs_source_t *_source, QWidget *parent = (QWidget *)nullptr);
~FilterItem();
FilterCell(QString text, obs_source_t *_source, QWidget *parent = (QWidget *)nullptr);
~FilterCell();

void SetText(QString text);

static void VisibilityChanged(void *data, calldata_t *cd);
static void FilterRenamed(void *data, calldata_t *cd);
};

class ParentCell : public QLabel {
Q_OBJECT

OBSSignal parentRenamedSignal;

public:
ParentCell(QString text, obs_source_t *source, QWidget *parent = (QWidget *)nullptr);
~ParentCell();

static void ParentRenamed(void *data, calldata_t *cd);
};

class BranchOutputStatus : public QFrame {
Q_OBJECT

struct OutputLabels {
filter_t *filter;
FilterItem *filterItem;
QTableWidgetItem *parentName;
FilterCell *filterCell;
ParentCell *parentCell;
QLabel *status;
QLabel *droppedFrames;
QLabel *megabytesSent;
Expand All @@ -69,9 +84,6 @@ class BranchOutputStatus : public QFrame {
void Update(bool rec);
void Reset();

static void FilterRenamed(void *data, calldata_t *cd);
static void ParentRenamed(void *data, calldata_t *cd);

long double kbps = 0.0l;
};

Expand All @@ -85,8 +97,8 @@ class BranchOutputStatus : public QFrame {
BranchOutputStatus(QWidget *parent = (QWidget *)nullptr);
~BranchOutputStatus();

void AddOutputLabels(filter_t *filter);
void RemoveOutputLabels(filter_t *filter);
void AddFilter(filter_t *filter);
void RemoveFilter(filter_t *filter);
void SetEabnleAll(bool enabled);

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/plugin-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,14 @@ void filter_add(void *data, obs_source_t *)
{
// Register to output status dock
auto filter = (filter_t *)data;
status_dock->AddOutputLabels(filter);
status_dock->AddFilter(filter);
}

void filter_remove(void *data, obs_source_t *)
{
// Unregister from output status dock
auto filter = (filter_t *)data;
status_dock->RemoveOutputLabels(filter);
status_dock->RemoveFilter(filter);
}

const char *get_name(void *)
Expand Down

0 comments on commit 0468967

Please sign in to comment.