Web API: /sdrangel/audio (PATCH) implementation

pull/127/head
f4exb 2017-11-24 17:12:53 +01:00
rodzic dad604dcf8
commit 72615b188e
18 zmienionych plików z 2059 dodań i 1688 usunięć

Wyświetl plik

@ -6,6 +6,8 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = serialdv
SUBDIRS += httpserver
SUBDIRS += logging
@ -59,5 +61,4 @@ SUBDIRS += plugins/channeltx/modwfm
SUBDIRS += plugins/channeltx/udpsink
# Main app must be last
CONFIG += ordered
SUBDIRS += app

Wyświetl plik

@ -1,67 +1,84 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 F4EXB //
// written by Edouard Griffiths //
// //
// 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 as version 3 of the License, or //
// //
// 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 V3 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 "audio/audiodeviceinfo.h"
#include "util/simpleserializer.h"
AudioDeviceInfo::AudioDeviceInfo() :
m_inputDeviceIndex(-1), // default device
m_outputDeviceIndex(-1), // default device
m_inputVolume(1.0f)
{
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
}
void AudioDeviceInfo::resetToDefaults()
{
m_inputDeviceIndex = -1;
m_outputDeviceIndex = -1;
m_inputVolume = 1.0f;
}
QByteArray AudioDeviceInfo::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_inputDeviceIndex);
s.writeS32(2, m_outputDeviceIndex);
s.writeFloat(3, m_inputVolume);
return s.final();
}
bool AudioDeviceInfo::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
resetToDefaults();
return false;
}
if(d.getVersion() == 1)
{
d.readS32(1, &m_inputDeviceIndex, -1);
d.readS32(2, &m_outputDeviceIndex, -1);
d.readFloat(3, &m_inputVolume, 1.0f);
return true;
}
else
{
resetToDefaults();
return false;
}
}
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 F4EXB //
// written by Edouard Griffiths //
// //
// 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 as version 3 of the License, or //
// //
// 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 V3 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 "audio/audiodeviceinfo.h"
#include "util/simpleserializer.h"
AudioDeviceInfo::AudioDeviceInfo() :
m_inputDeviceIndex(-1), // default device
m_outputDeviceIndex(-1), // default device
m_inputVolume(1.0f)
{
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
}
void AudioDeviceInfo::resetToDefaults()
{
m_inputDeviceIndex = -1;
m_outputDeviceIndex = -1;
m_inputVolume = 1.0f;
}
QByteArray AudioDeviceInfo::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_inputDeviceIndex);
s.writeS32(2, m_outputDeviceIndex);
s.writeFloat(3, m_inputVolume);
return s.final();
}
bool AudioDeviceInfo::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
resetToDefaults();
return false;
}
if(d.getVersion() == 1)
{
d.readS32(1, &m_inputDeviceIndex, -1);
d.readS32(2, &m_outputDeviceIndex, -1);
d.readFloat(3, &m_inputVolume, 1.0f);
return true;
}
else
{
resetToDefaults();
return false;
}
}
void AudioDeviceInfo::setInputDeviceIndex(int inputDeviceIndex)
{
int nbDevices = m_inputDevicesInfo.size();
m_inputDeviceIndex = inputDeviceIndex < -1 ? -1 : inputDeviceIndex >= nbDevices ? nbDevices-1 : inputDeviceIndex;
}
void AudioDeviceInfo::setOutputDeviceIndex(int outputDeviceIndex)
{
int nbDevices = m_outputDevicesInfo.size();
m_outputDeviceIndex = outputDeviceIndex < -1 ? -1 : outputDeviceIndex >= nbDevices ? nbDevices-1 : outputDeviceIndex;
}
void AudioDeviceInfo::setInputVolume(float inputVolume)
{
m_inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume;
}

Wyświetl plik

