fix time up or down
This commit is contained in:
parent
d3999a80d2
commit
28575bc8c5
@ -1,5 +1,7 @@
|
||||
#include "workspace/Timestep.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
@ -14,6 +16,10 @@ Timestep::Timestep(const std::vector<double>& steps, const QString& path, WorkSp
|
||||
, path_(path)
|
||||
, workSpace_(parent) {
|
||||
maxTime_ = *steps_.rbegin();
|
||||
// 初始化为 1.0x,如果列表中没有 1.0,则取最接近中间的默认索引
|
||||
auto it = std::find(speedLevels_.begin(), speedLevels_.end(), 1.0);
|
||||
speedIndex_ = it != speedLevels_.end() ? int(std::distance(speedLevels_.begin(), it)) : speedIndex_;
|
||||
currentStep_ = speedLevels_[speedIndex_];
|
||||
}
|
||||
|
||||
Timestep* Timestep::Load(const QString& path, WorkSpace* workSpace) {
|
||||
@ -91,6 +97,11 @@ void Timestep::Start() {
|
||||
return;
|
||||
}
|
||||
workSpace_->Begin();
|
||||
// 重置速度为 1x 并通知 UI
|
||||
auto it = std::find(speedLevels_.begin(), speedLevels_.end(), 1.0);
|
||||
speedIndex_ = it != speedLevels_.end() ? int(std::distance(speedLevels_.begin(), it)) : speedIndex_;
|
||||
currentStep_ = speedLevels_[speedIndex_];
|
||||
emit StepChanged(currentStep_);
|
||||
emit StatusChanged((int)playStatus_);
|
||||
}
|
||||
|
||||
@ -123,17 +134,28 @@ void Timestep::Stop() {
|
||||
return;
|
||||
}
|
||||
workSpace_->End();
|
||||
// 停止时也恢复为 1x,避免停后再次播放仍是异常倍率
|
||||
auto it = std::find(speedLevels_.begin(), speedLevels_.end(), 1.0);
|
||||
speedIndex_ = it != speedLevels_.end() ? int(std::distance(speedLevels_.begin(), it)) : speedIndex_;
|
||||
currentStep_ = speedLevels_[speedIndex_];
|
||||
emit StepChanged(currentStep_);
|
||||
emit StatusChanged((int)playStatus_);
|
||||
}
|
||||
|
||||
void Timestep::Up() {
|
||||
currentSpeed *= 2;
|
||||
currentStep_ *= currentSpeed;
|
||||
emit StepChanged(currentSpeed);
|
||||
// 提升到下一个倍率(封顶)
|
||||
if (speedIndex_ < int(speedLevels_.size()) - 1) {
|
||||
++speedIndex_;
|
||||
}
|
||||
currentStep_ = speedLevels_[speedIndex_];
|
||||
emit StepChanged(currentStep_);
|
||||
}
|
||||
|
||||
void Timestep::Down() {
|
||||
currentSpeed *= 0.5;
|
||||
currentStep_ *= currentSpeed;
|
||||
emit StepChanged(currentSpeed);
|
||||
// 降到上一个倍率(保底)
|
||||
if (speedIndex_ > 0) {
|
||||
--speedIndex_;
|
||||
}
|
||||
currentStep_ = speedLevels_[speedIndex_];
|
||||
emit StepChanged(currentStep_);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
void Stop();
|
||||
|
||||
void Up();
|
||||
void Down();
|
||||
void Down();
|
||||
|
||||
WorkSpace* GetWorkSpace() const {
|
||||
return workSpace_;
|
||||
@ -56,15 +56,18 @@ Q_SIGNALS:
|
||||
|
||||
|
||||
private:
|
||||
std::vector<double> steps_;
|
||||
QString path_;
|
||||
double current_{ 0.0 };
|
||||
double maxTime_{ 0.0 };
|
||||
double currentStep_{ 1.0 };
|
||||
double currentSpeed = { 1.0 };
|
||||
std::vector<double> steps_;
|
||||
QString path_;
|
||||
double current_{ 0.0 };
|
||||
double maxTime_{ 0.0 };
|
||||
// 播放速度(倍率),与 UI 显示一致,比如 0.5x、1x、2x
|
||||
double currentStep_{ 1.0 };
|
||||
// 有限倍率列表,防止无限放大/缩小导致无法恢复
|
||||
std::vector<double> speedLevels_{ 0.25, 0.5, 1.0, 2.0, 4.0, 8.0 };
|
||||
int speedIndex_{ 2 }; // 默认指向 1.0x
|
||||
|
||||
|
||||
PlayStatus playStatus_{ PlayStatus::PS_Stoped };
|
||||
WorkSpace* workSpace_{ nullptr };
|
||||
PlayStatus playStatus_{ PlayStatus::PS_Stoped };
|
||||
WorkSpace* workSpace_{ nullptr };
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user