Fix audio thumbs for non stereo clips

parent 8f965d1a
......@@ -460,6 +460,12 @@ std::shared_ptr<MarkerListModel> ClipModel::getMarkerModel() const
return pCore->projectItemModel()->getClipByBinID(m_binClipId)->getMarkerModel();
}
int ClipModel::audioChannels() const
{
READ_LOCK();
return pCore->projectItemModel()->getClipByBinID(m_binClipId)->audioChannels();
}
int ClipModel::fadeIn() const
{
return m_effectStack->getFadePosition(true);
......
......@@ -180,6 +180,9 @@ protected:
/** @brief Returns the marker model associated with this clip */
std::shared_ptr<MarkerListModel> getMarkerModel() const;
/** @brief Returns the number of audio channels for this clip */
int audioChannels() const;
bool audioEnabled() const;
bool isAudioOnly() const;
double getSpeed() const;
......
......@@ -196,6 +196,7 @@ QHash<int, QByteArray> TimelineItemModel::roleNames() const
roles[IsDisabledRole] = "disabled";
roles[IsAudioRole] = "audio";
roles[AudioLevelsRole] = "audioLevels";
roles[AudioChannelsRole] = "audioChannels";
roles[IsCompositeRole] = "composite";
roles[IsLockedRole] = "locked";
roles[FadeInRole] = "fadeIn";
......@@ -274,6 +275,8 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
break;
case AudioLevelsRole:
return clip->getAudioWaveform();
case AudioChannelsRole:
return clip->audioChannels();
case HasAudio:
return clip->audioEnabled();
case IsAudioRole:
......
......@@ -143,6 +143,7 @@ public:
SortRole,
ShowKeyframesRole,
AudioLevelsRole, /// clip only
AudioChannelsRole, /// clip only
IsCompositeRole, /// track only
IsLockedRole, /// track only
HeightRole, /// track only
......
......@@ -39,6 +39,7 @@ Rectangle {
property int outPoint: 0
property int clipDuration: 0
property bool isAudio: false
property int audioChannels
property bool isComposition: false
property bool showKeyframes: false
property bool isGrabbed: false
......
......@@ -42,9 +42,9 @@ Row {
TimelineWaveform {
width: Math.min(waveform.innerWidth, waveform.maxWidth)
height: waveform.height
channels: clipRoot.audioChannels
showItem: waveform.visible && (index * width) < waveform.scrollEnd && (index * width + width) > waveform.scrollStart
format: timeline.audioThumbFormat
property int channels: 2
inPoint: Math.round((clipRoot.inPoint + (index * waveform.maxWidth / clipRoot.timeScale)) * clipRoot.speed) * channels
outPoint: inPoint + Math.round(width / clipRoot.timeScale * clipRoot.speed) * channels
levels: clipRoot.audioLevels
......
......@@ -225,6 +225,7 @@ Column{
item.canBeAudio = model.canBeAudio
item.canBeVideo = model.canBeVideo
item.clipType = model.clipType
item.audioChannels = model.audioChannels
//item.binId= model.binId
} else {
console.log('loaded composition: ', model.start, ', ID: ', model.item, ', index: ', trackRoot.DelegateModel.itemsIndex)
......
......@@ -59,6 +59,7 @@ class TimelineWaveform : public QQuickPaintedItem
Q_PROPERTY(QVariant levels MEMBER m_audioLevels NOTIFY propertyChanged)
Q_PROPERTY(QColor fillColor MEMBER m_color NOTIFY propertyChanged)
Q_PROPERTY(int inPoint MEMBER m_inPoint NOTIFY inPointChanged)
Q_PROPERTY(int channels MEMBER m_channels NOTIFY audioChannelsChanged)
Q_PROPERTY(int outPoint MEMBER m_outPoint NOTIFY outPointChanged)
Q_PROPERTY(bool format MEMBER m_format NOTIFY propertyChanged)
Q_PROPERTY(bool showItem MEMBER m_showItem)
......@@ -111,25 +112,28 @@ public:
}
lastIdx = idx;
if (idx + 1 >= data.length()) break;
qreal level = qMax(data.at(idx).toReal(), data.at(idx + 1).toReal()) / 256;
double level = data.at(idx).toDouble() / 256;
for (int j = 1; j < m_channels; j++) {
level = qMax(level, data.at(idx + j).toDouble() / 256);
}
path.lineTo(i, height() - level * height());
}
path.lineTo(i, height());
painter->drawPath(path);
} else {
// Fill gradient
m_gradient.setFinalStop(0, height() / 4);
int channelHeight = height() / (2 * m_channels);
m_gradient.setFinalStop(0, channelHeight);
painter->setBrush(m_gradient);
// Draw separate channels
QMap<int, QPainterPath> positiveChannelPaths;
QMap<int, QPainterPath> negativeChannelPaths;
// TODO: get channels count
int channels = 2;
double i = 0;
double increment = qMax(1., 1 / indicesPrPixel);
for (int channel = 0; channel < channels; channel++) {
int y = height() - (2 * channel + 1) * height() / 4;
for (int channel = 0; channel < m_channels; channel++) {
int y = height() - (2 * channel + 1) * channelHeight;
positiveChannelPaths[channel].moveTo(-1, y);
negativeChannelPaths[channel].moveTo(-1, y);
// Draw channel median line
......@@ -143,12 +147,12 @@ public:
lastIdx = idx;
if (idx + channel >= data.length()) break;
qreal level = data.at(idx + channel).toReal() / 256;
positiveChannelPaths[channel].lineTo(i, y - level * height() / 4);
negativeChannelPaths[channel].lineTo(i, y + level * height() / 4);
positiveChannelPaths[channel].lineTo(i, y - level * channelHeight);
negativeChannelPaths[channel].lineTo(i, y + level * channelHeight);
}
}
for (int channel = 0; channel < channels; channel++) {
int y = height() - (2 * channel + 1) * height() / 4;
for (int channel = 0; channel < m_channels; channel++) {
int y = height() - (2 * channel + 1) * channelHeight;
positiveChannelPaths[channel].lineTo(i, y);
negativeChannelPaths[channel].lineTo(i, y);
painter->drawPath(positiveChannelPaths.value(channel));
......@@ -161,6 +165,7 @@ signals:
void propertyChanged();
void inPointChanged();
void outPointChanged();
void audioChannelsChanged();
private:
QVariant m_audioLevels;
......@@ -170,6 +175,7 @@ private:
bool m_format;
QLinearGradient m_gradient;
bool m_showItem;
int m_channels;
};
void registerTimelineItems()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment