mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-29 23:13:16 -04:00
Cleanup, reformat
This commit is contained in:
@@ -6,137 +6,137 @@
|
||||
#include <sstream>
|
||||
|
||||
DemodulatorMgr::DemodulatorMgr() :
|
||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorMgr::~DemodulatorMgr() {
|
||||
terminateAll();
|
||||
terminateAll();
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::newThread() {
|
||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||
|
||||
demods.push_back(newDemod);
|
||||
demods.push_back(newDemod);
|
||||
|
||||
std::stringstream label;
|
||||
label << demods.size();
|
||||
newDemod->setLabel(label.str());
|
||||
std::stringstream label;
|
||||
label << demods.size();
|
||||
newDemod->setLabel(label.str());
|
||||
|
||||
return newDemod;
|
||||
return newDemod;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::terminateAll() {
|
||||
while (demods.size()) {
|
||||
DemodulatorInstance *d = demods.back();
|
||||
deleteThread(d);
|
||||
}
|
||||
while (demods.size()) {
|
||||
DemodulatorInstance *d = demods.back();
|
||||
deleteThread(d);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||
return demods;
|
||||
return demods;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
|
||||
i = std::find(demods.begin(), demods.end(), demod);
|
||||
i = std::find(demods.begin(), demods.end(), demod);
|
||||
|
||||
if (activeDemodulator == demod) {
|
||||
activeDemodulator = NULL;
|
||||
}
|
||||
if (lastActiveDemodulator == demod) {
|
||||
lastActiveDemodulator = NULL;
|
||||
}
|
||||
if (activeVisualDemodulator == demod) {
|
||||
activeVisualDemodulator = NULL;
|
||||
}
|
||||
if (activeDemodulator == demod) {
|
||||
activeDemodulator = NULL;
|
||||
}
|
||||
if (lastActiveDemodulator == demod) {
|
||||
lastActiveDemodulator = NULL;
|
||||
}
|
||||
if (activeVisualDemodulator == demod) {
|
||||
activeVisualDemodulator = NULL;
|
||||
}
|
||||
|
||||
if (i != demods.end()) {
|
||||
demods.erase(i);
|
||||
demod->terminate();
|
||||
}
|
||||
if (i != demods.end()) {
|
||||
demods.erase(i);
|
||||
demod->terminate();
|
||||
}
|
||||
|
||||
demods_deleted.push_back(demod);
|
||||
demods_deleted.push_back(demod);
|
||||
|
||||
garbageCollect();
|
||||
garbageCollect();
|
||||
}
|
||||
|
||||
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
|
||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstance *testDemod = demods[i];
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstance *testDemod = demods[i];
|
||||
|
||||
int freqTest = testDemod->getParams().frequency;
|
||||
int bandwidthTest = testDemod->getParams().bandwidth;
|
||||
int halfBandwidthTest = bandwidthTest / 2;
|
||||
int freqTest = testDemod->getParams().frequency;
|
||||
int bandwidthTest = testDemod->getParams().bandwidth;
|
||||
int halfBandwidthTest = bandwidthTest / 2;
|
||||
|
||||
int halfBuffer = bandwidth / 2;
|
||||
int halfBuffer = bandwidth / 2;
|
||||
|
||||
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
||||
foundDemods->push_back(testDemod);
|
||||
}
|
||||
}
|
||||
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
|
||||
foundDemods->push_back(testDemod);
|
||||
}
|
||||
}
|
||||
|
||||
return foundDemods;
|
||||
return foundDemods;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool temporary) {
|
||||
if (!temporary) {
|
||||
if (activeDemodulator != NULL) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
} else {
|
||||
lastActiveDemodulator = demod;
|
||||
}
|
||||
}
|
||||
if (!temporary) {
|
||||
if (activeDemodulator != NULL) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
} else {
|
||||
lastActiveDemodulator = demod;
|
||||
}
|
||||
}
|
||||
|
||||
if (activeVisualDemodulator) {
|
||||
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
||||
}
|
||||
if (demod) {
|
||||
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
activeVisualDemodulator = demod;
|
||||
} else {
|
||||
DemodulatorInstance *last = getLastActiveDemodulator();
|
||||
if (last) {
|
||||
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
}
|
||||
activeVisualDemodulator = last;
|
||||
}
|
||||
if (activeVisualDemodulator) {
|
||||
activeVisualDemodulator->setVisualOutputQueue(NULL);
|
||||
}
|
||||
if (demod) {
|
||||
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
activeVisualDemodulator = demod;
|
||||
} else {
|
||||
DemodulatorInstance *last = getLastActiveDemodulator();
|
||||
if (last) {
|
||||
last->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
|
||||
}
|
||||
activeVisualDemodulator = last;
|
||||
}
|
||||
|
||||
activeDemodulator = demod;
|
||||
activeDemodulator = demod;
|
||||
|
||||
garbageCollect();
|
||||
garbageCollect();
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
||||
return activeDemodulator;
|
||||
return activeDemodulator;
|
||||
}
|
||||
|
||||
DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
||||
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
}
|
||||
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
|
||||
lastActiveDemodulator = activeDemodulator;
|
||||
}
|
||||
|
||||
return lastActiveDemodulator;
|
||||
return lastActiveDemodulator;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::garbageCollect() {
|
||||
if (demods_deleted.size()) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
if (demods_deleted.size()) {
|
||||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
|
||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||
if ((*i)->isTerminated()) {
|
||||
DemodulatorInstance *deleted = (*i);
|
||||
demods_deleted.erase(i);
|
||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||
if ((*i)->isTerminated()) {
|
||||
DemodulatorInstance *deleted = (*i);
|
||||
demods_deleted.erase(i);
|
||||
|
||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||
|
||||
delete deleted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete deleted;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user