mixerwidget.hpp 4.22 KB
Newer Older
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
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
/***************************************************************************
 *   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 MIXERWIDGET_H
#define MIXERWIDGET_H

#include "definitions.h"
#include "mlt++/MltService.h"

#include <memory>
#include <unordered_map>
#include <QWidget>
#include <QMutex>

class KDualAction;
class AudioLevelWidget;
class QSlider;
36
class QDial;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
37
class QSpinBox;
38
class QDoubleSpinBox;
39
class QLabel;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
40
41
class QToolButton;
class MixerManager;
Julius Künzel's avatar
Julius Künzel committed
42
class KSqueezedTextLabel;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
43
44
45

namespace Mlt {
    class Tractor;
46
    class Event;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
47
48
49
50
51
52
53
}

class MixerWidget : public QWidget
{
    Q_OBJECT

public:
54
55
    MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, QString trackTag, const QString &trackName, MixerManager *parent = nullptr);
    MixerWidget(int tid, Mlt::Tractor *service, QString trackTag, const QString &trackName, MixerManager *parent = nullptr);
56
    ~MixerWidget() override;
Julius Künzel's avatar
Julius Künzel committed
57
    void buildUI(Mlt::Tractor *service, const QString &trackName);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
58
    /** @brief discard stored audio values and reset vu-meter to 0 if requested */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
59
60
61
    void reset();
    /** @brief discard stored audio values */
    void clear();
62
    static void property_changed( mlt_service , MixerWidget *self, mlt_event_data data );
Julius Künzel's avatar
Julius Künzel committed
63
    void setTrackName(const QString &name);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
64
    void setMute(bool mute);
65
    /** @brief Returns true if track is muted
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
66
67
68
69
70
     * */
    bool isMute() const;
    /** @brief Uncheck the solo button
     * */
    void unSolo();
71
    /** @brief Connect the mixer widgets to the correspondent filters */
72
    void connectMixer(bool doConnect);
73
74
    /** @brief Disable/enable monitoring by disabling/enabling filter */
    void pauseMonitoring(bool pause);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
75

76
77
78
protected:
    void mousePressEvent(QMouseEvent *event) override;

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
79
80
public slots:
    void updateAudioLevel(int pos);
81
82
83
84
    void setRecordState(bool recording);

private slots:
    void gotRecLevels(QVector<qreal>levels);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
85
86
87
88
89
90
91

protected:
    MixerManager *m_manager;
    int m_tid;
    std::shared_ptr<Mlt::Filter> m_levelFilter;
    std::shared_ptr<Mlt::Filter> m_monitorFilter;
    std::shared_ptr<Mlt::Filter> m_balanceFilter;
92
93
    QMap<int, QVector<double>> m_levels;
    int m_channels;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
94
95
    KDualAction *m_muteAction;
    QSpinBox *m_balanceSpin;
Julius Künzel's avatar
Julius Künzel committed
96
    QSlider *m_balanceSlider;
97
    QDoubleSpinBox *m_volumeSpin;
98
    int m_maxLevels;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
99
100
101
102
103

private:
    std::shared_ptr<AudioLevelWidget> m_audioMeterWidget;
    QSlider *m_volumeSlider;
    QToolButton *m_solo;
104
    QToolButton *m_record;
105
    QToolButton *m_collapse;
Julius Künzel's avatar
Julius Künzel committed
106
    KSqueezedTextLabel *m_trackLabel;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
107
    QMutex m_storeMutex;
108
    double m_lastVolume;
109
    QVector <double>m_audioData;
110
    Mlt::Event *m_listener;
111
    bool m_recording;
Julius Künzel's avatar
Julius Künzel committed
112
    const QString m_trackTag;
113
114
    /** @Update track label to reflect state */
    void updateLabel();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
115
116
117
118

signals:
    void gotLevels(QPair <double, double>);
    void muteTrack(int tid, bool mute);
119
    void toggleSolo(int tid, bool toggled);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
120
121
122
123
};

#endif