From 085cab3d524cc27e0b5eb853727054b53625fe8a Mon Sep 17 00:00:00 2001 From: manongjohn <19245851+manongjohn@users.noreply.github.com> Date: Mon, 29 May 2023 14:52:14 -0400 Subject: [PATCH] Fix implicit scene frame count --- toonz/sources/toonz/subscenecommand.cpp | 39 ++----------------------- toonz/sources/toonzlib/txsheet.cpp | 35 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/toonz/sources/toonz/subscenecommand.cpp b/toonz/sources/toonz/subscenecommand.cpp index e2c5a013..1df1c505 100644 --- a/toonz/sources/toonz/subscenecommand.cpp +++ b/toonz/sources/toonz/subscenecommand.cpp @@ -1283,39 +1283,6 @@ void removeFx(TXsheet *xsh, TFx *fx) { //----------------------------------------------------------------------------- -int getChildFrameCount(TXsheet *childXsh) { - if (!childXsh) return 0; - - int frameCount = childXsh->getFrameCount(); - - // For implicit holds, use last Stop Frame marker or last Key frame marker as - // frame count - if (Preferences::instance()->isImplicitHoldEnabled()) { - for (int c = 0; c < childXsh->getColumnCount(); c++) { - int r0, r1; - - r1 = childXsh->getMaxFrame(c); - TXshCell cell = childXsh->getCell(r1, c); - // If last frame is a stop frame, don't check for keyframe in the same - // column in case of overshoot - if (cell.getFrameId().isStopFrame()) { - frameCount = std::max(frameCount, (r1 + 1)); - continue; - } - - TStageObject *pegbar = - childXsh->getStageObject(TStageObjectId::ColumnId(c)); - if (!pegbar) continue; - if (!pegbar->getKeyframeRange(r0, r1)) continue; - frameCount = std::max(frameCount, (r1 + 1)); - } - } - - return frameCount; -} - -//----------------------------------------------------------------------------- - void collapseColumns(std::set indices, bool columnsOnly) { // return if there is no selected columns if (indices.empty()) return; @@ -1371,7 +1338,7 @@ void collapseColumns(std::set indices, bool columnsOnly) { xsh->insertColumn(index); // set subxsheet cells in the parent xhseet - int r, rowCount = getChildFrameCount(childXsh); + int r, rowCount = childXsh->getFrameCount(); for (r = 0; r < rowCount; ++r) xsh->setCell(r, index, TXshCell(xl, TFrameId(r + 1))); @@ -1474,7 +1441,7 @@ void collapseColumns(std::set indices, xsh->insertColumn(index); - int r, rowCount = getChildFrameCount(childXsh); + int r, rowCount = childXsh->getFrameCount(); for (r = 0; r < rowCount; r++) xsh->setCell(r, index, TXshCell(xl, TFrameId(r + 1))); @@ -1548,7 +1515,7 @@ void collapseColumns(std::set indices, const std::set &fxs, if (output) xsh->getFxDag()->removeOutputFx(output); } - int rowCount = getChildFrameCount(childXsh); + int rowCount = childXsh->getFrameCount(); int r; for (r = 0; r < rowCount; r++) xsh->setCell(r, index, TXshCell(xl, TFrameId(r + 1))); diff --git a/toonz/sources/toonzlib/txsheet.cpp b/toonz/sources/toonzlib/txsheet.cpp index a8f3f05c..374ce33f 100644 --- a/toonz/sources/toonzlib/txsheet.cpp +++ b/toonz/sources/toonzlib/txsheet.cpp @@ -229,7 +229,40 @@ unsigned long TXsheet::id() const { return m_imp->m_id; } //----------------------------------------------------------------------------- -int TXsheet::getFrameCount() const { return m_imp->m_frameCount; } +int TXsheet::getFrameCount() const { + if (!Preferences::instance()->isImplicitHoldEnabled()) + return m_imp->m_frameCount; + + // For implicit holds, use last Stop Frame marker or last Key frame marker as + // frame count + int r0, r1; + + int frameCount = m_imp->m_frameCount; + for (int c = 0; c < getColumnCount(); c++) { + + r1 = getMaxFrame(c); + TXshCell cell = getCell(r1, c); + // If last frame is a stop frame, don't check for keyframe in the same + // column in case of overshoot + if (cell.getFrameId().isStopFrame()) { + frameCount = std::max(frameCount, r1); + continue; + } + + TStageObject *pegbar = getStageObject(TStageObjectId::ColumnId(c)); + if (!pegbar) continue; + if (!pegbar->getKeyframeRange(r0, r1)) continue; + frameCount = std::max(frameCount, (r1 + 1)); + } + + // Check camera keys + TStageObjectId cameraId = getStageObjectTree()->getCurrentCameraId(); + TStageObject *camera = getStageObject(cameraId); + if (camera && camera->getKeyframeRange(r0, r1)) + frameCount = std::max(frameCount, (r1 + 1)); + + return frameCount; +} //-----------------------------------------------------------------------------