clipsnapmodel.hpp 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/***************************************************************************
 *   Copyright (C) 2019 by Jean-Baptiste Mardelle                                  *
 *   This file is part of Kdenlive. See www.kdenlive.org.                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) version 3 or any later version accepted by the       *
 *   membership of KDE e.V. (or its successor approved  by the membership  *
 *   of KDE e.V.), which shall act as a proxy defined in Section 14 of     *
 *   version 3 of the license.                                             *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#ifndef CLIPSNAPMODEL_H
#define CLIPSNAPMODEL_H

25 26
#include "snapmodel.hpp"

27 28
#include <map>
#include <memory>
29
#include <unordered_set>
30 31 32 33

class MarkerListModel;

/** @brief This class represents the snap points of a clip of the timeline.
34
    Basically, one can add or remove snap points
35 36 37
 *
 */

38
class ClipSnapModel : public virtual SnapInterface, public std::enable_shared_from_this<SnapInterface>
39 40 41 42 43
{
public:
    ClipSnapModel();

    /* @brief Adds a snappoint at given position */
44
    void addPoint(int position) override;
45 46

    /* @brief Removes a snappoint from given position */
47
    void removePoint(int position) override;
48

49
    void registerSnapModel(const std::weak_ptr<SnapModel> &snapModel, int position, int in, int out, double speed = 1.);
50
    void deregisterSnapModel();
51 52 53

    void setReferenceModel(const std::weak_ptr<MarkerListModel> &markerModel, double speed);

54 55
    void updateSnapModelPos(int newPos);
    void updateSnapModelInOut(std::pair<int, int> newInOut);
56
    /* @brief Retrieve all snap points */
57
    void allSnaps(std::vector<int> &snaps, int offset = 0);
58 59 60 61 62


private:
    std::weak_ptr<SnapModel> m_registeredSnap;
    std::weak_ptr<MarkerListModel> m_parentModel;
63 64 65 66
    std::unordered_set<int> m_snapPoints;
    int m_inPoint;
    int m_outPoint;
    int m_position;
67
    double m_speed{1.};
68 69
    void addAllSnaps();
    void removeAllSnaps();
70 71 72 73

};

#endif