@ -1,52 +1,55 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 F4EXB //
// written by Edouard Griffiths //
// //
// 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 as version 3 of the License, or //
// //
// 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 V3 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 INCLUDE_AUDIODEVICEINFO_H
#define INCLUDE_AUDIODEVICEINFO_H
#include <QStringList>
#include <QList>
#include <QAudioDeviceInfo>
#include "util/export.h"
class SDRANGEL_API AudioDeviceInfo {
public:
AudioDeviceInfo();
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
int getInputDeviceIndex() const { return m_inputDeviceIndex; }
int getOutputDeviceIndex() const { return m_outputDeviceIndex; }
float getInputVolume() const { return m_inputVolume; }
private:
QList<QAudioDeviceInfo> m_inputDevicesInfo;
QList<QAudioDeviceInfo> m_outputDevicesInfo;
int m_inputDeviceIndex;
int m_outputDeviceIndex;
float m_inputVolume;
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
friend class AudioDialog;
friend class MainSettings;
};
#endif // INCLUDE_AUDIODEVICEINFO_H
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 F4EXB //
// written by Edouard Griffiths //
// //
// 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 as version 3 of the License, or //
// //
// 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 V3 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 INCLUDE_AUDIODEVICEINFO_H
#define INCLUDE_AUDIODEVICEINFO_H
#include <QStringList>
#include <QList>
#include <QAudioDeviceInfo>
#include "util/export.h"
class SDRANGEL_API AudioDeviceInfo {
public:
AudioDeviceInfo();
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
int getInputDeviceIndex() const { return m_inputDeviceIndex; }
int getOutputDeviceIndex() const { return m_outputDeviceIndex; }
float getInputVolume() const { return m_inputVolume; }
void setInputDeviceIndex(int inputDeviceIndex);
void setOutputDeviceIndex(int inputDeviceIndex);
void setInputVolume(float inputVolume);
private:
QList<QAudioDeviceInfo> m_inputDevicesInfo;
QList<QAudioDeviceInfo> m_outputDevicesInfo;
int m_inputDeviceIndex;
int m_outputDeviceIndex;
float m_inputVolume;
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
friend class AudioDialog;
friend class MainSettings;
};
#endif // INCLUDE_AUDIODEVICEINFO_H

Wyświetl plik

