1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 13:21:50 -05:00

Multiple sources for the same preset. Working more or less

This commit is contained in:
f4exb 2015-10-02 04:04:38 +02:00
parent 51914b4767
commit 83d6d9d190
8 changed files with 200 additions and 46 deletions

View File

@ -103,7 +103,7 @@ private:
PluginManager* m_pluginManager; PluginManager* m_pluginManager;
void loadSettings(); void loadSettings();
void loadPresetSettings(Preset* preset); void loadPresetSettings(const Preset* preset);
void savePresetSettings(Preset* preset); void savePresetSettings(Preset* preset);
void saveSettings(); void saveSettings();

View File

@ -47,8 +47,10 @@ public:
void registerSampleSource(const QString& sourceName, PluginInterface* plugin); void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
void loadSettings(Preset* preset); void loadSettings(const Preset* preset);
void loadSourceSettings(const Preset* preset);
void saveSettings(Preset* preset); void saveSettings(Preset* preset);
void saveSourceSettings(Preset* preset);
void freeAll(); void freeAll();

View File

@ -0,0 +1,34 @@
#ifndef INCLUDE_SETTINGS_H
#define INCLUDE_SETTINGS_H
#include <QString>
#include "preferences.h"
#include "preset.h"
class MainSettings {
public:
MainSettings();
~MainSettings();
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* getWorkingPreset() { return &m_workingPreset; }
int getSourceIndex() const { return m_preferences.getSourceIndex(); }
void setSourceIndex(int value) { m_preferences.setSourceIndex(value); }
protected:
Preferences m_preferences;
Preset m_workingPreset;
typedef QList<Preset*> Presets;
Presets m_presets;
};
#endif // INCLUDE_SETTINGS_H

View File

@ -64,19 +64,8 @@ public:
void setSourceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence, const QByteArray& config) void setSourceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence, const QByteArray& config)
{ {
addOrUpdateSourceConfig(sourceId, sourceSerial, sourceSequence, config); addOrUpdateSourceConfig(sourceId, sourceSerial, sourceSequence, config);
/*
m_sourceId = sourceId;
m_sourceSerial = sourceSerial;
m_sourceSequence = sourceSequence;
m_sourceConfig = config;*/
} }
/*
const QString& getSourceId() const { return m_sourceId; }
const QString& getSourceSerial() const { return m_sourceSerial; }
const int getSourceSequence() const { return m_sourceSequence; }
const QByteArray& getSourceConfig() const { return m_sourceConfig; }*/
void addOrUpdateSourceConfig(const QString& sourceId, void addOrUpdateSourceConfig(const QString& sourceId,
const QString& sourceSerial, const QString& sourceSerial,
int sourceSequence, int sourceSequence,
@ -84,7 +73,7 @@ public:
const QByteArray* findBestSourceConfig(const QString& sourceId, const QByteArray* findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial, const QString& sourceSerial,
int sourceSequence); int sourceSequence) const;
protected: protected:
// group and preset description // group and preset description

View File

@ -124,9 +124,10 @@ MainWindow::MainWindow(QWidget* parent) :
if (nbSources > 0) if (nbSources > 0)
{ {
//bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true); m_pluginManager->selectSampleSource(sampleSourceIndex);
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
ui->sampleSource->setCurrentIndex(sampleSourceIndex); ui->sampleSource->setCurrentIndex(sampleSourceIndex);
//ui->sampleSource->blockSignals(sampleSourceSignalsBlocked); ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
} }
qDebug() << "MainWindow::MainWindow: load current preset settings..."; qDebug() << "MainWindow::MainWindow: load current preset settings...";
@ -211,12 +212,13 @@ void MainWindow::loadSettings()
} }
} }
void MainWindow::loadPresetSettings(Preset* preset) void MainWindow::loadPresetSettings(const Preset* preset)
{ {
qDebug("MainWindow::loadPresetSettings: preset [%s | %s]", qDebug("MainWindow::loadPresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()), qPrintable(preset->getGroup()),
qPrintable(preset->getDescription())); qPrintable(preset->getDescription()));
ui->glSpectrumGUI->deserialize(preset->getSpectrumConfig());
m_pluginManager->loadSettings(preset); m_pluginManager->loadSettings(preset);
// has to be last step // has to be last step
@ -229,7 +231,6 @@ void MainWindow::saveSettings()
savePresetSettings(m_settings.getWorkingPreset()); savePresetSettings(m_settings.getWorkingPreset());
m_settings.save(); m_settings.save();
} }
void MainWindow::savePresetSettings(Preset* preset) void MainWindow::savePresetSettings(Preset* preset)
@ -238,6 +239,8 @@ void MainWindow::savePresetSettings(Preset* preset)
qPrintable(preset->getGroup()), qPrintable(preset->getGroup()),
qPrintable(preset->getDescription())); qPrintable(preset->getDescription()));
preset->setSpectrumConfig(ui->glSpectrumGUI->serialize());
preset->clearChannels();
m_pluginManager->saveSettings(preset); m_pluginManager->saveSettings(preset);
preset->setLayout(saveState()); preset->setLayout(saveState());
@ -498,14 +501,16 @@ void MainWindow::on_presetLoad_clicked()
if(item == 0) if(item == 0)
{ {
qDebug("MainWindow::on_presetLoad_clicked: item null");
updatePresetControls(); updatePresetControls();
return; return;
} }
Preset* preset = qvariant_cast<Preset*>(item->data(0, Qt::UserRole)); const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if(preset == 0) if(preset == 0)
{ {
qDebug("MainWindow::on_presetLoad_clicked: preset null");
return; return;
} }
@ -556,10 +561,10 @@ void MainWindow::on_action_Preferences_triggered()
void MainWindow::on_sampleSource_currentIndexChanged(int index) void MainWindow::on_sampleSource_currentIndexChanged(int index)
{ {
savePresetSettings(m_settings.getWorkingPreset()); m_pluginManager->saveSourceSettings(m_settings.getWorkingPreset());
m_pluginManager->selectSampleSource(ui->sampleSource->currentIndex()); m_pluginManager->selectSampleSource(ui->sampleSource->currentIndex());
m_settings.setSourceIndex(ui->sampleSource->currentIndex()); m_settings.setSourceIndex(ui->sampleSource->currentIndex());
m_pluginManager->loadSettings(m_settings.getWorkingPreset()); m_pluginManager->loadSourceSettings(m_settings.getWorkingPreset());
} }
void MainWindow::on_action_About_triggered() void MainWindow::on_action_About_triggered()

