]> git.sesse.net Git - kdenlive/blob - src/abstractmonitor.h
Use enum instead of string to identify monitors
[kdenlive] / src / abstractmonitor.h
1 /***************************************************************************
2  *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #ifndef ABSTRACTMONITOR_H
21 #define ABSTRACTMONITOR_H
22
23 #include "definitions.h"
24
25 #include <QObject>
26 #include <QVector>
27 #include <QWidget>
28 #include <QImage>
29 #include <QPainter>
30 #include <QFrame>
31 #include <QTimer>
32
33 #include <stdint.h>
34
35 class VideoPreviewContainer : public QFrame
36 {
37     Q_OBJECT
38 public:
39     VideoPreviewContainer(QWidget *parent = 0);
40     ~VideoPreviewContainer();
41     /** @brief Set the image to be displayed, will be put in the queue. */
42     void setImage(QImage img);
43     /** @brief Start the display refresh timer. */
44     void start();
45     /** @brief Stop the display refresh timer. */
46     void stop();
47     /** @brief Set the display ratio for this display. */
48     void setRatio(double ratio);
49
50 protected:
51     virtual void paintEvent(QPaintEvent */*event*/);
52     virtual void resizeEvent(QResizeEvent * event);
53
54 private:
55     /** @brief The display aspect ratio for profile. */
56     double m_dar;
57     /** @brief When true, the whole widget surface will be repainted, useful when resizing widget. */
58     bool m_refresh;
59     /** @brief The rectangle defining the area for painting our image. */
60     QRect m_displayRect;
61     /** @brief The queue of images to be displayed. */
62     QList <QImage *> m_imageQueue;
63     /** @brief We refresh the image with a timer, since this widget is only for preview during capture. */
64     QTimer m_refreshTimer;
65     /** @brief Re-calculate the display zone after a resize or aspect ratio change. */
66     void updateDisplayZone();
67 };
68
69
70
71 class AbstractRender: public QObject
72 {
73 Q_OBJECT public:
74
75     /** @brief Build an abstract MLT Renderer
76      *  @param name A unique identifier for this renderer
77      *  @param winid The parent widget identifier (required for SDL display). Set to 0 for OpenGL rendering
78      *  @param profile The MLT profile used for the renderer (default one will be used if empty). */
79     AbstractRender(Kdenlive::MONITORID name, QWidget *parent = 0):QObject(parent), sendFrameForAnalysis(false), m_name(name) {};
80
81     /** @brief Destroy the MLT Renderer. */
82     virtual ~AbstractRender() {};
83
84     /** @brief This property is used to decide if the renderer should convert it's frames to QImage for use in other Kdenlive widgets. */
85     bool sendFrameForAnalysis;
86     
87     /** @brief This property is used to decide if the renderer should send audio data for monitoring. */
88     bool analyseAudio;
89     
90     const QString &name() const {return m_name;};
91
92     /** @brief Someone needs us to send again a frame. */
93     virtual void sendFrameUpdate() = 0;
94
95 private:
96     QString m_name;
97     
98 signals:
99     /** @brief The renderer refreshed the current frame. */
100     void frameUpdated(QImage);
101
102     /** @brief This signal contains the audio of the current frame. */
103     void audioSamplesSignal(QVector<int16_t>,int,int,int);
104 };
105
106 class AbstractMonitor : public QWidget
107 {
108     Q_OBJECT
109 public:
110     AbstractMonitor(Kdenlive::MONITORID id, QWidget *parent = 0): QWidget(parent) {m_id = id;};
111     Kdenlive::MONITORID id() {return m_id;};
112     virtual ~AbstractMonitor() {};
113     virtual AbstractRender *abstractRender() = 0;
114
115 public slots:
116     virtual void stop() = 0;
117     virtual void start() = 0;
118
119 protected:
120     Kdenlive::MONITORID m_id;
121 };
122
123 #endif