Skip to content

Commit 80e84a5

Browse files
committed
Support editing loop
1 parent 53d5f07 commit 80e84a5

28 files changed

+777
-50
lines changed

src/libs/application/dspxmodel/src/AnchorNode.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace dspx {
1919

2020
void AnchorNodePrivate::setInterp(AnchorNode::InterpolationMode interp_) {
2121
Q_Q(AnchorNode);
22-
if (auto engine = qjsEngine(q); engine && (interp_ != AnchorNode::None && interp_ != AnchorNode::Linear && interp_ != AnchorNode::Hermite)) {
23-
engine->throwError(QJSValue::RangeError, QStringLiteral("Interpolation mode must be one of None, Linear, or Hermite"));
22+
if ((interp_ != AnchorNode::None && interp_ != AnchorNode::Linear && interp_ != AnchorNode::Hermite)) {
23+
if (auto engine = qjsEngine(q))
24+
engine->throwError(QJSValue::RangeError, QStringLiteral("Interpolation mode must be one of None, Linear, or Hermite"));
2425
return;
2526
}
2627
setInterpUnchecked(interp_);
@@ -33,8 +34,9 @@ namespace dspx {
3334

3435
void AnchorNodePrivate::setX(int x_) {
3536
Q_Q(AnchorNode);
36-
if (auto engine = qjsEngine(q); engine && x_ < 0) {
37-
engine->throwError(QJSValue::RangeError, QStringLiteral("Position must be greater or equal to 0"));
37+
if (x_ < 0) {
38+
if (auto engine = qjsEngine(q))
39+
engine->throwError(QJSValue::RangeError, QStringLiteral("Position must be greater or equal to 0"));
3840
return;
3941
}
4042
setXUnchecked(x_);

src/libs/application/dspxmodel/src/ClipTime.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ namespace dspx {
3737

3838
void ClipTimePrivate::setLength(int length_) {
3939
Q_Q(ClipTime);
40-
if (auto engine = qjsEngine(q); engine && length_ < 0) {
41-
engine->throwError(QJSValue::RangeError, QStringLiteral("Length must be greater than or equal to 0"));
40+
if (length_ < 0) {
41+
if (auto engine = qjsEngine(q))
42+
engine->throwError(QJSValue::RangeError, QStringLiteral("Length must be greater than or equal to 0"));
4243
return;
4344
}
4445
setLengthUnchecked(length_);
@@ -51,8 +52,9 @@ namespace dspx {
5152

5253
void ClipTimePrivate::setClipStart(int clipStart_) {
5354
Q_Q(ClipTime);
54-
if (auto engine = qjsEngine(q); engine && clipStart_ < 0) {
55-
engine->throwError(QJSValue::RangeError, QStringLiteral("ClipStart must be greater than or equal to 0"));
55+
if (clipStart_ < 0) {
56+
if (auto engine = qjsEngine(q))
57+
engine->throwError(QJSValue::RangeError, QStringLiteral("ClipStart must be greater than or equal to 0"));
5658
return;
5759
}
5860
setClipStartUnchecked(clipStart_);
@@ -65,8 +67,9 @@ namespace dspx {
6567

6668
void ClipTimePrivate::setClipLen(int clipLen_) {
6769
Q_Q(ClipTime);
68-
if (auto engine = qjsEngine(q); engine && clipLen_ < 0) {
69-
engine->throwError(QJSValue::RangeError, QStringLiteral("ClipLen must be greater than or equal to 0"));
70+
if (clipLen_ < 0) {
71+
if (auto engine = qjsEngine(q))
72+
engine->throwError(QJSValue::RangeError, QStringLiteral("ClipLen must be greater than or equal to 0"));
7073
return;
7174
}
7275
setClipLenUnchecked(clipLen_);

src/libs/application/dspxmodel/src/Control.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ namespace dspx {
3333

3434
void ControlPrivate::setGain(double gain_) {
3535
Q_Q(Control);
36-
if (auto engine = qjsEngine(q); engine && (gain_ < 0)) {
37-
engine->throwError(QJSValue::RangeError, QStringLiteral("Gain must be greater or equal to 0"));
36+
if ((gain_ < 0)) {
37+
if (auto engine = qjsEngine(q))
38+
engine->throwError(QJSValue::RangeError, QStringLiteral("Gain must be greater or equal to 0"));
3839
return;
3940
}
4041
setGainUnchecked(gain_);
@@ -47,8 +48,9 @@ namespace dspx {
4748

4849
void ControlPrivate::setPan(double pan_) {
4950
Q_Q(Control);
50-
if (auto engine = qjsEngine(q); engine && (pan_ < -1 || pan_ > 1)) {
51-
engine->throwError(QJSValue::RangeError, QStringLiteral("Pan must be in range [-1.0, 1.0]"));
51+
if ((pan_ < -1 || pan_ > 1)) {
52+
if (auto engine = qjsEngine(q))
53+
engine->throwError(QJSValue::RangeError, QStringLiteral("Pan must be in range [-1.0, 1.0]"));
5254
return;
5355
}
5456
setPanUnchecked(pan_);

src/libs/application/dspxmodel/src/EntityObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace dspx {
2222
EntityObject::~EntityObject() {
2323
Q_D(EntityObject);
2424
if (d->model && d->handle) {
25-
25+
Q_ASSERT(false && "EntityObject::~EntityObject: handle is not null. You should call Model::destroyItem() to delete EntityObject.");
2626
}
2727
}
2828

src/libs/application/dspxmodel/src/Global.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ namespace dspx {
3434

3535
void GlobalPrivate::setCentShift(int centShift) {
3636
Q_Q(Global);
37-
if (auto engine = qjsEngine(q); engine && (centShift < -50 || centShift > 50)) {
38-
engine->throwError(QJSValue::RangeError, QStringLiteral("Cent shift must be in range [-50, 50]"));
37+
if ((centShift < -50 || centShift > 50)) {
38+
if (auto engine = qjsEngine(q))
39+
engine->throwError(QJSValue::RangeError, QStringLiteral("Cent shift must be in range [-50, 50]"));
3940
return;
4041
}
4142
setCentShiftUnchecked(centShift);

src/libs/application/dspxmodel/src/Label.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace dspx {
1919

2020
void LabelPrivate::setPos(int pos_) {
2121
Q_Q(Label);
22-
if (auto engine = qjsEngine(q); engine && pos_ < -0) {
23-
engine->throwError(QJSValue::RangeError, QStringLiteral("Pos must be greater or equal to 0"));
22+
if (pos_ < -0) {
23+
if (auto engine = qjsEngine(q))
24+
engine->throwError(QJSValue::RangeError, QStringLiteral("Pos must be greater or equal to 0"));
2425
return;
2526
}
2627
setPosUnchecked(pos_);

src/libs/application/dspxmodel/src/Model.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ namespace dspx {
210210
}
211211

212212
QDspx::Model Model::toQDspx() const {
213-
return {
213+
QDspx::Model model = {
214214
.version = QDspx::Model::V1,
215215
.content = {
216216
.global = global()->toQDspx(),
@@ -220,6 +220,14 @@ namespace dspx {
220220
.workspace = workspace()->toQDspx(),
221221
}
222222
};
223+
model.content.workspace["diffscope"] = QJsonObject{
224+
{"loop", QJsonObject{
225+
{"enabled", timeline()->isLoopEnabled()},
226+
{"start", timeline()->loopStart()},
227+
{"length", timeline()->loopLength()},
228+
}}
229+
};
230+
return model;
223231
}
224232

225233
void Model::fromQDspx(const QDspx::Model &model) {
@@ -229,6 +237,21 @@ namespace dspx {
229237
d->timeline->fromQDspx(model.content.timeline);
230238
d->tracks->fromQDspx(model.content.tracks);
231239
d->workspace->fromQDspx(model.content.workspace);
240+
{
241+
auto loop = model.content.workspace.value("diffscope").value("loop").toObject();
242+
auto enabled = loop.value("enabled").toBool();
243+
auto start = loop.value("start").toInt();
244+
auto length = loop.value("length").toInt();
245+
if (start < 0 || length <= 0) {
246+
d->timeline->setLoopEnabled(false);
247+
d->timeline->setLoopStart(0);
248+
d->timeline->setLoopLength(1920);
249+
} else {
250+
d->timeline->setLoopEnabled(enabled);
251+
d->timeline->setLoopStart(start);
252+
d->timeline->setLoopLength(length);
253+
}
254+
}
232255
}
233256

234257
Label *Model::createLabel() {
@@ -357,6 +380,12 @@ namespace dspx {
357380
ModelPrivate::proxySetEntityPropertyNotify(d->master, property, value);
358381
break;
359382
}
383+
case ModelStrategy::P_LoopEnabled:
384+
case ModelStrategy::P_LoopLength:
385+
case ModelStrategy::P_LoopStart: {
386+
ModelPrivate::proxySetEntityPropertyNotify(d->timeline, property, value);
387+
break;
388+
}
360389
default:
361390
Q_UNREACHABLE();
362391
}

src/libs/application/dspxmodel/src/ModelStrategy.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ namespace dspx {
6969
P_KeyNumber,
7070
P_Language,
7171
P_Length,
72+
P_LoopEnabled,
73+
P_LoopLength,
74+
P_LoopStart,
7275
P_Measure,
7376
P_Name,
7477
P_Numerator,
@@ -236,6 +239,10 @@ namespace dspx {
236239
auto v = value.toInt();
237240
return v >= 0;
238241
};
242+
static auto validateIntGreaterZero = [](const QVariant &value) {
243+
auto v = value.toInt();
244+
return v > 0;
245+
};
239246
static auto validateDoubleGreaterOrEqualZero = [](const QVariant &value) {
240247
auto v = value.toDouble();
241248
return v >= 0;
@@ -280,7 +287,10 @@ namespace dspx {
280287
{P_EditorName, QMetaType::QString},
281288
{P_ControlGain, QMetaType::Double},
282289
{P_ControlPan, QMetaType::Double, validatePan},
283-
{P_ControlMute, QMetaType::Bool}
290+
{P_ControlMute, QMetaType::Bool},
291+
{P_LoopEnabled, QMetaType::Bool},
292+
{P_LoopStart, QMetaType::Int, validateIntGreaterOrEqualZero},
293+
{P_LoopLength, QMetaType::Int, validateIntGreaterZero},
284294
};
285295
case EI_Label: return {
286296
{P_Position, QMetaType::Int, validateIntGreaterOrEqualZero},

0 commit comments

Comments
 (0)