1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
|
/*
SPDX-FileCopyrightText: 2020-2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "catch.hpp"
#include "test_utils.hpp"
// test specific headers
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
#include <QString>
#include <cmath>
#include <iostream>
#include <tuple>
#include <unordered_set>
#include "core.h"
#include "definitions.h"
using namespace fakeit;
TEST_CASE("Simple Mix", "[SameTrackMix]")
{
// Ensure our core profile is correct
REQUIRE(pCore->timecode().fps() == 25.);
REQUIRE(pCore->getDurationFromString(KdenliveSettings::mix_duration()) == 25);
// Create timeline
auto binModel = pCore->projectItemModel();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
// Here we do some trickery to enable testing.
// We mock the project class so that the undoStack function returns our undoStack
KdenliveDoc document(undoStack);
pCore->projectManager()->testSetDocument(&document);
QDateTime documentDate = QDateTime::currentDateTime();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
auto timeline = document.getTimeline(document.uuid());
pCore->projectManager()->testSetActiveTimeline(timeline);
// Create a request
int tid1 = timeline->getTrackIndexFromPosition(0);
int tid3 = timeline->getTrackIndexFromPosition(1);
int tid2 = timeline->getTrackIndexFromPosition(2);
int tid4 = timeline->getTrackIndexFromPosition(3);
// Create clip with audio
QString binId = KdenliveTests::createProducerWithSound(pCore->getProjectProfile(), binModel, 100);
// Create video clip
QString binId2 = KdenliveTests::createProducer(pCore->getProjectProfile(), "red", binModel, 50, false);
// Setup insert stream data
QMap<int, QString> audioInfo;
audioInfo.insert(1, QStringLiteral("stream1"));
KdenliveTests::setAudioTargets(timeline, audioInfo);
// Create AV clip 1
int cid1;
int cid2;
int cid3;
int cid4;
int cid5;
int audio1;
int audio2;
int audio5;
REQUIRE(timeline->requestClipInsertion(binId, tid2, 100, cid1));
REQUIRE(timeline->requestItemResize(cid1, 10, true, true));
audio1 = timeline->getClipSplitPartner(cid1);
// Create AV clip 2
REQUIRE(timeline->requestClipInsertion(binId, tid2, 110, cid2));
REQUIRE(timeline->requestItemResize(cid2, 10, true, true));
REQUIRE(timeline->requestClipMove(cid2, tid2, 110));
audio2 = timeline->getClipSplitPartner(cid2);
// Create color clip 1
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 500, cid3));
REQUIRE(timeline->requestItemResize(cid3, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 520, cid4));
REQUIRE(timeline->requestItemResize(cid4, 20, true, true));
int mixDuration = pCore->getDurationFromString(KdenliveSettings::mix_duration());
auto state0 = [&]() {
REQUIRE(timeline->getClipsCount() == 6);
REQUIRE(timeline->getClipPlaytime(cid1) == 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 10);
REQUIRE(timeline->getClipPosition(cid2) == 110);
REQUIRE(timeline->getClipPosition(cid3) == 500);
REQUIRE(timeline->getClipPlaytime(cid3) == 20);
REQUIRE(timeline->getClipPosition(cid4) == 520);
REQUIRE(timeline->getClipPlaytime(cid4) == 20);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid1)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
};
auto state0b = [&]() {
REQUIRE(timeline->getClipsCount() == 8);
REQUIRE(timeline->getClipPlaytime(cid1) == 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 10);
REQUIRE(timeline->getClipPosition(cid2) == 110);
REQUIRE(timeline->getClipPlaytime(cid5) == 10);
REQUIRE(timeline->getClipPosition(cid5) == 120);
REQUIRE(timeline->getClipPosition(cid3) == 500);
REQUIRE(timeline->getClipPlaytime(cid3) == 20);
REQUIRE(timeline->getClipPosition(cid4) == 520);
REQUIRE(timeline->getClipPlaytime(cid4) == 20);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid1)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
};
auto state1 = [&]() {
REQUIRE(timeline->getClipsCount() == 6);
REQUIRE(timeline->getClipPlaytime(cid1) > 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) > 10);
REQUIRE(timeline->getClipPosition(cid2) < 110);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
};
auto state1b = [&]() {
REQUIRE(timeline->getClipsCount() == 8);
REQUIRE(timeline->getClipPlaytime(cid1) > 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(audio1) == 0);
REQUIRE(timeline->getClipPlaytime(cid2) > 10);
REQUIRE(timeline->getClipPosition(cid2) < 110);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(audio2) == 1);
REQUIRE(timeline->getClipPlaytime(cid5) == 10);
REQUIRE(timeline->getClipPosition(cid5) == 120);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(audio5) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
};
auto state3 = [&, mixDuration]() {
REQUIRE(timeline->getClipsCount() == 6);
REQUIRE(timeline->getClipPlaytime(cid1) > 30);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) > 30);
REQUIRE(timeline->getClipPosition(cid2) < 130);
REQUIRE(timeline->getMixDuration(cid2) == mixDuration);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
};
auto state2 = [&]() {
REQUIRE(timeline->getClipsCount() == 6);
REQUIRE(timeline->getClipPlaytime(cid3) == 32);
REQUIRE(timeline->getClipPosition(cid3) == 500);
REQUIRE(timeline->getClipPlaytime(cid4) == 33);
REQUIRE(timeline->getClipPosition(cid4) == 507);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid1)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
};
SECTION("Create and delete mix on color clips")
{
// Cid3 at 500, length 20
// Cid4 at 520, length 20
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
undoStack->undo();
state0();
undoStack->redo();
state2();
undoStack->undo();
state0();
}
SECTION("Add mix and resize last clip in playlist")
{
// Cid3 at 500, length 20
// Cid4 at 520, length 20
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
// Resize clip 4
REQUIRE(timeline->requestItemResize(cid4, 60, true, true));
REQUIRE(timeline->getClipPlaytime(cid4) == 60);
undoStack->undo();
REQUIRE(timeline->getClipPlaytime(cid4) == 33);
undoStack->redo();
REQUIRE(timeline->getClipPlaytime(cid4) == 60);
undoStack->undo();
undoStack->undo();
state0();
undoStack->redo();
state2();
undoStack->undo();
state0();
}
SECTION("Create mix on color clips and move main (right side) clip")
{
// CID 3 length=20, pos=500, CID4 length=20, pos=520
// Default mix duration = 25 frames (12 before / 13 after)
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
// Move right clip to the left, should fail
REQUIRE(timeline->requestClipMove(cid4, tid2, 506) == false);
// Move clip inside mix zone, should delete the mix
REQUIRE(timeline->requestClipMove(cid4, tid2, 509));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
state2();
// Move clip outside mix zone, should delete the mix and move it back to playlist 0
REQUIRE(timeline->requestClipMove(cid4, tid2, 600));
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
undoStack->undo();
state2();
// Move clip to another track, should delete mix
REQUIRE(timeline->requestClipMove(cid4, tid4, 600));
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
undoStack->undo();
state2();
undoStack->undo();
state0();
}
SECTION("Create mix on color clip and move left side clip")
{
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
// Move left clip to the right, should silently fail
REQUIRE(timeline->requestClipMove(cid3, tid2, 502, true, true, false) == false);
REQUIRE(timeline->getClipPosition(cid3) == 500);
// Move clip inside mix zone, should delete the mix
REQUIRE(timeline->requestClipMove(cid3, tid2, 499));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
state2();
// Move clip outside mix zone, should delete the mix
REQUIRE(timeline->requestClipMove(cid3, tid2, 450));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
state2();
// Move clip to another track, should delete mix
REQUIRE(timeline->requestClipMove(cid3, tid4, 600));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
undoStack->undo();
state2();
undoStack->undo();
state0();
}
SECTION("Create mix on color clips and move some to another track")
{
state0();
// insert third color clip
cid5 = -1;
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->getClipPosition(cid5) == 540);
audio5 = timeline->getClipSplitPartner(cid5);
// CID 3 length=20, pos=500, CID4 length=20, pos=520, CID5 length=20, pos=540
// Default mix duration = 25 frames (12 before / 13 after)
REQUIRE(timeline->mixClip(cid3));
REQUIRE(timeline->mixClip(cid4));
REQUIRE(timeline->getClipPosition(cid5) < 540);
undoStack->undo();
REQUIRE(timeline->getClipPosition(cid5) == 540);
undoStack->redo();
REQUIRE(timeline->getClipPosition(cid5) < 540);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Move middle clip to another track, should delete the mixes
REQUIRE(timeline->requestClipMove(cid4, tid4, 500));
REQUIRE(timeline->getClipPosition(cid5) == 540);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
// Undo track move
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Undo mixes
undoStack->undo();
undoStack->undo();
// undo 3rd clip resize & insert
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Create mix on color clips and group move")
{
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
// Move clip inside mix zone, should resize the mix
auto g1 = std::unordered_set<int>({cid3, cid4});
REQUIRE(timeline->requestClipsGroup(g1));
// Move clip to another track, should delete mix
REQUIRE(timeline->requestClipMove(cid4, tid4, 600));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 1);
undoStack->undo();
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 0);
state2();
// Move on same track
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->requestClipMove(cid4, tid3, 800));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
undoStack->undo();
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
state2();
// Undo group
undoStack->undo();
// Undo mix
undoStack->undo();
state0();
}
SECTION("Create and delete mix on AV clips")
{
state0();
// Clips are cid1 at 100, cid2 at 110
REQUIRE(timeline->requestItemResize(cid2, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid2, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid2, tid2, 110));
REQUIRE(timeline->mixClip(cid1));
state1();
undoStack->undo();
state0();
undoStack->redo();
state1();
undoStack->undo();
state0();
}
SECTION("Create mix and move AV clips")
{
// CID 1 length=10, pos=100, CID2 length=10, pos=110
// Default mix duration = 25 frames (12 before / 13 after)
// Resize CID2 so that it has some space to expand left
REQUIRE(timeline->requestItemResize(cid2, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid2, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid2, tid2, 110));
// Resize clip, should resize the mix
state0();
REQUIRE(timeline->mixClip(cid2));
state1();
// Resize right clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid2, 15, false, true) == 15);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
undoStack->undo();
state1();
// Resize left clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid1, 18, true, true) == 18);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
undoStack->undo();
state1();
// Move clip outside mix zone, should delete the mix
REQUIRE(timeline->requestClipMove(cid2, tid2, 200));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
undoStack->undo();
state1();
// Undo mix
undoStack->undo();
state0();
}
SECTION("Create chained mixes on AV clips")
{
// CID 1 length=10, pos=100, CID2 length=10, pos=110
// Default mix duration = 25 frames (12 before / 13 after)
// Resize CID2 so that it has some space to expand left
REQUIRE(timeline->requestItemResize(cid2, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid2, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid2, tid2, 110));
state0();
// Create a third AV clip and make some space
cid5 = -1;
REQUIRE(timeline->requestClipInsertion(binId, tid2, 120, cid5));
REQUIRE(timeline->requestItemResize(cid5, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid5, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid5, tid2, 120));
audio5 = timeline->getClipSplitPartner(cid5);
state0b();
// CID 1 length=10, pos=100, CID2 length=20, pos=130, CID5 length=20, pos=130
// Create mix between cid1 and cid2
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 0);
REQUIRE(timeline->mixClip(cid1));
state1b();
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid2) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixIsReversed(audio2) == false);
// Create mix between cid2 and cid5
REQUIRE(timeline->mixClip(cid2));
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid2) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixIsReversed(audio2) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixIsReversed(audio5) == true);
// Undo cid5 mix
undoStack->undo();
state1b();
// Undo cid2 mix
undoStack->undo();
// Undo cid5
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Create mix on color clip and test resize")
{
state0();
// CID 3 length=20, pos=500, CID4 length=20, pos=520
// Default mix duration = 25 frames (12 before / 13 after)
REQUIRE(timeline->mixClip(cid3));
state2();
// Resize left clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid3, 24, true, true) == 24);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->undo();
state2();
// Resize left clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid3, 4, true, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
state2();
// Resize right clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid4, 16, false, true) == 16);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->undo();
state2();
// Resize right clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid4, 4, false, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
state2();
// Resize right clip before left clip, should limit the resize to left clip position
REQUIRE(timeline->requestItemResize(cid4, 50, false, true) == 40);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->undo();
state2();
// Resize left clip past right clip, should limit the resize to left clip position
REQUIRE(timeline->requestItemResize(cid3, 100, true, true) == 40);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->undo();
state2();
// Before mix: CID 3 length=20, pos=500, CID4 length=20, pos=520
// Default mix duration = 25 frames (12 before / 13 after)
// Resize left clip before right clip start, then right clip outside left clip, should delete the mix
REQUIRE(timeline->requestItemResize(cid3, 20, true, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->requestItemResize(cid4, 20, false, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
undoStack->undo();
state2();
// Resize right clip after left clip end, then left clip outside right clip, should delete the mix
REQUIRE(timeline->requestItemResize(cid4, 20, false, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->requestItemResize(cid3, 20, true, true) == 20);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
undoStack->undo();
undoStack->undo();
state2();
undoStack->undo();
state0();
}
SECTION("Create mix on AV clips and resize")
{
state0();
// CID 1 length=10, pos=100, CID2 length=10, pos=110
REQUIRE(timeline->getClipPlaytime(cid1) == 10);
REQUIRE(timeline->getClipPlaytime(cid2) == 10);
// Resize clip in to have some space for mix
REQUIRE(timeline->requestItemResize(cid2, 90, true, true) == 90);
REQUIRE(timeline->requestItemResize(cid2, 30, false, true) == 30);
REQUIRE(timeline->requestClipMove(cid2, tid2, 130));
REQUIRE(timeline->requestItemResize(cid1, 30, true, true) == 30);
REQUIRE(timeline->mixClip(cid1));
state3();
// CID 1 length=30, pos=100, CID2 length=30, pos=130
// Default mix duration = 25 frames (12 before / 13 after)
// Resize left clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid1, 35, true, true) == 35);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 1);
undoStack->undo();
state3();
// Resize left clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid1, 10, true, true) == 30);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 0);
undoStack->undo();
state3();
// Resize right clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid2, 25, false, true) == 25);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 1);
undoStack->undo();
state3();
// Resize right clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid2, 4, false, true) == 30);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 0);
undoStack->undo();
state3();
// Resize right clip before left clip, should limit to left clip position
REQUIRE(timeline->requestItemResize(cid2, 80, false, true) == 60);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 1);
undoStack->undo();
state3();
// Resize left clip after right clip, should limit to right clip duration
REQUIRE(timeline->requestItemResize(cid1, 80, true, true) == 60);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid3)->mixCount() == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid1) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid2) == 1);
undoStack->undo();
state3();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test chained mixes on color clips")
{
// Add 2 more color clips
cid5 = -1;
int cid6;
int cid7;
state0();
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 560, cid6));
REQUIRE(timeline->requestItemResize(cid6, 40, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 600, cid7));
REQUIRE(timeline->requestItemResize(cid7, 20, true, true));
audio5 = timeline->getClipSplitPartner(cid5);
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=20
// Cid5 pos=540, duration=20
// Cid6 pos=560, duration=40
// Cid7 pos=600, duration=20
// Mix 3 and 4
REQUIRE(timeline->mixClip(cid3));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
// Mix 6 and 7
REQUIRE(timeline->mixClip(cid6));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Mix 5 and 6
REQUIRE(timeline->mixClip(cid5));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 3);
// Undo mix 5 and 6
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Undo mix 6 and 7
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
// Undo mix 3 and 4
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test chained mixes and clip resize")
{
// Add 3 more color clips
cid5 = -1;
int cid6;
int cid7;
state0();
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 560, cid6));
REQUIRE(timeline->requestItemResize(cid6, 40, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 600, cid7));
REQUIRE(timeline->requestItemResize(cid7, 20, true, true));
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=20
// Cid5 pos=540, duration=20
// Cid6 pos=560, duration=40
// Cid7 pos=600, duration=20
auto mix0 = [&]() {
REQUIRE(timeline->getClipsCount() == 9);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
};
auto mix1 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
};
// Mix 4 and 5
REQUIRE(timeline->mixClip(cid4));
mix0();
// Mix 6 and 7
REQUIRE(timeline->mixClip(cid6));
mix1();
// Test resize, should fail
int clipSize = timeline->getClipPlaytime(cid5);
REQUIRE(timeline->requestItemResize(cid5, 38, true, true) == clipSize);
clipSize = timeline->getClipPlaytime(cid6);
REQUIRE(timeline->requestItemResize(cid6, 60, false, true) == clipSize);
// Undo second mix
undoStack->undo();
// Undo first mix
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test grouped mixes and clip resize")
{
// Add 3 more color clips
cid5 = -1;
int cid6;
int cid7;
state0();
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 560, cid6));
REQUIRE(timeline->requestItemResize(cid6, 40, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid4, 520, cid7));
REQUIRE(timeline->requestItemResize(cid7, 20, true, true));
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=20
// Cid5 pos=540, duration=20
// Cid6 pos=560, duration=40
// Cid7 pos=520, duration=20 on tid4
auto mix1 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
};
// Mix cid3 & cid4
REQUIRE(timeline->mixClip(cid3));
REQUIRE(timeline->getClipPlaytime(cid4) == 33);
// Group cid4 and cid7
auto g1 = std::unordered_set<int>({cid4, cid7});
REQUIRE(timeline->requestClipsGroup(g1));
// Try to resize the grouped cid7, should not be allowed
REQUIRE(timeline->requestItemResize(cid7, 23, true, true) == -1);
// Mix cid5 & cid6
REQUIRE(timeline->mixClip(cid6));
mix1();
// Try to resize the grouped cid7, should not be allowed
REQUIRE(timeline->requestItemResize(cid7, 23, true, true) == -1);
// Undo second mix
undoStack->undo();
// Undo group
undoStack->undo();
// Undo first mix
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test chained mixes and check mix direction")
{
// Add 3 more color clips
cid5 = -1;
int cid6;
int cid7;
state0();
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 560, cid6));
REQUIRE(timeline->requestItemResize(cid6, 40, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 600, cid7));
REQUIRE(timeline->requestItemResize(cid7, 20, true, true));
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=20
// Cid5 pos=540, duration=20
// Cid6 pos=560, duration=40
// Cid7 pos=600, duration=20
auto mix0 = [&]() {
REQUIRE(timeline->getClipsCount() == 9);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
};
auto mix1 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == true);
};
auto mix2 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 3);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid7) == false);
};
auto mix3 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 4);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid4) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid7) == true);
};
// Mix 4 and 5
REQUIRE(timeline->mixClip(cid4));
mix0();
// Mix 5 and 6
REQUIRE(timeline->mixClip(cid5));
mix1();
// Mix 6 and 7
REQUIRE(timeline->mixClip(cid6));
mix2();
// Mix 3 and 4, this will revert all subsequent mixes
REQUIRE(timeline->mixClip(cid3));
mix3();
// Undo mix 3 and 4
undoStack->undo();
mix2();
// Now switch mixes to Slide type
timeline->switchComposition(cid7, QStringLiteral("slide"));
timeline->switchComposition(cid6, QStringLiteral("slide"));
timeline->switchComposition(cid5, QStringLiteral("slide"));
mix2();
// Mix 3 and 4, this will revert all subsequent mixes
REQUIRE(timeline->mixClip(cid3));
mix3();
// Undo mix 3 and 4
undoStack->undo();
mix2();
// Now switch mixes to Wipe type
timeline->switchComposition(cid7, QStringLiteral("wipe"));
timeline->switchComposition(cid6, QStringLiteral("wipe"));
timeline->switchComposition(cid5, QStringLiteral("wipe"));
mix2();
// Mix 3 and 4, this will revert all subsequent mixes
REQUIRE(timeline->mixClip(cid3));
mix3();
// Undo mix 3 and 4
undoStack->undo();
mix2();
// Undo Wipe mix switch on cid5
undoStack->undo();
// Undo mix switch on cid6
undoStack->undo();
// Undo mix switch on cid7
undoStack->undo();
mix2();
// Undo Slide mix switch on cid5
undoStack->undo();
// Undo mix switch on cid6
undoStack->undo();
// Undo mix switch on cid7
undoStack->undo();
mix2();
// Undo mix 6 and 7
undoStack->undo();
mix1();
// Undo mix 5 and 6
undoStack->undo();
mix0();
// Undo mix 4 and 5
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test mixes track move and direction")
{
// Add 3 more av clips
cid5 = -1;
int cid6;
int cid7;
state0();
REQUIRE(timeline->requestClipInsertion(binId, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->requestClipInsertion(binId, tid2, 560, cid6));
REQUIRE(timeline->requestItemResize(cid6, 40, true, true));
REQUIRE(timeline->requestClipInsertion(binId, tid2, 600, cid7));
REQUIRE(timeline->requestItemResize(cid7, 20, true, true));
audio5 = timeline->getClipSplitPartner(cid5);
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=20
// Cid5 pos=540, duration=20
// Cid6 pos=560, duration=40
// Cid7 pos=600, duration=20
auto mix0 = [&]() {
REQUIRE(timeline->getClipsCount() == 12);
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
};
auto mix1 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == true);
};
auto mix2 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 3);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid7) == false);
};
auto mix3 = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 4);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid4) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid5) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid6) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixIsReversed(cid7) == true);
};
auto mix3b = [&]() {
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid7) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixCount() == 4);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixIsReversed(cid4) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixIsReversed(cid5) == true);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixIsReversed(cid6) == false);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid4)->mixIsReversed(cid7) == true);
};
// Mix 4 and 5
REQUIRE(timeline->mixClip(cid4));
mix0();
// Mix 5 and 6
REQUIRE(timeline->mixClip(cid5));
mix1();
// Mix 6 and 7
REQUIRE(timeline->mixClip(cid6));
mix2();
// Mix 3 and 4, this will revert all subsequent mixes
REQUIRE(timeline->mixClip(cid3));
mix3();
// Move everything to another track
auto g1 = std::unordered_set<int>({cid3, cid4, cid5, cid6, cid7});
REQUIRE(timeline->requestClipsGroup(g1));
REQUIRE(timeline->requestClipMove(cid3, tid4, 600));
// Now clips 3, 4, 5, 6 and 7 will be on top video track. Check mixes have the correct direction
mix3b();
// Undo track move
undoStack->undo();
mix3();
// Redo track move
undoStack->redo();
mix3b();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Test chained mixes and cuts")
{
// Add 2 more color clips
cid5 = -1;
int cid6;
state0();
REQUIRE(timeline->requestItemResize(cid4, 80, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 600, cid5));
REQUIRE(timeline->requestItemResize(cid5, 80, true, true));
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 680, cid6));
REQUIRE(timeline->requestItemResize(cid6, 80, true, true));
audio5 = timeline->getClipSplitPartner(cid5);
// Cid3 pos=500, duration=20
// Cid4 pos=520, duration=80
// Cid5 pos=600, duration=80
// Cid6 pos=680, duration=80
// Mix 3 and 4
REQUIRE(timeline->mixClip(cid3));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
// Mix 4 and 5
REQUIRE(timeline->mixClip(cid4));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Mix 5 and 6
REQUIRE(timeline->mixClip(cid5));
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 1);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 3);
// Now try to cut mixes and check they are in the correct subplaylist
// Cut a clip with mix start only
REQUIRE(TimelineFunctions::requestClipCut(timeline, cid3, 505));
// Get newly created cut clip
int clone = timeline->getClipByPosition(tid2, 506, 0);
// Ensure each clip is on the correct playlist
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(clone) == 0);
// Undo cid3 cut
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
undoStack->redo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 1);
undoStack->undo();
// Cut a clip with mix at start and end
REQUIRE(TimelineFunctions::requestClipCut(timeline, cid4, 540));
// Get newly created cut clip
clone = timeline->getClipByPosition(tid2, 540, 1);
// Ensure each clip is on the correct playlist
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(clone) == 1);
// Undo cid3 cut
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->redo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(clone) == 1);
undoStack->undo();
// Cut a clip with mix at end
REQUIRE(TimelineFunctions::requestClipCut(timeline, cid6, 710));
// Get newly created cut clip
clone = timeline->getClipByPosition(tid2, 710, 0);
// Ensure each clip is on the correct playlist
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(clone) == 0);
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
undoStack->redo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(clone) == 0);
undoStack->undo();
// Undo mix 5 and 6
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 2);
// Undo mix 4 and 5
undoStack->undo();
REQUIRE(timeline->getClipSubPlaylistIndex(cid3) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid4) == 1);
REQUIRE(timeline->getClipSubPlaylistIndex(cid5) == 0);
REQUIRE(timeline->getClipSubPlaylistIndex(cid6) == 0);
REQUIRE(KdenliveTests::getTrackById_const(timeline, tid2)->mixCount() == 1);
// Undo mix 3 and 4
undoStack->undo();
// Undo insert/resize ops
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
timeline.reset();
pCore->projectManager()->closeCurrentDocument(false, false);
}
|