Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 148 lines (122 sloc) 4.419 kb
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
#pragma once
#include "Synced.h"
#include "VideoFile.h"
#include "WtsAudio.h"


namespace WTS {

class ScoreSymbol;

/** Project data container.
* Eventually all project specific data should end up here.
*/
class Project : public QObject {
    Q_OBJECT
public:
    enum MarkerType {
        NONE,
        EVENT,
        SCENE,
        ANY,
    };

    class Marker : public WTS::Synced {
    protected:
        MarkerType m_type;
        QPixmap m_snapshot;

        float m_tension;

    public:
        Marker(MarkerType type, qint64 ms, QObject * parent)
            : WTS::Synced(ms, parent)
            , m_type(type)
            , m_tension(0.5)
        {}

        MarkerType type() const { return m_type; }
        const QPixmap& snapshot() const { return m_snapshot; }
        void setSnapshot(const QPixmap& snapshot) { m_snapshot = snapshot; }

        float tension() const { return m_tension; }
        void setTension(float value) { m_tension = value; }
    };

    // exceptions
    struct InvalidProject {};
    struct CantChangeDuration {};

    // testing helpers
    explicit Project(QObject * parent = 0);
    void setDuration(qint64 duration);
    bool isValid() const;

    // normal api
    Project(const QString& path, QObject * parent = 0);
    double finalTension() const { return m_finalTension; }
    void addMarker(MarkerType type, qint64 when, float tension);
    QList<Marker *> getMarkers(MarkerType type = ANY, bool forward = true) const;
    QPainterPath tensionCurve(float width, float height = 1.0f, Marker * from = 0, Marker * to = 0);
    qint64 duration() const {
        throwIfInvalid();
        return m_videoFile ? m_videoFile->duration() : m_duration; }
    int videoWidth() const {
        throwIfInvalid();
        return m_videoFile->width();
    }
    int videoHeight() const {
        throwIfInvalid();
        return m_videoFile->height();
    }
    VideoFile * videoFile() {
        return m_videoFile;
    }
    const VideoFile * videoFile() const { return m_videoFile; }
    static QDir movDir();
    QDir dataDir() const { return m_dataDir; }
    QString moviePath() const { return videoFile()->path(); }
    QString movieFilename() const { return QFileInfo(moviePath()).fileName(); }
    void addBufferAt(WtsAudio::BufferAt * newBuff);
    WtsAudio::BufferAt *copyScratch(WtsAudio::BufferAt * newBuff);
    QString pdfPath();

    QList<WtsAudio::BufferAt *> getSequence() const { return m_sequence; }

public slots:
    // see if samples changed on disk and reload if so
    void reScanSamples();
    void openInExternalApp(SoundBuffer*);
    void setFinalTension(double value) { m_finalTension = value; }
    void setMarkerTension(int markerIndex, float tension);
    void removalRequested(WTS::Synced* synced);

    void save();
    void load();
    void print(QPrinter&, const QList<WTS::ScoreSymbol *>&);

    void setSecPerPage( int sec ) { setMsPerPage( (qint64)sec * 1000 ); }
    void setMsPerPage( qint64 ms ) { m_msPerPage = ms; }

signals:

    void saveSection(QXmlStreamWriter& writer);
    void loadSection(QXmlStreamReader& reader);

    // changes
    void sampleChanged(SoundBuffer * sample);
    void newBufferAt(WtsAudio::BufferAt * bufferAt);
    void syncedItemRemoved(WTS::Synced * synced);
    void tensionChanged();
    void storyBoardChanged();

protected slots:
    void saveStoryboard(QXmlStreamWriter&);
    void saveSequence(QXmlStreamWriter&);
    bool loadStoryboard(QXmlStreamReader&);
    bool loadSequence(QXmlStreamReader&);

protected:
    QString makeSampleName();
    void removeMarkerAt(quint64 at);
    void removeBufferAt(WtsAudio::BufferAt * newBuff);

    void drawTimeScale( qint64 start, qint64 end, QPainter& painter, const QRect& target );
    void drawSceneThumbs( Marker * sceneMarker, qint64 start, qint64 end, QPainter& painter, const QRect& target );
    void drawScore( const QList<WTS::ScoreSymbol *>& score, qint64 start, qint64 end, QPainter& painter, const QRect& target );

    bool m_loading;
    double m_finalTension;
    QMap<qint64, Project::Marker *> m_markers;
    VideoFile * m_videoFile;
    QDir m_dataDir;
    QList<WtsAudio::BufferAt *> m_sequence;
    int m_lastSampleNameNum;
    static QDir s_movDir;
    static bool s_movDirFound;

    // print style
    QPen m_markerPen;
    qint64 m_msPerPage;

private:
    void setup();
    void throwIfInvalid() const;
    qint64 m_duration;
};

}
Something went wrong with that request. Please try again.