clang-format: Apply formatting

Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
This commit is contained in:
jp9000
2019-06-22 22:13:45 -07:00
parent 53615ee10f
commit f53df7da64
567 changed files with 34068 additions and 32903 deletions

View File

@@ -5,8 +5,7 @@
#include "decklink-ui-main.h"
DecklinkOutputUI::DecklinkOutputUI(QWidget *parent)
: QDialog(parent),
ui(new Ui_Output)
: QDialog(parent), ui(new Ui_Output)
{
ui->setupUi(this);
@@ -20,8 +19,10 @@ DecklinkOutputUI::DecklinkOutputUI(QWidget *parent)
connect(ui->startOutput, SIGNAL(released()), this, SLOT(StartOutput()));
connect(ui->stopOutput, SIGNAL(released()), this, SLOT(StopOutput()));
connect(ui->startPreviewOutput, SIGNAL(released()), this, SLOT(StartPreviewOutput()));
connect(ui->stopPreviewOutput, SIGNAL(released()), this, SLOT(StopPreviewOutput()));
connect(ui->startPreviewOutput, SIGNAL(released()), this,
SLOT(StartPreviewOutput()));
connect(ui->stopPreviewOutput, SIGNAL(released()), this,
SLOT(StopPreviewOutput()));
}
void DecklinkOutputUI::ShowHideDialog()
@@ -43,25 +44,26 @@ void DecklinkOutputUI::SetupPropertiesView()
if (data)
obs_data_apply(settings, data);
propertiesView = new OBSPropertiesView(settings,
"decklink_output",
(PropertiesReloadCallback) obs_get_output_properties,
170);
propertiesView = new OBSPropertiesView(
settings, "decklink_output",
(PropertiesReloadCallback)obs_get_output_properties, 170);
ui->propertiesLayout->addWidget(propertiesView);
obs_data_release(settings);
connect(propertiesView, SIGNAL(Changed()), this, SLOT(PropertiesChanged()));
connect(propertiesView, SIGNAL(Changed()), this,
SLOT(PropertiesChanged()));
}
void DecklinkOutputUI::SaveSettings()
{
BPtr<char> modulePath = obs_module_get_config_path(obs_current_module(), "");
BPtr<char> modulePath =
obs_module_get_config_path(obs_current_module(), "");
os_mkdirs(modulePath);
BPtr<char> path = obs_module_get_config_path(obs_current_module(),
"decklinkOutputProps.json");
BPtr<char> path = obs_module_get_config_path(
obs_current_module(), "decklinkOutputProps.json");
obs_data_t *settings = propertiesView->GetSettings();
if (settings)
@@ -79,15 +81,15 @@ void DecklinkOutputUI::SetupPreviewPropertiesView()
if (data)
obs_data_apply(settings, data);
previewPropertiesView = new OBSPropertiesView(settings,
"decklink_output",
(PropertiesReloadCallback) obs_get_output_properties,
170);
previewPropertiesView = new OBSPropertiesView(
settings, "decklink_output",
(PropertiesReloadCallback)obs_get_output_properties, 170);
ui->previewPropertiesLayout->addWidget(previewPropertiesView);
obs_data_release(settings);
connect(previewPropertiesView, SIGNAL(Changed()), this, SLOT(PreviewPropertiesChanged()));
connect(previewPropertiesView, SIGNAL(Changed()), this,
SLOT(PreviewPropertiesChanged()));
}
void DecklinkOutputUI::SavePreviewSettings()
@@ -96,15 +98,14 @@ void DecklinkOutputUI::SavePreviewSettings()
os_mkdirs(modulePath);
char *path = obs_module_get_config_path(obs_current_module(),
"decklinkPreviewOutputProps.json");
char *path = obs_module_get_config_path(
obs_current_module(), "decklinkPreviewOutputProps.json");
obs_data_t *settings = previewPropertiesView->GetSettings();
if (settings)
obs_data_save_json_safe(settings, path, "tmp", "bak");
}
void DecklinkOutputUI::StartOutput()
{
SaveSettings();
@@ -121,7 +122,6 @@ void DecklinkOutputUI::PropertiesChanged()
SaveSettings();
}
void DecklinkOutputUI::StartPreviewOutput()
{
SavePreviewSettings();

View File

@@ -6,7 +6,7 @@
#include "../../UI/properties-view.hpp"
class DecklinkOutputUI : public QDialog {
Q_OBJECT
Q_OBJECT
private:
OBSPropertiesView *propertiesView;
OBSPropertiesView *previewPropertiesView;

View File

@@ -37,8 +37,8 @@ static struct preview_output context = {0};
OBSData load_settings()
{
BPtr<char> path = obs_module_get_config_path(obs_current_module(),
"decklinkOutputProps.json");
BPtr<char> path = obs_module_get_config_path(
obs_current_module(), "decklinkOutputProps.json");
BPtr<char> jsonData = os_quick_read_utf8_file(path);
if (!!jsonData) {
obs_data_t *data = obs_data_create_from_json(jsonData);
@@ -57,8 +57,9 @@ void output_start()
OBSData settings = load_settings();
if (settings != nullptr) {
output = obs_output_create("decklink_output",
"decklink_output", settings, NULL);
output = obs_output_create("decklink_output",
"decklink_output", settings,
NULL);
obs_output_start(output);
obs_data_release(settings);
@@ -77,11 +78,10 @@ void output_stop()
}
}
OBSData load_preview_settings()
{
BPtr<char> path = obs_module_get_config_path(obs_current_module(),
"decklinkPreviewOutputProps.json");
BPtr<char> path = obs_module_get_config_path(
obs_current_module(), "decklinkPreviewOutputProps.json");
BPtr<char> jsonData = os_quick_read_utf8_file(path);
if (!!jsonData) {
obs_data_t *data = obs_data_create_from_json(jsonData);
@@ -103,8 +103,9 @@ void preview_output_start()
OBSData settings = load_preview_settings();
if (settings != nullptr) {
context.output = obs_output_create("decklink_output",
"decklink_preview_output", settings, NULL);
context.output = obs_output_create(
"decklink_output", "decklink_preview_output",
settings, NULL);
obs_get_video_info(&context.ovi);
@@ -112,11 +113,14 @@ void preview_output_start()
uint32_t height = context.ovi.base_height;
obs_enter_graphics();
context.texrender = gs_texrender_create(GS_BGRA, GS_ZS_NONE);
context.stagesurface = gs_stagesurface_create(width, height, GS_BGRA);
context.texrender =
gs_texrender_create(GS_BGRA, GS_ZS_NONE);
context.stagesurface =
gs_stagesurface_create(width, height, GS_BGRA);
obs_leave_graphics();
const video_output_info *mainVOI = video_output_get_info(obs_get_video());
const video_output_info *mainVOI =
video_output_get_info(obs_get_video());
video_output_info vi = {0};
vi.format = VIDEO_FORMAT_BGRA;
@@ -131,15 +135,21 @@ void preview_output_start()
video_output_open(&context.video_queue, &vi);
obs_frontend_add_event_callback(on_preview_scene_changed, &context);
obs_frontend_add_event_callback(
on_preview_scene_changed, &context);
if (obs_frontend_preview_program_mode_active()) {
context.current_source = obs_frontend_get_current_preview_scene();
context.current_source =
obs_frontend_get_current_preview_scene();
} else {
context.current_source = obs_frontend_get_current_scene();
context.current_source =
obs_frontend_get_current_scene();
}
obs_add_main_render_callback(render_preview_source, &context);
obs_add_main_render_callback(render_preview_source,
&context);
obs_output_set_media(context.output, context.video_queue, obs_get_audio());
obs_output_set_media(context.output,
context.video_queue,
obs_get_audio());
obs_output_start(context.output);
preview_output_running = true;
@@ -153,8 +163,10 @@ void preview_output_stop()
obs_output_stop(context.output);
video_output_stop(context.video_queue);
obs_remove_main_render_callback(render_preview_source, &context);
obs_frontend_remove_event_callback(on_preview_scene_changed, &context);
obs_remove_main_render_callback(render_preview_source,
&context);
obs_frontend_remove_event_callback(on_preview_scene_changed,
&context);
obs_source_release(context.current_source);
@@ -171,33 +183,34 @@ void preview_output_stop()
void on_preview_scene_changed(enum obs_frontend_event event, void *param)
{
auto ctx = (struct preview_output*)param;
auto ctx = (struct preview_output *)param;
switch (event) {
case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED:
case OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED:
obs_source_release(ctx->current_source);
ctx->current_source = obs_frontend_get_current_preview_scene();
break;
case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED:
case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED:
case OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED:
obs_source_release(ctx->current_source);
ctx->current_source = obs_frontend_get_current_preview_scene();
break;
case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED:
obs_source_release(ctx->current_source);
ctx->current_source = obs_frontend_get_current_scene();
break;
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
if (!obs_frontend_preview_program_mode_active()) {
obs_source_release(ctx->current_source);
ctx->current_source = obs_frontend_get_current_scene();
break;
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
if (!obs_frontend_preview_program_mode_active()) {
obs_source_release(ctx->current_source);
ctx->current_source = obs_frontend_get_current_scene();
}
break;
default:
break;
}
break;
default:
break;
}
}
void render_preview_source(void *param, uint32_t cx, uint32_t cy)
{
auto ctx = (struct preview_output*)param;
auto ctx = (struct preview_output *)param;
if (!ctx->current_source) return;
if (!ctx->current_source)
return;
uint32_t width = obs_source_get_base_width(ctx->current_source);
uint32_t height = obs_source_get_base_height(ctx->current_source);
@@ -209,7 +222,8 @@ void render_preview_source(void *param, uint32_t cx, uint32_t cy)
vec4_zero(&background);
gs_clear(GS_CLEAR_COLOR, &background, 0.0f, 0);
gs_ortho(0.0f, (float)width, 0.0f, (float)height, -100.0f, 100.0f);
gs_ortho(0.0f, (float)width, 0.0f, (float)height, -100.0f,
100.0f);
gs_blend_state_push();
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
@@ -220,18 +234,25 @@ void render_preview_source(void *param, uint32_t cx, uint32_t cy)
gs_texrender_end(ctx->texrender);
struct video_frame output_frame;
if (video_output_lock_frame(ctx->video_queue, &output_frame, 1, os_gettime_ns()))
{
gs_stage_texture(ctx->stagesurface, gs_texrender_get_texture(ctx->texrender));
if (video_output_lock_frame(ctx->video_queue, &output_frame, 1,
os_gettime_ns())) {
gs_stage_texture(
ctx->stagesurface,
gs_texrender_get_texture(ctx->texrender));
if (gs_stagesurface_map(ctx->stagesurface, &ctx->video_data, &ctx->video_linesize)) {
if (gs_stagesurface_map(ctx->stagesurface,
&ctx->video_data,
&ctx->video_linesize)) {
uint32_t linesize = output_frame.linesize[0];
for (uint32_t i = 0; i < ctx->ovi.base_height; i++) {
for (uint32_t i = 0; i < ctx->ovi.base_height;
i++) {
uint32_t dst_offset = linesize * i;
uint32_t src_offset = ctx->video_linesize * i;
memcpy(output_frame.data[0] + dst_offset,
ctx->video_data + src_offset,
linesize);
uint32_t src_offset =
ctx->video_linesize * i;
memcpy(output_frame.data[0] +
dst_offset,
ctx->video_data + src_offset,
linesize);
}
gs_stagesurface_unmap(ctx->stagesurface);
@@ -245,18 +266,16 @@ void render_preview_source(void *param, uint32_t cx, uint32_t cy)
void addOutputUI(void)
{
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
obs_module_text("Decklink Output"));
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("Decklink Output"));
QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window();
QMainWindow *window = (QMainWindow *)obs_frontend_get_main_window();
obs_frontend_push_ui_translation(obs_module_get_string);
doUI = new DecklinkOutputUI(window);
obs_frontend_pop_ui_translation();
auto cb = []() {
doUI->ShowHideDialog();
};
auto cb = []() { doUI->ShowHideDialog(); };
action->connect(action, &QAction::triggered, cb);
}
@@ -271,7 +290,8 @@ static void OBSEvent(enum obs_frontend_event event, void *)
OBSData previewSettings = load_preview_settings();
if (previewSettings && obs_data_get_bool(previewSettings, "auto_start"))
if (previewSettings &&
obs_data_get_bool(previewSettings, "auto_start"))
preview_output_start();
}
}

View File

@@ -17,7 +17,7 @@
using namespace std;
static Display* xdisplay = 0;
static Display *xdisplay = 0;
Display *disp()
{
@@ -39,31 +39,22 @@ void cleanupDisplay()
static bool ewmhIsSupported()
{
Display *display = disp();
Atom netSupportingWmCheck = XInternAtom(display,
"_NET_SUPPORTING_WM_CHECK", true);
Atom netSupportingWmCheck =
XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", true);
Atom actualType;
int format = 0;
unsigned long num = 0, bytes = 0;
unsigned char *data = NULL;
Window ewmh_window = 0;
int status = XGetWindowProperty(
display,
DefaultRootWindow(display),
netSupportingWmCheck,
0L,
1L,
false,
XA_WINDOW,
&actualType,
&format,
&num,
&bytes,
&data);
int status = XGetWindowProperty(display, DefaultRootWindow(display),
netSupportingWmCheck, 0L, 1L, false,
XA_WINDOW, &actualType, &format, &num,
&bytes, &data);
if (status == Success) {
if (num > 0) {
ewmh_window = ((Window*)data)[0];
ewmh_window = ((Window *)data)[0];
}
if (data) {
XFree(data);
@@ -72,21 +63,12 @@ static bool ewmhIsSupported()
}
if (ewmh_window) {
status = XGetWindowProperty(
display,
ewmh_window,
netSupportingWmCheck,
0L,
1L,
false,
XA_WINDOW,
&actualType,
&format,
&num,
&bytes,
&data);
status = XGetWindowProperty(display, ewmh_window,
netSupportingWmCheck, 0L, 1L, false,
XA_WINDOW, &actualType, &format,
&num, &bytes, &data);
if (status != Success || num == 0 ||
ewmh_window != ((Window*)data)[0]) {
ewmh_window != ((Window *)data)[0]) {
ewmh_window = 0;
}
if (status == Success && data) {
@@ -111,24 +93,15 @@ static std::vector<Window> getTopLevelWindows()
Atom actualType;
int format;
unsigned long num, bytes;
Window* data = 0;
Window *data = 0;
for (int i = 0; i < ScreenCount(disp()); ++i) {
Window rootWin = RootWindow(disp(), i);
int status = XGetWindowProperty(
disp(),
rootWin,
netClList,
0L,
~0L,
false,
AnyPropertyType,
&actualType,
&format,
&num,
&bytes,
(uint8_t**)&data);
int status = XGetWindowProperty(disp(), rootWin, netClList, 0L,
~0L, false, AnyPropertyType,
&actualType, &format, &num,
&bytes, (uint8_t **)&data);
if (status != Success) {
continue;
@@ -147,11 +120,10 @@ static std::string GetWindowTitle(size_t i)
{
Window w = getTopLevelWindows().at(i);
std::string windowTitle;
char* name;
char *name;
int status = XFetchName(disp(), w, &name);
if (status >= Success && name != nullptr)
{
if (status >= Success && name != nullptr) {
std::string str(name);
windowTitle = str;
}
@@ -165,7 +137,7 @@ void GetWindowList(vector<string> &windows)
{
windows.resize(0);
for (size_t i = 0; i < getTopLevelWindows().size(); ++i){
for (size_t i = 0; i < getTopLevelWindows().size(); ++i) {
if (GetWindowTitle(i) != "")
windows.emplace_back(GetWindowTitle(i));
}
@@ -181,24 +153,14 @@ void GetCurrentWindowTitle(string &title)
Atom actualType;
int format;
unsigned long num, bytes;
Window* data = 0;
char* name;
Window *data = 0;
char *name;
Window rootWin = RootWindow(disp(), 0);
XGetWindowProperty(
disp(),
rootWin,
active,
0L,
~0L,
false,
AnyPropertyType,
&actualType,
&format,
&num,
&bytes,
(uint8_t**)&data);
XGetWindowProperty(disp(), rootWin, active, 0L, ~0L, false,
AnyPropertyType, &actualType, &format, &num, &bytes,
(uint8_t **)&data);
int status = XFetchName(disp(), data[0], &name);

View File

@@ -32,7 +32,7 @@ static bool WindowValid(HWND window)
return false;
GetClientRect(window, &rect);
styles = GetWindowLongPtr(window, GWL_STYLE);
styles = GetWindowLongPtr(window, GWL_STYLE);
ex_styles = GetWindowLongPtr(window, GWL_EXSTYLE);
if (ex_styles & WS_EX_TOOLWINDOW)

View File

@@ -69,23 +69,19 @@ struct SwitcherData {
}
}
inline ~SwitcherData()
{
Stop();
}
inline ~SwitcherData() { Stop(); }
};
static SwitcherData *switcher = nullptr;
static inline QString MakeSwitchName(const QString &scene,
const QString &window)
const QString &window)
{
return QStringLiteral("[") + scene + QStringLiteral("]: ") + window;
}
SceneSwitcher::SceneSwitcher(QWidget *parent)
: QDialog(parent),
ui(new Ui_SceneSwitcher)
: QDialog(parent), ui(new Ui_SceneSwitcher)
{
ui->setupUi(this);
@@ -95,7 +91,7 @@ SceneSwitcher::SceneSwitcher(QWidget *parent)
switcher->Prune();
BPtr<char*> scenes = obs_frontend_get_scene_names();
BPtr<char *> scenes = obs_frontend_get_scene_names();
char **temp = scenes;
while (*temp) {
const char *name = *temp;
@@ -110,7 +106,7 @@ SceneSwitcher::SceneSwitcher(QWidget *parent)
ui->noMatchDontSwitch->setChecked(true);
ui->noMatchSwitchScene->setCurrentText(
GetWeakSourceName(switcher->nonMatchingScene).c_str());
GetWeakSourceName(switcher->nonMatchingScene).c_str());
ui->checkInterval->setValue(switcher->interval);
vector<string> windows;
@@ -121,11 +117,10 @@ SceneSwitcher::SceneSwitcher(QWidget *parent)
for (auto &s : switcher->switches) {
string sceneName = GetWeakSourceName(s.scene);
QString text = MakeSwitchName(sceneName.c_str(),
s.window.c_str());
QString text =
MakeSwitchName(sceneName.c_str(), s.window.c_str());
QListWidgetItem *item = new QListWidgetItem(text,
ui->switches);
QListWidgetItem *item = new QListWidgetItem(text, ui->switches);
item->setData(Qt::UserRole, s.window.c_str());
}
@@ -137,7 +132,7 @@ SceneSwitcher::SceneSwitcher(QWidget *parent)
loading = false;
}
void SceneSwitcher::closeEvent(QCloseEvent*)
void SceneSwitcher::closeEvent(QCloseEvent *)
{
obs_frontend_save();
}
@@ -149,8 +144,7 @@ int SceneSwitcher::FindByData(const QString &window)
for (int i = 0; i < count; i++) {
QListWidgetItem *item = ui->switches->item(i);
QString itemWindow =
item->data(Qt::UserRole).toString();
QString itemWindow = item->data(Qt::UserRole).toString();
if (itemWindow == window) {
idx = i;
@@ -206,16 +200,16 @@ void SceneSwitcher::on_add_clicked()
if (idx == -1) {
try {
lock_guard<mutex> lock(switcher->m);
switcher->switches.emplace_back(source,
windowName.toUtf8().constData());
QListWidgetItem *item = new QListWidgetItem(text,
ui->switches);
switcher->switches.emplace_back(
source, windowName.toUtf8().constData());
QListWidgetItem *item =
new QListWidgetItem(text, ui->switches);
item->setData(Qt::UserRole, v);
} catch (const regex_error &) {
QMessageBox::warning(this,
obs_module_text("InvalidRegex.Title"),
obs_module_text("InvalidRegex.Text"));
QMessageBox::warning(
this, obs_module_text("InvalidRegex.Title"),
obs_module_text("InvalidRegex.Text"));
}
} else {
QListWidgetItem *item = ui->switches->item(idx);
@@ -274,8 +268,7 @@ void SceneSwitcher::on_startAtLaunch_toggled(bool value)
void SceneSwitcher::UpdateNonMatchingScene(const QString &name)
{
obs_source_t *scene = obs_get_source_by_name(
name.toUtf8().constData());
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
switcher->nonMatchingScene = ws;
@@ -303,8 +296,7 @@ void SceneSwitcher::on_noMatchSwitch_clicked()
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
}
void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(
const QString &text)
void SceneSwitcher::on_noMatchSwitchScene_currentTextChanged(const QString &text)
{
if (loading)
return;
@@ -357,13 +349,13 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
for (SceneSwitch &s : switcher->switches) {
obs_data_t *array_obj = obs_data_create();
obs_source_t *source = obs_weak_source_get_source(
s.scene);
obs_source_t *source =
obs_weak_source_get_source(s.scene);
if (source) {
const char *n = obs_source_get_name(source);
obs_data_set_string(array_obj, "scene", n);
obs_data_set_string(array_obj, "window_title",
s.window.c_str());
s.window.c_str());
obs_data_array_push_back(array, array_obj);
obs_source_release(source);
}
@@ -376,9 +368,9 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
obs_data_set_int(obj, "interval", switcher->interval);
obs_data_set_string(obj, "non_matching_scene",
nonMatchingSceneName.c_str());
nonMatchingSceneName.c_str());
obs_data_set_bool(obj, "switch_if_not_matching",
switcher->switchIfNotMatching);
switcher->switchIfNotMatching);
obs_data_set_bool(obj, "active", switcher->th.joinable());
obs_data_set_array(obj, "switches", array);
@@ -389,8 +381,8 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
} else {
switcher->m.lock();
obs_data_t *obj = obs_data_get_obj(save_data,
"auto-scene-switcher");
obs_data_t *obj =
obs_data_get_obj(save_data, "auto-scene-switcher");
obs_data_array_t *array = obs_data_get_array(obj, "switches");
size_t count = obs_data_array_count(array);
@@ -420,8 +412,7 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
obs_data_get_string(array_obj, "window_title");
switcher->switches.emplace_back(
GetWeakSourceByName(scene),
window);
GetWeakSourceByName(scene), window);
obs_data_release(array_obj);
}
@@ -476,18 +467,18 @@ void SwitcherData::Thread()
for (SceneSwitch &s : switches) {
try {
bool matches = regex_match(
title, s.re);
title, s.re);
if (matches) {
match = true;
scene = s.scene;
break;
}
} catch (const regex_error &) {}
} catch (const regex_error &) {
}
}
}
if (!match && switchIfNotMatching &&
nonMatchingScene) {
if (!match && switchIfNotMatching && nonMatchingScene) {
match = true;
scene = nonMatchingScene;
}
@@ -513,7 +504,7 @@ void SwitcherData::Thread()
void SwitcherData::Start()
{
if (!switcher->th.joinable())
switcher->th = thread([] () {switcher->Thread();});
switcher->th = thread([]() { switcher->Thread(); });
}
void SwitcherData::Stop()
@@ -542,17 +533,16 @@ static void OBSEvent(enum obs_frontend_event event, void *)
extern "C" void InitSceneSwitcher()
{
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
obs_module_text("SceneSwitcher"));
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("SceneSwitcher"));
switcher = new SwitcherData;
auto cb = [] ()
{
auto cb = []() {
obs_frontend_push_ui_translation(obs_module_get_string);
QMainWindow *window =
(QMainWindow*)obs_frontend_get_main_window();
(QMainWindow *)obs_frontend_get_main_window();
SceneSwitcher ss(window);
ss.exec();

View File

@@ -1,33 +1,24 @@
#include "captions-handler.hpp"
captions_handler::captions_handler(
captions_cb callback,
enum audio_format format,
uint32_t sample_rate)
captions_handler::captions_handler(captions_cb callback,
enum audio_format format,
uint32_t sample_rate)
: cb(callback)
{
if (!reset_resampler(format, sample_rate))
throw CAPTIONS_ERROR_GENERIC_FAIL;
}
bool captions_handler::reset_resampler(
enum audio_format format,
uint32_t sample_rate)
bool captions_handler::reset_resampler(enum audio_format format,
uint32_t sample_rate)
try {
obs_audio_info ai;
if (!obs_get_audio_info(&ai))
throw std::string("Failed to get OBS audio info");
resample_info src = {
ai.samples_per_sec,
AUDIO_FORMAT_FLOAT_PLANAR,
ai.speakers
};
resample_info dst = {
sample_rate,
format,
SPEAKERS_MONO
};
resample_info src = {ai.samples_per_sec, AUDIO_FORMAT_FLOAT_PLANAR,
ai.speakers};
resample_info dst = {sample_rate, format, SPEAKERS_MONO};
if (!resampler.reset(dst, src))
throw std::string("Failed to create audio resampler");
@@ -46,9 +37,9 @@ void captions_handler::push_audio(const audio_data *audio)
uint64_t ts_offset;
bool success;
success = audio_resampler_resample(resampler,
out, &frames, &ts_offset,
(const uint8_t *const *)audio->data, audio->frames);
success = audio_resampler_resample(resampler, out, &frames, &ts_offset,
(const uint8_t *const *)audio->data,
audio->frames);
if (success)
pcm_data(out[0], frames);
}

View File

@@ -9,10 +9,7 @@ class resampler_obj {
audio_resampler_t *resampler = nullptr;
public:
inline ~resampler_obj()
{
audio_resampler_destroy(resampler);
}
inline ~resampler_obj() { audio_resampler_destroy(resampler); }
inline bool reset(const resample_info &dst, const resample_info &src)
{
@@ -21,15 +18,15 @@ public:
return !!resampler;
}
inline operator audio_resampler_t*() {return resampler;}
inline operator audio_resampler_t *() { return resampler; }
};
/* ------------------------------------------------------------------------- */
typedef std::function<void (const std::string &)> captions_cb;
typedef std::function<void(const std::string &)> captions_cb;
#define captions_error(s) std::string(obs_module_text("Captions.Error." ## s))
#define CAPTIONS_ERROR_GENERIC_FAIL captions_error("GenericFail")
#define captions_error(s) std::string(obs_module_text("Captions.Error."##s))
#define CAPTIONS_ERROR_GENERIC_FAIL captions_error("GenericFail")
/* ------------------------------------------------------------------------- */
@@ -38,22 +35,17 @@ class captions_handler {
resampler_obj resampler;
protected:
inline void callback(const std::string &text)
{
cb(text);
}
inline void callback(const std::string &text) { cb(text); }
virtual void pcm_data(const void *data, size_t frames)=0;
virtual void pcm_data(const void *data, size_t frames) = 0;
/* always resamples to 1 channel */
bool reset_resampler(enum audio_format format, uint32_t sample_rate);
public:
/* throw std::string for errors shown to users */
captions_handler(
captions_cb callback,
enum audio_format format,
uint32_t sample_rate);
captions_handler(captions_cb callback, enum audio_format format,
uint32_t sample_rate);
virtual ~captions_handler() {}
void push_audio(const audio_data *audio);
@@ -62,6 +54,6 @@ public:
/* ------------------------------------------------------------------------- */
struct captions_handler_info {
std::string (*name)(void);
std::string (*name)(void);
captions_handler *(*create)(captions_cb cb, const std::string &lang);
};

View File

@@ -8,16 +8,17 @@
using namespace std;
#if 0
#define debugfunc(format, ...) blog(LOG_DEBUG, "[Captions] %s(" format ")", \
__FUNCTION__, ##__VA_ARGS__)
#define debugfunc(format, ...) \
blog(LOG_DEBUG, "[Captions] %s(" format ")", __FUNCTION__, \
##__VA_ARGS__)
#else
#define debugfunc(format, ...)
#endif
CaptionStream::CaptionStream(DWORD samplerate_, mssapi_captions *handler_) :
handler(handler_),
samplerate(samplerate_),
event(CreateEvent(nullptr, false, false, nullptr))
CaptionStream::CaptionStream(DWORD samplerate_, mssapi_captions *handler_)
: handler(handler_),
samplerate(samplerate_),
event(CreateEvent(nullptr, false, false, nullptr))
{
buf_info.ulMsMinNotification = 50;
buf_info.ulMsBufferSize = 500;
@@ -66,15 +67,15 @@ STDMETHODIMP CaptionStream::QueryInterface(REFIID riid, void **ppv)
} else if (riid == IID_IStream) {
AddRef();
*ppv = (IStream*)this;
*ppv = (IStream *)this;
} else if (riid == IID_ISpStreamFormat) {
AddRef();
*ppv = (ISpStreamFormat*)this;
*ppv = (ISpStreamFormat *)this;
} else if (riid == IID_ISpAudio) {
AddRef();
*ppv = (ISpAudio*)this;
*ppv = (ISpAudio *)this;
} else {
*ppv = nullptr;
@@ -134,8 +135,7 @@ STDMETHODIMP CaptionStream::Read(void *data, ULONG bytes, ULONG *read_bytes)
return hr;
}
STDMETHODIMP CaptionStream::Write(const void *, ULONG bytes,
ULONG*)
STDMETHODIMP CaptionStream::Write(const void *, ULONG bytes, ULONG *)
{
debugfunc("data, %lu, written_bytes", bytes);
UNUSED_PARAMETER(bytes);
@@ -146,7 +146,7 @@ STDMETHODIMP CaptionStream::Write(const void *, ULONG bytes,
// IStream methods
STDMETHODIMP CaptionStream::Seek(LARGE_INTEGER move, DWORD origin,
ULARGE_INTEGER *new_pos)
ULARGE_INTEGER *new_pos)
{
debugfunc("%lld, %lx, new_pos", move, origin);
UNUSED_PARAMETER(move);
@@ -170,8 +170,8 @@ STDMETHODIMP CaptionStream::SetSize(ULARGE_INTEGER new_size)
}
STDMETHODIMP CaptionStream::CopyTo(IStream *stream, ULARGE_INTEGER bytes,
ULARGE_INTEGER *read_bytes,
ULARGE_INTEGER *written_bytes)
ULARGE_INTEGER *read_bytes,
ULARGE_INTEGER *written_bytes)
{
HRESULT hr;
@@ -213,7 +213,7 @@ STDMETHODIMP CaptionStream::Revert(void)
}
STDMETHODIMP CaptionStream::LockRegion(ULARGE_INTEGER offset,
ULARGE_INTEGER size, DWORD type)
ULARGE_INTEGER size, DWORD type)
{
debugfunc("%llu, %llu, %ld", offset, size, type);
UNUSED_PARAMETER(offset);
@@ -224,7 +224,7 @@ STDMETHODIMP CaptionStream::LockRegion(ULARGE_INTEGER offset,
}
STDMETHODIMP CaptionStream::UnlockRegion(ULARGE_INTEGER offset,
ULARGE_INTEGER size, DWORD type)
ULARGE_INTEGER size, DWORD type)
{
debugfunc("%llu, %llu, %ld", offset, size, type);
UNUSED_PARAMETER(offset);
@@ -250,7 +250,7 @@ STDMETHODIMP CaptionStream::Stat(STATSTG *stg, DWORD flag)
if (flag == STATFLAG_DEFAULT) {
size_t byte_size = (wcslen(stat_name) + 1) * sizeof(wchar_t);
stg->pwcsName = (wchar_t*)CoTaskMemAlloc(byte_size);
stg->pwcsName = (wchar_t *)CoTaskMemAlloc(byte_size);
memcpy(stg->pwcsName, stat_name, byte_size);
}
@@ -267,7 +267,7 @@ STDMETHODIMP CaptionStream::Clone(IStream **stream)
// ISpStreamFormat methods
STDMETHODIMP CaptionStream::GetFormat(GUID *guid,
WAVEFORMATEX **co_mem_wfex_out)
WAVEFORMATEX **co_mem_wfex_out)
{
debugfunc("guid, co_mem_wfex_out");
@@ -282,7 +282,7 @@ STDMETHODIMP CaptionStream::GetFormat(GUID *guid,
void *wfex = CoTaskMemAlloc(sizeof(format));
memcpy(wfex, &format, sizeof(format));
*co_mem_wfex_out = (WAVEFORMATEX*)wfex;
*co_mem_wfex_out = (WAVEFORMATEX *)wfex;
return S_OK;
}
@@ -296,7 +296,7 @@ STDMETHODIMP CaptionStream::SetState(SPAUDIOSTATE state_, ULONGLONG)
}
STDMETHODIMP CaptionStream::SetFormat(REFGUID guid_ref,
const WAVEFORMATEX *wfex)
const WAVEFORMATEX *wfex)
{
debugfunc("guid, wfex");
if (!wfex)
@@ -306,7 +306,7 @@ STDMETHODIMP CaptionStream::SetFormat(REFGUID guid_ref,
lock_guard<mutex> lock(m);
memcpy(&format, wfex, sizeof(format));
if (!handler->reset_resampler(AUDIO_FORMAT_16BIT,
wfex->nSamplesPerSec))
wfex->nSamplesPerSec))
return E_FAIL;
/* 50 msec */
@@ -354,7 +354,7 @@ STDMETHODIMP CaptionStream::GetBufferInfo(SPAUDIOBUFFERINFO *buf_info_)
}
STDMETHODIMP CaptionStream::GetDefaultFormat(GUID *format,
WAVEFORMATEX **co_mem_wfex_out)
WAVEFORMATEX **co_mem_wfex_out)
{
debugfunc("format, co_mem_wfex_out");
@@ -365,7 +365,7 @@ STDMETHODIMP CaptionStream::GetDefaultFormat(GUID *format,
memcpy(wfex, &format, sizeof(format));
*format = SPDFID_WaveFormatEx;
*co_mem_wfex_out = (WAVEFORMATEX*)wfex;
*co_mem_wfex_out = (WAVEFORMATEX *)wfex;
return S_OK;
}

View File

@@ -13,10 +13,11 @@
class CircleBuf {
circlebuf buf = {};
public:
inline ~CircleBuf() {circlebuf_free(&buf);}
inline operator circlebuf*() {return &buf;}
inline circlebuf *operator->() {return &buf;}
inline ~CircleBuf() { circlebuf_free(&buf); }
inline operator circlebuf *() { return &buf; }
inline circlebuf *operator->() { return &buf; }
};
class mssapi_captions;
@@ -54,38 +55,38 @@ public:
// ISequentialStream methods
STDMETHODIMP Read(void *data, ULONG bytes, ULONG *read_bytes) override;
STDMETHODIMP Write(const void *data, ULONG bytes, ULONG *written_bytes)
override;
STDMETHODIMP Write(const void *data, ULONG bytes,
ULONG *written_bytes) override;
// IStream methods
STDMETHODIMP Seek(LARGE_INTEGER move, DWORD origin,
ULARGE_INTEGER *new_pos) override;
ULARGE_INTEGER *new_pos) override;
STDMETHODIMP SetSize(ULARGE_INTEGER new_size) override;
STDMETHODIMP CopyTo(IStream *stream, ULARGE_INTEGER bytes,
ULARGE_INTEGER *read_bytes,
ULARGE_INTEGER *written_bytes) override;
ULARGE_INTEGER *read_bytes,
ULARGE_INTEGER *written_bytes) override;
STDMETHODIMP Commit(DWORD commit_flags) override;
STDMETHODIMP Revert(void) override;
STDMETHODIMP LockRegion(ULARGE_INTEGER offset, ULARGE_INTEGER size,
DWORD type) override;
DWORD type) override;
STDMETHODIMP UnlockRegion(ULARGE_INTEGER offset, ULARGE_INTEGER size,
DWORD type) override;
DWORD type) override;
STDMETHODIMP Stat(STATSTG *stg, DWORD flags) override;
STDMETHODIMP Clone(IStream **stream) override;
// ISpStreamFormat methods
STDMETHODIMP GetFormat(GUID *guid, WAVEFORMATEX **co_mem_wfex_out)
override;
STDMETHODIMP GetFormat(GUID *guid,
WAVEFORMATEX **co_mem_wfex_out) override;
// ISpAudio methods
STDMETHODIMP SetState(SPAUDIOSTATE state, ULONGLONG reserved) override;
STDMETHODIMP SetFormat(REFGUID guid_ref, const WAVEFORMATEX *wfex)
override;
STDMETHODIMP SetFormat(REFGUID guid_ref,
const WAVEFORMATEX *wfex) override;
STDMETHODIMP GetStatus(SPAUDIOSTATUS *status) override;
STDMETHODIMP SetBufferInfo(const SPAUDIOBUFFERINFO *buf_info) override;
STDMETHODIMP GetBufferInfo(SPAUDIOBUFFERINFO *buf_info) override;
STDMETHODIMP GetDefaultFormat(GUID *format,
WAVEFORMATEX **co_mem_wfex_out) override;
WAVEFORMATEX **co_mem_wfex_out) override;
STDMETHODIMP_(HANDLE) EventHandle(void) override;
STDMETHODIMP GetVolumeLevel(ULONG *level) override;
STDMETHODIMP SetVolumeLevel(ULONG level) override;

View File

@@ -1,16 +1,13 @@
#include "captions-mssapi.hpp"
#define do_log(type, format, ...) blog(type, "[Captions] " format, \
##__VA_ARGS__)
#define do_log(type, format, ...) \
blog(type, "[Captions] " format, ##__VA_ARGS__)
#define error(format, ...) do_log(LOG_ERROR, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
mssapi_captions::mssapi_captions(
captions_cb callback,
const std::string &lang) try
: captions_handler(callback, AUDIO_FORMAT_16BIT, 16000)
{
mssapi_captions::mssapi_captions(captions_cb callback, const std::string &lang)
try : captions_handler(callback, AUDIO_FORMAT_16BIT, 16000) {
HRESULT hr;
std::wstring wlang;
@@ -33,7 +30,7 @@ mssapi_captions::mssapi_captions(
throw HRError("SpFindBestToken failed", hr);
hr = CoCreateInstance(CLSID_SpInprocRecognizer, nullptr, CLSCTX_ALL,
__uuidof(ISpRecognizer), (void**)&recognizer);
__uuidof(ISpRecognizer), (void **)&recognizer);
if (FAILED(hr))
throw HRError("CoCreateInstance for recognizer failed", hr);
@@ -50,7 +47,7 @@ mssapi_captions::mssapi_captions(
throw HRError("CreateRecoContext failed", hr);
ULONGLONG interest = SPFEI(SPEI_RECOGNITION) |
SPFEI(SPEI_END_SR_STREAM);
SPFEI(SPEI_END_SR_STREAM);
hr = context->SetInterest(interest, interest);
if (FAILED(hr))
throw HRError("SetInterest failed", hr);
@@ -80,7 +77,7 @@ mssapi_captions::mssapi_captions(
throw HRError("LoadDictation failed", hr);
try {
t = std::thread([this] () {main_thread();});
t = std::thread([this]() { main_thread(); });
} catch (...) {
throw "Failed to create thread";
}
@@ -133,8 +130,8 @@ try {
ISpRecoResult *result = event.RecoResult();
CoTaskMemPtr<wchar_t> text;
hr = result->GetText((ULONG)-1, (ULONG)-1,
true, &text, nullptr);
hr = result->GetText((ULONG)-1, (ULONG)-1, true,
&text, nullptr);
if (FAILED(hr))
continue;
@@ -168,12 +165,7 @@ void mssapi_captions::pcm_data(const void *data, size_t frames)
}
captions_handler_info mssapi_info = {
[] () -> std::string
{
return "Microsoft Speech-to-Text";
},
[] (captions_cb cb, const std::string &lang) -> captions_handler *
{
[]() -> std::string { return "Microsoft Speech-to-Text"; },
[](captions_cb cb, const std::string &lang) -> captions_handler * {
return new mssapi_captions(cb, lang);
}
};
}};

View File

@@ -27,16 +27,16 @@
class mssapi_captions : public captions_handler {
friend class CaptionStream;
ComPtr<CaptionStream> audio;
ComPtr<CaptionStream> audio;
ComPtr<ISpObjectToken> token;
ComPtr<ISpRecoGrammar> grammar;
ComPtr<ISpRecognizer> recognizer;
ComPtr<ISpRecognizer> recognizer;
ComPtr<ISpRecoContext> context;
HANDLE notify;
WinHandle stop;
std::thread t;
bool started = false;
HANDLE notify;
WinHandle stop;
std::thread t;
bool started = false;
void main_thread();

View File

@@ -31,8 +31,8 @@
#include "captions-mssapi.hpp"
#define do_log(type, format, ...) blog(type, "[Captions] " format, \
##__VA_ARGS__)
#define do_log(type, format, ...) \
blog(type, "[Captions] " format, ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
@@ -48,10 +48,10 @@ struct obs_captions {
unique_ptr<captions_handler> handler;
LANGID lang_id = GetUserDefaultUILanguage();
std::unordered_map<std::string, captions_handler_info&> handler_types;
std::unordered_map<std::string, captions_handler_info &> handler_types;
inline void register_handler(const char *id,
captions_handler_info &info)
captions_handler_info &info)
{
handler_types.emplace(id, info);
}
@@ -60,7 +60,7 @@ struct obs_captions {
void stop();
obs_captions();
inline ~obs_captions() {stop();}
inline ~obs_captions() { stop(); }
};
static obs_captions *captions = nullptr;
@@ -74,9 +74,9 @@ struct locale_info {
inline locale_info() {}
inline locale_info(const locale_info &) = delete;
inline locale_info(locale_info &&li)
: name(std::move(li.name)),
id(li.id)
{}
: name(std::move(li.name)), id(li.id)
{
}
};
static void get_valid_locale_names(vector<locale_info> &names);
@@ -84,16 +84,14 @@ static bool valid_lang(LANGID id);
/* ------------------------------------------------------------------------- */
CaptionsDialog::CaptionsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui_CaptionsDialog)
CaptionsDialog::CaptionsDialog(QWidget *parent)
: QDialog(parent), ui(new Ui_CaptionsDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
auto cb = [this] (obs_source_t *source)
{
auto cb = [this](obs_source_t *source) {
uint32_t caps = obs_source_get_output_flags(source);
QString name = obs_source_get_name(source);
@@ -111,8 +109,11 @@ CaptionsDialog::CaptionsDialog(QWidget *parent) :
ui->source->blockSignals(true);
ui->source->addItem(QStringLiteral(""));
ui->source->setCurrentIndex(0);
obs_enum_sources([] (void *data, obs_source_t *source) {
return (*static_cast<cb_t*>(data))(source);}, &cb);
obs_enum_sources(
[](void *data, obs_source_t *source) {
return (*static_cast<cb_t *>(data))(source);
},
&cb);
ui->source->blockSignals(false);
for (auto &ht : captions->handler_types) {
@@ -232,8 +233,8 @@ static void caption_text(const std::string &text)
}
}
static void audio_capture(void*, obs_source_t*,
const struct audio_data *audio, bool)
static void audio_capture(void *, obs_source_t *,
const struct audio_data *audio, bool)
{
captions->handler->push_audio(audio);
}
@@ -245,14 +246,13 @@ void obs_captions::start()
auto pair = handler_types.find(handler_id);
if (pair == handler_types.end()) {
warn("Failed to find handler '%s'",
handler_id.c_str());
warn("Failed to find handler '%s'", handler_id.c_str());
return;
}
if (!LCIDToLocaleName(lang_id, wname, 256, 0)) {
warn("Failed to get locale name: %d",
(int)GetLastError());
(int)GetLastError());
return;
}
@@ -271,24 +271,24 @@ void obs_captions::start()
}
try {
captions_handler *h = pair->second.create(caption_text,
lang_name);
captions_handler *h =
pair->second.create(caption_text, lang_name);
handler.reset(h);
OBSSource s = OBSGetStrongRef(source);
obs_source_add_audio_capture_callback(s,
audio_capture, nullptr);
obs_source_add_audio_capture_callback(s, audio_capture,
nullptr);
} catch (std::string text) {
QWidget *window =
(QWidget*)obs_frontend_get_main_window();
(QWidget *)obs_frontend_get_main_window();
warn("Failed to create handler: %s", text.c_str());
QMessageBox::warning(window,
QMessageBox::warning(
window,
obs_module_text("Captions.Error.GenericFail"),
text.c_str());
}
}
}
@@ -297,8 +297,8 @@ void obs_captions::stop()
{
OBSSource s = OBSGetStrongRef(source);
if (s)
obs_source_remove_audio_capture_callback(s,
audio_capture, nullptr);
obs_source_remove_audio_capture_callback(s, audio_capture,
nullptr);
handler.reset();
}
@@ -332,42 +332,18 @@ static void get_valid_locale_names(vector<locale_info> &locales)
char locale_name[256];
static const LANGID default_locales[] = {
0x0409,
0x0401,
0x0402,
0x0403,
0x0404,
0x0405,
0x0406,
0x0407,
0x0408,
0x040a,
0x040b,
0x040c,
0x040d,
0x040e,
0x040f,
0x0410,
0x0411,
0x0412,
0x0413,
0x0414,
0x0415,
0x0416,
0x0417,
0x0418,
0x0419,
0x041a,
0
};
0x0409, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406,
0x0407, 0x0408, 0x040a, 0x040b, 0x040c, 0x040d, 0x040e,
0x040f, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415,
0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0};
/* ---------------------------------- */
LANGID def_id = GetUserDefaultUILanguage();
LANGID id = def_id;
if (valid_lang(id) && get_locale_name(id, locale_name)) {
dstr_copy(cur.name, obs_module_text(
"Captions.CurrentSystemLanguage"));
dstr_copy(cur.name,
obs_module_text("Captions.CurrentSystemLanguage"));
dstr_replace(cur.name, "%1", locale_name);
cur.id = id;
@@ -381,8 +357,7 @@ static void get_valid_locale_names(vector<locale_info> &locales)
while (*locale) {
id = *locale;
if (id != def_id &&
valid_lang(id) &&
if (id != def_id && valid_lang(id) &&
get_locale_name(id, locale_name)) {
dstr_copy(cur.name, locale_name);
@@ -418,17 +393,17 @@ static void obs_event(enum obs_frontend_event event, void *)
FreeCaptions();
}
static void save_caption_data(obs_data_t *save_data, bool saving, void*)
static void save_caption_data(obs_data_t *save_data, bool saving, void *)
{
if (saving) {
obs_data_t *obj = obs_data_create();
obs_data_set_string(obj, "source",
captions->source_name.c_str());
captions->source_name.c_str());
obs_data_set_bool(obj, "enabled", !!captions->handler);
obs_data_set_int(obj, "lang_id", captions->lang_id);
obs_data_set_string(obj, "provider",
captions->handler_id.c_str());
captions->handler_id.c_str());
obs_data_set_obj(save_data, "captions", obj);
obs_data_release(obj);
@@ -440,15 +415,15 @@ static void save_caption_data(obs_data_t *save_data, bool saving, void*)
obj = obs_data_create();
obs_data_set_default_int(obj, "lang_id",
GetUserDefaultUILanguage());
GetUserDefaultUILanguage());
obs_data_set_default_string(obj, "provider", DEFAULT_HANDLER);
bool enabled = obs_data_get_bool(obj, "enabled");
captions->source_name = obs_data_get_string(obj, "source");
captions->lang_id = (int)obs_data_get_int(obj, "lang_id");
captions->handler_id = obs_data_get_string(obj, "provider");
captions->source = GetWeakSourceByName(
captions->source_name.c_str());
captions->source =
GetWeakSourceByName(captions->source_name.c_str());
obs_data_release(obj);
if (enabled)
@@ -458,17 +433,15 @@ static void save_caption_data(obs_data_t *save_data, bool saving, void*)
extern "C" void InitCaptions()
{
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
obs_module_text("Captions"));
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("Captions"));
captions = new obs_captions;
auto cb = [] ()
{
auto cb = []() {
obs_frontend_push_ui_translation(obs_module_get_string);
QWidget *window =
(QWidget*)obs_frontend_get_main_window();
QWidget *window = (QWidget *)obs_frontend_get_main_window();
CaptionsDialog dialog(window);
dialog.exec();

View File

@@ -13,19 +13,18 @@ using namespace std;
OutputTimer *ot;
OutputTimer::OutputTimer(QWidget *parent)
: QDialog(parent),
ui(new Ui_OutputTimer)
: QDialog(parent), ui(new Ui_OutputTimer)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QObject::connect(ui->outputTimerStream, SIGNAL(clicked()), this,
SLOT(StreamingTimerButton()));
SLOT(StreamingTimerButton()));
QObject::connect(ui->outputTimerRecord, SIGNAL(clicked()), this,
SLOT(RecordingTimerButton()));
SLOT(RecordingTimerButton()));
QObject::connect(ui->buttonBox->button(QDialogButtonBox::Close),
SIGNAL(clicked()), this, SLOT(hide()));
SIGNAL(clicked()), this, SLOT(hide()));
streamingTimer = new QTimer(this);
streamingTimerDisplay = new QTimer(this);
@@ -34,7 +33,7 @@ OutputTimer::OutputTimer(QWidget *parent)
recordingTimerDisplay = new QTimer(this);
}
void OutputTimer::closeEvent(QCloseEvent*)
void OutputTimer::closeEvent(QCloseEvent *)
{
obs_frontend_save();
}
@@ -78,9 +77,7 @@ void OutputTimer::StreamTimerStart()
int minutes = ui->streamingTimerMinutes->value();
int seconds = ui->streamingTimerSeconds->value();
int total = (((hours * 3600) +
(minutes * 60)) +
seconds) * 1000;
int total = (((hours * 3600) + (minutes * 60)) + seconds) * 1000;
if (total == 0)
total = 1000;
@@ -89,10 +86,10 @@ void OutputTimer::StreamTimerStart()
streamingTimer->setSingleShot(true);
QObject::connect(streamingTimer, SIGNAL(timeout()),
SLOT(EventStopStreaming()));
SLOT(EventStopStreaming()));
QObject::connect(streamingTimerDisplay, SIGNAL(timeout()), this,
SLOT(UpdateStreamTimerDisplay()));
SLOT(UpdateStreamTimerDisplay()));
streamingTimer->start();
streamingTimerDisplay->start(1000);
@@ -112,9 +109,7 @@ void OutputTimer::RecordTimerStart()
int minutes = ui->recordingTimerMinutes->value();
int seconds = ui->recordingTimerSeconds->value();
int total = (((hours * 3600) +
(minutes * 60)) +
seconds) * 1000;
int total = (((hours * 3600) + (minutes * 60)) + seconds) * 1000;
if (total == 0)
total = 1000;
@@ -123,10 +118,10 @@ void OutputTimer::RecordTimerStart()
recordingTimer->setSingleShot(true);
QObject::connect(recordingTimer, SIGNAL(timeout()),
SLOT(EventStopRecording()));
SLOT(EventStopRecording()));
QObject::connect(recordingTimerDisplay, SIGNAL(timeout()), this,
SLOT(UpdateRecordTimerDisplay()));
SLOT(UpdateRecordTimerDisplay()));
recordingTimer->start();
recordingTimerDisplay->start(1000);
@@ -226,60 +221,57 @@ static void SaveOutputTimer(obs_data_t *save_data, bool saving, void *)
obs_data_t *obj = obs_data_create();
obs_data_set_int(obj, "streamTimerHours",
ot->ui->streamingTimerHours->value());
ot->ui->streamingTimerHours->value());
obs_data_set_int(obj, "streamTimerMinutes",
ot->ui->streamingTimerMinutes->value());
ot->ui->streamingTimerMinutes->value());
obs_data_set_int(obj, "streamTimerSeconds",
ot->ui->streamingTimerSeconds->value());
ot->ui->streamingTimerSeconds->value());
obs_data_set_int(obj, "recordTimerHours",
ot->ui->recordingTimerHours->value());
ot->ui->recordingTimerHours->value());
obs_data_set_int(obj, "recordTimerMinutes",
ot->ui->recordingTimerMinutes->value());
ot->ui->recordingTimerMinutes->value());
obs_data_set_int(obj, "recordTimerSeconds",
ot->ui->recordingTimerSeconds->value());
ot->ui->recordingTimerSeconds->value());
obs_data_set_bool(obj, "autoStartStreamTimer",
ot->ui->autoStartStreamTimer->isChecked());
ot->ui->autoStartStreamTimer->isChecked());
obs_data_set_bool(obj, "autoStartRecordTimer",
ot->ui->autoStartRecordTimer->isChecked());
ot->ui->autoStartRecordTimer->isChecked());
obs_data_set_obj(save_data, "output-timer", obj);
obs_data_release(obj);
} else {
obs_data_t *obj = obs_data_get_obj(save_data,
"output-timer");
obs_data_t *obj = obs_data_get_obj(save_data, "output-timer");
if (!obj)
obj = obs_data_create();
ot->ui->streamingTimerHours->setValue(
obs_data_get_int(obj, "streamTimerHours"));
obs_data_get_int(obj, "streamTimerHours"));
ot->ui->streamingTimerMinutes->setValue(
obs_data_get_int(obj, "streamTimerMinutes"));
obs_data_get_int(obj, "streamTimerMinutes"));
ot->ui->streamingTimerSeconds->setValue(
obs_data_get_int(obj, "streamTimerSeconds"));
obs_data_get_int(obj, "streamTimerSeconds"));
ot->ui->recordingTimerHours->setValue(
obs_data_get_int(obj, "recordTimerHours"));
obs_data_get_int(obj, "recordTimerHours"));
ot->ui->recordingTimerMinutes->setValue(
obs_data_get_int(obj, "recordTimerMinutes"));
obs_data_get_int(obj, "recordTimerMinutes"));
ot->ui->recordingTimerSeconds->setValue(
obs_data_get_int(obj, "recordTimerSeconds"));
obs_data_get_int(obj, "recordTimerSeconds"));
ot->ui->autoStartStreamTimer->setChecked(
obs_data_get_bool(obj, "autoStartStreamTimer"));
obs_data_get_bool(obj, "autoStartStreamTimer"));
ot->ui->autoStartRecordTimer->setChecked(
obs_data_get_bool(obj, "autoStartRecordTimer"));
obs_data_get_bool(obj, "autoStartRecordTimer"));
obs_data_release(obj);
}
}
extern "C" void FreeOutputTimer()
{
}
extern "C" void FreeOutputTimer() {}
static void OBSEvent(enum obs_frontend_event event, void *)
{
@@ -299,19 +291,16 @@ static void OBSEvent(enum obs_frontend_event event, void *)
extern "C" void InitOutputTimer()
{
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
obs_module_text("OutputTimer"));
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("OutputTimer"));
obs_frontend_push_ui_translation(obs_module_get_string);
QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window();
QMainWindow *window = (QMainWindow *)obs_frontend_get_main_window();
ot = new OutputTimer(window);
auto cb = [] ()
{
ot->ShowHideDialog();
};
auto cb = []() { ot->ShowHideDialog(); };
obs_frontend_pop_ui_translation();

View File

@@ -43,7 +43,7 @@
/* ----------------------------------------------------------------- */
using OBSScript = OBSObj<obs_script_t*, obs_script_destroy>;
using OBSScript = OBSObj<obs_script_t *, obs_script_destroy>;
struct ScriptData {
std::vector<OBSScript> scripts;
@@ -92,11 +92,10 @@ ScriptLogWindow::ScriptLogWindow() : QWidget(nullptr)
QHBoxLayout *buttonLayout = new QHBoxLayout();
QPushButton *clearButton = new QPushButton(tr("Clear"));
connect(clearButton, &QPushButton::clicked,
this, &ScriptLogWindow::ClearWindow);
connect(clearButton, &QPushButton::clicked, this,
&ScriptLogWindow::ClearWindow);
QPushButton *closeButton = new QPushButton(tr("Close"));
connect(closeButton, &QPushButton::clicked,
this, &QDialog::hide);
connect(closeButton, &QPushButton::clicked, this, &QDialog::hide);
buttonLayout->addStretch();
buttonLayout->addWidget(clearButton);
@@ -112,8 +111,8 @@ ScriptLogWindow::ScriptLogWindow() : QWidget(nullptr)
resize(600, 400);
config_t *global_config = obs_frontend_get_global_config();
const char *geom = config_get_string(global_config,
"ScriptLogWindow", "geometry");
const char *geom =
config_get_string(global_config, "ScriptLogWindow", "geometry");
if (geom != nullptr) {
QByteArray ba = QByteArray::fromBase64(QByteArray(geom));
restoreGeometry(ba);
@@ -121,16 +120,15 @@ ScriptLogWindow::ScriptLogWindow() : QWidget(nullptr)
setWindowTitle(obs_module_text("ScriptLogWindow"));
connect(edit->verticalScrollBar(), &QAbstractSlider::sliderMoved,
this, &ScriptLogWindow::ScrollChanged);
connect(edit->verticalScrollBar(), &QAbstractSlider::sliderMoved, this,
&ScriptLogWindow::ScrollChanged);
}
ScriptLogWindow::~ScriptLogWindow()
{
config_t *global_config = obs_frontend_get_global_config();
config_set_string(global_config,
"ScriptLogWindow", "geometry",
saveGeometry().toBase64().constData());
config_set_string(global_config, "ScriptLogWindow", "geometry",
saveGeometry().toBase64().constData());
}
void ScriptLogWindow::ScrollChanged(int val)
@@ -180,17 +178,15 @@ void ScriptLogWindow::Clear()
/* ----------------------------------------------------------------- */
ScriptsTool::ScriptsTool()
: QWidget (nullptr),
ui (new Ui_ScriptsTool)
ScriptsTool::ScriptsTool() : QWidget(nullptr), ui(new Ui_ScriptsTool)
{
ui->setupUi(this);
RefreshLists();
#if PYTHON_UI
config_t *config = obs_frontend_get_global_config();
const char *path = config_get_string(config, "Python",
"Path" ARCH_NAME);
const char *path =
config_get_string(config, "Python", "Path" ARCH_NAME);
ui->pythonPath->setText(path);
ui->pythonPathLabel->setText(obs_module_text(PYTHONPATH_LABEL_TEXT));
#else
@@ -201,7 +197,7 @@ ScriptsTool::ScriptsTool()
delete propertiesView;
propertiesView = new QWidget();
propertiesView->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
QSizePolicy::Expanding);
ui->propertiesLayout->addWidget(propertiesView);
}
@@ -217,8 +213,8 @@ void ScriptsTool::RemoveScript(const char *path)
const char *script_path = obs_script_get_path(script);
if (strcmp(script_path, path) == 0) {
scriptData->scripts.erase(
scriptData->scripts.begin() + i);
scriptData->scripts.erase(scriptData->scripts.begin() +
i);
break;
}
}
@@ -323,7 +319,8 @@ void ScriptsTool::on_addScripts_clicked()
scriptData->scripts.emplace_back(script);
QListWidgetItem *item = new QListWidgetItem(script_file);
QListWidgetItem *item =
new QListWidgetItem(script_file);
item->setData(Qt::UserRole, QString(file));
ui->scripts->addItem(item);
@@ -343,8 +340,10 @@ void ScriptsTool::on_removeScripts_clicked()
QList<QListWidgetItem *> items = ui->scripts->selectedItems();
for (QListWidgetItem *item : items)
RemoveScript(item->data(Qt::UserRole).toString()
.toUtf8().constData());
RemoveScript(item->data(Qt::UserRole)
.toString()
.toUtf8()
.constData());
RefreshLists();
}
@@ -352,8 +351,10 @@ void ScriptsTool::on_reloadScripts_clicked()
{
QList<QListWidgetItem *> items = ui->scripts->selectedItems();
for (QListWidgetItem *item : items)
ReloadScript(item->data(Qt::UserRole).toString()
.toUtf8().constData());
ReloadScript(item->data(Qt::UserRole)
.toString()
.toUtf8()
.constData());
on_scripts_currentRowChanged(ui->scripts->currentRow());
}
@@ -368,9 +369,7 @@ void ScriptsTool::on_pythonPathBrowse_clicked()
{
QString curPath = ui->pythonPath->text();
QString newPath = QFileDialog::getExistingDirectory(
this,
ui->pythonPathLabel->text(),
curPath);
this, ui->pythonPathLabel->text(), curPath);
if (newPath.isEmpty())
return;
@@ -406,14 +405,14 @@ void ScriptsTool::on_scripts_currentRowChanged(int row)
if (row == -1) {
propertiesView = new QWidget();
propertiesView->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
QSizePolicy::Expanding);
ui->propertiesLayout->addWidget(propertiesView);
ui->description->setText(QString());
return;
}
QByteArray array = ui->scripts->item(row)->data(Qt::UserRole)
.toString().toUtf8();
QByteArray array =
ui->scripts->item(row)->data(Qt::UserRole).toString().toUtf8();
const char *path = array.constData();
obs_script_t *script = scriptData->FindScript(path);
@@ -425,9 +424,10 @@ void ScriptsTool::on_scripts_currentRowChanged(int row)
OBSData settings = obs_script_get_settings(script);
obs_data_release(settings);
propertiesView = new OBSPropertiesView(settings, script,
(PropertiesReloadCallback)obs_script_get_properties,
(PropertiesUpdateCallback)obs_script_update);
propertiesView = new OBSPropertiesView(
settings, script,
(PropertiesReloadCallback)obs_script_get_properties,
(PropertiesUpdateCallback)obs_script_update);
ui->propertiesLayout->addWidget(propertiesView);
ui->description->setText(obs_script_get_description(script));
}
@@ -457,8 +457,7 @@ static void obs_event(enum obs_frontend_event event, void *)
static void load_script_data(obs_data_t *load_data, bool, void *)
{
obs_data_array_t *array = obs_data_get_array(load_data,
"scripts-tool");
obs_data_array_t *array = obs_data_get_array(load_data, "scripts-tool");
delete scriptData;
scriptData = new ScriptData;
@@ -509,21 +508,19 @@ static void save_script_data(obs_data_t *save_data, bool saving, void *)
}
static void script_log(void *, obs_script_t *script, int log_level,
const char *message)
const char *message)
{
QString qmsg;
if (script) {
qmsg = QStringLiteral("[%1] %2").arg(
obs_script_get_file(script),
message);
obs_script_get_file(script), message);
} else {
qmsg = QStringLiteral("[Unknown Script] %1").arg(message);
}
QMetaObject::invokeMethod(scriptLogWindow, "AddLogMsg",
Q_ARG(int, log_level),
Q_ARG(QString, qmsg));
Q_ARG(int, log_level), Q_ARG(QString, qmsg));
}
extern "C" void InitScripts()
@@ -533,13 +530,13 @@ extern "C" void InitScripts()
obs_scripting_load();
obs_scripting_set_log_callback(script_log, nullptr);
QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction(
obs_module_text("Scripts"));
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("Scripts"));
#if PYTHON_UI
config_t *config = obs_frontend_get_global_config();
const char *python_path = config_get_string(config, "Python",
"Path" ARCH_NAME);
const char *python_path =
config_get_string(config, "Python", "Path" ARCH_NAME);
if (!obs_scripting_python_loaded() && python_path && *python_path)
obs_scripting_load_python(python_path);
@@ -547,8 +544,7 @@ extern "C" void InitScripts()
scriptData = new ScriptData;
auto cb = [] ()
{
auto cb = []() {
obs_frontend_push_ui_translation(obs_module_get_string);
if (!scriptsWindow) {