mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-08-08 00:22:28 -04:00
Save / Load session working
This commit is contained in:
parent
2c5eb4f946
commit
f454c34245
@ -115,6 +115,7 @@ AppFrame::AppFrame() :
|
|||||||
menu->Append(wxID_SAVE, "&Save Session");
|
menu->Append(wxID_SAVE, "&Save Session");
|
||||||
menu->Append(wxID_SAVEAS, "Save Session &As..");
|
menu->Append(wxID_SAVEAS, "Save Session &As..");
|
||||||
menu->AppendSeparator();
|
menu->AppendSeparator();
|
||||||
|
menu->Append(wxID_RESET, "&Reset Session");
|
||||||
menu->Append(wxID_CLOSE);
|
menu->Append(wxID_CLOSE);
|
||||||
|
|
||||||
menuBar->Append(menu, wxT("&File"));
|
menuBar->Append(menu, wxT("&File"));
|
||||||
@ -159,6 +160,14 @@ AppFrame::AppFrame() :
|
|||||||
|
|
||||||
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), DEFAULT_FREQ));
|
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), DEFAULT_FREQ));
|
||||||
|
|
||||||
|
wxAcceleratorEntry entries[3];
|
||||||
|
entries[0].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN);
|
||||||
|
entries[1].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE);
|
||||||
|
entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_SAVEAS);
|
||||||
|
|
||||||
|
wxAcceleratorTable accel(3, entries);
|
||||||
|
SetAcceleratorTable(accel);
|
||||||
|
|
||||||
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
||||||
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
||||||
// ShowFullScreen(true);
|
// ShowFullScreen(true);
|
||||||
@ -181,11 +190,15 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
|||||||
wxGetApp().setOffset(ofs);
|
wxGetApp().setOffset(ofs);
|
||||||
}
|
}
|
||||||
} else if (event.GetId() == wxID_SAVE) {
|
} else if (event.GetId() == wxID_SAVE) {
|
||||||
|
if (!currentSessionFile.empty()) {
|
||||||
|
saveSession(currentSessionFile);
|
||||||
|
} else {
|
||||||
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||||
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveSession(saveFileDialog.GetPath().ToStdString());
|
saveSession(saveFileDialog.GetPath().ToStdString());
|
||||||
|
}
|
||||||
} else if (event.GetId() == wxID_OPEN) {
|
} else if (event.GetId() == wxID_OPEN) {
|
||||||
wxFileDialog openFileDialog(this, _("Open XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
wxFileDialog openFileDialog(this, _("Open XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||||
if (openFileDialog.ShowModal() == wxID_CANCEL) {
|
if (openFileDialog.ShowModal() == wxID_CANCEL) {
|
||||||
@ -193,6 +206,15 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
|||||||
}
|
}
|
||||||
loadSession(openFileDialog.GetPath().ToStdString());
|
loadSession(openFileDialog.GetPath().ToStdString());
|
||||||
} else if (event.GetId() == wxID_SAVEAS) {
|
} else if (event.GetId() == wxID_SAVEAS) {
|
||||||
|
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||||
|
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saveSession(saveFileDialog.GetPath().ToStdString());
|
||||||
|
} else if (event.GetId() == wxID_RESET) {
|
||||||
|
wxGetApp().getDemodMgr().terminateAll();
|
||||||
|
wxGetApp().setFrequency(DEFAULT_FREQ);
|
||||||
|
wxGetApp().setOffset(0);
|
||||||
} else if (event.GetId() == wxID_EXIT) {
|
} else if (event.GetId() == wxID_EXIT) {
|
||||||
Close(false);
|
Close(false);
|
||||||
}
|
}
|
||||||
@ -333,7 +355,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wxGetApp().getDemodMgr().terminateAll();
|
wxGetApp().getDemodMgr().terminateAll();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DataNode *header = l.rootNode()->getNext("header");
|
DataNode *header = l.rootNode()->getNext("header");
|
||||||
@ -346,6 +368,8 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
|
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
|
||||||
std::cout << "\tOffset: " << offset << std::endl;
|
std::cout << "\tOffset: " << offset << std::endl;
|
||||||
|
|
||||||
|
wxGetApp().setOffset(offset);
|
||||||
|
wxGetApp().setFrequency(center_freq);
|
||||||
|
|
||||||
DataNode *demodulators = l.rootNode()->getNext("demodulators");
|
DataNode *demodulators = l.rootNode()->getNext("demodulators");
|
||||||
|
|
||||||
@ -364,7 +388,37 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0;
|
int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0;
|
||||||
std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : "";
|
std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : "";
|
||||||
|
|
||||||
std::cout << "\tFound demodulator at frequency " << freq << " type " << type << std::endl;
|
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread();
|
||||||
|
newDemod->setDemodulatorType(type);
|
||||||
|
newDemod->setBandwidth(bandwidth);
|
||||||
|
newDemod->setFrequency(freq);
|
||||||
|
newDemod->updateLabel(freq);
|
||||||
|
if (squelch_enabled) {
|
||||||
|
newDemod->setSquelchEnabled(true);
|
||||||
|
newDemod->setSquelchLevel(squelch_level);
|
||||||
|
}
|
||||||
|
if (stereo) {
|
||||||
|
newDemod->setStereo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool found_device = false;
|
||||||
|
std::map<int, RtAudio::DeviceInfo>::iterator i;
|
||||||
|
for (i = outputDevices.begin(); i != outputDevices.end(); i++) {
|
||||||
|
if (i->second.name == output_device) {
|
||||||
|
newDemod->setOutputDevice(i->first);
|
||||||
|
found_device = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found_device) {
|
||||||
|
std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output.";
|
||||||
|
}
|
||||||
|
|
||||||
|
newDemod->run();
|
||||||
|
|
||||||
|
wxGetApp().bindDemodulator(newDemod);
|
||||||
|
|
||||||
|
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
||||||
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
||||||
std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
|
std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
|
||||||
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
|
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
|
||||||
@ -381,4 +435,5 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentSessionFile = fileName;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#define wxID_RT_AUDIO_DEVICE 1000
|
#define wxID_RT_AUDIO_DEVICE 1000
|
||||||
#define wxID_SET_FREQ_OFFSET 2001
|
#define wxID_SET_FREQ_OFFSET 2001
|
||||||
|
#define wxID_RESET 2002
|
||||||
|
|
||||||
// Define a new frame type
|
// Define a new frame type
|
||||||
class AppFrame: public wxFrame {
|
class AppFrame: public wxFrame {
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#define DEFAULT_FFT_SIZE 2048
|
#define DEFAULT_FFT_SIZE 2048
|
||||||
|
|
||||||
//#define DEFAULT_FREQ 98900000
|
#define DEFAULT_FREQ 100000000
|
||||||
#define DEFAULT_FREQ 132000000
|
|
||||||
#define AUDIO_FREQUENCY 44100
|
#define AUDIO_FREQUENCY 44100
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -213,7 +213,9 @@ float DemodulatorInstance::getSquelchLevel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setOutputDevice(int device_id) {
|
void DemodulatorInstance::setOutputDevice(int device_id) {
|
||||||
if (audioThread) {
|
if (!active) {
|
||||||
|
audioThread->setInitOutputDevice(device_id);
|
||||||
|
} else if (audioThread) {
|
||||||
AudioThreadCommand command;
|
AudioThreadCommand command;
|
||||||
command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE;
|
command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE;
|
||||||
command.int_value = device_id;
|
command.int_value = device_id;
|
||||||
@ -232,7 +234,12 @@ void DemodulatorInstance::checkBandwidth() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setDemodulatorType(int demod_type_in) {
|
void DemodulatorInstance::setDemodulatorType(int demod_type_in) {
|
||||||
if (demodulatorThread && threadQueueControl) {
|
if (!active) {
|
||||||
|
currentDemodType = demod_type_in;
|
||||||
|
checkBandwidth();
|
||||||
|
demodulatorPreThread->getParams().demodType = currentDemodType;
|
||||||
|
demodulatorThread->setDemodulatorType(currentDemodType);
|
||||||
|
} else if (demodulatorThread && threadQueueControl) {
|
||||||
DemodulatorThreadControlCommand command;
|
DemodulatorThreadControlCommand command;
|
||||||
command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE;
|
command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE;
|
||||||
currentDemodType = demod_type_in;
|
currentDemodType = demod_type_in;
|
||||||
@ -247,7 +254,11 @@ int DemodulatorInstance::getDemodulatorType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorInstance::setBandwidth(int bw) {
|
void DemodulatorInstance::setBandwidth(int bw) {
|
||||||
if (demodulatorPreThread && threadQueueCommand) {
|
if (!active) {
|
||||||
|
currentBandwidth = bw;
|
||||||
|
checkBandwidth();
|
||||||
|
demodulatorPreThread->getParams().bandwidth = currentBandwidth;
|
||||||
|
} else if (demodulatorPreThread && threadQueueCommand) {
|
||||||
DemodulatorThreadCommand command;
|
DemodulatorThreadCommand command;
|
||||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH;
|
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH;
|
||||||
currentBandwidth = bw;
|
currentBandwidth = bw;
|
||||||
@ -255,7 +266,6 @@ void DemodulatorInstance::setBandwidth(int bw) {
|
|||||||
command.llong_value = currentBandwidth;
|
command.llong_value = currentBandwidth;
|
||||||
threadQueueCommand->push(command);
|
threadQueueCommand->push(command);
|
||||||
}
|
}
|
||||||
demodulatorPreThread->getParams().bandwidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DemodulatorInstance::getBandwidth() {
|
int DemodulatorInstance::getBandwidth() {
|
||||||
@ -269,7 +279,10 @@ void DemodulatorInstance::setFrequency(long long freq) {
|
|||||||
if ((freq - getBandwidth() / 2) <= 0) {
|
if ((freq - getBandwidth() / 2) <= 0) {
|
||||||
freq = getBandwidth() / 2;
|
freq = getBandwidth() / 2;
|
||||||
}
|
}
|
||||||
if (demodulatorPreThread && threadQueueCommand) {
|
if (!active) {
|
||||||
|
currentFrequency = freq;
|
||||||
|
demodulatorPreThread->getParams().frequency = currentFrequency;
|
||||||
|
} else if (demodulatorPreThread && threadQueueCommand) {
|
||||||
DemodulatorThreadCommand command;
|
DemodulatorThreadCommand command;
|
||||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY;
|
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY;
|
||||||
currentFrequency = freq;
|
currentFrequency = freq;
|
||||||
|
@ -29,6 +29,7 @@ DemodulatorInstance *DemodulatorMgr::newThread() {
|
|||||||
void DemodulatorMgr::terminateAll() {
|
void DemodulatorMgr::terminateAll() {
|
||||||
while (demods.size()) {
|
while (demods.size()) {
|
||||||
DemodulatorInstance *d = demods.back();
|
DemodulatorInstance *d = demods.back();
|
||||||
|
wxGetApp().removeDemodulator(d);
|
||||||
deleteThread(d);
|
deleteThread(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,8 +55,8 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
|||||||
|
|
||||||
if (i != demods.end()) {
|
if (i != demods.end()) {
|
||||||
demods.erase(i);
|
demods.erase(i);
|
||||||
demod->terminate();
|
|
||||||
}
|
}
|
||||||
|
demod->terminate();
|
||||||
|
|
||||||
demods_deleted.push_back(demod);
|
demods_deleted.push_back(demod);
|
||||||
|
|
||||||
|
@ -130,9 +130,8 @@ void SDRPostThread::threadMain() {
|
|||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
||||||
DemodulatorInstance *demod = *i;
|
DemodulatorInstance *demod = *i;
|
||||||
|
if (demod->getFrequency() != data_in->frequency
|
||||||
if (demod->getParams().frequency != data_in->frequency
|
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) {
|
||||||
&& abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
activeDemods++;
|
activeDemods++;
|
||||||
@ -165,8 +164,8 @@ void SDRPostThread::threadMain() {
|
|||||||
DemodulatorInstance *demod = *i;
|
DemodulatorInstance *demod = *i;
|
||||||
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
|
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
|
||||||
|
|
||||||
if (demod->getParams().frequency != data_in->frequency
|
if (demod->getFrequency() != data_in->frequency
|
||||||
&& abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) {
|
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) {
|
||||||
if (demod->isActive()) {
|
if (demod->isActive()) {
|
||||||
demod->setActive(false);
|
demod->setActive(false);
|
||||||
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
|
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user