Changeset View
Changeset View
Standalone View
Standalone View
src/timeline2/model/timelinemodel.cpp
Context not available. | |||||
383 | } | 383 | } | ||
---|---|---|---|---|---|
384 | ok = getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, local_undo, local_redo, local_list); | 384 | ok = getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, local_undo, local_redo, local_list); | ||
385 | if (!ok) { | 385 | if (!ok) { | ||
386 | // qDebug()<<"-------------\n\nINSERTION FAILED, REVERTING\n\n-------------------"; | 386 | //qDebug()<<"-------------\n\nINSERTION FAILED, REVERTING\n\n-------------------"; | ||
387 | bool undone = local_undo(); | 387 | bool undone = local_undo(); | ||
388 | Q_ASSERT(undone); | 388 | Q_ASSERT(undone); | ||
389 | return false; | 389 | return false; | ||
Context not available. | |||||
402 | QWriteLocker locker(&m_lock); | 402 | QWriteLocker locker(&m_lock); | ||
403 | Q_ASSERT(m_allClips.count(clipId) > 0); | 403 | Q_ASSERT(m_allClips.count(clipId) > 0); | ||
404 | if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) { | 404 | if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) { | ||
405 | qDebug()<<"// SAME FRAME MOVE, ABORT"; | ||||
405 | return true; | 406 | return true; | ||
406 | } | 407 | } | ||
407 | if (m_groups->isInGroup(clipId)) { | 408 | if (m_groups->isInGroup(clipId)) { | ||
Context not available. | |||||
418 | std::function<bool(void)> redo = []() { return true; }; | 419 | std::function<bool(void)> redo = []() { return true; }; | ||
419 | Updates list; | 420 | Updates list; | ||
420 | bool res = requestClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo, list); | 421 | bool res = requestClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo, list); | ||
422 | qDebug()<<"// CLIP MOVED: "<<res; | ||||
421 | if (res) { | 423 | if (res) { | ||
422 | if (updateView) { | 424 | if (updateView) { | ||
425 | qDebug()<<"// PREPARING UPDATES"; | ||||
423 | ModelUpdater::applyUpdates(undo, redo, list); | 426 | ModelUpdater::applyUpdates(undo, redo, list); | ||
424 | } | 427 | } | ||
425 | if (logUndo) { | 428 | if (logUndo) { | ||
Context not available. | |||||
461 | return res; | 464 | return res; | ||
462 | } | 465 | } | ||
463 | 466 | | |||
464 | int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance, bool allowViewUpdate) | 467 | int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance) | ||
465 | { | 468 | { | ||
466 | #ifdef LOGGING | 469 | #ifdef LOGGING | ||
467 | m_logFile << "timeline->suggestClipMove(" << clipId << "," << trackId << " ," << position << "); " << std::endl; | 470 | m_logFile << "timeline->suggestClipMove(" << clipId << "," << trackId << " ," << position << "); " << std::endl; | ||
Context not available. | |||||
470 | Q_ASSERT(isClip(clipId)); | 473 | Q_ASSERT(isClip(clipId)); | ||
471 | Q_ASSERT(isTrack(trackId)); | 474 | Q_ASSERT(isTrack(trackId)); | ||
472 | int currentPos = getClipPosition(clipId); | 475 | int currentPos = getClipPosition(clipId); | ||
473 | if (currentPos == position) { | 476 | int sourceTrackId = getClipTrackId(clipId); | ||
477 | if (currentPos == position && sourceTrackId == trackId) { | ||||
474 | return position; | 478 | return position; | ||
475 | } | 479 | } | ||
476 | bool after = position > currentPos; | 480 | bool after = position > currentPos; | ||
Context not available. | |||||
498 | } | 502 | } | ||
499 | } | 503 | } | ||
500 | // we check if move is possible | 504 | // we check if move is possible | ||
501 | bool possible; | 505 | bool possible = requestClipMove(clipId, trackId, position, true, false, false); | ||
502 | if (allowViewUpdate) { | 506 | if (!possible) { | ||
503 | possible = requestClipMove(clipId, trackId, position, false, false, false); | 507 | qDebug() << "CANNOT MOVE CLIP : "<<clipId<<" ON TK: "<<trackId<<", AT POS: "<<position; | ||
504 | } else { | 508 | } else { | ||
505 | possible = requestClipMoveAttempt(clipId, trackId, position); | | |||
506 | } | | |||
507 | if (possible) { | | |||
508 | return position; | 509 | return position; | ||
509 | } | 510 | } | ||
510 | // Find best possible move | 511 | // Find best possible move | ||
511 | if (!m_groups->isInGroup(clipId)) { | 512 | if (!m_groups->isInGroup(clipId)) { | ||
512 | // Easy | 513 | // Easy | ||
514 | //int currentTrackId = getClipTrackId(clipId); | ||||
515 | // Try same track move | ||||
516 | trackId = sourceTrackId; | ||||
517 | possible = requestClipMove(clipId, trackId, position, true, false, false); | ||||
518 | if (!possible) { | ||||
519 | qDebug() << "CANNOT MOVE CLIP : "<<clipId<<" ON TK: "<<trackId<<", AT POS: "<<position; | ||||
520 | } else { | ||||
521 | return position; | ||||
522 | } | ||||
513 | int blank_length = getTrackById(trackId)->getBlankSizeNearClip(clipId, after); | 523 | int blank_length = getTrackById(trackId)->getBlankSizeNearClip(clipId, after); | ||
514 | qDebug() << "Found blank" << blank_length; | 524 | qDebug() << "Found blank" << blank_length; | ||
515 | if (blank_length < INT_MAX) { | 525 | if (blank_length < INT_MAX) { | ||
Context not available. | |||||
519 | position = currentPos - blank_length; | 529 | position = currentPos - blank_length; | ||
520 | } | 530 | } | ||
521 | } else { | 531 | } else { | ||
522 | return false; | 532 | return currentPos; | ||
523 | } | | |||
524 | if (allowViewUpdate) { | | |||
525 | possible = requestClipMove(clipId, trackId, position, false, false, false); | | |||
526 | } else { | | |||
527 | possible = requestClipMoveAttempt(clipId, trackId, position); | | |||
528 | } | 533 | } | ||
534 | possible = requestClipMove(clipId, trackId, position, true, false, false); | ||||
529 | return possible ? position : currentPos; | 535 | return possible ? position : currentPos; | ||
530 | } | 536 | } | ||
531 | // find best pos for groups | 537 | // find best pos for groups | ||
Context not available. | |||||
577 | } | 583 | } | ||
578 | } | 584 | } | ||
579 | } | 585 | } | ||
586 | /* | ||||
587 | * This returns erratic results, moving clips to 0. | ||||
580 | if (blank_length != 0) { | 588 | if (blank_length != 0) { | ||
581 | int updatedPos = currentPos + (after ? blank_length : -blank_length); | 589 | int updatedPos = currentPos + (after ? blank_length : -blank_length); | ||
590 | qDebug()<<"===== CURRENTPOS: "<<currentPos<<", AFT: "<<after<<", BLANK: "<<blank_length; | ||||
582 | if (allowViewUpdate) { | 591 | if (allowViewUpdate) { | ||
583 | possible = requestClipMove(clipId, trackId, updatedPos, false, false, false); | 592 | possible = requestClipMove(clipId, trackId, updatedPos, true, false, false); | ||
584 | } else { | 593 | } else { | ||
585 | possible = requestClipMoveAttempt(clipId, trackId, updatedPos); | 594 | possible = requestClipMoveAttempt(clipId, trackId, updatedPos); | ||
586 | } | 595 | } | ||
587 | if (possible) { | 596 | if (possible) { | ||
597 | qDebug()<<" * ** * RETURNING UPDATED POS: "<<updatedPos<<"\n________________________"; | ||||
588 | return updatedPos; | 598 | return updatedPos; | ||
589 | } | 599 | } | ||
590 | } | 600 | }*/ | ||
591 | return currentPos; | 601 | return currentPos; | ||
592 | } | 602 | } | ||
593 | 603 | | |||
Context not available. | |||||
601 | Q_ASSERT(isTrack(trackId)); | 611 | Q_ASSERT(isTrack(trackId)); | ||
602 | int currentPos = getCompositionPosition(compoId); | 612 | int currentPos = getCompositionPosition(compoId); | ||
603 | int currentTrack = getCompositionTrackId(compoId); | 613 | int currentTrack = getCompositionTrackId(compoId); | ||
604 | if (currentPos == position || currentTrack != trackId) { | 614 | if (currentPos == position && currentTrack == trackId) { | ||
605 | return position; | 615 | return position; | ||
606 | } | 616 | } | ||
607 | 617 | | |||
Context not available. | |||||
633 | } | 643 | } | ||
634 | } | 644 | } | ||
635 | // we check if move is possible | 645 | // we check if move is possible | ||
636 | Fun undo = []() { return true; }; | 646 | 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; | 647 | qDebug() << "Original move success" << possible; | ||
641 | if (possible) { | 648 | if (possible) { | ||
642 | bool undone = undo(); | | |||
643 | Q_ASSERT(undone); | | |||
644 | return position; | 649 | return position; | ||
645 | } | 650 | } | ||
646 | bool after = position > currentPos; | 651 | /*bool after = position > currentPos; | ||
647 | int blank_length = getTrackById(trackId)->getBlankSizeNearComposition(compoId, after); | 652 | int blank_length = getTrackById(trackId)->getBlankSizeNearComposition(compoId, after); | ||
648 | qDebug() << "Found blank" << blank_length; | 653 | qDebug() << "Found blank" << blank_length; | ||
649 | if (blank_length < INT_MAX) { | 654 | if (blank_length < INT_MAX) { | ||
Context not available. | |||||
651 | return currentPos + blank_length; | 656 | return currentPos + blank_length; | ||
652 | } | 657 | } | ||
653 | return currentPos - blank_length; | 658 | return currentPos - blank_length; | ||
654 | } | 659 | }*/ | ||
655 | return position; | 660 | return currentPos; | ||
656 | } | 661 | } | ||
657 | 662 | | |||
658 | bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo, Updates &list) | 663 | bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo, Updates &list) | ||
Context not available. | |||||
1841 | return getCompositionPlaytime(itemId); | 1846 | return getCompositionPlaytime(itemId); | ||
1842 | } | 1847 | } | ||
1843 | 1848 | | |||
1844 | int TimelineModel::getTrackCompositionsCount(int compoId) const | 1849 | int TimelineModel::getTrackCompositionsCount(int trackId) const | ||
1845 | { | 1850 | { | ||
1846 | return getTrackById_const(compoId)->getCompositionsCount(); | 1851 | Q_ASSERT(isTrack(trackId)); | ||
1852 | return getTrackById_const(trackId)->getCompositionsCount(); | ||||
1847 | } | 1853 | } | ||
1848 | 1854 | | |||
1849 | bool TimelineModel::requestCompositionMove(int compoId, int trackId, int position, bool updateView, bool logUndo) | 1855 | bool TimelineModel::requestCompositionMove(int compoId, int trackId, int position, bool updateView, bool logUndo) | ||
Context not available. |