@ -28,6 +28,7 @@ namespace Swagger
class SWGInstanceChannelsResponse;
class SWGLoggingInfo;
class SWGAudioDevices;
class SWGAudioDevicesSelect;
class SWGErrorResponse;
}
@ -92,6 +93,15 @@ public:
Swagger::SWGErrorResponse& error __attribute__((unused)))
{ return 501; }
/**
* Handler of /sdrangel/audio (PATCH) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int instanceAudioPatch(
Swagger::SWGAudioDevicesSelect& response __attribute__((unused)),
Swagger::SWGErrorResponse& error __attribute__((unused)))
{ return 501; }
static QString instanceSummaryURL;
static QString instanceDevicesURL;
static QString instanceChannelsURL;

Wyświetl plik

@ -54,165 +54,16 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
{
QByteArray path=request.getPath();
if (path == WebAPIAdapterInterface::instanceSummaryURL)
{
if (request.getMethod() == "GET")
{
Swagger::SWGInstanceSummaryResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
int status = m_adapter->instanceSummary(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
else if (path == WebAPIAdapterInterface::instanceDevicesURL)
{
Swagger::SWGInstanceDevicesResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1");
int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
else if (path == WebAPIAdapterInterface::instanceChannelsURL)
{
Swagger::SWGInstanceChannelsResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1");
int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
else if (path == WebAPIAdapterInterface::instanceLoggingURL)
{
Swagger::SWGLoggingInfo normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
int status = m_adapter->instanceLoggingGet(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else if (request.getMethod() == "PUT")
{
try
{
QString jsonStr = request.getBody();
QByteArray jsonBytes(jsonStr.toStdString().c_str());
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error);
if (error.error == QJsonParseError::NoError)
{
normalResponse.fromJson(jsonStr);
int status = m_adapter->instanceLoggingPut(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
QString errorMsg = QString("Input JSON error: ") + error.errorString();
errorResponse.init();
*errorResponse.getMessage() = errorMsg;
response.setStatus(400, errorMsg.toUtf8());
response.write(errorResponse.asJson().toUtf8());
}
}
catch (const std::exception& ex)
{
QString errorMsg = QString("Error parsing request: ") + ex.what();
errorResponse.init();
*errorResponse.getMessage() = errorMsg;
response.setStatus(500, errorMsg.toUtf8());
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
else if (path == WebAPIAdapterInterface::instanceAudioURL)
{
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
Swagger::SWGAudioDevices normalResponse;
int status = m_adapter->instanceAudioGet(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else if (request.getMethod() == "PATCH")
{
Swagger::SWGAudioDevicesSelect normalResponse;
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
if (path == WebAPIAdapterInterface::instanceSummaryURL) {
instanceSummaryService(request, response);
} else if (path == WebAPIAdapterInterface::instanceDevicesURL) {
instanceDevicesService(request, response);
} else if (path == WebAPIAdapterInterface::instanceChannelsURL) {
instanceChannelsService(request, response);
} else if (path == WebAPIAdapterInterface::instanceLoggingURL) {
instanceLoggingService(request, response);
} else if (path == WebAPIAdapterInterface::instanceAudioURL) {
instanceAudioService(request, response);
}
else
{
@ -223,7 +74,197 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
QByteArray path = "/index.html";
m_staticFileController->service(path, response);
//response.setStatus(404,"Not found");
}
}
}
void WebAPIRequestMapper::instanceSummaryService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
if (request.getMethod() == "GET")
{
Swagger::SWGInstanceSummaryResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
int status = m_adapter->instanceSummary(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
void WebAPIRequestMapper::instanceDevicesService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
Swagger::SWGInstanceDevicesResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1");
int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
void WebAPIRequestMapper::instanceChannelsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
Swagger::SWGInstanceChannelsResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1");
int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
void WebAPIRequestMapper::instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
Swagger::SWGLoggingInfo normalResponse;
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
int status = m_adapter->instanceLoggingGet(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else if (request.getMethod() == "PUT")
{
QString jsonStr = request.getBody();
if (parseJsonBody(jsonStr, response))
{
normalResponse.fromJson(jsonStr);
int status = m_adapter->instanceLoggingPut(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
void WebAPIRequestMapper::instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "GET")
{
Swagger::SWGAudioDevices normalResponse;
int status = m_adapter->instanceAudioGet(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else if (request.getMethod() == "PATCH")
{
Swagger::SWGAudioDevicesSelect normalResponse;
QString jsonStr = request.getBody();
if (parseJsonBody(jsonStr, response))
{
normalResponse.fromJson(jsonStr);
int status = m_adapter->instanceAudioPatch(normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response)
{
Swagger::SWGErrorResponse errorResponse;
try
{
QByteArray jsonBytes(jsonStr.toStdString().c_str());
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error);
if (error.error != QJsonParseError::NoError)
{
QString errorMsg = QString("Input JSON error: ") + error.errorString();
errorResponse.init();
*errorResponse.getMessage() = errorMsg;
response.setStatus(400, errorMsg.toUtf8());
response.write(errorResponse.asJson().toUtf8());
}
return (error.error == QJsonParseError::NoError);
}
catch (const std::exception& ex)
{
QString errorMsg = QString("Error parsing request: ") + ex.what();
errorResponse.init();
*errorResponse.getMessage() = errorMsg;
response.setStatus(500, errorMsg.toUtf8());
response.write(errorResponse.asJson().toUtf8());
return false;
}
}

Wyświetl plik

@ -19,6 +19,8 @@
#ifndef SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_
#define SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_
#include <QJsonParseError>
#include "httprequesthandler.h"
#include "httprequest.h"
#include "httpresponse.h"
@ -36,6 +38,14 @@ public:
private:
WebAPIAdapterInterface *m_adapter;
qtwebapp::StaticFileController *m_staticFileController;
void instanceSummaryService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceDevicesService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceChannelsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response);
};
#endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */

Wyświetl plik

@ -27,6 +27,7 @@
#include "device/deviceenumerator.h"
#include "dsp/devicesamplesource.h"
#include "dsp/devicesamplesink.h"
#include "dsp/dspengine.h"
#include "plugin/pluginapi.h"
#include "plugin/pluginmanager.h"
#include "channel/channelsinkapi.h"
@ -37,6 +38,7 @@
#include "SWGInstanceChannelsResponse.h"
#include "SWGDeviceListItem.h"
#include "SWGAudioDevices.h"
#include "SWGAudioDevicesSelect.h"
#include "SWGErrorResponse.h"
#include "webapiadaptergui.h"
@ -264,24 +266,58 @@ int WebAPIAdapterGUI::instanceAudioGet(
response.setInputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex());
response.setNbOutputDevices(nbOutputDevices);
response.setOutputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex());
QList<QString*> *inputDeviceNames = response.getInputDevices();
QList<QString*> *outputDeviceNames = response.getOutputDevices();
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume());
QList<Swagger::SWGAudioDevice*> *inputDevices = response.getInputDevices();
QList<Swagger::SWGAudioDevice*> *outputDevices = response.getOutputDevices();
for (int i = 0; i < nbInputDevices; i++)
{
inputDeviceNames->append(new QString());
*inputDeviceNames->back() = audioInputDevices[i].deviceName();
inputDevices->append(new Swagger::SWGAudioDevice);
*inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
}
for (int i = 0; i < nbOutputDevices; i++)
{
outputDeviceNames->append(new QString());
*outputDeviceNames->back() = audioOutputDevices[i].deviceName();
outputDevices->append(new Swagger::SWGAudioDevice);
*outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
}
return 200;
}
int WebAPIAdapterGUI::instanceAudioPatch(
Swagger::SWGAudioDevicesSelect& response,
Swagger::SWGErrorResponse& error)
{
// response input is the query actually
float inputVolume = response.getInputVolume();
int inputIndex = response.getInputIndex();
int outputIndex = response.getOutputIndex();
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices();
int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size();
inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume;
inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex;
outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex;
m_mainWindow.m_audioDeviceInfo.setInputVolume(inputVolume);
m_mainWindow.m_audioDeviceInfo.setInputDeviceIndex(inputIndex);
m_mainWindow.m_audioDeviceInfo.setOutputDeviceIndex(outputIndex);
m_mainWindow.m_dspEngine->setAudioInputVolume(inputVolume);
m_mainWindow.m_dspEngine->setAudioInputDeviceIndex(inputIndex);
m_mainWindow.m_dspEngine->setAudioOutputDeviceIndex(outputIndex);
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume());
response.setInputIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex());
response.setOutputIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex());
return 200;
}
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
{
if (msgTypeString == "debug") {

Wyświetl plik

@ -57,6 +57,10 @@ public:
Swagger::SWGAudioDevices& response,
Swagger::SWGErrorResponse& error);
virtual int instanceAudioPatch(
Swagger::SWGAudioDevicesSelect& response,
Swagger::SWGErrorResponse& error);
private:
MainWindow& m_mainWindow;

Wyświetl plik

@ -633,11 +633,16 @@ definitions:
AudioDevices:
description: "List of audio devices available in the system"
required:
- inputVolume
- nbInputDevices
- inputDeviceSelectedIndex
- nbOutputDevices
- outputDeviceSelectedIndex
properties:
inputVolume:
description: "Audio input volume [0.0..1.0]"
type: number
format: float
nbInputDevices:
description: "Number of input audio devices"
type: integer
@ -645,10 +650,10 @@ definitions:
description: "Index of selected input audio devices (-1 if default)"
type: integer
inputDevices:
description: "Names of input devices"
description: "List of input devices"
type: array
items:
type: string
$ref: "#/definitions/AudioDevice"
nbOutputDevices:
description: "Number of output audio devices"
type: integer
@ -656,17 +661,31 @@ definitions:
description: "Index of selected output audio devices (-1 if default)"
type: integer
outputDevices:
description: "Names of output devices"
description: "List of output devices"
type: array
items:
type: string
$ref: "#/definitions/AudioDevice"
AudioDevice:
description: "Audio device"
properties:
name:
description: "Displayable name of the device"
type: string
AudioDevicesSelect:
description: "Audio devices selected"
required:
- inputVolume
- inputIndex
- outputIndex
properties:
input:
inputVolume:
description: "Audio input volume [0.0..1.0]"
type: number
format: float
inputIndex:
description: "Index of the audio input device (-1 for default)"
type: integer
output:
outputIndex:
description: "Index of the audio output device (-1 for default)"
type: integer
LocationInformation:

Wyświetl plik

@ -0,0 +1,95 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
#include "SWGAudioDevice.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGAudioDevice::SWGAudioDevice(QString* json) {
init();
this->fromJson(*json);
}
SWGAudioDevice::SWGAudioDevice() {
init();
}
SWGAudioDevice::~SWGAudioDevice() {
this->cleanup();
}
void
SWGAudioDevice::init() {
name = new QString("");
}
void
SWGAudioDevice::cleanup() {
if(name != nullptr) {
delete name;
}
}
SWGAudioDevice*
SWGAudioDevice::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGAudioDevice::fromJsonObject(QJsonObject &pJson) {
::Swagger::setValue(&name, pJson["name"], "QString", "QString");
}
QString
SWGAudioDevice::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGAudioDevice::asJsonObject() {
QJsonObject* obj = new QJsonObject();
toJsonValue(QString("name"), name, obj, QString("QString"));
return obj;
}
QString*
SWGAudioDevice::getName() {
return name;
}
void
SWGAudioDevice::setName(QString* name) {
this->name = name;
}
}

