Implemented multiple sample sources for one preset

pull/6/head
Edouard Griffiths 2015-10-01 16:57:33 +02:00
rodzic c85813b577
commit fa79c55f41
6 zmienionych plików z 241 dodań i 44 usunięć

Wyświetl plik

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

Wyświetl plik

@ -47,7 +47,7 @@ public:
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
void loadSettings(const Preset* preset);
void loadSettings(Preset* preset);
void saveSettings(Preset* preset);
void freeAll();
@ -58,6 +58,7 @@ public:
void fillSampleSourceSelector(QComboBox* comboBox);
int selectSampleSource(int index);
int selectFirstSampleSource(const QString& sourceId);
int selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence);
private:
struct ChannelRegistration {

Wyświetl plik

@ -61,6 +61,7 @@ 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)
{
m_sourceId = sourceId;
@ -72,7 +73,7 @@ public:
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; }
const QByteArray& getSourceConfig() const { return m_sourceConfig; }*/
void addOrUpdateSourceConfig(const QString& sourceId,
const QString& sourceSerial,
@ -83,6 +84,8 @@ public:
const QString& sourceSerial,
int sourceSequence);
const QByteArray* findCurrentSourceConfig(QString& sourceId, QString& sourceSerial, int& sourceSequence) const;
protected:
// group and preset description
QString m_group;
@ -107,6 +110,7 @@ protected:
// sources and configurations
SourceConfigs m_sourceConfigs;
SourceConfigs::const_iterator m_currentSourceConfig;
// screen and dock layout
QByteArray m_layout;

Wyświetl plik

