Skip to content

Commit

Permalink
Hotfix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
p-yukusai authored Jan 19, 2024
2 parents 0be30c4 + 7af815b commit c252bf0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 46 deletions.
85 changes: 57 additions & 28 deletions src/ctrl/ExportParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,24 @@ class Exporter {
msgBox.exec();
}

bool finish(const std::function<bool()>& aWaiter) {
static constexpr int kMSec = 100;
bool finish(const std::function<bool()>& aWaiter, const exportUI::form* formPointer, int frameTickMax) {
QApplication::setOverrideCursor(Qt::BusyCursor);
if (mProcess) {
mProcess->closeWriteChannel();
int progressTicks = 0;
while (!mProcess->waitForFinished()) {
qDebug() << "Waiting for encode finish: " << this->mProcess->readAll().data();
mProcess->waitForFinished(kMSec);
QApplication::processEvents();
progressTicks++;
if (progressTicks == 4) {
progressTicks = 0;
}
if(formPointer != nullptr) {
formPointer->loadingMessage->setText(getProgressMessage(progressTicks));
formPointer->frameCounter->setText(getFrameMessage(frameTickMax, progressTicks));
formPointer->progressBar->setValue(static_cast<int>(100 * mProgress));
}
qDebug() << "Waiting for encode finish...";
mProcess->waitForFinished(5);
if (!aWaiter() || isExportFinished(export_obj.result) || export_errored(export_obj.result)) {
break;
}
Expand All @@ -909,8 +919,10 @@ class Exporter {
qDebug() << "Argument: " << export_obj.argument;
qDebug("------------");
mProcess.reset();
QApplication::restoreOverrideCursor();
return exitStatus == QProcess::NormalExit;
}
QApplication::restoreOverrideCursor();
return QProcess::NotRunning;
}
void destroyFramebuffers() {
Expand Down Expand Up @@ -1011,7 +1023,7 @@ class Exporter {
// message generation
QString getProgressMessage(int dotTick) const {
QString pDots;
const QString currentStatus = mIndex == mFrameCount ? tr("Encoding") : tr("Exporting");
const QString currentStatus = mIndex == mFrameCount ? tr("Encoding, please wait") : tr("Exporting");
if (dotTick == 0) {
return sCenterL + currentStatus + sCenterR;
}
Expand All @@ -1020,17 +1032,22 @@ class Exporter {
}
return sCenterL + currentStatus + pDots + sCenterR;
}
QString getFrameMessage(int tick) const {
QString getFrameMessage(int tick, int dotTick) const {
QString rString;
QString pDots;
for (int x = 0; x < dotTick; x++) {
pDots.append(".");
}
if (mSaveAsImage) {
rString = sCenterL + tr("Current frame: ") + QString::number(tick) + "/" + QString::number(mFrameCount) +
sCenterR;
}
// As it turns out doing pDots makes the encoder go wobbly and it's kind of disorientating, will keep here anyway
// in case i figure out later how to make it not so hard on the eyes.
else {
if(mParam.exportType == exportTarget::video && (mParam.videoParams.format == availableVideoFormats::gif
|| mParam.generalParams.useCustomPalette)){
if(*encodedFrame == 0){
rString = sCenterL + tr("Frame rendered: ") + QString::number(mIndex) + "/" + QString::number(mFrameCount) +
" | " + tr("Frame encoded: ") + tr(" Unable to get encoder data when generating / using palettes") +
" | " + tr("Frame encoded: ") + tr(" Processing...") +
sCenterR;
}
else {
Expand Down Expand Up @@ -1233,7 +1250,7 @@ class Exporter {
if(!export_errored(export_obj.result)){
export_obj.result = ffmpeg::ExportCanceled;
}
finish([=]() -> bool { return true; });
finish([=]() -> bool{ return true; }, form, frameTicks );
widget->deleteLater();
// Clean-up
if (!mSaveAsImage) {
Expand All @@ -1247,7 +1264,7 @@ class Exporter {
if (export_errored(export_obj.result)) {
qDebug("Export errored");
export_obj.errorLog.append("FFmpeg error detected, stopping render.");
finish([=]() -> bool { return true; });
finish([=]() -> bool { return true; }, form, frameTicks );
widget->deleteLater();
// Clean-up
if (!mSaveAsImage) {
Expand All @@ -1269,12 +1286,12 @@ class Exporter {
// a better idea to achieve the same please let me know!
form->pixmapLabel->setPixmap(QPixmap::fromImage(currentFrame).scaled(500, 300, Qt::KeepAspectRatio));
form->loadingMessage->setText(getProgressMessage(progressTicks));
form->frameCounter->setText(getFrameMessage(frameTicks));
form->frameCounter->setText(getFrameMessage(frameTicks, progressTicks));
form->progressBar->setValue(static_cast<int>(100 * mProgress));
QApplication::processEvents();
}
if (!mSaveAsImage) {
finish([=]() -> bool { return true; });
finish([=]() -> bool { return true; }, form, frameTicks );
}
if(exportResult.resultType == Ongoing && !export_errored(export_obj.result)) {
export_obj.result = ffmpeg::ExportSuccess;
Expand Down Expand Up @@ -1310,6 +1327,23 @@ class Exporter {
mProcess->connect(process, &QProcess::readyRead, [=] {
if (this->mProcess) {
export_obj.log.push_back(QString(this->mProcess->readAll().data()));
QString logs = export_obj.log.last();
bool containsErrors = (logs.contains("error", Qt::CaseInsensitive)
|| logs.contains("conversion failed", Qt::CaseInsensitive)
|| logs.contains("invalid", Qt::CaseInsensitive)
|| logs.contains("null", Qt::CaseInsensitive))
// Safely ignored errors
&& !logs.contains("invalid maxval", Qt::CaseInsensitive);

// Some errors during encoding are acceptable as FFmpeg will take care of them, as such we'll
// ignore them if the encoder has done at least one frame as this means it's doing something and not
// just failing to encode anything at all.
if (containsErrors && *encodedFrame == 0) {
export_obj.result = ffmpeg::ExportArgError;
export_obj.errorLog.append("The argument given to FFmpeg is invalid, conversion failed.");
export_obj.errorLog.append(logs);
mCancelled = true;
}
if (export_obj.log.last().contains("frame")) {
QRegularExpression rx(R"(frame\s*=\s*(\d+))");
*encodedFrame = rx.match(export_obj.log.last()).captured(1).toInt();
Expand All @@ -1321,24 +1355,19 @@ class Exporter {
mProcess->connect(process, &QProcess::bytesWritten, [=] {
if (this->mProcess) {
if (export_obj.procWaitTick >= 25) {
export_obj.result = ffmpeg::ExportTimedout;
export_obj.errorLog.append("Unable to read process data for 25+ ticks, FFmpeg timed out.");
mCancelled = true;
if(this->mProcess.isNull() || !this->mProcess->isReadable() || !this->mProcess->isWritable()) {
export_obj.result = ffmpeg::ExportTimedout;
export_obj.errorLog.append("Unable to read process data for 25+ ticks, FFmpeg timed out.");
mCancelled = true;
}
else {
export_obj.procWaitTick = 0;
}
}
export_obj.writeLog.push_back(QString(this->mProcess->readAll().data()));
QString lastLog = export_obj.log.last();
QString lastWriteLog = export_obj.log.last();
if(lastLog.contains("Conversion failed!") || lastWriteLog.contains("Conversion failed!")) {
export_obj.result = ffmpeg::ExportArgError;
export_obj.errorLog.append("The argument given to FFmpeg is invalid, conversion failed.");
mCancelled = true;
}

if ((mParam.exportType == exportTarget::video &&
mParam.videoParams.format == availableVideoFormats::gif) || mParam.generalParams.useCustomPalette) {
export_obj.procWaitTick = 0;
}
else if(lastLog == export_obj.latestLog && lastWriteLog == export_obj.latestWriteLog) {
if(lastLog == export_obj.latestLog && lastWriteLog == export_obj.latestWriteLog) {
export_obj.procWaitTick += 1;
}
else {
Expand Down Expand Up @@ -1409,7 +1438,7 @@ inline Exporter::Exporter(core::Project& aProject, QDialog* widget, exportParam&
mOverwriteConfirmation(false) {}
inline Exporter::~Exporter() {
// Finalize
finish([=] { return true; });
finish([=] { return true; }, nullptr, 0);
// Kill buffer
gl::Global::makeCurrent();
destroyFramebuffers();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/GeneralSettingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ GeneralSettingDialog::GeneralSettingDialog(GUIResources& aGUIResources, QWidget*
bAutoCbCopy = !isAutoCbCopy.isValid() || isAutoCbCopy.toBool();

auto isAutoFFmpegCheck = settings.value("ffmpeg_check");
mAutoFFmpegCheck = !isAutoFFmpegCheck.isValid() || isAutoFFmpegCheck.toBool();
mAutoFFmpegCheck = isAutoFFmpegCheck.isValid()? true : isAutoFFmpegCheck.toBool();

auto isKeyDelay = settings.value("generalsettings/keybindings/keyDelay");
mKeyDelay = isKeyDelay.isValid() ? isKeyDelay.toInt() : 125;
Expand Down
5 changes: 4 additions & 1 deletion src/gui/TimeLineEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ TimeLineEditorWidget::TimeLineEditorWidget(ViaPoint& aViaPoint, QWidget* aParent
auto* out = new QAction(tr("Out"), this);
auto* all = new QAction(tr("All"), this);

QVector<QAction*> ranges{all, in, out};
QVector<QAction*> ranges{in, out, all};
int x = 0;
for (auto range: ranges) {
mSelectRange->addAction(range);
Expand Down Expand Up @@ -308,6 +308,9 @@ void TimeLineEditorWidget::updateTheme(theme::Theme& aTheme) {
Q_UNUSED(aTheme) // TODO
mTimelineTheme.reset();
}
QSize TimeLineEditorWidget::getEditorSize() const {
return mEditor->modelSpaceSize();
}

void TimeLineEditorWidget::paintEvent(QPaintEvent* aEvent) {
QPainter painter;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/TimeLineEditorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class TimeLineEditorWidget: public QWidget {
void updateProjectAttribute();
void updateTheme(theme::Theme&);

QSize getEditorSize() const;

core::Frame currentFrame() const;
int maxFrame() const;

Expand Down
24 changes: 8 additions & 16 deletions src/gui/TimeLineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TimeLineWidget::TimeLineWidget(
mCameraInfo(),
mAbstractCursor(),
mVerticalScrollValue(0),
mHorizontalScrollValue(0),
mTimer(),
mElapsed(),
mBeginFrame(),
Expand Down Expand Up @@ -71,22 +72,16 @@ int TimeLineWidget::getFps() const { return mProject ? mProject->attribute().fps
double TimeLineWidget::getOneFrameTime() const { return 1000.0 / getFps(); }

QPoint TimeLineWidget::viewportTransform() const {
// @note bug? Sometimes, the value of vertical scroll bar is different from the set value.-
QPoint point = {-this->horizontalScrollBar()->value(), -this->verticalScrollBar()->value()};
// @note by yukusai: Fixed by the heresy you see below you, Qt is atrocious I swear...
if (mVerticalScrollValue != this->verticalScrollBar()->value()) {
point.setY(
mVerticalScrollValue > this->verticalScrollBar()->value() ? -mVerticalScrollValue
: -this->verticalScrollBar()->value()
);
}
// Do *not* use the value from the scrollbar itself, it does not work as intended.
QPoint point = {-this->horizontalScrollBar()->value(), -mVerticalScrollValue};
return point;
}

void TimeLineWidget::setScrollBarValue(const QPoint& aViewportTransform) {
this->horizontalScrollBar()->setValue(aViewportTransform.x());
this->verticalScrollBar()->setValue(aViewportTransform.y());
mVerticalScrollValue = aViewportTransform.y();
this->horizontalScrollBar()->setValue(-aViewportTransform.x());
this->verticalScrollBar()->setValue(-aViewportTransform.y());
mVerticalScrollValue = -aViewportTransform.y();
mHorizontalScrollValue = -aViewportTransform.x();
}

void TimeLineWidget::updateCamera() {
Expand Down Expand Up @@ -203,12 +198,9 @@ void TimeLineWidget::wheelEvent(QWheelEvent* aEvent) {
aEvent->ignore();
QPoint viewTrans = viewportTransform();
const QPoint cursor = aEvent->position().toPoint();

mInner->updateWheel(aEvent);

const QRect rectNext = mInner->rect();
viewTrans.setX(cursor.x() * rectNext.width() / mInner->parentWidget()->size().width());
// viewTrans.setX(static_cast<int>(cursor.x() + scale * (viewTrans.x() - cursor.x())));
viewTrans.setX(cursor.x() * rectNext.width() / mInner->parentWidget()->size().width() * -1);
setScrollBarValue(viewTrans);
updateCamera();
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/TimeLineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class TimeLineWidget: public QScrollArea {
core::CameraInfo mCameraInfo;
core::AbstractCursor mAbstractCursor;
int mVerticalScrollValue;
int mHorizontalScrollValue;

// for animation
QTimer mTimer;
Expand Down

0 comments on commit c252bf0

Please sign in to comment.