From c71b20bb95be98fe593c65731726ac0ce2702ee9 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Sun, 14 Sep 2025 20:43:56 +0800 Subject: [PATCH] add: add 3 functions. Provide the way to get current audio and video params. --- app/CMakeLists.txt | 4 +- app/common/CMakeLists.txt | 78 +++++++++---------- app/common/Current.cpp | 22 ++++++ app/common/Current.h | 62 ++++++++++++++++ app/pluginSupport/OliveInstance.cpp | 95 ++++++++++++++---------- app/pluginSupport/OliveInstance.h | 8 +- app/widget/timebased/timebasedwidget.cpp | 4 +- 7 files changed, 190 insertions(+), 83 deletions(-) create mode 100644 app/common/Current.cpp create mode 100644 app/common/Current.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 3776f5be6..37ccd41ed 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -26,7 +26,6 @@ set(OLIVE_SOURCES add_subdirectory(audio) add_subdirectory(cli) add_subdirectory(codec) -add_subdirectory(common) add_subdirectory(config) add_subdirectory(dialog) add_subdirectory(node) @@ -73,7 +72,10 @@ add_library(libolive-editor ${OLIVE_SOURCES} ${OLIVE_RESOURCES} ) +add_subdirectory(common) add_subdirectory(pluginSupport) + + target_compile_features(libolive-editor PUBLIC cxx_std_23) include_directories(../third_party/openfx/include ../third_party/openfx/HostSupport/include) diff --git a/app/common/CMakeLists.txt b/app/common/CMakeLists.txt index 68155d78a..310af6aef 100644 --- a/app/common/CMakeLists.txt +++ b/app/common/CMakeLists.txt @@ -14,43 +14,43 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -set(OLIVE_SOURCES - ${OLIVE_SOURCES} - common/cancelableobject.h - common/channellayout.h - common/commandlineparser.cpp - common/commandlineparser.h - common/crashpadinterface.cpp - common/crashpadinterface.h - common/crashpadutils.h - common/debug.cpp - common/debug.h - common/decibel.h - common/define.h - common/ffmpegutils.cpp - common/ffmpegutils.h - common/filefunctions.cpp - common/filefunctions.h - common/html.cpp - common/html.h - common/jobtime.cpp - common/jobtime.h - common/lerp.h - common/memorypool.h - common/ocioutils.cpp - common/ocioutils.h - common/oiioutils.cpp - common/oiioutils.h - common/otioutils.h - common/qtutils.cpp - common/qtutils.h - common/range.h - common/ratiodialog.cpp - common/ratiodialog.h - common/threadsafemap.h - common/tohex.h - common/util.h - common/xmlutils.cpp - common/xmlutils.h - PARENT_SCOPE +target_sources(libolive-editor PRIVATE + cancelableobject.h + channellayout.h + commandlineparser.cpp + commandlineparser.h + crashpadinterface.cpp + crashpadinterface.h + crashpadutils.h + Current.cpp + Current.h + debug.cpp + debug.h + decibel.h + define.h + ffmpegutils.cpp + ffmpegutils.h + filefunctions.cpp + filefunctions.h + html.cpp + html.h + jobtime.cpp + jobtime.h + lerp.h + memorypool.h + ocioutils.cpp + ocioutils.h + oiioutils.cpp + oiioutils.h + otioutils.h + qtutils.cpp + qtutils.h + range.h + ratiodialog.cpp + ratiodialog.h + threadsafemap.h + tohex.h + util.h + xmlutils.cpp + xmlutils.h ) diff --git a/app/common/Current.cpp b/app/common/Current.cpp new file mode 100644 index 000000000..75e2d276c --- /dev/null +++ b/app/common/Current.cpp @@ -0,0 +1,22 @@ +/* + * Olive Community Edition - Non-Linear Video Editor + * Copyright (C) 2025 Olive CE Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "Current.h" + +Current Current::current; \ No newline at end of file diff --git a/app/common/Current.h b/app/common/Current.h new file mode 100644 index 000000000..b2076e351 --- /dev/null +++ b/app/common/Current.h @@ -0,0 +1,62 @@ +/* + * Olive Community Edition - Non-Linear Video Editor + * Copyright (C) 2025 Olive CE Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef CURRENT_H +#define CURRENT_H +#include "render/videoparams.h" + +class Current { +public: + static Current& getInstance() + { + return current; + } + olive::VideoParams& currentVideoParams() + { + return currentVideoParams_; + } + olive::AudioParams& currentAudioParams() + { + return currentAudioParams_; + } + void setCurrentVideoParams(olive::VideoParams& params) + { + currentVideoParams_ = params; + } + void setCurrentAudioParams(olive::AudioParams& params) + { + currentAudioParams_ = params; + } + void setCurrentVideoParams(olive::VideoParams&& params) + { + currentVideoParams_ = params; + } + void setCurrentAudioParams(olive::AudioParams&& params) + { + currentAudioParams_ = params; + } +private: + static Current current; + olive::VideoParams currentVideoParams_; + olive::AudioParams currentAudioParams_; +}; + + + +#endif //CURRENT_H diff --git a/app/pluginSupport/OliveInstance.cpp b/app/pluginSupport/OliveInstance.cpp index 7c3177df8..2737e2f3a 100644 --- a/app/pluginSupport/OliveInstance.cpp +++ b/app/pluginSupport/OliveInstance.cpp @@ -18,90 +18,103 @@ #include "OliveInstance.h" #include "ofxCore.h" #include "ofxMessage.h" +#include "common/Current.h" + #include #include #include #include #include #include -namespace olive{ -namespace plugin { -OfxStatus OliveInstance::vmessage(const char* type, - const char* id, - const char* format, - va_list args){ +namespace olive +{ +namespace plugin +{ +OfxStatus OliveInstance::vmessage(const char *type, const char *id, + const char *format, va_list args) +{ + char *buffer = new char[1024]; - char *buffer=new char[1024]; - - memset(buffer, 0, 1024*sizeof(char)); + memset(buffer, 0, 1024 * sizeof(char)); vsprintf(buffer, format, args); QString message(buffer); - delete [] buffer; + delete[] buffer; - if(strncmp(type, kOfxMessageQuestion, strlen(kOfxMessageQuestion))){ + if (strncmp(type, kOfxMessageQuestion, strlen(kOfxMessageQuestion))) { + auto ret = QMessageBox::information( + nullptr, "", message, QMessageBox::Ok, QMessageBox::Cancel); - auto ret= QMessageBox::information(nullptr, - "", message, - QMessageBox::Ok, QMessageBox::Cancel); - - if(ret==QMessageBox::Ok){ + if (ret == QMessageBox::Ok) { return kOfxStatReplyYes; - } - else { + } else { return kOfxStatReplyNo; - } + } - } - else{ - QMessageBox::information(nullptr, - "", message); + } else { + QMessageBox::information(nullptr, "", message); return kOfxStatOK; } } -OfxStatus OliveInstance::setPersistentMessage(const char* type, - const char* id, - const char* format, - va_list args){ - char *buffer=new char[1024]; +OfxStatus OliveInstance::setPersistentMessage(const char *type, const char *id, + const char *format, va_list args) +{ + char *buffer = new char[1024]; - memset(buffer, 0, 1024*sizeof(char)); - int ret=vsprintf(buffer, format, args); - if(ret<0){ + memset(buffer, 0, 1024 * sizeof(char)); + int ret = vsprintf(buffer, format, args); + if (ret < 0) { return kOfxStatFailed; } QString message(buffer); - delete [] buffer; + delete[] buffer; // If This is a error message - if(strncmp(type, kOfxMessageError, strlen(kOfxMessageError))==0){ - persistentErrors_.append({ErrorType::Error, message}); + if (strncmp(type, kOfxMessageError, strlen(kOfxMessageError)) == 0) { + persistentErrors_.append({ ErrorType::Error, message }); QMessageBox::critical(nullptr, "", message); // TODO: tell the shell to show the error } // A warning - else if(strncmp(type, kOfxMessageWarning, strlen(kOfxMessageError))==0){ - persistentErrors_.append({ErrorType::Warning, message}); + else if (strncmp(type, kOfxMessageWarning, strlen(kOfxMessageError)) == 0) { + persistentErrors_.append({ ErrorType::Warning, message }); QMessageBox::warning(nullptr, "", message); // TODO: tell the shell to show the warning } // A simple information - else if(strncmp(type, kOfxMessageMessage, strlen(kOfxMessageError))==0){ - persistentErrors_.append({ErrorType::Message, message}); + else if (strncmp(type, kOfxMessageMessage, strlen(kOfxMessageError)) == 0) { + persistentErrors_.append({ ErrorType::Message, message }); QMessageBox::information(nullptr, "", message); - } - else{ + } else { return kOfxStatFailed; } return kOfxStatOK; } -OfxStatus OliveInstance::clearPersistentMessage(){ +OfxStatus OliveInstance::clearPersistentMessage() +{ persistentErrors_.clear(); // TODO: tell the shell to remove message. return kOfxStatOK; } +void OliveInstance::getProjectSize(double &xSize, double &ySize) const +{ + xSize = Current::getInstance().currentVideoParams().width(); + ySize = Current::getInstance().currentVideoParams().height(); +} +void OliveInstance::getProjectOffset(double &xOffset, double &yOffset) const +{ + xOffset = Current::getInstance().currentVideoParams().x(); + yOffset = Current::getInstance().currentVideoParams().y(); +} +void OliveInstance::getProjectExtent(double &xSize, double &ySize) const +{ + xSize = Current::getInstance().currentVideoParams().width(); + ySize = Current::getInstance().currentVideoParams().height(); + // TODO: Ensure this project does not support this. +} + } } diff --git a/app/pluginSupport/OliveInstance.h b/app/pluginSupport/OliveInstance.h index 2ae62b768..d2dc4ed9f 100644 --- a/app/pluginSupport/OliveInstance.h +++ b/app/pluginSupport/OliveInstance.h @@ -64,7 +64,13 @@ public: const char* format, va_list args) override; - OfxStatus clearPersistentMessage() override; + OfxStatus clearPersistentMessage() override; + + void getProjectSize(double& xSize, double& ySize) const override; + void getProjectOffset(double& xOffset, double& yOffset) const override; + void getProjectExtent(double& xSize, double& ySize) const override; + + private: QList persistentErrors_; diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index c087f0e4b..5fabbdcba 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -24,6 +24,7 @@ #include "common/range.h" #include "config/config.h" #include "core.h" +#include "common/Current.h" #include "dialog/markerproperties/markerpropertiesdialog.h" #include "node/project/sequence/sequence.h" #include "timeline/timelineundoworkarea.h" @@ -90,7 +91,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node) // Set viewer node ViewerOutput *old = viewer_node_; viewer_node_ = node; - + Current::getInstance().setCurrentVideoParams(viewer_node_->GetVideoParams()); + Current::getInstance().setCurrentAudioParams(viewer_node_->GetAudioParams()); if (old) { // Call potential derivative functions for disconnecting the viewer node DisconnectNodeEvent(old);