View File

@ -83,7 +83,7 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf
m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin)); m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin));
} }
void PluginManager::loadSettings(Preset* preset) void PluginManager::loadSettings(const Preset* preset)
{ {
fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
@ -142,6 +142,13 @@ void PluginManager::loadSettings(Preset* preset)
renameChannelInstances(); renameChannelInstances();
loadSourceSettings(preset);
}
void PluginManager::loadSourceSettings(const Preset* preset)
{
fprintf(stderr, "PluginManager::loadSourceSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
if(m_sampleSourcePluginGUI != 0) if(m_sampleSourcePluginGUI != 0)
{ {
const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence); const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence);
@ -151,15 +158,6 @@ void PluginManager::loadSettings(Preset* preset)
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId); qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(*sourceConfig); m_sampleSourcePluginGUI->deserialize(*sourceConfig);
} }
/*
qDebug("PluginManager::loadSettings: source compare [%s] vs [%s]", qPrintable(m_sampleSourceId), qPrintable(preset->getSourceId()));
// TODO: have one set of source presets per identified source (preset -> find source with name)
if(m_sampleSourceId == preset->getSourceId())
{
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(preset->getSourceConfig());
}*/
qint64 centerFrequency = preset->getCenterFrequency(); qint64 centerFrequency = preset->getCenterFrequency();
m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency); m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency);
@ -181,17 +179,8 @@ bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstance
void PluginManager::saveSettings(Preset* preset) void PluginManager::saveSettings(Preset* preset)
{ {
if(m_sampleSourcePluginGUI != NULL) qDebug("PluginManager::saveSettings");
{ saveSourceSettings(preset);
preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
//preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
}
/*
else
{
preset->setSourceConfig(QString::null, QString::null, 0, QByteArray());
}*/
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
@ -201,6 +190,18 @@ void PluginManager::saveSettings(Preset* preset)
} }
} }
void PluginManager::saveSourceSettings(Preset* preset)
{
qDebug("PluginManager::saveSourceSettings");
if(m_sampleSourcePluginGUI != NULL)
{
preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
//preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
}
}
void PluginManager::freeAll() void PluginManager::freeAll()
{ {
m_dspEngine->stopAcquistion(); m_dspEngine->stopAcquistion();

View File

@ -0,0 +1,94 @@
#include <QSettings>
#include <QStringList>
#include "settings/mainsettings.h"
MainSettings::MainSettings()
{
resetToDefaults();
}
MainSettings::~MainSettings()
{
for(int i = 0; i < m_presets.count(); ++i)
{
delete m_presets[i];
}
}
void MainSettings::load()
{
QSettings s;
m_preferences.deserialize(qUncompress(QByteArray::fromBase64(s.value("preferences").toByteArray())));
m_workingPreset.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 MainSettings::save() const
{
QSettings s;
s.setValue("preferences", qCompress(m_preferences.serialize()).toBase64());
s.setValue("current", qCompress(m_workingPreset.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 MainSettings::resetToDefaults()
{
m_preferences.resetToDefaults();
m_workingPreset.resetToDefaults();
}
Preset* MainSettings::newPreset(const QString& group, const QString& description)
{
Preset* preset = new Preset();
preset->setGroup(group);
preset->setDescription(description);
m_presets.append(preset);
return preset;
}
void MainSettings::deletePreset(const Preset* preset)
{
m_presets.removeAll((Preset*)preset);
delete (Preset*)preset;
}

View File

@ -34,6 +34,7 @@ QByteArray Preset::serialize() const
s.writeString(2, m_description); s.writeString(2, m_description);
s.writeU64(3, m_centerFrequency); s.writeU64(3, m_centerFrequency);
s.writeBlob(4, m_layout); s.writeBlob(4, m_layout);
s.writeBlob(5, m_spectrumConfig);
s.writeS32(20, m_sourceConfigs.size()); s.writeS32(20, m_sourceConfigs.size());
@ -44,7 +45,7 @@ QByteArray Preset::serialize() const
s.writeS32(26 + i*4, m_sourceConfigs[i].m_sourceSequence); s.writeS32(26 + i*4, m_sourceConfigs[i].m_sourceSequence);
s.writeBlob(27 + i*4, m_sourceConfigs[i].m_config); s.writeBlob(27 + i*4, m_sourceConfigs[i].m_config);
qDebug("Preset::serialize: source: id: %ss, ser: %s, seq: %d", qDebug("Preset::serialize: source: id: %s, ser: %s, seq: %d",
qPrintable(m_sourceConfigs[i].m_sourceId), qPrintable(m_sourceConfigs[i].m_sourceId),
qPrintable(m_sourceConfigs[i].m_sourceSerial), qPrintable(m_sourceConfigs[i].m_sourceSerial),
m_sourceConfigs[i].m_sourceSequence); m_sourceConfigs[i].m_sourceSequence);
@ -55,6 +56,16 @@ QByteArray Preset::serialize() const
} }
} }
s.writeS32(200, m_channelConfigs.size());
for(int i = 0; i < m_channelConfigs.size(); i++)
{
qDebug("Preset::serialize: channel: id: %s", qPrintable(m_channelConfigs[i].m_channel));
s.writeString(201 + i * 2, m_channelConfigs[i].m_channel);
s.writeBlob(202 + i * 2, m_channelConfigs[i].m_config);
}
return s.final(); return s.final();
} }
@ -74,6 +85,7 @@ bool Preset::deserialize(const QByteArray& data)
d.readString(2, &m_description, "no name"); d.readString(2, &m_description, "no name");
d.readU64(3, &m_centerFrequency, 0); d.readU64(3, &m_centerFrequency, 0);
d.readBlob(4, &m_layout); d.readBlob(4, &m_layout);
d.readBlob(5, &m_spectrumConfig);
qDebug("Preset::deserialize: m_group: %s m_description: %s m_centerFrequency: %llu", qDebug("Preset::deserialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group), qPrintable(m_group),
@ -88,7 +100,9 @@ bool Preset::deserialize(const QByteArray& data)
sourcesCount = ((200-23)/4) - 1; sourcesCount = ((200-23)/4) - 1;
} }
for(int i = 0; i < sourcesCount; i++) m_sourceConfigs.clear();
for (int i = 0; i < sourcesCount; i++)
{ {
QString sourceId, sourceSerial; QString sourceId, sourceSerial;
int sourceSequence; int sourceSequence;
@ -110,7 +124,22 @@ bool Preset::deserialize(const QByteArray& data)
} }
} }
return true; qint32 channelCount;
d.readS32(200, &channelCount, 0);
m_channelConfigs.clear();
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);
qDebug("Preset::deserialize: channel: id: %s", qPrintable(channel));
m_channelConfigs.append(ChannelConfig(channel, config));
}
} }
else else
{ {
@ -159,7 +188,7 @@ void Preset::addOrUpdateSourceConfig(const QString& sourceId,
const QByteArray* Preset::findBestSourceConfig(const QString& sourceId, const QByteArray* Preset::findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial, const QString& sourceSerial,
int sourceSequence) int sourceSequence) const
{ {
SourceConfigs::const_iterator it = m_sourceConfigs.begin(); SourceConfigs::const_iterator it = m_sourceConfigs.begin();
SourceConfigs::const_iterator itFirstOfKind = m_sourceConfigs.end(); SourceConfigs::const_iterator itFirstOfKind = m_sourceConfigs.end();