Commit 6e3a0c21 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Misc fixes in audio recording - show rec button in mixers when entering monitor mode

parent c88c0b5b
Pipeline #181444 passed with stage
in 7 minutes and 5 seconds
......@@ -49,9 +49,15 @@ MixerManager::MixerManager(QWidget *parent)
m_channelsLayout = new QHBoxLayout;
m_channelsLayout->setContentsMargins(0, 0, 0, 0);
m_masterBox->setContentsMargins(0, 0, 0, 0);
m_channelsLayout->setSpacing(4);
//m_channelsLayout->setSpacing(4);
m_channelsLayout->setSpacing(1);
channelsBoxContainer->setLayout(m_channelsLayout);
m_channelsLayout->addStretch(10);
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::VLine);
line->setFrameShadow(QFrame::Sunken);
line->setFixedWidth(3);
m_box->addWidget(line);
m_box->addLayout(m_masterBox);
setLayout(m_box);
}
......@@ -137,12 +143,8 @@ void MixerManager::registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service,
}
});
m_mixers[tid] = mixer;
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::VLine);
line->setFrameShadow(QFrame::Sunken);
m_channelsLayout->insertWidget(0, line);
m_channelsLayout->insertWidget(0, mixer.get());
m_recommendedWidth = (mixer->minimumWidth() + 12 + line->minimumWidth()) * (qMin(2, int(m_mixers.size())));
m_recommendedWidth = (mixer->minimumWidth() + 1) * (qMin(2, int(m_mixers.size()))) + 3;
if (!KdenliveSettings::mixerCollapse()) {
m_channelsBox->setMinimumWidth(m_recommendedWidth);
}
......
......@@ -287,6 +287,16 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackName)
emit toggleSolo(m_tid, toggled);
updateLabel();
});
m_record = new QToolButton(this);
m_record->setIcon(QIcon::fromTheme("media-record"));
m_record->setToolTip(i18n("Record audio"));
m_record->setCheckable(true);
m_record->setAutoRaise(true);
m_record->setVisible(false);
connect(m_record, &QToolButton::toggled, this, [&](bool toggled) {
emit pCore->recordAudio(m_tid, toggled);
});
m_monitor = new QToolButton(this);
m_monitor->setIcon(QIcon::fromTheme("audio-input-microphone"));
......@@ -294,6 +304,10 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackName)
m_monitor->setCheckable(true);
m_monitor->setAutoRaise(true);
connect(m_monitor, &QToolButton::toggled, this, [&](bool toggled) {
if (!toggled && (m_recording || pCore->isMediaCapturing())) {
// Abort recording if in progress
emit pCore->recordAudio(m_tid, false);
}
m_manager->monitorAudio(m_tid, toggled);
});
} else {
......@@ -367,6 +381,9 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackName)
if (m_solo) {
buttonslay->addWidget(m_solo);
}
if (m_record) {
buttonslay->addWidget(m_record);
}
if (m_monitor) {
buttonslay->addWidget(m_monitor);
}
......@@ -540,11 +557,16 @@ void MixerWidget::updateMonitorState()
void MixerWidget::monitorAudio(bool monitor)
{
QSignalBlocker bk(m_monitor);
qDebug()<<":::: MONIOTORING AUDIO: "<<monitor;
if (monitor) {
m_monitor->setChecked(true);
m_solo->setVisible(false);
m_record->setVisible(true);
updateMonitorState();
} else {
m_monitor->setChecked(false);
m_solo->setVisible(true);
m_record->setVisible(false);
updateMonitorState();
reset();
}
......
......@@ -90,6 +90,7 @@ private:
QSlider *m_volumeSlider;
QToolButton *m_solo;
QToolButton *m_collapse;
QToolButton *m_record;
QToolButton *m_monitor;
KSqueezedTextLabel *m_trackLabel;
QMutex m_storeMutex;
......
......@@ -149,6 +149,7 @@ MediaCapture::MediaCapture(QObject *parent)
, m_path(QUrl())
, m_recordState(0)
, m_tid(-1)
, m_readyForRecord(false)
{
m_resetTimer.setInterval(5000);
m_resetTimer.setSingleShot(true);
......@@ -268,7 +269,11 @@ void MediaCapture::recordAudio(int tid, bool record)
m_recLevels.clear();
m_lastPos = -1;
emit audioLevels(QVector <qreal>());
emit pCore->finalizeRecording(getCaptureOutputLocation().toLocalFile());
// m_readyForRecord is true if we were only displaying the countdown but real recording didn't start yet
if (!m_readyForRecord) {
emit pCore->finalizeRecording(getCaptureOutputLocation().toLocalFile());
}
m_readyForRecord = false;
}
emit recordStateChanged(tid, m_recordState == QMediaRecorder::RecordingState);
});
......@@ -277,6 +282,7 @@ void MediaCapture::recordAudio(int tid, bool record)
if (record && m_audioRecorder->state() == QMediaRecorder::StoppedState) {
m_recTimer.invalidate();
m_resetTimer.stop();
m_readyForRecord = true;
setAudioCaptureDevice();
m_audioRecorder->setAudioInput(m_audioDevice);
setCaptureOutputLocation();
......@@ -311,6 +317,7 @@ int MediaCapture::startCapture()
m_lastPos = -1;
m_recTimer.start();
m_audioRecorder->record();
m_readyForRecord = false;
return m_tid;
}
......@@ -430,7 +437,7 @@ int MediaCapture::recordState() const
bool MediaCapture::isRecording() const
{
if (m_audioRecorder && m_audioRecorder->state() != QMediaRecorder::StoppedState) {
if (m_readyForRecord || (m_audioRecorder && m_audioRecorder->state() != QMediaRecorder::StoppedState)) {
return true;
}
if (m_videoRecorder && m_videoRecorder->state() != QMediaRecorder::StoppedState) {
......
......@@ -98,6 +98,8 @@ private:
int m_recordState;
int m_lastPos;
int m_tid;
/** @brief true if we started the record countdown */
bool m_readyForRecord;
QTimer m_resetTimer;
QMutex m_recMutex;
......
......@@ -1043,7 +1043,7 @@ bool Core::isMediaCapturing() const
void Core::switchCapture()
{
emit recordAudio(-1);
emit recordAudio(-1, !isMediaCapturing());
}
MediaCapture *Core::getAudioDevice()
......
......@@ -388,5 +388,5 @@ signals:
/** @brief Audio recording was started or stopped*/
void switchTimelineRecord(bool on);
/** @brief Launch audio recording on track tid*/
void recordAudio(int tid);
void recordAudio(int tid, bool record);
};
......@@ -1552,7 +1552,7 @@ void Monitor::slotSwitchPlay()
pCore->getAudioDevice()->resumeRecording();
}
} else if (pCore->getAudioDevice()->isMonitoring()) {
pCore->recordAudio(-1);
pCore->recordAudio(-1, true);
}
m_glMonitor->switchPlay(play, m_offset);
bool showDropped = false;
......@@ -2677,3 +2677,11 @@ void Monitor::startCountDown()
QMetaObject::invokeMethod(root, "startCountdown");
}
}
void Monitor::stopCountDown()
{
QQuickItem *root = m_glMonitor->rootObject();
if (root) {
QMetaObject::invokeMethod(root, "stopCountdown");
}
}
......@@ -145,6 +145,7 @@ public:
void fixFocus();
/** @brief Show a rec countdown over the monitor **/
void startCountDown();
void stopCountDown();
protected:
void mousePressEvent(QMouseEvent *event) override;
......
......@@ -4495,12 +4495,16 @@ QColor TimelineController::selectionColor() const
return scheme.foreground(KColorScheme::NeutralText).color();
}
void TimelineController::switchRecording(int trackId)
void TimelineController::switchRecording(int trackId, bool record)
{
if (trackId == -1) {
trackId = pCore->mixer()->recordTrack();
}
if (!pCore->isMediaCapturing()) {
if (record) {
if (pCore->isMediaCapturing()) {
// Already recording, abort
return;
}
qDebug() << "start recording" << trackId;
if (!m_model->isTrack(trackId)) {
qDebug() << "ERROR: Starting to capture on invalid track " << trackId;
......@@ -4527,6 +4531,7 @@ void TimelineController::switchRecording(int trackId)
pCore->startMediaCapture(trackId, true, false);
pCore->getMonitor(Kdenlive::ProjectMonitor)->startCountDown();
} else {
pCore->getMonitor(Kdenlive::ProjectMonitor)->stopCountDown();
pCore->stopMediaCapture(trackId, true, false);
emit stopAudioRecord();
pCore->monitorManager()->slotPause();
......
......@@ -125,7 +125,7 @@ public:
/** @brief Show/hide audio record controls on a track
*/
Q_INVOKABLE void switchRecording(int trackId);
Q_INVOKABLE void switchRecording(int trackId, bool record);
/** @brief Add recorded file to timeline
*/
void finishRecording(const QString &recordedFile);
......
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