Commit 1ee9dc36 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Improve timeline audio record preview (position and duration of the recording...

Improve timeline audio record preview (position and duration of the recording now adjusts when scaling timeline)
parent c3e74e3f
......@@ -988,6 +988,44 @@ int SubtitleModel::getNextSub(int id) const
return -1;
}
void SubtitleModel::subtitleFileFromZone(int in, int out, const QString &outFile)
{
QJsonArray list;
double fps = pCore->getCurrentFps();
GenTime zoneIn(in, fps);
GenTime zoneOut(out, fps);
for (auto subtitle : m_subtitleList) {
GenTime inTime = subtitle.first;
GenTime outTime = subtitle.second.second;
if (outTime < zoneIn) {
// Outside zone
continue;
}
if (zoneOut > GenTime() && inTime > zoneOut) {
// Outside zone
continue;
}
if (inTime < zoneIn) {
inTime = zoneIn;
}
if (zoneOut > GenTime() && outTime > zoneOut) {
outTime = zoneOut;
}
inTime -= zoneIn;
outTime -= zoneIn;
QJsonObject currentSubtitle;
currentSubtitle.insert(QLatin1String("startPos"), QJsonValue(inTime.seconds()));
currentSubtitle.insert(QLatin1String("dialogue"), QJsonValue(subtitle.second.first));
currentSubtitle.insert(QLatin1String("endPos"), QJsonValue(outTime.seconds()));
list.push_back(currentSubtitle);
// qDebug()<<subtitle.first.seconds();
}
QJsonDocument jsonDoc(list);
QString subData = QString(jsonDoc.toJson());
saveSubtitleData(subData, outFile);
}
QString SubtitleModel::toJson()
{
// qDebug()<< "to JSON";
......@@ -1030,6 +1068,18 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
if (masterFile.isEmpty()) {
m_subtitleFilter->set("av.filename", outFile.toUtf8().constData());
}
int line = saveSubtitleData(data, outFile);
qDebug() << "Saving subtitle filter: " << outFile;
if (line > 0) {
m_subtitleFilter->set("av.filename", outFile.toUtf8().constData());
m_tractor->attach(*m_subtitleFilter.get());
} else {
m_tractor->detach(*m_subtitleFilter.get());
}
}
int SubtitleModel::saveSubtitleData(const QString &data, const QString &outFile)
{
bool assFormat = outFile.endsWith(".ass");
if (!assFormat) {
qDebug() << "srt/vtt/sbv file import"; // if imported file isn't .ass, it is .srt format
......@@ -1041,7 +1091,7 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
auto json = QJsonDocument::fromJson(data.toUtf8());
if (!json.isArray()) {
qDebug() << "Error : Json file should be an array";
return;
return 0;
}
int line = 0;
auto list = json.array();
......@@ -1119,13 +1169,7 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
}
outF.close();
}
qDebug() << "Saving subtitle filter: " << outFile;
if (line > 0) {
m_subtitleFilter->set("av.filename", outFile.toUtf8().constData());
m_tractor->attach(*m_subtitleFilter.get());
} else {
m_tractor->detach(*m_subtitleFilter.get());
}
return line;
}
void SubtitleModel::updateSub(int id, const QVector<int> &roles)
......
......@@ -207,6 +207,7 @@ void MediaCapture::switchMonitorState(bool run)
break;
}
m_lastPos = currentPos;
emit recDurationChanged();
}
}
emit levelsChanged();
......
......@@ -47,6 +47,7 @@ class MediaCapture : public QObject
Q_OBJECT
Q_PROPERTY(QVector<qreal> levels READ levels NOTIFY levelsChanged)
Q_PROPERTY(int recordState READ recordState NOTIFY recordStateChanged)
Q_PROPERTY(int recDuration MEMBER m_lastPos NOTIFY recDurationChanged)
public:
MediaCapture(QObject *parent);
......@@ -96,6 +97,7 @@ private:
QVector<qreal> m_levels;
QVector<double> m_recLevels;
int m_recordState;
/** @brief Duration of the recording */
int m_lastPos;
int m_tid;
/** @brief true if we started the record countdown */
......@@ -111,4 +113,5 @@ signals:
void recordStateChanged(int tid, bool recording);
void recordDone();
void audioLevels(QVector<qreal> levels);
void recDurationChanged();
};
......@@ -1013,7 +1013,9 @@ void Core::stopMediaCapture(int tid, bool checkAudio, bool checkVideo)
void Core::monitorAudio(int tid, bool monitor)
{
m_mainWindow->getCurrentTimeline()->controller()->switchTrackRecord(tid, monitor);
m_monitorManager->projectMonitor()->switchRecordButton(monitor);
if (monitor && pCore->monitorManager()->projectMonitor()->isPlaying()) {
pCore->monitorManager()->projectMonitor()->stop();
}
}
void Core::startRecording()
......
......@@ -113,6 +113,7 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
, m_forceSizeFactor(0)
, m_offset(id == Kdenlive::ProjectMonitor ? TimelineModel::seekDuration : 0)
, m_lastMonitorSceneType(MonitorSceneDefault)
, m_displayingCountdown(true)
{
auto *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
......@@ -1546,8 +1547,14 @@ void Monitor::slotSwitchPlay()
} else if (recState == QMediaRecorder::PausedState && play) {
pCore->getAudioDevice()->resumeRecording();
}
m_displayingCountdown = true;
} else if (pCore->getAudioDevice()->isMonitoring()) {
pCore->recordAudio(-1, true);
if (m_displayingCountdown) {
m_displayingCountdown = false;
m_playAction->setActive(false);
return;
}
}
m_glMonitor->switchPlay(play, m_offset);
bool showDropped = false;
......@@ -2691,10 +2698,3 @@ void Monitor::stopCountDown()
}
}
void Monitor::switchRecordButton(bool record)
{
if (record && isPlaying()) {
stop();
}
m_playAction->setInactiveIcon(QIcon::fromTheme(record ? QStringLiteral("media-record") : QStringLiteral("media-playback-start")));
}
......@@ -146,8 +146,6 @@ public:
/** @brief Show a rec countdown over the monitor **/
void startCountDown();
void stopCountDown();
/** @brief When we are in audio monitoring mode, play button turns to rec **/
void switchRecordButton(bool record);
protected:
void mousePressEvent(QMouseEvent *event) override;
......@@ -215,6 +213,7 @@ private:
int m_forceSizeFactor;
int m_offset;
MonitorSceneType m_lastMonitorSceneType;
bool m_displayingCountdown;
MonitorAudioLevel *m_audioMeterWidget;
QTimer m_droppedTimer;
double m_displayedFps;
......
......@@ -24,11 +24,9 @@ Item {
// Paused
recbutton.color = 'white'
recbutton.ToolTip.text = i18n("Paused")
recordInfo.text = i18n("Paused")
} else {
recbutton.color = 'darkred'
recbutton.ToolTip.text = i18n("Record")
recordInfo.text = i18n("Record")
}
}
RowLayout {
......
......@@ -57,16 +57,20 @@ Rectangle {
function startAudioRecord(tid) {
var tk = Logic.getTrackById(tid)
recordPlaceHolder.y = tk.y + subtitleTrack.height
recordPlaceHolder.height = tk.height
recordStartPlaceHolder.x = root.consumerPosition * root.timeScale
recordPlaceHolder.anchors.right = cursor.left
recordPlaceHolder.y = Qt.binding(function() { return tk.y + subtitleTrack.height })
recordPlaceHolder.height = Qt.binding(function() { return tk.height })
var startFrame = root.consumerPosition
recordStartPlaceHolder.x = Qt.binding(function() { return startFrame * root.timeScale })
recordPlaceHolder.visible = true
recordPlaceHolder.width = Qt.binding(function() { return audiorec.recDuration * root.timeScale })
}
function stopAudioRecord() {
recordPlaceHolder.visible = false
recordPlaceHolder.anchors.right = undefined
recordStartPlaceHolder.x = 0
recordStartPlaceHolder.y = 0
recordPlaceHolder.width = 0
recordPlaceHolder.height = 0
}
function fitZoom() {
......
Supports Markdown
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