bool AddNew(QWidget *parent, const char *id, const char *name) { obs_source_t source = obs_get_output_source(0); obs_scene_t scene = obs_scene_from_source(source); bool success = false; if (!source) return false; source = obs_get_source_by_name(name); if (source) { QMessageBox::information(parent, QTStr("NameExists.Title"), QTStr("NameExists.Text")); } else { source = obs_source_create(OBS_SOURCE_TYPE_INPUT, id, name, NULL); if (source) { obs_add_source(source); obs_scene_add(scene, source); success = true; } } obs_source_release(source); obs_scene_release(scene); return success; }
void OBSBasic::AddSourceWithProperty(const char *id) { size_t curTime = base::Time::Now().ToTimeT(); const char *src_name = obs_source_get_display_name(id); std::ostringstream os; os << src_name << "_" << curTime; std::string name = os.str(); OBSScene scene = GetCurrentScene(); if (!scene) return; obs_source_t * source = obs_source_create(id, name.c_str(), NULL, nullptr); if (source) { obs_scene_atomic_update(scene, [](void *data, obs_scene_t *scene){ obs_scene_add(scene, (obs_source_t *)data); }, source); } CreatePropertiesWindow(source, true); obs_source_release(source); }
obs_source_t *obs_load_source(obs_data_t *source_data) { obs_source_t *source; const char *name = obs_data_get_string(source_data, "name"); const char *id = obs_data_get_string(source_data, "id"); obs_data_t *settings = obs_data_get_obj(source_data, "settings"); double volume; source = obs_source_create(OBS_SOURCE_TYPE_INPUT, id, name, settings); obs_data_set_default_double(source_data, "volume", 1.0); volume = obs_data_get_double(source_data, "volume"); obs_source_set_volume(source, (float)volume); obs_data_release(settings); return source; }
bool AddNew(QWidget *parent, const char *id, const char *name, const bool visible, OBSSource &newSource) { OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow()); OBSScene scene = main->GetCurrentScene(); bool success = false; if (!scene) return false; obs_source_t *source = obs_get_source_by_name(name); if (source) { OBSMessageBox::information(parent, QTStr("NameExists.Title"), QTStr("NameExists.Text")); } else { source = obs_source_create(id, name, NULL, nullptr); if (source) { AddSourceData data; data.source = source; data.visible = visible; obs_enter_graphics(); obs_scene_atomic_update(scene, AddSource, &data); obs_leave_graphics(); newSource = source; success = true; } } obs_source_release(source); return success; }
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int numCmd) { HWND hwnd = NULL; base_set_log_handler(do_log); try { hwnd = CreateTestWindow(instance); if (!hwnd) throw "Couldn't create main window"; /* ------------------------------------------------------ */ /* create OBS */ CreateOBS(hwnd); /* ------------------------------------------------------ */ /* load module */ if (obs_load_module("test-input") != 0) throw "Couldn't load module"; /* ------------------------------------------------------ */ /* create source */ SourceContext source = obs_source_create(SOURCE_INPUT, "random", "some randon source", NULL); if (!source) throw "Couldn't create random test source"; /* ------------------------------------------------------ */ /* create filter */ SourceContext filter = obs_source_create(SOURCE_FILTER, "test", "a nice little green filter", NULL); if (!filter) throw "Couldn't create test filter"; obs_source_filter_add(source, filter); /* ------------------------------------------------------ */ /* create scene and add source to scene (twice) */ SceneContext scene = obs_scene_create("test scene"); if (!scene) throw "Couldn't create scene"; AddTestItems(scene, source); /* ------------------------------------------------------ */ /* set the scene as the primary draw source and go */ obs_set_output_source(0, source); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } catch (char *error) { MessageBoxA(NULL, error, NULL, 0); } obs_shutdown(); blog(LOG_INFO, "Number of memory leaks: %llu", bnum_allocs()); DestroyWindow(hwnd); return 0; }
obs_scene_t *obs_scene_create(const char *name) { struct obs_source *source = obs_source_create("scene", name, NULL, NULL); return source->context.data; }
void BiLiTextSourcePropertyDlg::setupSourcePropertiesUI() { //注意:添加控件时,记得根据需要在最后添加控件的变动通知监视! //否则可能导致点了确定之后设置没有保存进去 ui.PropertyNameLab->setText(tr("Text Property")); //select from file auto FileTxtLayout = new QHBoxLayout(); FileTxtLayout->setSpacing(0); FileTxtLayout->setContentsMargins(0, 0, 0, 0); FromFileCheckBox = new QCheckBox(ui.PropertyWid); FromFileCheckBox->setFixedHeight(13); FromFileCheckBox->setObjectName(QStringLiteral("FromFileCheckBox")); FromFileCheckBox->setProperty("FromFileCheckBox", qVPtr<QCheckBox>::toVariant(FromFileCheckBox) ); auto BrowseFileBtn = new QPushButton(ui.PropertyWid); BrowseFileBtn->setObjectName(QStringLiteral("BrowseFileBtn")); QSizePolicy sizePolicyBrowseFileBtn(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicyBrowseFileBtn.setHeightForWidth(BrowseFileBtn->sizePolicy().hasHeightForWidth()); BrowseFileBtn->setSizePolicy(sizePolicyBrowseFileBtn); BrowseFileBtn->setMinimumSize(QSize(50, 25)); BrowseFileBtn->setMaximumSize(QSize(50, 25)); FilePathEdit = new QPlainTextEdit(); FilePathEdit->setObjectName(QStringLiteral("FilePathEdit")); QSizePolicy sizePolicyFilePathEdit(QSizePolicy::Expanding, QSizePolicy::Fixed); sizePolicyFilePathEdit.setHorizontalStretch(0); sizePolicyFilePathEdit.setVerticalStretch(0); sizePolicyFilePathEdit.setHeightForWidth(FilePathEdit->sizePolicy().hasHeightForWidth()); FilePathEdit->setSizePolicy(sizePolicyFilePathEdit); FilePathEdit->setFixedHeight(30); FilePathEdit->setReadOnly(true); connect(BrowseFileBtn, &QPushButton::clicked, [this](){ QString path = QFileDialog::getOpenFileName(this, tr("Select File"), QDir::currentPath(), tr("TxtFile (*.txt *.int *.log )")); if (path.isEmpty()) return; QFileInfo fileInfo(path); if (!fileInfo.isFile()) return; FilePathEdit->setPlainText(path); }); QSpacerItem *fileSpacer0 = new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *fileSpacer1 = new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); //QSpacerItem *fileSpacer2 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); FileTxtLayout->addWidget(FromFileCheckBox); FileTxtLayout->addItem(fileSpacer0); FileTxtLayout->addWidget(BrowseFileBtn); FileTxtLayout->addItem(fileSpacer1); FileTxtLayout->addWidget(FilePathEdit); PlainTextEdit = new QPlainTextEdit(); PlainTextEdit->setObjectName(QStringLiteral("PlainTextEdit")); QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(PlainTextEdit->sizePolicy().hasHeightForWidth()); PlainTextEdit->setSizePolicy(sizePolicy); PlainTextEdit->setFixedHeight(60); connect(PlainTextEdit, SIGNAL(textChanged()), this, SLOT(mSltTxtChanged())); auto FontHLayout = new QHBoxLayout(); FontHLayout->setSpacing(0); FontHLayout->setContentsMargins(0, 0, 27, 0); auto FontLab = new QLabel(ui.PropertyWid); FontLab->setObjectName(QStringLiteral("FontLab")); QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicy1.setHorizontalStretch(0); sizePolicy1.setVerticalStretch(0); sizePolicy1.setHeightForWidth(FontLab->sizePolicy().hasHeightForWidth()); FontLab->setSizePolicy(sizePolicy1); FontLab->setMinimumSize(QSize(62, 30)); FontLab->setMaximumSize(QSize(62, 30)); FontLab->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); FontHLayout->addWidget(FontLab); QSpacerItem *FontHLayout_spacer_h0 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); FontHLayout->addItem(FontHLayout_spacer_h0); FontComboBox = new QFontComboBox(ui.PropertyWid); FontComboBox->setFixedSize(142, 30); FontComboBox->setObjectName(QStringLiteral("FontComboBox")); FontComboBox->setStyleSheet(QStringLiteral("")); FontHLayout->addWidget(FontComboBox); connect(FontComboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(mSltFontComboxChanged(const QString &))); QSpacerItem *FontHLayout_spacer_h1 = new QSpacerItem(30, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); FontHLayout->addItem(FontHLayout_spacer_h1); auto ColorLab = new QLabel(ui.PropertyWid); ColorLab->setObjectName(QStringLiteral("ColorLab")); sizePolicy1.setHeightForWidth(ColorLab->sizePolicy().hasHeightForWidth()); ColorLab->setSizePolicy(sizePolicy1); ColorLab->setMinimumSize(QSize(40, 30)); ColorLab->setMaximumSize(QSize(40, 30)); ColorLab->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); FontHLayout->addWidget(ColorLab); QSpacerItem *FontHLayout_spacer_h2 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); FontHLayout->addItem(FontHLayout_spacer_h2); QVBoxLayout *ColorChangeBtn_layout = new QVBoxLayout(); ColorChangeBtn_layout->setSpacing(0); ColorChangeBtn_layout->setContentsMargins(0, 5, 0, 5); ColorChangeBtn = new QPushButton(ui.PropertyWid); ColorChangeBtn->setObjectName(QStringLiteral("ColorChangeBtn")); sizePolicy1.setHeightForWidth(ColorChangeBtn->sizePolicy().hasHeightForWidth()); ColorChangeBtn->setSizePolicy(sizePolicy1); ColorChangeBtn->setMinimumSize(QSize(30, 20)); ColorChangeBtn->setMaximumSize(QSize(30, 20)); ColorChangeBtn_layout->addWidget(ColorChangeBtn); FontHLayout->addLayout(ColorChangeBtn_layout); connect(ColorChangeBtn, &QPushButton::clicked, this, &BiLiTextSourcePropertyDlg::mSltColorChangeBtn); auto StyleHSpacer1 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); auto StyleHSpacer2 = new QSpacerItem(30, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); auto StyleHLayout = new QHBoxLayout(); StyleHLayout->setContentsMargins(0, 0, 151, 0); StyleHLayout->setSpacing(0); auto StyleLab = new QLabel(ui.PropertyWid); StyleLab->setObjectName(QStringLiteral("StyleLab")); sizePolicy1.setHeightForWidth(StyleLab->sizePolicy().hasHeightForWidth()); StyleLab->setSizePolicy(sizePolicy1); StyleLab->setMinimumSize(QSize(62, 13)); StyleLab->setMaximumSize(QSize(62, 13)); StyleLab->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); StyleHLayout->addWidget(StyleLab); StyleHLayout->addItem(StyleHSpacer1); auto BoldStyleCheckBox = new QCheckBox(ui.PropertyWid); BoldStyleCheckBox->setFixedHeight(13); BoldStyleCheckBox->setObjectName(QStringLiteral("BoldStyleCheckBox")); StyleHLayout->addWidget(BoldStyleCheckBox); auto ItalicCheckBox = new QCheckBox(ui.PropertyWid); ItalicCheckBox->setFixedHeight(13); ItalicCheckBox->setObjectName(QStringLiteral("ItalicCheckBox")); StyleHLayout->addItem(StyleHSpacer2); StyleHLayout->addWidget(ItalicCheckBox); FontComboBox->setProperty("BoldStyleCheckBox", qVPtr<QCheckBox>::toVariant(BoldStyleCheckBox) ); FontComboBox->setProperty("ItalicCheckBox", qVPtr<QCheckBox>::toVariant(ItalicCheckBox) ); auto OpacitySliderHLayout = new QHBoxLayout(); OpacitySliderHLayout->setSpacing(0); OpacitySliderHLayout->setContentsMargins(0, 0, 0, 0); auto OpacityLabel = new QLabel(); OpacityLabel->setObjectName("OpacityLabel"); OpacityLabel->setText(QApplication::translate("TextAddForm", "Opacity:", 0)); OpacityLabel->setMinimumSize(QSize(62, 16)); OpacityLabel->setMaximumSize(QSize(62, 16)); OpacityLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); OpacityValLabel = new QLabel(); OpacityValLabel->setObjectName("OpacityValLabel"); OpacityValLabel->setFixedSize(38, 16); OpacityValLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); auto OpacitySlider = new CircleSliderSlider(this); OpacitySlider->setFixedWidth(150); OpacitySlider->setRange(0, 255, 0); QSpacerItem *OpacitySliderHLayout_spacer0 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *OpacitySliderHLayout_spacer1 = new QSpacerItem(8, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *OpacitySliderHLayout_spacer2 = new QSpacerItem(8, 10, QSizePolicy::Expanding, QSizePolicy::Fixed); OpacitySliderHLayout->addWidget(OpacityLabel); OpacitySliderHLayout->addItem(OpacitySliderHLayout_spacer0); OpacitySliderHLayout->addWidget(OpacitySlider); OpacitySliderHLayout->addItem(OpacitySliderHLayout_spacer1); OpacitySliderHLayout->addWidget(OpacityValLabel); OpacitySliderHLayout->addItem(OpacitySliderHLayout_spacer2); ColorChangeBtn->setProperty("OpacitySlider", qVPtr<CircleSliderSlider>::toVariant(OpacitySlider)); ColorChangeBtn->setProperty("OpacityValLabel", qVPtr<QLabel>::toVariant(OpacityValLabel) ); QSpacerItem *ScrollSpeedSliderHLayout_spacer0 = new QSpacerItem(4, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *ScrollSpeedSliderHLayout_spacer1 = new QSpacerItem(8, 10, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *ScrollSpeedSliderHLayout_spacer2 = new QSpacerItem(8, 10, QSizePolicy::Expanding, QSizePolicy::Fixed); auto ScrollSpeedSliderHLayout = new QHBoxLayout(); ScrollSpeedSliderHLayout->setSpacing(0); ScrollSpeedSliderHLayout->setContentsMargins(0, 0, 0, 0); auto ScrollSpeedLabel = new QLabel(); ScrollSpeedLabel->setObjectName("ScrollSpeedLabel"); ScrollSpeedLabel->setText(QApplication::translate("TextAddForm", "ScrollSpeed:", 0)); ScrollSpeedLabel->setMinimumSize(QSize(62, 16)); ScrollSpeedLabel->setMaximumSize(QSize(62, 16)); ScrollSpeedLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); ScrollSpeedValLabel = new QLabel(); ScrollSpeedValLabel->setObjectName("ScrollSpeedValLabel"); ScrollSpeedSlider = new CircleSliderSlider(nullptr); ScrollSpeedSlider->setFixedWidth(150); ScrollSpeedValLabel->setFixedWidth(38); ScrollSpeedValLabel->setFixedHeight(16); ScrollSpeedValLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); ScrollSpeedSlider->setRange(0, 300, 0); ScrollSpeedSliderHLayout->addWidget(ScrollSpeedLabel); ScrollSpeedSliderHLayout->addItem(ScrollSpeedSliderHLayout_spacer0); ScrollSpeedSliderHLayout->addWidget(ScrollSpeedSlider); ScrollSpeedSliderHLayout->addItem(ScrollSpeedSliderHLayout_spacer1); ScrollSpeedSliderHLayout->addWidget(ScrollSpeedValLabel); ScrollSpeedSliderHLayout->addItem(ScrollSpeedSliderHLayout_spacer2); auto MainVLayout = new QVBoxLayout(ui.PropertyWid); MainVLayout->setObjectName(QStringLiteral("MainVLayout")); MainVLayout->setContentsMargins(14, 20, 14, 30); MainVLayout->setSpacing(0); QSpacerItem *spacer_v0 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *spacer_v1 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *spacer_v2 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *spacer_v3 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *spacer_v4 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); MainVLayout->addWidget(PlainTextEdit); MainVLayout->addItem(spacer_v0); MainVLayout->addLayout(FileTxtLayout); MainVLayout->addItem(spacer_v4); MainVLayout->addLayout(FontHLayout); MainVLayout->addItem(spacer_v1); MainVLayout->addLayout(StyleHLayout); MainVLayout->addItem(spacer_v2); MainVLayout->addLayout(OpacitySliderHLayout); MainVLayout->addItem(spacer_v3); MainVLayout->addLayout(ScrollSpeedSliderHLayout); FontLab->setText(QApplication::translate("TextAddForm", "Font:", 0)); ColorLab->setText(QApplication::translate("TextAddForm", "Color:", 0)); StyleLab->setText(QApplication::translate("TextAddForm", "Style:", 0)); BoldStyleCheckBox->setText(QApplication::translate("TextAddForm", "Bold", 0)); ItalicCheckBox->setText(QApplication::translate("TextAddForm", "Italic", 0)); FromFileCheckBox->setText(QApplication::translate("TextAddForm", "FromFile", 0)); BrowseFileBtn->setText(QApplication::translate("TextAddForm", "Browse", 0)); QMetaObject::connectSlotsByName(ui.PropertyWid); obs_data_t* settings = obs_source_get_settings(mSrc); DataToWidget(BILI_DATA_FONT(), FontComboBox, settings, "font"); DataToWidget(BILI_DATA_INT(), ColorChangeBtn, settings, "color1"); DataToWidget(BILI_DATA_STRING(), PlainTextEdit, settings, "text"); DataToWidget(BILI_DATA_STRING(), FilePathEdit, settings, "text_file"); DataToWidget(BILI_DATA_BOOL(), FromFileCheckBox, settings, "from_file"); obs_data_release(settings); //为文字源创建filter scrollFilter = obs_source_get_filter_by_name(mSrc, scroll_filter_id); if (!scrollFilter) { scrollFilter = obs_source_create(OBS_SOURCE_TYPE_FILTER, scroll_filter_id, scroll_filter_id, 0, 0); obs_source_filter_add(mSrc, scrollFilter); obs_data_t* settings = obs_data_create(); obs_data_set_bool(settings, "disable_repeat_if_no_speed", true); obs_source_update(scrollFilter, settings); obs_data_release(settings); } QObject::connect(ScrollSpeedSlider, &CircleSliderSlider::valueChanged, this, &BiLiTextSourcePropertyDlg::OnScrollSpeedSliderChanged); QObject::connect(OpacitySlider, &CircleSliderSlider::valueChanged, this, &BiLiTextSourcePropertyDlg::OnOpacitySliderChanged); //读取filter设置 FilterDataToWidget(BILI_DATA_DOUBLE(), ScrollSpeedSlider, mSrc, scroll_filter_id, "speed_x"); //读取透明度设置 settings = obs_source_get_settings(mSrc); int64_t color1 = obs_data_get_int(settings, "color1"); obs_data_release(settings); int opacity = (color1 >> 24) & 0xff; OpacitySlider->setValue(opacity); ScrollSpeedValLabel->setText(QString("%1%").arg(ScrollSpeedSlider->value())); OpacityValLabel->setText(QString("%1%").arg(OpacitySlider->value() * 100 / 255)); //添加监听控件变动 mChangeEvnetFilter->Watch({ PlainTextEdit, FontComboBox, /*ColorChangeBtn, */BoldStyleCheckBox, ItalicCheckBox, OpacitySlider, ScrollSpeedSlider, FromFileCheckBox, FilePathEdit }); connect(mChangeEvnetFilter.get(), SIGNAL(OnChangedSignal()), this, SLOT(mSltOnSettingChanged())); }