Changeset View
Changeset View
Standalone View
Standalone View
src/timeline2/model/timelinemodel.cpp
Context not available. | |||||
166 | return getClipTrackId(itemId); | 166 | return getClipTrackId(itemId); | ||
---|---|---|---|---|---|
167 | } | 167 | } | ||
168 | 168 | | |||
169 | void TimelineModel::setItemTrackId(int itemId, int trackId) | ||||
170 | { | ||||
171 | READ_LOCK(); | ||||
172 | Q_ASSERT(isClip(itemId) || isComposition(itemId)); | ||||
173 | if (isComposition(itemId)) { | ||||
174 | m_allCompositions[itemId]->setCurrentTrackId(trackId); | ||||
175 | } else { | ||||
176 | m_allClips[itemId]->setCurrentTrackId(trackId); | ||||
177 | m_allClips[itemId]->setGrab(true); | ||||
178 | } | ||||
179 | qDebug()<<"// SETTING CLIP "<<itemId<<", TRACK: "<<trackId; | ||||
180 | } | ||||
181 | | ||||
169 | int TimelineModel::getClipPosition(int clipId) const | 182 | int TimelineModel::getClipPosition(int clipId) const | ||
170 | { | 183 | { | ||
171 | READ_LOCK(); | 184 | READ_LOCK(); | ||
Context not available. | |||||
228 | { | 241 | { | ||
229 | READ_LOCK(); | 242 | READ_LOCK(); | ||
230 | Q_ASSERT(isTrack(trackId)); | 243 | Q_ASSERT(isTrack(trackId)); | ||
244 | qDebug()<<"*** CLIPS ON TRACK: "<<trackId<<" = "<<getTrackById_const(trackId)->getClipsCount(); | ||||
231 | int count = getTrackById_const(trackId)->getClipsCount(); | 245 | int count = getTrackById_const(trackId)->getClipsCount(); | ||
232 | return count; | 246 | return count; | ||
233 | } | 247 | } | ||
Context not available. | |||||
383 | } | 397 | } | ||
384 | ok = getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, local_undo, local_redo, local_list); | 398 | ok = getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, local_undo, local_redo, local_list); | ||
385 | if (!ok) { | 399 | if (!ok) { | ||
386 | // qDebug()<<"-------------\n\nINSERTION FAILED, REVERTING\n\n-------------------"; | 400 | qDebug()<<"-------------\n\nINSERTION FAILED, REVERTING\n\n-------------------"; | ||
387 | bool undone = local_undo(); | 401 | bool undone = local_undo(); | ||
388 | Q_ASSERT(undone); | 402 | Q_ASSERT(undone); | ||
389 | return false; | 403 | return false; | ||
390 | } | 404 | } | ||
405 | qDebug()<<"*** INSERTED CLIP COMMAND: "<<clipId<<"\n+++++++++++++++++++"; | ||||
391 | list.insert(list.end(), local_list.begin(), local_list.end()); | 406 | list.insert(list.end(), local_list.begin(), local_list.end()); | ||
392 | UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo); | 407 | UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo); | ||
393 | return true; | 408 | return true; | ||
Context not available. | |||||
402 | QWriteLocker locker(&m_lock); | 417 | QWriteLocker locker(&m_lock); | ||
403 | Q_ASSERT(m_allClips.count(clipId) > 0); | 418 | Q_ASSERT(m_allClips.count(clipId) > 0); | ||
404 | if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) { | 419 | if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) { | ||
420 | qDebug()<<"// SAME FRAME MOVE, ABORT"; | ||||
405 | return true; | 421 | return true; | ||
406 | } | 422 | } | ||
407 | if (m_groups->isInGroup(clipId)) { | 423 | if (m_groups->isInGroup(clipId)) { | ||
Context not available. | |||||
418 | std::function<bool(void)> redo = []() { return true; }; | 434 | std::function<bool(void)> redo = []() { return true; }; | ||
419 | Updates list; | 435 | Updates list; | ||
420 | bool res = requestClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo, list); | 436 | bool res = requestClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo, list); | ||
437 | qDebug()<<"// CLIP MOVED: "<<res; | ||||
421 | if (res) { | 438 | if (res) { | ||
422 | if (updateView) { | 439 | if (updateView) { | ||
440 | qDebug()<<"// PREPARING UPDATES"; | ||||
423 | ModelUpdater::applyUpdates(undo, redo, list); | 441 | ModelUpdater::applyUpdates(undo, redo, list); | ||
424 | } | 442 | } | ||
425 | if (logUndo) { | 443 | if (logUndo) { | ||
Context not available. | |||||
461 | return res; | 479 | return res; | ||
462 | } | 480 | } | ||
463 | 481 | | |||
464 | int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance, bool allowViewUpdate) | 482 | int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance) | ||
465 | { | 483 | { | ||
466 | #ifdef LOGGING | 484 | #ifdef LOGGING | ||
467 | m_logFile << "timeline->suggestClipMove(" << clipId << "," << trackId << " ," << position << "); " << std::endl; | 485 | m_logFile << "timeline->suggestClipMove(" << clipId << "," << trackId << " ," << position << "); " << std::endl; | ||
Context not available. | |||||
470 | Q_ASSERT(isClip(clipId)); | 488 | Q_ASSERT(isClip(clipId)); | ||
471 | Q_ASSERT(isTrack(trackId)); | 489 | Q_ASSERT(isTrack(trackId)); | ||
472 | int currentPos = getClipPosition(clipId); | 490 | int currentPos = getClipPosition(clipId); | ||
473 | if (currentPos == position) { | 491 | int sourceTrackId = getClipTrackId(clipId); | ||
492 | if (currentPos == position && sourceTrackId == trackId) { | ||||
474 | return position; | 493 | return position; | ||
475 | } | 494 | } | ||
476 | bool after = position > currentPos; | 495 | bool after = position > currentPos; | ||
Context not available. | |||||
498 | } | 517 | } | ||
499 | } | 518 | } | ||
500 | // we check if move is possible | 519 | // we check if move is possible | ||
501 | bool possible; | 520 | bool possible = requestClipMove(clipId, trackId, position, true, false, false); | ||
502 | if (allowViewUpdate) { | 521 | if (!possible) { | ||
503 | possible = requestClipMove(clipId, trackId, position, false, false, false); | 522 | qDebug() << "CANNOT MOVE CLIP : "<<clipId<<" ON TK: "<<trackId<<", AT POS: "<<position; | ||
504 | } else { | 523 | } else { | ||
505 | possible = requestClipMoveAttempt(clipId, trackId, position); | | |||
506 | } | | |||
507 | if (possible) { | | |||
508 | return position; | 524 | return position; | ||
509 | } | 525 | } | ||
510 | // Find best possible move | 526 | // Find best possible move | ||
511 | if (!m_groups->isInGroup(clipId)) { | 527 | if (!m_groups->isInGroup(clipId)) { | ||
512 | // Easy | 528 | // Easy | ||
529 | //int currentTrackId = getClipTrackId(clipId); | ||||
530 | // Try same track move | ||||
531 | trackId = sourceTrackId; | ||||
532 | possible = requestClipMove(clipId, trackId, position, true, false, false); | ||||
533 | if (!possible) { | ||||
534 | qDebug() << "CANNOT MOVE CLIP : "<<clipId<<" ON TK: "<<trackId<<", AT POS: "<<position; | ||||
535 | } else { | ||||
536 | return position; | ||||
537 | } | ||||
513 | int blank_length = getTrackById(trackId)->getBlankSizeNearClip(clipId, after); | 538 | int blank_length = getTrackById(trackId)->getBlankSizeNearClip(clipId, after); | ||
514 | qDebug() << "Found blank" << blank_length; | 539 | qDebug() << "Found blank" << blank_length; | ||
515 | if (blank_length < INT_MAX) { | 540 | if (blank_length < INT_MAX) { | ||
Context not available. | |||||
519 | position = currentPos - blank_length; | 544 | position = currentPos - blank_length; | ||
520 | } | 545 | } | ||
521 | } else { | 546 | } else { | ||
522 | return false; | 547 | return currentPos; | ||
523 | } | | |||
524 | if (allowViewUpdate) { | | |||
525 | possible = requestClipMove(clipId, trackId, position, false, false, false); | | |||
526 | } else { | | |||
527 | possible = requestClipMoveAttempt(clipId, trackId, position); | | |||
528 | } | 548 | } | ||
549 | possible = requestClipMove(clipId, trackId, position, true, false, false); | ||||
529 | return possible ? position : currentPos; | 550 | return possible ? position : currentPos; | ||
530 | } | 551 | } | ||
531 | // find best pos for groups | 552 | // find best pos for groups | ||
Context not available. | |||||
577 | } | 598 | } | ||
578 | } | 599 | } | ||
579 | } | 600 | } | ||
601 | /* | ||||
602 | * This returns erratic results, moving clips to 0. | ||||
580 | if (blank_length != 0) { | 603 | if (blank_length != 0) { | ||
581 | int updatedPos = currentPos + (after ? blank_length : -blank_length); | 604 | int updatedPos = currentPos + (after ? blank_length : -blank_length); | ||
605 | qDebug()<<"===== CURRENTPOS: "<<currentPos<<", AFT: "<<after<<", BLANK: "<<blank_length; | ||||
582 | if (allowViewUpdate) { | 606 | if (allowViewUpdate) { | ||
583 | possible = requestClipMove(clipId, trackId, updatedPos, false, false, false); | 607 | possible = requestClipMove(clipId, trackId, updatedPos, true, false, false); | ||
584 | } else { | 608 | } else { | ||
585 | possible = requestClipMoveAttempt(clipId, trackId, updatedPos); | 609 | possible = requestClipMoveAttempt(clipId, trackId, updatedPos); | ||
586 | } | 610 | } | ||
587 | if (possible) { | 611 | if (possible) { | ||
612 | qDebug()<<" * ** * RETURNING UPDATED POS: "<<updatedPos<<"\n________________________"; | ||||
588 | return updatedPos; | 613 | return updatedPos; | ||
589 | } | 614 | } | ||
590 | } | 615 | }*/ | ||
591 | return currentPos; | 616 | return currentPos; | ||
592 | } | 617 | } | ||
593 | 618 | | |||
Context not available. | |||||
601 | Q_ASSERT(isTrack(trackId)); | 626 | Q_ASSERT(isTrack(trackId)); | ||
602 | int currentPos = getCompositionPosition(compoId); | 627 | int currentPos = getCompositionPosition(compoId); | ||
603 | int currentTrack = getCompositionTrackId(compoId); | 628 | int currentTrack = getCompositionTrackId(compoId); | ||
604 | if (currentPos == position || currentTrack != trackId) { | 629 | if (currentPos == position && currentTrack == trackId) { | ||
605 | return position; | 630 | return position; | ||
606 | } | 631 | } | ||
607 | 632 | | |||
Context not available. | |||||
633 | } | 658 | } | ||
634 | } | 659 | } | ||
635 | // we check if move is possible | 660 | // we check if move is possible | ||
636 | Fun undo = []() { return true; }; | 661 | bool possible = requestCompositionMove(compoId, trackId, position, true, false); | ||
637 | Fun redo = []() { return true; }; | | |||
638 | Updates list; | | |||
639 | bool possible = requestCompositionMove(compoId, trackId, m_allCompositions[compoId]->getForcedTrack(), position, false, undo, redo, list); | | |||
640 | qDebug() << "Original move success" << possible; | 662 | qDebug() << "Original move success" << possible; | ||
641 | if (possible) { | 663 | if (possible) { | ||
642 | bool undone = undo(); | | |||
643 | Q_ASSERT(undone); | | |||
644 | return position; | 664 | return position; | ||
645 | } | 665 | } | ||
646 | bool after = position > currentPos; | 666 | /*bool after = position > currentPos; | ||
647 | int blank_length = getTrackById(trackId)->getBlankSizeNearComposition(compoId, after); | 667 | int blank_length = getTrackById(trackId)->getBlankSizeNearComposition(compoId, after); | ||
648 | qDebug() << "Found blank" << blank_length; | 668 | qDebug() << "Found blank" << blank_length; | ||
649 | if (blank_length < INT_MAX) { | 669 | if (blank_length < INT_MAX) { | ||
Context not available. | |||||
651 | return currentPos + blank_length; | 671 | return currentPos + blank_length; | ||
652 | } | 672 | } | ||
653 | return currentPos - blank_length; | 673 | return currentPos - blank_length; | ||
654 | } | 674 | }*/ | ||
655 | return position; | 675 | return currentPos; | ||
656 | } | 676 | } | ||
657 | 677 | | |||
658 | bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo, Updates &list) | 678 | bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo, Updates &list) | ||
Context not available. | |||||
1841 | return getCompositionPlaytime(itemId); | 1861 | return getCompositionPlaytime(itemId); | ||
1842 | } | 1862 | } | ||
1843 | 1863 | | |||
1844 | int TimelineModel::getTrackCompositionsCount(int compoId) const | 1864 | int TimelineModel::getTrackCompositionsCount(int trackId) const | ||
1845 | { | 1865 | { | ||
1846 | return getTrackById_const(compoId)->getCompositionsCount(); | 1866 | Q_ASSERT(isTrack(trackId)); | ||
1867 | qDebug()<<"*** COMPOSITIONS ON TRACK: "<<trackId<<" = "<<getTrackById_const(trackId)->getCompositionsCount(); | ||||
1868 | return getTrackById_const(trackId)->getCompositionsCount(); | ||||
1847 | } | 1869 | } | ||
1848 | 1870 | | |||
1849 | bool TimelineModel::requestCompositionMove(int compoId, int trackId, int position, bool updateView, bool logUndo) | 1871 | bool TimelineModel::requestCompositionMove(int compoId, int trackId, int position, bool updateView, bool logUndo) | ||
Context not available. | |||||
1873 | int min = getCompositionPosition(compoId); | 1895 | int min = getCompositionPosition(compoId); | ||
1874 | int max = min + getCompositionPlaytime(compoId); | 1896 | int max = min + getCompositionPlaytime(compoId); | ||
1875 | int tk = getCompositionTrackId(compoId); | 1897 | int tk = getCompositionTrackId(compoId); | ||
1898 | qDebug()<<" * * * *REQUESTING COMPO MOVE TO TK: "<<trackId; | ||||
1876 | bool res = requestCompositionMove(compoId, trackId, m_allCompositions[compoId]->getForcedTrack(), position, updateView, undo, redo, list); | 1899 | bool res = requestCompositionMove(compoId, trackId, m_allCompositions[compoId]->getForcedTrack(), position, updateView, undo, redo, list); | ||
1877 | if (tk > -1) { | 1900 | if (tk > -1) { | ||
1878 | min = qMin(min, getCompositionPosition(compoId)); | 1901 | min = qMin(min, getCompositionPosition(compoId)); | ||
Context not available. |