@ -115,13 +115,27 @@ MainWindow::MainWindow(QWidget* parent) :
qDebug() << "MainWindow::MainWindow: select SampleSource from settings...";
int sampleSourceIndex = m_pluginManager->selectFirstSampleSource(m_settings.getCurrent()->getSourceId()); // select SampleSource from settings
Preset *currentPreset = m_settings.getCurrent();
if(sampleSourceIndex >= 0)
if (currentPreset != 0)
{
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
ui->sampleSource->setCurrentIndex(sampleSourceIndex);
ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
QString sourceId, sourceSerial;
int sourceSequence;
const QByteArray *sourceConfig;
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);
}
}
}
qDebug() << "MainWindow::MainWindow: load current preset settings...";
@ -206,9 +220,12 @@ void MainWindow::loadSettings()
}
}
void MainWindow::loadPresetSettings(const Preset* preset)
void MainWindow::loadPresetSettings(Preset* preset)
{
qDebug() << "MainWindow::loadPresetSettings: preset: " << preset->getSourceId().toStdString().c_str();
qDebug("MainWindow::loadPresetSettings: group: %s desc: %s Fcenter: %llu Hz",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()),
preset->getCenterFrequency());
ui->glSpectrumGUI->deserialize(preset->getSpectrumConfig());
@ -229,7 +246,10 @@ void MainWindow::saveSettings()
void MainWindow::savePresetSettings(Preset* preset)
{
qDebug() << "MainWindow::savePresetSettings: preset: " << preset->getSourceId().toStdString().c_str();
qDebug("MainWindow::savePresetSettings: group: %s desc: %s Fcenter: %llu Hz",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()),
preset->getCenterFrequency());
preset->setSpectrumConfig(ui->glSpectrumGUI->serialize());
preset->clearChannels();
@ -497,7 +517,7 @@ void MainWindow::on_presetLoad_clicked()
return;
}
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
Preset* preset = qvariant_cast<Preset*>(item->data(0, Qt::UserRole));
if(preset == 0)
{

Wyświetl plik

@ -83,7 +83,7 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf
m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin));
}
void PluginManager::loadSettings(const Preset* preset)
void PluginManager::loadSettings(Preset* preset)
{
fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
@ -144,6 +144,14 @@ void PluginManager::loadSettings(const Preset* preset)
if(m_sampleSourcePluginGUI != 0)
{
const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence);
if (sourceConfig != 0)
{
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
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)
@ -151,9 +159,8 @@ void PluginManager::loadSettings(const Preset* preset)
{
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(preset->getSourceConfig());
}
}*/
// FIXME: get center frequency from preset center frequency
qint64 centerFrequency = preset->getCenterFrequency();
m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency);
}
@ -176,13 +183,15 @@ void PluginManager::saveSettings(Preset* preset)
{
if(m_sampleSourcePluginGUI != NULL)
{
preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
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
@ -264,7 +273,7 @@ void PluginManager::fillSampleSourceSelector(QComboBox* comboBox)
int PluginManager::selectSampleSource(int index)
{
qDebug() << "PluginManager::selectSampleSource by index";
qDebug("PluginManager::selectSampleSource by index: index: %d", index);
m_dspEngine->stopAcquistion();
@ -296,19 +305,18 @@ int PluginManager::selectSampleSource(int index)
{
index = 0;
}
else
{
return -1;
}
}
}
if(index == -1)
{
return -1;
}
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "m_sampleSource at index " << index
qDebug() << "PluginManager::selectSampleSource by index: m_sampleSource at index " << index
<< " id: " << m_sampleSourceId.toStdString().c_str()
<< " ser: " << m_sampleSourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence;
@ -320,7 +328,7 @@ int PluginManager::selectSampleSource(int index)
int PluginManager::selectFirstSampleSource(const QString& sourceId)
{
qDebug() << "PluginManager::selectFirstSampleSource by id: " << sourceId.toStdString().c_str();
qDebug("PluginManager::selectFirstSampleSource by id: [%s]", qPrintable(sourceId));
int index = -1;
@ -334,9 +342,7 @@ int PluginManager::selectFirstSampleSource(const QString& sourceId)
m_sampleSourceId.clear();
}
qDebug("finding first sample source [%s]", qPrintable(sourceId));
for(int i = 0; i < m_sampleSourceDevices.count(); i++)
for (int i = 0; i < m_sampleSourceDevices.count(); i++)
{
qDebug("*** %s vs %s", qPrintable(m_sampleSourceDevices[i].m_sourceId), qPrintable(sourceId));
@ -353,11 +359,10 @@ int PluginManager::selectFirstSampleSource(const QString& sourceId)
{
index = 0;
}
}
if(index == -1)
{
return -1;
else
{
return -1;
}
}
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
@ -374,6 +379,73 @@ int PluginManager::selectFirstSampleSource(const QString& sourceId)
return index;
}
int PluginManager::selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence)
{
qDebug("PluginManager::selectSampleSourceBySequence by sequence: id: %s ser: %s seq: %d", qPrintable(sourceId), qPrintable(sourceSerial), sourceSequence);
int index = -1;
int index_matchingSequence = -1;
int index_firstOfKind = -1;
for (int i = 0; i < m_sampleSourceDevices.count(); i++)
{
if (m_sampleSourceDevices[i].m_sourceId == sourceId)
{
index_firstOfKind = i;
if (m_sampleSourceDevices[i].m_sourceSerial == sourceSerial)
{
index = i; // exact match
break;
}
if (m_sampleSourceDevices[i].m_sourceSequence == sourceSequence)
{
index_matchingSequence = i;
}
}
}
if(index == -1) // no exact match
{
if (index_matchingSequence == -1) // no matching sequence
{
if (index_firstOfKind == -1) // no matching device type
{
if(m_sampleSourceDevices.count() > 0) // take first if any
{
index = 0;
}
else
{
return -1; // return if no device attached
}
}
else
{
index = index_firstOfKind; // take first that matches device type
}
}
else
{
index = index_matchingSequence; // take the one that matches the sequence in the device type
}
}
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "PluginManager::selectSampleSourceBySequence by sequence: m_sampleSource at index " << index
<< " id: " << qPrintable(m_sampleSourceId)
<< " ser: " << qPrintable(m_sampleSourceSerial)
<< " seq: " << m_sampleSourceSequence;
m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId);
return index;
}
void PluginManager::loadPlugins(const QDir& dir)
{
QDir pluginsDir(dir);

Wyświetl plik

@ -19,26 +19,56 @@ void Preset::resetToDefaults()
m_channelConfigs.clear();
m_sourceId.clear();
m_sourceConfig.clear();
m_currentSourceConfig = m_sourceConfigs.end();
}
QByteArray Preset::serialize() const
{
qDebug() << "Preset::serialize (" << this->getSourceId().toStdString().c_str() << ")";
qDebug("Preset::serialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group),
qPrintable(m_description),
m_centerFrequency);
SimpleSerializer s(1);
s.writeString(1, m_group);
s.writeString(2, m_description);
s.writeU64(3, m_centerFrequency);
s.writeBlob(4, m_layout);
s.writeBlob(5, m_spectrumConfig);
s.writeString(6, m_sourceId);
s.writeBlob(7, m_sourceConfig);
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);
s.writeString(25 + i*4, m_sourceConfigs[i].m_sourceSerial);
s.writeS32(26 + i*4, m_sourceConfigs[i].m_sourceSequence);
s.writeBlob(27 + i*4, m_sourceConfigs[i].m_config);
if (i >= (200-23)/4) // full!
{
break;
}
}
s.writeS32(200, m_channelConfigs.size());
qDebug() << " m_group: " << m_group.toStdString().c_str();
for(int i = 0; i < m_channelConfigs.size(); i++) {
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);
}
@ -48,7 +78,6 @@ QByteArray Preset::serialize() const
bool Preset::deserialize(const QByteArray& data)
{
qDebug() << "Preset::deserialize (" << this->getSourceId().toStdString().c_str() << ")";
SimpleDeserializer d(data);
if(!d.isValid()) {
@ -65,20 +94,66 @@ bool Preset::deserialize(const QByteArray& data)
d.readString(6, &m_sourceId);
d.readBlob(7, &m_sourceConfig);
qDebug() << "Preset::deserialize: m_group: " << m_group.toStdString().c_str();
qDebug("Preset::deserialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group),
qPrintable(m_description),
m_centerFrequency);
qint32 sourcesCount = 0;
d.readS32(20, &sourcesCount, 0);
if (sourcesCount >= (200-20)/4) // limit was hit!
{
sourcesCount = ((200-20)/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);
m_sourceConfigs.append(SourceConfig(sourceId, sourceSerial, sourceSequence, sourceConfig));
if (hasCurrentConfig && (sourceId == currentSourceId) && (sourceSequence == currentSourceSequence))
{
m_currentSourceConfig = m_sourceConfigs.end();
m_currentSourceConfig--;
}
}
qint32 channelCount = 0;
d.readS32(200, &channelCount, 0);
for(int i = 0; i < channelCount; i++) {
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 {
}
else
{
resetToDefaults();
return false;
}
@ -114,11 +189,14 @@ void Preset::addOrUpdateSourceConfig(const QString& sourceId,
if (it == m_sourceConfigs.end())
{
m_sourceConfigs.push_back(SourceConfig(sourceId, sourceSerial, sourceSequence, config));
m_sourceConfigs.append(SourceConfig(sourceId, sourceSerial, sourceSequence, config));
m_currentSourceConfig = m_sourceConfigs.end();
--m_currentSourceConfig;
}
else
{
it->m_config = config;
m_currentSourceConfig = it;
}
}
@ -164,20 +242,42 @@ 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;
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;
}
}