audio preferences
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# Olive - Non-Linear Video Editor
|
||||
# Copyright (C) 2019 Olive Team
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
audio/audiomanager.h
|
||||
audio/audiomanager.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,111 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "audiomanager.h"
|
||||
|
||||
AudioManager* AudioManager::audio_ = nullptr;
|
||||
|
||||
void AudioManager::CreateInstance()
|
||||
{
|
||||
if (audio_ == nullptr) {
|
||||
audio_ = new AudioManager();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioManager::DestroyInstance()
|
||||
{
|
||||
delete audio_;
|
||||
audio_ = nullptr;
|
||||
}
|
||||
|
||||
AudioManager *AudioManager::instance()
|
||||
{
|
||||
return audio_;
|
||||
}
|
||||
|
||||
void AudioManager::RefreshDevices()
|
||||
{
|
||||
if (refreshing_devices_) {
|
||||
return;
|
||||
}
|
||||
|
||||
input_devices_.clear();
|
||||
output_devices_.clear();
|
||||
|
||||
refreshing_devices_ = true;
|
||||
|
||||
refresh_thread_.start(QThread::LowPriority);
|
||||
}
|
||||
|
||||
bool AudioManager::IsRefreshing()
|
||||
{
|
||||
return refreshing_devices_;
|
||||
}
|
||||
|
||||
const QList<QAudioDeviceInfo> &AudioManager::ListInputDevices()
|
||||
{
|
||||
return input_devices_;
|
||||
}
|
||||
|
||||
const QList<QAudioDeviceInfo> &AudioManager::ListOutputDevices()
|
||||
{
|
||||
return output_devices_;
|
||||
}
|
||||
|
||||
AudioManager::AudioManager() :
|
||||
output_(nullptr),
|
||||
refreshing_devices_(false)
|
||||
{
|
||||
RefreshDevices();
|
||||
|
||||
connect(&refresh_thread_, SIGNAL(ListsReady()), this, SLOT(RefreshThreadDone()));
|
||||
}
|
||||
|
||||
void AudioManager::RefreshThreadDone()
|
||||
{
|
||||
output_devices_ = refresh_thread_.output_devices();
|
||||
input_devices_ = refresh_thread_.input_devices();
|
||||
|
||||
refreshing_devices_ = false;
|
||||
|
||||
emit DeviceListReady();
|
||||
}
|
||||
|
||||
AudioRefreshDevicesThread::AudioRefreshDevicesThread()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioRefreshDevicesThread::run()
|
||||
{
|
||||
output_devices_ = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
input_devices_ = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
|
||||
emit ListsReady();
|
||||
}
|
||||
|
||||
const QList<QAudioDeviceInfo>& AudioRefreshDevicesThread::input_devices()
|
||||
{
|
||||
return input_devices_;
|
||||
}
|
||||
|
||||
const QList<QAudioDeviceInfo>& AudioRefreshDevicesThread::output_devices()
|
||||
{
|
||||
return output_devices_;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef AUDIOMANAGER_H
|
||||
#define AUDIOMANAGER_H
|
||||
|
||||
#include <memory>
|
||||
#include <QAudioOutput>
|
||||
#include <QThread>
|
||||
|
||||
/**
|
||||
* @brief A thread for refreshing the total list of devices on the system
|
||||
*
|
||||
* Refreshing devices causes a noticeable pause in execution. Doing it another thread is intended to avoid this.
|
||||
*/
|
||||
class AudioRefreshDevicesThread : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioRefreshDevicesThread();
|
||||
|
||||
virtual void run() override;
|
||||
|
||||
const QList<QAudioDeviceInfo>& input_devices();
|
||||
const QList<QAudioDeviceInfo>& output_devices();
|
||||
|
||||
signals:
|
||||
void ListsReady();
|
||||
|
||||
private:
|
||||
QList<QAudioDeviceInfo> input_devices_;
|
||||
QList<QAudioDeviceInfo> output_devices_;
|
||||
};
|
||||
|
||||
class AudioManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void CreateInstance();
|
||||
static void DestroyInstance();
|
||||
|
||||
static AudioManager* instance();
|
||||
|
||||
void RefreshDevices();
|
||||
|
||||
bool IsRefreshing();
|
||||
|
||||
const QList<QAudioDeviceInfo>& ListInputDevices();
|
||||
const QList<QAudioDeviceInfo>& ListOutputDevices();
|
||||
|
||||
signals:
|
||||
void DeviceListReady();
|
||||
|
||||
private:
|
||||
AudioManager();
|
||||
|
||||
QList<QAudioDeviceInfo> input_devices_;
|
||||
|
||||
QList<QAudioDeviceInfo> output_devices_;
|
||||
|
||||
static AudioManager* audio_;
|
||||
|
||||
std::unique_ptr<QAudioOutput> output_;
|
||||
|
||||
bool refreshing_devices_;
|
||||
|
||||
AudioRefreshDevicesThread refresh_thread_;
|
||||
|
||||
private slots:
|
||||
void RefreshThreadDone();
|
||||
|
||||
};
|
||||
|
||||
#endif // AUDIOMANAGER_H
|
||||
Reference in New Issue
Block a user