Debian Codegraph @

au4/src/playback/view/toolbars/components/timecodemodel.h

raw
1 /*
2 * Audacity: A Digital Audio Editor
3 */
4 #pragma once
5
6 #include <QAbstractListModel>
7 #include <QQuickItem>
8
9 #include "timecodeformatter.h"
10 #include "fieldsinteractioncontroller.h"
11
12 namespace au::playback {
13 class TimecodeModel : public QAbstractListModel
14 {
15 Q_OBJECT
16
17 Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged FINAL)
18
19 Q_PROPERTY(double sampleRate READ sampleRate WRITE setSampleRate NOTIFY sampleRateChanged FINAL)
20 Q_PROPERTY(double tempo READ tempo WRITE setTempo NOTIFY tempoChanged FINAL)
21 Q_PROPERTY(int upperTimeSignature READ upperTimeSignature WRITE setUpperTimeSignature NOTIFY upperTimeSignatureChanged FINAL)
22 Q_PROPERTY(int lowerTimeSignature READ lowerTimeSignature WRITE setLowerTimeSignature NOTIFY lowerTimeSignatureChanged FINAL)
23
24 Q_PROPERTY(QVariantList availableFormats READ availableFormats NOTIFY availableFormatsChanged)
25 Q_PROPERTY(int currentFormat READ currentFormat WRITE setCurrentFormat NOTIFY currentFormatChanged FINAL)
26
27 Q_PROPERTY(int currentEditedFieldIndex READ currentEditedFieldIndex
28 WRITE setCurrentEditedFieldIndex NOTIFY currentEditedFieldIndexChanged FINAL)
29
30 Q_PROPERTY(QQuickItem * visualItem READ visualItem WRITE setVisualItem CONSTANT)
31
32 public:
33 explicit TimecodeModel(QObject* parent = nullptr);
34
35 enum class ViewFormatType {
36 Undefined = -1,
37 Seconds,
38 SecondsMilliseconds,
39 HHMMSS,
40 DDHHMMSS,
41 HHMMSSHundredths,
42 HHMMSSMilliseconds,
43 HHMMSSSamples,
44 Samples,
45 HHMMSSFilmFrames,
46 FilmFrames,
47 HHMMSSNTSCDropFrames,
48 HHMMSSNTSCNonDropFrames,
49 NTSCFrames,
50 HHMMSSPALFrames,
51 PALFrames,
52 HHMMSSCDDAFrames,
53 CDDAFrames,
54 BarBeat,
55 BarBeatTick
56 };
57
58 struct ViewFormat {
59 ViewFormatType type = ViewFormatType::Undefined;
60 QString title;
61 QString formatStr;
62 };
63
64 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
65 QVariant data(const QModelIndex& index, int role) const override;
66 QHash<int, QByteArray> roleNames() const override;
67
68 double value() const;
69 void setValue(double value);
70
71 int currentFormat() const;
72 void setCurrentFormat(int format);
73
74 int currentEditedFieldIndex() const;
75 void setCurrentEditedFieldIndex(int index);
76
77 QQuickItem* visualItem() const;
78 void setVisualItem(QQuickItem* item);
79
80 QVariantList availableFormats();
81
82 double sampleRate() const;
83 void setSampleRate(double sampleRate);
84
85 double tempo() const;
86 void setTempo(double tempo);
87
88 int upperTimeSignature() const;
89 void setUpperTimeSignature(int timeSignature);
90
91 int lowerTimeSignature() const;
92 void setLowerTimeSignature(int timeSignature);
93
94 signals:
95 void valueChanged();
96
97 void sampleRateChanged();
98 void tempoChanged();
99 void upperTimeSignatureChanged();
100 void lowerTimeSignatureChanged();
101
102 void availableFormatsChanged();
103 void currentFormatChanged();
104
105 void currentEditedFieldIndexChanged();
106
107 private:
108 friend class TimecodeModelTests;
109
110 enum Roles {
111 rSymbol = Qt::UserRole + 1,
112 rIsEditable
113 };
114
115 void reloadFormatter();
116 void initFormatter();
117
118 void initFieldInteractionController();
119
120 void updateValueString();
121
122 double m_value = -1.0;
123 QString m_valueString;
124
125 double m_sampleRate = 1.0;
126 double m_tempo = 0;
127 int m_upperTimeSignature = 0;
128 int m_lowerTimeSignature = 0;
129
130 std::shared_ptr<TimecodeFormatter> m_formatter;
131 std::shared_ptr<FieldsInteractionController> m_fieldsInteractionController;
132
133 QList<ViewFormat> m_availableViewFormats;
134 int m_currentFormat = int(ViewFormatType::HHMMSS);
135 };
136 }