1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 05:41:56 -05:00

Multiple sources in preset. Interim state #1

This commit is contained in:
f4exb 2015-10-02 02:22:56 +02:00
parent fa79c55f41
commit 51914b4767
11 changed files with 63 additions and 239 deletions

View File

@ -108,7 +108,7 @@ set(sdrbase_SOURCES
sdrbase/settings/preferences.cpp
sdrbase/settings/preset.cpp
sdrbase/settings/settings.cpp
sdrbase/settings/mainsettings.cpp
sdrbase/util/message.cpp
sdrbase/util/messagequeue.cpp
@ -186,7 +186,7 @@ set(sdrbase_HEADERS
include-gpl/settings/preferences.h
include-gpl/settings/preset.h
include-gpl/settings/settings.h
include-gpl/settings/mainsettings.h
include/util/export.h
include/util/message.h

View File

@ -20,7 +20,7 @@
#include <QMainWindow>
#include <QTimer>
#include "settings/settings.h"
#include "settings/mainsettings.h"
#include "util/messagequeue.h"
#include "util/export.h"
@ -75,7 +75,7 @@ private:
MessageQueue m_inputMessageQueue;
Settings m_settings;
MainSettings m_settings;
SpectrumVis* m_spectrumVis;
FileSink *m_fileSink;

View File

@ -55,7 +55,7 @@ public:
bool handleMessage(const Message& message);
void updateSampleSourceDevices();
void fillSampleSourceSelector(QComboBox* comboBox);
int fillSampleSourceSelector(QComboBox* comboBox);
int selectSampleSource(int index);
int selectFirstSampleSource(const QString& sourceId);
int selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence);

View File

@ -15,6 +15,8 @@ public:
const QString& getSourceType() const { return m_sourceType; }
void setSourceDevice(const QString& value) { m_sourceDevice= value; }
const QString& getSourceDevice() const { return m_sourceDevice; }
void setSourceIndex(const int value) { m_sourceIndex = value; }
int getSourceIndex() const { return m_sourceIndex; }
void setAudioType(const QString& value) { m_audioType = value; }
const QString& getAudioType() const { return m_audioType; }
@ -24,6 +26,7 @@ public:
protected:
QString m_sourceType;
QString m_sourceDevice;
int m_sourceIndex;
QString m_audioType;
QString m_audioDevice;

View File

@ -61,15 +61,17 @@ public:
int getChannelCount() const { return m_channelConfigs.count(); }
const ChannelConfig& getChannelConfig(int index) const { return m_channelConfigs.at(index); }
/*
void setSourceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence, const QByteArray& config)
{
addOrUpdateSourceConfig(sourceId, sourceSerial, sourceSequence, config);
/*
m_sourceId = sourceId;
m_sourceSerial = sourceSerial;
m_sourceSequence = sourceSequence;
m_sourceConfig = config;
m_sourceConfig = config;*/
}
/*
const QString& getSourceId() const { return m_sourceId; }
const QString& getSourceSerial() const { return m_sourceSerial; }
const int getSourceSequence() const { return m_sourceSequence; }
@ -84,8 +86,6 @@ public:
const QString& sourceSerial,
int sourceSequence);
const QByteArray* findCurrentSourceConfig(QString& sourceId, QString& sourceSerial, int& sourceSequence) const;
protected:
// group and preset description
QString m_group;
@ -110,7 +110,6 @@ protected:
// sources and configurations
SourceConfigs m_sourceConfigs;
SourceConfigs::const_iterator m_currentSourceConfig;
// screen and dock layout
QByteArray m_layout;

View File

@ -1,32 +0,0 @@
#ifndef INCLUDE_SETTINGS_H
#define INCLUDE_SETTINGS_H
#include <QString>
#include "preferences.h"
#include "preset.h"
class Settings {
public:
Settings();
~Settings();
void load();
void save() const;
void resetToDefaults();
Preset* newPreset(const QString& group, const QString& description);
void deletePreset(const Preset* preset);
int getPresetCount() const { return m_presets.count(); }
const Preset* getPreset(int index) const { return m_presets[index]; }
Preset* getCurrent() { return &m_current; }
protected:
Preferences m_preferences;
Preset m_current;
typedef QList<Preset*> Presets;
Presets m_presets;
};
#endif // INCLUDE_SETTINGS_H

View File

@ -98,7 +98,7 @@ MainWindow::MainWindow(QWidget* parent) :
m_pluginManager->loadPlugins();
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
m_pluginManager->fillSampleSourceSelector(ui->sampleSource);
int nbSources = m_pluginManager->fillSampleSourceSelector(ui->sampleSource);
ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
@ -115,32 +115,23 @@ MainWindow::MainWindow(QWidget* parent) :
qDebug() << "MainWindow::MainWindow: select SampleSource from settings...";
Preset *currentPreset = m_settings.getCurrent();
int sampleSourceIndex = m_settings.getSourceIndex();
if (currentPreset != 0)
if(sampleSourceIndex >= nbSources)
{
QString sourceId, sourceSerial;
int sourceSequence;
const QByteArray *sourceConfig;
sampleSourceIndex = 0;
}
sourceConfig = currentPreset->findCurrentSourceConfig(sourceId, sourceSerial, sourceSequence);
if (sourceConfig != 0)
{
int sampleSourceIndex = m_pluginManager->selectSampleSourceBySerialOrSequence(sourceId, sourceSerial, sourceSequence); // select SampleSource from settings
if(sampleSourceIndex >= 0)
{
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
ui->sampleSource->setCurrentIndex(sampleSourceIndex);
ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
}
}
if (nbSources > 0)
{
//bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
ui->sampleSource->setCurrentIndex(sampleSourceIndex);
//ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
}
qDebug() << "MainWindow::MainWindow: load current preset settings...";
loadPresetSettings(m_settings.getCurrent());
loadPresetSettings(m_settings.getWorkingPreset());
qDebug() << "MainWindow::MainWindow: apply settings...";
@ -222,12 +213,9 @@ void MainWindow::loadSettings()
void MainWindow::loadPresetSettings(Preset* preset)
{
qDebug("MainWindow::loadPresetSettings: group: %s desc: %s Fcenter: %llu Hz",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()),
preset->getCenterFrequency());
ui->glSpectrumGUI->deserialize(preset->getSpectrumConfig());
qDebug("MainWindow::loadPresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
m_pluginManager->loadSettings(preset);
@ -239,20 +227,17 @@ void MainWindow::saveSettings()
{
qDebug() << "MainWindow::saveSettings";
savePresetSettings(m_settings.getCurrent());
savePresetSettings(m_settings.getWorkingPreset());
m_settings.save();
}
void MainWindow::savePresetSettings(Preset* preset)
{
qDebug("MainWindow::savePresetSettings: group: %s desc: %s Fcenter: %llu Hz",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()),
preset->getCenterFrequency());
qDebug("MainWindow::savePresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
preset->setSpectrumConfig(ui->glSpectrumGUI->serialize());
preset->clearChannels();
m_pluginManager->saveSettings(preset);
preset->setLayout(saveState());
@ -571,7 +556,10 @@ void MainWindow::on_action_Preferences_triggered()
void MainWindow::on_sampleSource_currentIndexChanged(int index)
{
savePresetSettings(m_settings.getWorkingPreset());
m_pluginManager->selectSampleSource(ui->sampleSource->currentIndex());
m_settings.setSourceIndex(ui->sampleSource->currentIndex());
m_pluginManager->loadSettings(m_settings.getWorkingPreset());
}
void MainWindow::on_action_About_triggered()

View File

@ -264,11 +264,13 @@ void PluginManager::updateSampleSourceDevices()
}
}
void PluginManager::fillSampleSourceSelector(QComboBox* comboBox)
int PluginManager::fillSampleSourceSelector(QComboBox* comboBox)
{
comboBox->clear();
for(int i = 0; i < m_sampleSourceDevices.count(); i++)
int i;
for(i = 0; i < m_sampleSourceDevices.count(); i++)
comboBox->addItem(m_sampleSourceDevices[i].m_displayName, i);
return i;
}
int PluginManager::selectSampleSource(int index)

View File

@ -21,6 +21,7 @@ QByteArray Preferences::serialize() const
s.writeString(2, m_sourceDevice);
s.writeString(3, m_audioType);
s.writeString(4, m_audioDevice);
s.writeS32(5, m_sourceIndex);
return s.final();
}
@ -38,6 +39,7 @@ bool Preferences::deserialize(const QByteArray& data)
d.readString(2, &m_sourceDevice);
d.readString(3, &m_audioType);
d.readString(4, &m_audioDevice);
d.readS32(5, &m_sourceIndex);
return true;
} else {
resetToDefaults();

View File

@ -19,12 +19,11 @@ void Preset::resetToDefaults()
m_channelConfigs.clear();
m_sourceId.clear();
m_sourceConfig.clear();
m_currentSourceConfig = m_sourceConfigs.end();
}
QByteArray Preset::serialize() const
{
qDebug("Preset::serialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qDebug("Preset::serialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group),
qPrintable(m_description),
m_centerFrequency);
@ -35,23 +34,9 @@ QByteArray Preset::serialize() const
s.writeString(2, m_description);
s.writeU64(3, m_centerFrequency);
s.writeBlob(4, m_layout);
s.writeBlob(5, m_spectrumConfig);
s.writeS32(20, m_sourceConfigs.size());
if ( m_currentSourceConfig == m_sourceConfigs.end())
{
s.writeBool(21, false); // no current source available
s.writeString(22, "");
s.writeS32(23, 0);
}
else
{
s.writeBool(21, true); // current source available
s.writeString(22, m_currentSourceConfig->m_sourceId);
s.writeS32(23, m_currentSourceConfig->m_sourceSequence);
}
for (int i = 0; i < m_sourceConfigs.size(); i++)
{
s.writeString(24 + i*4, m_sourceConfigs[i].m_sourceId);
@ -59,20 +44,17 @@ QByteArray Preset::serialize() const
s.writeS32(26 + i*4, m_sourceConfigs[i].m_sourceSequence);
s.writeBlob(27 + i*4, m_sourceConfigs[i].m_config);
qDebug("Preset::serialize: source: id: %ss, ser: %s, seq: %d",
qPrintable(m_sourceConfigs[i].m_sourceId),
qPrintable(m_sourceConfigs[i].m_sourceSerial),
m_sourceConfigs[i].m_sourceSequence);
if (i >= (200-23)/4) // full!
{
break;
}
}
s.writeS32(200, m_channelConfigs.size());
for(int i = 0; i < m_channelConfigs.size(); i++)
{
s.writeString(201 + i * 2, m_channelConfigs[i].m_channel);
s.writeBlob(202 + i * 2, m_channelConfigs[i].m_config);
}
return s.final();
}
@ -80,19 +62,18 @@ bool Preset::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
if (!d.isValid())
{
resetToDefaults();
return false;
}
if(d.getVersion() == 1) {
if (d.getVersion() == 1)
{
d.readString(1, &m_group, "default");
d.readString(2, &m_description, "no name");
d.readU64(3, &m_centerFrequency, 0);
d.readBlob(4, &m_layout);
d.readBlob(5, &m_spectrumConfig);
d.readString(6, &m_sourceId);
d.readBlob(7, &m_sourceConfig);
qDebug("Preset::deserialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group),
@ -102,54 +83,33 @@ bool Preset::deserialize(const QByteArray& data)
qint32 sourcesCount = 0;
d.readS32(20, &sourcesCount, 0);
if (sourcesCount >= (200-20)/4) // limit was hit!
if (sourcesCount >= (200-23)/4) // limit was hit!
{
sourcesCount = ((200-20)/4) - 1;
sourcesCount = ((200-23)/4) - 1;
}
bool hasCurrentConfig;
QString currentSourceId;
int currentSourceSequence;
m_currentSourceConfig = m_sourceConfigs.end();
d.readBool(21, &hasCurrentConfig, false);
d.readString(22, &currentSourceId, QString::null);
d.readS32(23, &currentSourceSequence);
for(int i = 0; i < sourcesCount; i++)
{
QString sourceId, sourceSerial;
int sourceSequence;
QByteArray sourceConfig;
d.readString(21 + i*4, &sourceId, "");
d.readString(22 + i*4, &sourceSerial, "");
d.readS32(23 + i*4, &sourceSequence, 0);
d.readBlob(24 + i*4, &sourceConfig);
d.readString(24 + i*4, &sourceId, "");
d.readString(25 + i*4, &sourceSerial, "");
d.readS32(26 + i*4, &sourceSequence, 0);
d.readBlob(27 + i*4, &sourceConfig);
m_sourceConfigs.append(SourceConfig(sourceId, sourceSerial, sourceSequence, sourceConfig));
if (hasCurrentConfig && (sourceId == currentSourceId) && (sourceSequence == currentSourceSequence))
if (!sourceId.isEmpty())
{
m_currentSourceConfig = m_sourceConfigs.end();
m_currentSourceConfig--;
qDebug("Preset::deserialize: source: id: %ss, ser: %s, seq: %d",
qPrintable(sourceId),
qPrintable(sourceSerial),
sourceSequence);
m_sourceConfigs.append(SourceConfig(sourceId, sourceSerial, sourceSequence, sourceConfig));
}
}
qint32 channelCount = 0;
d.readS32(200, &channelCount, 0);
for(int i = 0; i < channelCount; i++)
{
QString channel;
QByteArray config;
d.readString(201 + i * 2, &channel, "unknown-channel");
d.readBlob(202 + i * 2, &config);
m_channelConfigs.append(ChannelConfig(channel, config));
}
return true;
}
else
@ -190,13 +150,10 @@ void Preset::addOrUpdateSourceConfig(const QString& sourceId,
if (it == m_sourceConfigs.end())
{
m_sourceConfigs.append(SourceConfig(sourceId, sourceSerial, sourceSequence, config));
m_currentSourceConfig = m_sourceConfigs.end();
--m_currentSourceConfig;
}
else
{
it->m_config = config;
m_currentSourceConfig = it;
}
}
@ -243,41 +200,22 @@ const QByteArray* Preset::findBestSourceConfig(const QString& sourceId,
if (itMatchSequence != m_sourceConfigs.end()) // match sequence ?
{
qDebug("Preset::findBestSourceConfig: sequence matched: id: %s seq: %d", qPrintable(it->m_sourceId), it->m_sourceSequence);
m_currentSourceConfig = itMatchSequence;
return &(itMatchSequence->m_config);
}
else if (itFirstOfKind != m_sourceConfigs.end()) // match source type ?
{
qDebug("Preset::findBestSourceConfig: first of kind matched: id: %s", qPrintable(it->m_sourceId));
m_currentSourceConfig = itFirstOfKind;
return &(itFirstOfKind->m_config);
}
else // definitely not found !
{
qDebug("Preset::findBestSourceConfig: no match");
m_currentSourceConfig = m_sourceConfigs.end();
return 0;
}
}
else // exact match
{
qDebug("Preset::findBestSourceConfig: serial matched (exact): id: %s ser: %d", qPrintable(it->m_sourceId), qPrintable(it->m_sourceSerial));
m_currentSourceConfig = it;
qDebug("Preset::findBestSourceConfig: serial matched (exact): id: %s ser: %s", qPrintable(it->m_sourceId), qPrintable(it->m_sourceSerial));
return &(it->m_config);
}
}
const QByteArray* Preset::findCurrentSourceConfig(QString& sourceId, QString& sourceSerial, int& sourceSequence) const
{
if (m_currentSourceConfig == m_sourceConfigs.end())
{
return 0;
}
else
{
sourceId = m_currentSourceConfig->m_sourceId;
sourceSerial = m_currentSourceConfig->m_sourceSerial;
sourceSequence = m_currentSourceConfig->m_sourceSequence;
return &m_currentSourceConfig->m_config;
}
}

View File

@ -1,76 +0,0 @@
#include <QSettings>
#include <QStringList>
#include "settings/settings.h"
Settings::Settings()
{
resetToDefaults();
}
Settings::~Settings()
{
for(int i = 0; i < m_presets.count(); ++i)
delete m_presets[i];
}
void Settings::load()
{
QSettings s;
m_preferences.deserialize(qUncompress(QByteArray::fromBase64(s.value("preferences").toByteArray())));
m_current.deserialize(qUncompress(QByteArray::fromBase64(s.value("current").toByteArray())));
QStringList groups = s.childGroups();
for(int i = 0; i < groups.size(); ++i) {
if(groups[i].startsWith("preset")) {
s.beginGroup(groups[i]);
Preset* preset = new Preset;
if(preset->deserialize(qUncompress(QByteArray::fromBase64(s.value("data").toByteArray()))))
m_presets.append(preset);
else delete preset;
s.endGroup();
}
}
}
void Settings::save() const
{
QSettings s;
s.setValue("preferences", qCompress(m_preferences.serialize()).toBase64());
s.setValue("current", qCompress(m_current.serialize()).toBase64());
QStringList groups = s.childGroups();
for(int i = 0; i < groups.size(); ++i) {
if(groups[i].startsWith("preset"))
s.remove(groups[i]);
}
for(int i = 0; i < m_presets.count(); ++i) {
QString group = QString("preset-%1").arg(i + 1);
s.beginGroup(group);
s.setValue("data", qCompress(m_presets[i]->serialize()).toBase64());
s.endGroup();
}
}
void Settings::resetToDefaults()
{
m_preferences.resetToDefaults();
m_current.resetToDefaults();
}
Preset* Settings::newPreset(const QString& group, const QString& description)
{
Preset* preset = new Preset();
preset->setGroup(group);
preset->setDescription(description);
m_presets.append(preset);
return preset;
}
void Settings::deletePreset(const Preset* preset)
{
m_presets.removeAll((Preset*)preset);
delete (Preset*)preset;
}