Verified Commit f84305c3 authored by Phobos D'thorga's avatar Phobos D'thorga 🐲
Browse files

* Work has begun on the Qt Audio-based inputs/outputs now. Soon, we should...

* Work has begun on the Qt Audio-based inputs/outputs now. Soon, we should have an operable recording mechanism for the encoding of multimedia files.
parent edea53b8
Pipeline #1021 passed with stages
in 27 minutes and 5 seconds
......@@ -766,7 +766,8 @@ namespace Database {
enum AudioPlaybackDlg {
GkAudioDlgLastFolderBrowsed,
GkRecordDlgLastFolderBrowsed
GkRecordDlgLastFolderBrowsed,
GkRecordDlgLastCodecSelected
};
enum general_stat_cfg {
......
......@@ -630,6 +630,9 @@ void GkLevelDb::write_audio_playback_dlg_settings(const QString &value, const Au
case AudioPlaybackDlg::GkRecordDlgLastFolderBrowsed:
batch.Put("GkRecordDlgLastFolderBrowsed", value.toStdString());
break;
case AudioPlaybackDlg::GkRecordDlgLastCodecSelected:
batch.Put("GkRecordDlgLastCodecSelected", value.toStdString());
break;
default:
throw std::runtime_error(tr("Invalid key has been provided for writing Audio Playback settings relating to Google LevelDB!").toStdString());
}
......@@ -2648,6 +2651,9 @@ QString GkLevelDb::read_audio_playback_dlg_settings(const AudioPlaybackDlg &key)
case AudioPlaybackDlg::GkRecordDlgLastFolderBrowsed:
status = db->Get(read_options, "GkRecordDlgLastFolderBrowsed", &value);
break;
case AudioPlaybackDlg::GkRecordDlgLastCodecSelected:
status = db->Get(read_options, "GkRecordDlgLastCodecSelected", &value);
break;
default:
throw std::runtime_error(tr("Invalid key has been provided for reading Audio Playback dialog settings relating to Google LevelDB!").toStdString());
}
......
......@@ -521,6 +521,10 @@ void GkAudioEncoding::encodeOpus(const qint32 &bitrate, const qint32 &sample_rat
// otherwise is likely to result in worsened multimedia quality and/or overall performance.
//
err = opus_encoder_ctl(m_opusEncoder, OPUS_SET_BITRATE(bitrate));
gkEventLogger->publishEvent(tr("Initiate encoding with Opus as the codec! Frame size: %1. Sample rate: %2. Bit rate: %3. Channels: %4.")
.arg(QString::number(m_size), QString::number(sample_rate), QString::number(bitrate), QString::number(m_channels)), GkSeverity::Info, "",
false, true, false, false, false);
while (!m_buffer.isEmpty() && m_recActive == GkAudioRecordStatus::Active) {
QByteArray input = m_buffer.mid(0, m_size);
m_buffer.remove(0, m_size);
......
......@@ -99,7 +99,7 @@ GkAudioPlayDialog::GkAudioPlayDialog(QPointer<GkLevelDb> database,
//
audio_out_play = false;
audio_out_stop = false;
audio_out_record = false;
m_audioRecReady = false;
audio_out_skip_fwd = false;
audio_out_skip_bck = false;
......@@ -298,7 +298,7 @@ void GkAudioPlayDialog::on_pushButton_playback_play_clicked()
void GkAudioPlayDialog::on_pushButton_playback_record_clicked()
{
try {
if (m_recordDirPath.isEmpty() && !audio_out_record) { // We first need to choose a destination to record towards!
if (m_recordDirPath.path().isEmpty() || !m_audioRecReady) { // We first need to choose a destination to record towards!
auto def_path = gkDb->read_audio_playback_dlg_settings(AudioPlaybackDlg::GkRecordDlgLastFolderBrowsed); // There has been a previously used path that the user has used, and it's been remembered by Google LevelDB!
if (def_path.isEmpty()) {
def_path = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
......@@ -307,37 +307,62 @@ void GkAudioPlayDialog::on_pushButton_playback_record_clicked()
//
// Open a QFileDialog so a user may choose a directory to save files within!
const QString filePath = QFileDialog::getExistingDirectory(this, tr("Save Directory for Recordings"), def_path);
gkDb->write_audio_playback_dlg_settings(QString::number(ui->comboBox_playback_rec_codec->currentIndex()),
AudioPlaybackDlg::GkRecordDlgLastCodecSelected);
if (filePath.isEmpty()) { // No file has supposedly been chosen!
emit cleanupForms(GkClearForms::Recording);
return;
}
if (!m_recordDirPath.isReadable()) {
emit cleanupForms(GkClearForms::Recording);
throw std::invalid_argument(tr("Unable to use directory, \"%1\", for reading and/or writing!")
.arg(m_recordDirPath.path()).toStdString());
}
//
// The chosen directory/path is legitimate and ready-to-use!
ui->lineEdit_playback_file_location->setText(m_recordDirPath.path());
gkDb->write_audio_playback_dlg_settings(m_recordDirPath.path(), AudioPlaybackDlg::GkRecordDlgLastFolderBrowsed);
//
// Reset all of the form elements and set the designated path...
emit cleanupForms(GkClearForms::All);
const auto last_codec_used = gkDb->read_audio_playback_dlg_settings(AudioPlaybackDlg::GkRecordDlgLastCodecSelected);
ui->comboBox_playback_rec_codec->setCurrentIndex(last_codec_used.toInt());
m_recordDirPath.setPath(filePath);
m_audioRecReady = true; // Recording state is TRUE!
emit recStatus(GkAudioRecordStatus::Paused);
GkAudioFramework::CodecSupport codec_used = gkDb->convCodecSupportFromIdxToEnum(ui->comboBox_playback_rec_codec->currentData().toInt());
return;
} else if (gkAudioEncoding->getRecStatus() == GkAudioRecordStatus::Paused) { // Now that the destination has been chosen, start recording when the button is pressed again!
//
// Start recording; begin state...
if (m_recordDirPath.isReadable()) { // Verify that the directory itself exists!
ui->lineEdit_playback_file_location->setText(m_recordDirPath.path());
gkDb->write_audio_playback_dlg_settings(m_recordDirPath.path(), AudioPlaybackDlg::GkRecordDlgLastFolderBrowsed);
//
// Determine the codec used...
GkAudioFramework::CodecSupport codec_used = gkDb->convCodecSupportFromIdxToEnum(ui->comboBox_playback_rec_codec->currentData().toInt());
if (codec_used != GkAudioFramework::CodecSupport::Loopback) {
emit recStatus(GkAudioRecordStatus::Active);
gkPaAudioPlayer->record(codec_used, m_recordDirPath);
gkStringFuncs->changePushButtonColor(ui->pushButton_playback_record, false);
} else {
throw std::runtime_error(tr("Loopback mode is unsupported during recording!").toStdString());
}
} else {
throw std::invalid_argument(tr("Unable to use directory, \"%1\", for reading and/or writing!")
.arg(m_recordDirPath.path()).toStdString());
}
} else { // Now that the destination has been chosen, start recording when the button is pressed again!
gkStringFuncs->changePushButtonColor(ui->pushButton_playback_record, false);
audio_out_record = true; // Recording state is TRUE!
} else {
//
// End or pause recording; end state...
m_audioRecReady = false; // Recording state is FALSE!
emit recStatus(GkAudioRecordStatus::Finished);
gkStringFuncs->changePushButtonColor(ui->pushButton_playback_record, true);
return;
}
//
// End or pause recording; end state...
gkStringFuncs->changePushButtonColor(ui->pushButton_playback_record, true);
audio_out_record = false; // Recording state is FALSE!
emit recStatus(GkAudioRecordStatus::Finished);
} catch (const std::exception &e) {
gkStringFuncs->print_exception(e);
}
......
......@@ -123,7 +123,7 @@ private:
// QPushButtons, etc.
bool audio_out_play;
bool audio_out_stop;
bool audio_out_record;
bool m_audioRecReady;
bool audio_out_skip_fwd;
bool audio_out_skip_bck;
......
......@@ -62,7 +62,7 @@
<x>0</x>
<y>0</y>
<width>582</width>
<height>548</height>
<height>557</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
......@@ -132,14 +132,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_playback_rec_bitrate">
<property name="text">
<string>Bitrate: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QFrame" name="frame_playback_rec_bitrate">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
......@@ -198,6 +198,16 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_playback_rec_source">
<property name="text">
<string>Source: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_playback_rec_source"/>
</item>
</layout>
</widget>
</item>
......@@ -565,10 +575,10 @@ QPushButton:disabled {
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
......@@ -590,10 +600,10 @@ QPushButton:disabled {
<item>
<widget class="QFrame" name="frame_api_details_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<property name="leftMargin">
......@@ -617,10 +627,10 @@ QPushButton:disabled {
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
......@@ -642,19 +652,19 @@ QPushButton:disabled {
<item>
<widget class="QFrame" name="frame_api_details_inner_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
......@@ -728,10 +738,10 @@ QPushButton:disabled {
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
......@@ -762,10 +772,10 @@ QPushButton:disabled {
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
......
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