Wyświetl plik

@ -0,0 +1,55 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/*
* SWGAudioDevice.h
*
* Audio device
*/
#ifndef SWGAudioDevice_H_
#define SWGAudioDevice_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGAudioDevice: public SWGObject {
public:
SWGAudioDevice();
SWGAudioDevice(QString* json);
virtual ~SWGAudioDevice();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGAudioDevice* fromJson(QString &jsonString);
QString* getName();
void setName(QString* name);
private:
QString* name;
};
}
#endif /* SWGAudioDevice_H_ */

Wyświetl plik

@ -37,12 +37,13 @@ SWGAudioDevices::~SWGAudioDevices() {
void
SWGAudioDevices::init() {
input_volume = 0.0f;
nb_input_devices = 0;
input_device_selected_index = 0;
input_devices = new QList<QString*>();
input_devices = new QList<SWGAudioDevice*>();
nb_output_devices = 0;
output_device_selected_index = 0;
output_devices = new QList<QString*>();
output_devices = new QList<SWGAudioDevice*>();
}
void
@ -50,9 +51,10 @@ SWGAudioDevices::cleanup() {
if(input_devices != nullptr) {
QList<QString*>* arr = input_devices;
foreach(QString* o, *arr) {
QList<SWGAudioDevice*>* arr = input_devices;
foreach(SWGAudioDevice* o, *arr) {
delete o;
}
delete input_devices;
@ -61,8 +63,8 @@ SWGAudioDevices::cleanup() {
if(output_devices != nullptr) {
QList<QString*>* arr = output_devices;
foreach(QString* o, *arr) {
QList<SWGAudioDevice*>* arr = output_devices;
foreach(SWGAudioDevice* o, *arr) {
delete o;
}
delete output_devices;
@ -80,15 +82,16 @@ SWGAudioDevices::fromJson(QString &json) {
void
SWGAudioDevices::fromJsonObject(QJsonObject &pJson) {
::Swagger::setValue(&input_volume, pJson["inputVolume"], "float", "");
::Swagger::setValue(&nb_input_devices, pJson["nbInputDevices"], "qint32", "");
::Swagger::setValue(&input_device_selected_index, pJson["inputDeviceSelectedIndex"], "qint32", "");
::Swagger::setValue(&input_devices, pJson["inputDevices"], "QList", "QString");
::Swagger::setValue(&input_devices, pJson["inputDevices"], "QList", "SWGAudioDevice");
::Swagger::setValue(&nb_output_devices, pJson["nbOutputDevices"], "qint32", "");
::Swagger::setValue(&output_device_selected_index, pJson["outputDeviceSelectedIndex"], "qint32", "");
::Swagger::setValue(&output_devices, pJson["outputDevices"], "QList", "QString");
::Swagger::setValue(&output_devices, pJson["outputDevices"], "QList", "SWGAudioDevice");
}
@ -106,12 +109,14 @@ QJsonObject*
SWGAudioDevices::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("inputVolume", QJsonValue(input_volume));
obj->insert("nbInputDevices", QJsonValue(nb_input_devices));
obj->insert("inputDeviceSelectedIndex", QJsonValue(input_device_selected_index));
QJsonArray input_devicesJsonArray;
toJsonArray((QList<void*>*)input_devices, &input_devicesJsonArray, "input_devices", "QString");
toJsonArray((QList<void*>*)input_devices, &input_devicesJsonArray, "input_devices", "SWGAudioDevice");
obj->insert("inputDevices", input_devicesJsonArray);
obj->insert("nbOutputDevices", QJsonValue(nb_output_devices));
@ -119,12 +124,21 @@ SWGAudioDevices::asJsonObject() {
obj->insert("outputDeviceSelectedIndex", QJsonValue(output_device_selected_index));
QJsonArray output_devicesJsonArray;
toJsonArray((QList<void*>*)output_devices, &output_devicesJsonArray, "output_devices", "QString");
toJsonArray((QList<void*>*)output_devices, &output_devicesJsonArray, "output_devices", "SWGAudioDevice");
obj->insert("outputDevices", output_devicesJsonArray);
return obj;
}
float
SWGAudioDevices::getInputVolume() {
return input_volume;
}
void
SWGAudioDevices::setInputVolume(float input_volume) {
this->input_volume = input_volume;
}
qint32
SWGAudioDevices::getNbInputDevices() {
return nb_input_devices;
@ -143,12 +157,12 @@ SWGAudioDevices::setInputDeviceSelectedIndex(qint32 input_device_selected_index)
this->input_device_selected_index = input_device_selected_index;
}
QList<QString*>*
QList<SWGAudioDevice*>*
SWGAudioDevices::getInputDevices() {
return input_devices;
}
void
SWGAudioDevices::setInputDevices(QList<QString*>* input_devices) {
SWGAudioDevices::setInputDevices(QList<SWGAudioDevice*>* input_devices) {
this->input_devices = input_devices;
}
@ -170,12 +184,12 @@ SWGAudioDevices::setOutputDeviceSelectedIndex(qint32 output_device_selected_inde
this->output_device_selected_index = output_device_selected_index;
}
QList<QString*>*
QList<SWGAudioDevice*>*
SWGAudioDevices::getOutputDevices() {
return output_devices;
}
void
SWGAudioDevices::setOutputDevices(QList<QString*>* output_devices) {
SWGAudioDevices::setOutputDevices(QList<SWGAudioDevice*>* output_devices) {
this->output_devices = output_devices;
}

Wyświetl plik

@ -22,8 +22,8 @@
#include <QJsonObject>
#include "SWGAudioDevice.h"
#include <QList>
#include <QString>
#include "SWGObject.h"
@ -43,14 +43,17 @@ public:
void fromJsonObject(QJsonObject &json);
SWGAudioDevices* fromJson(QString &jsonString);
float getInputVolume();
void setInputVolume(float input_volume);
qint32 getNbInputDevices();
void setNbInputDevices(qint32 nb_input_devices);
qint32 getInputDeviceSelectedIndex();
void setInputDeviceSelectedIndex(qint32 input_device_selected_index);
QList<QString*>* getInputDevices();
void setInputDevices(QList<QString*>* input_devices);
QList<SWGAudioDevice*>* getInputDevices();
void setInputDevices(QList<SWGAudioDevice*>* input_devices);
qint32 getNbOutputDevices();
void setNbOutputDevices(qint32 nb_output_devices);
@ -58,17 +61,18 @@ public:
qint32 getOutputDeviceSelectedIndex();
void setOutputDeviceSelectedIndex(qint32 output_device_selected_index);
QList<QString*>* getOutputDevices();
void setOutputDevices(QList<QString*>* output_devices);
QList<SWGAudioDevice*>* getOutputDevices();
void setOutputDevices(QList<SWGAudioDevice*>* output_devices);
private:
float input_volume;
qint32 nb_input_devices;
qint32 input_device_selected_index;
QList<QString*>* input_devices;
QList<SWGAudioDevice*>* input_devices;
qint32 nb_output_devices;
qint32 output_device_selected_index;
QList<QString*>* output_devices;
QList<SWGAudioDevice*>* output_devices;
};
}

Wyświetl plik

@ -37,14 +37,16 @@ SWGAudioDevicesSelect::~SWGAudioDevicesSelect() {
void
SWGAudioDevicesSelect::init() {
input = 0;
output = 0;
input_volume = 0.0f;
input_index = 0;
output_index = 0;
}
void
SWGAudioDevicesSelect::cleanup() {
}
SWGAudioDevicesSelect*
@ -58,8 +60,9 @@ SWGAudioDevicesSelect::fromJson(QString &json) {
void
SWGAudioDevicesSelect::fromJsonObject(QJsonObject &pJson) {
::Swagger::setValue(&input, pJson["input"], "qint32", "");
::Swagger::setValue(&output, pJson["output"], "qint32", "");
::Swagger::setValue(&input_volume, pJson["inputVolume"], "float", "");
::Swagger::setValue(&input_index, pJson["inputIndex"], "qint32", "");
::Swagger::setValue(&output_index, pJson["outputIndex"], "qint32", "");
}
QString
@ -76,29 +79,40 @@ QJsonObject*
SWGAudioDevicesSelect::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("input", QJsonValue(input));
obj->insert("inputVolume", QJsonValue(input_volume));
obj->insert("output", QJsonValue(output));
obj->insert("inputIndex", QJsonValue(input_index));
obj->insert("outputIndex", QJsonValue(output_index));
return obj;
}
qint32
SWGAudioDevicesSelect::getInput() {
return input;
float
SWGAudioDevicesSelect::getInputVolume() {
return input_volume;
}
void
SWGAudioDevicesSelect::setInput(qint32 input) {
this->input = input;
SWGAudioDevicesSelect::setInputVolume(float input_volume) {
this->input_volume = input_volume;
}
qint32
SWGAudioDevicesSelect::getOutput() {
return output;
SWGAudioDevicesSelect::getInputIndex() {
return input_index;
}
void
SWGAudioDevicesSelect::setOutput(qint32 output) {
this->output = output;
SWGAudioDevicesSelect::setInputIndex(qint32 input_index) {
this->input_index = input_index;
}
qint32
SWGAudioDevicesSelect::getOutputIndex() {
return output_index;
}
void
SWGAudioDevicesSelect::setOutputIndex(qint32 output_index) {
this->output_index = output_index;
}

Wyświetl plik

@ -41,16 +41,20 @@ public:
void fromJsonObject(QJsonObject &json);
SWGAudioDevicesSelect* fromJson(QString &jsonString);
qint32 getInput();
void setInput(qint32 input);
float getInputVolume();
void setInputVolume(float input_volume);
qint32 getOutput();
void setOutput(qint32 output);
qint32 getInputIndex();
void setInputIndex(qint32 input_index);
qint32 getOutputIndex();
void setOutputIndex(qint32 output_index);
private:
qint32 input;
qint32 output;
float input_volume;
qint32 input_index;
qint32 output_index;
};
}

Wyświetl plik

@ -14,6 +14,7 @@
#define ModelFactory_H_
#include "SWGAudioDevice.h"
#include "SWGAudioDevices.h"
#include "SWGAudioDevicesSelect.h"
#include "SWGChannel.h"
@ -39,6 +40,9 @@
namespace Swagger {
inline void* create(QString type) {
if(QString("SWGAudioDevice").compare(type) == 0) {
return new SWGAudioDevice();
}
if(QString("SWGAudioDevices").compare(type) == 0) {
return new SWGAudioDevices();
}