1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

ScopeNG: use dynamic storage for TriggerCondition objects. Fixed destructors

This commit is contained in:
f4exb 2018-04-03 23:19:35 +02:00
parent 26b4b50d23
commit c9861c455b
2 changed files with 42 additions and 30 deletions

View File

@ -69,6 +69,9 @@ ScopeVisNG::ScopeVisNG(GLScopeNG* glScope) :
ScopeVisNG::~ScopeVisNG()
{
for (std::vector<TriggerCondition*>::iterator it = m_triggerConditions.begin(); it != m_triggerConditions.end(); ++ it) {
delete *it;
}
}
void ScopeVisNG::setSampleRate(int sampleRate)
@ -267,15 +270,15 @@ void ScopeVisNG::processTrace(const SampleVector::const_iterator& cbegin, const
{
if ((m_triggerState == TriggerUntriggered) || (m_triggerState == TriggerDelay))
{
TriggerCondition& triggerCondition = m_triggerConditions[m_currentTriggerIndex]; // current trigger condition
TriggerCondition* triggerCondition = m_triggerConditions[m_currentTriggerIndex]; // current trigger condition
while (begin < end)
{
if (m_triggerState == TriggerDelay)
{
if (triggerCondition.m_triggerDelayCount > 0) // skip samples during delay period
if (triggerCondition->m_triggerDelayCount > 0) // skip samples during delay period
{
triggerCondition.m_triggerDelayCount--;
triggerCondition->m_triggerDelayCount--;
++begin;
continue;
}
@ -301,11 +304,11 @@ void ScopeVisNG::processTrace(const SampleVector::const_iterator& cbegin, const
}
// look for trigger
if (m_triggerComparator.triggered(*begin, triggerCondition))
if (m_triggerComparator.triggered(*begin, *triggerCondition))
{
if (triggerCondition.m_triggerData.m_triggerDelay > 0)
if (triggerCondition->m_triggerData.m_triggerDelay > 0)
{
triggerCondition.m_triggerDelayCount = triggerCondition.m_triggerData.m_triggerDelay; // initialize delayed samples counter
triggerCondition->m_triggerDelayCount = triggerCondition->m_triggerData.m_triggerDelay; // initialize delayed samples counter
m_triggerState = TriggerDelay;
++begin;
continue;
@ -398,18 +401,18 @@ void ScopeVisNG::processTrace(const SampleVector::const_iterator& cbegin, const
bool ScopeVisNG::nextTrigger()
{
TriggerCondition& triggerCondition = m_triggerConditions[m_currentTriggerIndex]; // current trigger condition
TriggerCondition *triggerCondition = m_triggerConditions[m_currentTriggerIndex]; // current trigger condition
if (triggerCondition.m_triggerData.m_triggerRepeat > 0)
if (triggerCondition->m_triggerData.m_triggerRepeat > 0)
{
if (triggerCondition.m_triggerCounter < triggerCondition.m_triggerData.m_triggerRepeat)
if (triggerCondition->m_triggerCounter < triggerCondition->m_triggerData.m_triggerRepeat)
{
triggerCondition.m_triggerCounter++;
triggerCondition->m_triggerCounter++;
return true; // not final keep going
}
else
{
triggerCondition.m_triggerCounter = 0; // reset for next time
triggerCondition->m_triggerCounter = 0; // reset for next time
}
}
@ -623,8 +626,8 @@ bool ScopeVisNG::handleMessage(const Message& message)
{
QMutexLocker configLocker(&m_mutex);
MsgScopeVisNGAddTrigger& conf = (MsgScopeVisNGAddTrigger&) message;
m_triggerConditions.push_back(TriggerCondition(conf.getTriggerData()));
m_triggerConditions.back().initProjector();
m_triggerConditions.push_back(new TriggerCondition(conf.getTriggerData()));
m_triggerConditions.back()->initProjector();
return true;
}
else if (MsgScopeVisNGChangeTrigger::match(message))
@ -635,12 +638,12 @@ bool ScopeVisNG::handleMessage(const Message& message)
if (triggerIndex < m_triggerConditions.size())
{
m_triggerConditions[triggerIndex].setData(conf.getTriggerData());
m_triggerConditions[triggerIndex]->setData(conf.getTriggerData());
if (triggerIndex == m_focusedTriggerIndex)
{
computeDisplayTriggerLevels();
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex].m_triggerData);
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex]->m_triggerData);
updateGLScopeDisplay();
}
}
@ -653,8 +656,11 @@ bool ScopeVisNG::handleMessage(const Message& message)
MsgScopeVisNGRemoveTrigger& conf = (MsgScopeVisNGRemoveTrigger&) message;
uint32_t triggerIndex = conf.getTriggerIndex();
if (triggerIndex < m_triggerConditions.size()) {
if (triggerIndex < m_triggerConditions.size())
{
TriggerCondition *triggerCondition = m_triggerConditions[triggerIndex];
m_triggerConditions.erase(m_triggerConditions.begin() + triggerIndex);
delete triggerCondition;
}
return true;
@ -671,12 +677,12 @@ bool ScopeVisNG::handleMessage(const Message& message)
int nextTriggerIndex = (triggerIndex + (conf.getMoveUp() ? 1 : -1)) % m_triggerConditions.size();
TriggerCondition nextTrigger = m_triggerConditions[nextTriggerIndex];
TriggerCondition *nextTrigger = m_triggerConditions[nextTriggerIndex];
m_triggerConditions[nextTriggerIndex] = m_triggerConditions[triggerIndex];
m_triggerConditions[triggerIndex] = nextTrigger;
computeDisplayTriggerLevels();
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex].m_triggerData);
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex]->m_triggerData);
updateGLScopeDisplay();
return true;
@ -690,7 +696,7 @@ bool ScopeVisNG::handleMessage(const Message& message)
{
m_focusedTriggerIndex = triggerIndex;
computeDisplayTriggerLevels();
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex].m_triggerData);
m_glScope->setFocusedTriggerData(m_triggerConditions[m_focusedTriggerIndex]->m_triggerData);
updateGLScopeDisplay();
}
@ -854,9 +860,9 @@ void ScopeVisNG::computeDisplayTriggerLevels()
for (; itData != m_traces.m_tracesData.end(); ++itData)
{
if ((m_focusedTriggerIndex < m_triggerConditions.size()) && (m_triggerConditions[m_focusedTriggerIndex].m_projector.getProjectionType() == itData->m_projectionType))
if ((m_focusedTriggerIndex < m_triggerConditions.size()) && (m_triggerConditions[m_focusedTriggerIndex]->m_projector.getProjectionType() == itData->m_projectionType))
{
float level = m_triggerConditions[m_focusedTriggerIndex].m_triggerData.m_triggerLevel;
float level = m_triggerConditions[m_focusedTriggerIndex]->m_triggerData.m_triggerLevel;
float levelPowerLin = level + 1.0f;
float levelPowerdB = (100.0f * (level - 1.0f));
float v;

View File

@ -169,7 +169,7 @@ public:
{
if (triggerIndex < m_triggerConditions.size())
{
triggerData = m_triggerConditions[triggerIndex].m_triggerData;
triggerData = m_triggerConditions[triggerIndex]->m_triggerData;
}
}
@ -181,7 +181,7 @@ public:
}
}
const TriggerData& getTriggerData(uint32_t triggerIndex) const { return m_triggerConditions[triggerIndex].m_triggerData; }
const TriggerData& getTriggerData(uint32_t triggerIndex) const { return m_triggerConditions[triggerIndex]->m_triggerData; }
const std::vector<TraceData>& getTracesData() const { return m_traces.m_tracesData; }
uint32_t getNbTriggers() const { return m_triggerConditions.size(); }
@ -529,12 +529,10 @@ private:
m_triggerDelayCount(0),
m_triggerCounter(0)
{
qDebug("TriggerCondition");
}
~TriggerCondition()
{
qDebug("~TriggerCondition");
}
void initProjector()
@ -689,13 +687,11 @@ private:
TraceControl() : m_projector(Projector::ProjectionReal)
{
qDebug("TraceControl::TraceControl");
reset();
}
~TraceControl()
{
qDebug("TraceControl::~TraceControl");
}
void initProjector(Projector::ProjectionType projectionType)
@ -737,8 +733,18 @@ private:
~Traces()
{
if (m_x0) delete[] m_x0;
if (m_x1) delete[] m_x1;
for (std::vector<TraceControl*>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it) {
delete *it;
}
if (m_x0) {
delete[] m_x0;
}
if (m_x1) {
delete[] m_x1;
}
m_maxTraceSize = 0;
}
@ -937,7 +943,7 @@ private:
GLScopeNG* m_glScope;
uint32_t m_preTriggerDelay; //!< Pre-trigger delay in number of samples
std::vector<TriggerCondition> m_triggerConditions; //!< Chain of triggers
std::vector<TriggerCondition*> m_triggerConditions; //!< Chain of triggers
uint32_t m_currentTriggerIndex; //!< Index of current index in the chain
uint32_t m_focusedTriggerIndex; //!< Index of the trigger that has focus
TriggerState m_triggerState; //!< Current trigger state