Skip to content

Commit

Permalink
Merge pull request #1 from dunronet/preview-dsk
Browse files Browse the repository at this point in the history
Preview in Studio mode
  • Loading branch information
dunronet authored Oct 16, 2024
2 parents 02ea554 + 4279bfa commit a48c45b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
35 changes: 34 additions & 1 deletion downstream-keyer-dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void DownstreamKeyerDock::Load(obs_data_t *data)
for (size_t i = 0; i < count; i++) {
auto keyerData = obs_data_array_item(keyers, i);
auto keyer = new DownstreamKeyer(
this,
(int)(outputChannel + i),
QT_UTF8(obs_data_get_string(keyerData, "name")),
view, get_transitions, get_transitions_data);
Expand Down Expand Up @@ -412,6 +413,7 @@ void DownstreamKeyerDock::AddDefaultKeyer()
outputChannel = 7;
}
auto keyer = new DownstreamKeyer(
this,
outputChannel, QT_UTF8(obs_module_text("DefaultName")), view,
get_transitions, get_transitions_data);
tabs->addTab(keyer, keyer->objectName());
Expand Down Expand Up @@ -573,7 +575,8 @@ void DownstreamKeyerDock::Add()
if (NameDialog::AskForName(this, name)) {
if (outputChannel < 7 || outputChannel >= MAX_CHANNELS)
outputChannel = 7;
auto keyer = new DownstreamKeyer(outputChannel + tabs->count(),
auto keyer = new DownstreamKeyer(this,
outputChannel + tabs->count(),
QT_UTF8(name.c_str()), view,
get_transitions,
get_transitions_data);
Expand Down Expand Up @@ -703,6 +706,36 @@ bool DownstreamKeyerDock::RemoveExcludeScene(QString dskName,
return false;
}

void DownstreamKeyerDock::RefreshDSKPreview()
{

obs_source_t *preview_scene_as_source = obs_get_source_by_name("DownstreamKeyer Preview");

if (!preview_scene_as_source)
return;

obs_scene_t *scene = obs_scene_from_source(preview_scene_as_source);
obs_scene_enum_items(
scene, remove_item,
nullptr);

const int count = tabs->count();
for (int i = 0; i < count; i++) {
auto w = dynamic_cast<DownstreamKeyer *>(tabs->widget(i));
QListWidget *sl = w->getScenesListWidget();
const auto l = sl->selectedItems();
const auto newSource =
l.count()
? obs_get_source_by_name(QT_TO_UTF8(l.value(0)->text()))
: nullptr;
if (newSource) {
obs_scene_add(scene, newSource);
obs_source_release(newSource);
}
}
obs_source_release(preview_scene_as_source);
}

void DownstreamKeyerDock::get_downstream_keyers(obs_data_t *request_data,
obs_data_t *response_data,
void *param)
Expand Down
5 changes: 5 additions & 0 deletions downstream-keyer-dock.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#pragma once
#ifndef DOWNSTREAMKEYERDOCK_H
#define DOWNSTREAMKEYERDOCK_H

#include <QDockWidget>
#include <qmenu.h>
#include <QTabWidget>
Expand Down Expand Up @@ -75,4 +78,6 @@ private slots:
static void remove_exclude_scene(obs_data_t *request_data,
obs_data_t *response_data,
void *param);
void RefreshDSKPreview();
};
#endif
12 changes: 10 additions & 2 deletions downstream-keyer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "downstream-keyer.hpp"
#include "downstream-keyer-dock.hpp"

#include <QCheckBox>
#include <QComboBox>
Expand All @@ -18,9 +19,10 @@

extern obs_websocket_vendor vendor;

DownstreamKeyer::DownstreamKeyer(int channel, QString name, obs_view_t *v,
DownstreamKeyer::DownstreamKeyer(DownstreamKeyerDock *parent, int channel, QString name, obs_view_t *v,
get_transitions_callback_t gt, void *gtd)
: outputChannel(channel),
: parent(parent),
outputChannel(channel),
transition(nullptr),
showTransition(nullptr),
hideTransition(nullptr),
Expand Down Expand Up @@ -369,6 +371,7 @@ void DownstreamKeyer::apply_selected_source()

void DownstreamKeyer::on_scenesList_itemSelectionChanged()
{
parent->RefreshDSKPreview(); // let parent know preview would need to be refreshed
if (tie->isChecked())
return;

Expand Down Expand Up @@ -1044,3 +1047,8 @@ LockedCheckBox::LockedCheckBox()
}

LockedCheckBox::LockedCheckBox(QWidget *parent) : QCheckBox(parent) {}

QListWidget *DownstreamKeyer::getScenesListWidget() // expose scenesList widget to parent (and others...)
{
return scenesList;
}
10 changes: 9 additions & 1 deletion downstream-keyer.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#ifndef DOWNSTREAMKEYER_H
#define DOWNSTREAMKEYER_H

#include <QCheckBox>
#include <qcombobox.h>
Expand All @@ -12,6 +14,8 @@
#include "obs-websocket-api.h"
#include "obs.h"

class DownstreamKeyerDock; // Forward declaration of ParentClass

typedef void (*get_transitions_callback_t)(
void *data, struct obs_frontend_source_list *sources);

Expand All @@ -29,6 +33,7 @@ class DownstreamKeyer : public QWidget {
Q_OBJECT

private:
DownstreamKeyerDock *parent;
int outputChannel;
obs_source_t *transition;
obs_source_t *showTransition;
Expand Down Expand Up @@ -77,7 +82,7 @@ private slots:
signals:

public:
DownstreamKeyer(int channel, QString name, obs_view_t *view = nullptr,
DownstreamKeyer(DownstreamKeyerDock *parent, int channel, QString name, obs_view_t *view = nullptr,
get_transitions_callback_t get_transitions = nullptr,
void *get_transitions_data = nullptr);
~DownstreamKeyer();
Expand All @@ -100,4 +105,7 @@ private slots:
bool RemoveScene(QString scene_name);
void SetTie(bool tie);
void SetOutputChannel(int outputChannel);
QListWidget *getScenesListWidget();
};

#endif

0 comments on commit a48c45b

Please sign in to comment.