2014-11-12 21:55:11 -05:00
|
|
|
#include "ScopeCanvas.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include "AppFrame.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint)
|
|
|
|
EVT_IDLE(ScopeCanvas::OnIdle)
|
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) :
|
|
|
|
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
|
2015-04-22 22:54:48 -04:00
|
|
|
wxFULL_REPAINT_ON_RESIZE), parent(parent), stereo(false), ppmMode(false) {
|
2014-11-12 21:55:11 -05:00
|
|
|
|
|
|
|
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeCanvas::~ScopeCanvas() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
void ScopeCanvas::setWaveformPoints(std::vector<float> &waveform_points_in) {
|
|
|
|
waveform_points = waveform_points_in;
|
|
|
|
}
|
|
|
|
|
2014-12-29 00:24:10 -05:00
|
|
|
void ScopeCanvas::setStereo(bool state) {
|
|
|
|
stereo = state;
|
2014-12-26 23:28:18 -05:00
|
|
|
}
|
|
|
|
|
2014-12-31 21:31:37 -05:00
|
|
|
void ScopeCanvas::setDeviceName(std::string device_name) {
|
|
|
|
deviceName = device_name;
|
|
|
|
deviceName.append(" ");
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:54:48 -04:00
|
|
|
void ScopeCanvas::setPPMMode(bool ppmMode) {
|
|
|
|
this->ppmMode = ppmMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScopeCanvas::getPPMMode() {
|
|
|
|
return ppmMode;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
|
|
|
wxPaintDC dc(this);
|
2015-02-10 23:49:34 -05:00
|
|
|
#ifdef __APPLE__ // force half-rate?
|
|
|
|
glFinish();
|
|
|
|
#endif
|
2014-11-12 21:55:11 -05:00
|
|
|
const wxSize ClientSize = GetClientSize();
|
|
|
|
|
2015-01-22 22:14:00 -05:00
|
|
|
if (!wxGetApp().getAudioVisualQueue()->empty()) {
|
|
|
|
AudioThreadInput *demodAudioData;
|
|
|
|
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
|
2015-05-28 18:30:53 -04:00
|
|
|
|
|
|
|
int iMax = demodAudioData?demodAudioData->data.size():0;
|
|
|
|
|
2015-05-27 23:22:19 -04:00
|
|
|
if (demodAudioData && iMax) {
|
|
|
|
if (waveform_points.size() != iMax * 2) {
|
|
|
|
waveform_points.resize(iMax * 2);
|
2015-01-22 22:14:00 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 23:22:19 -04:00
|
|
|
demodAudioData->busy_update.lock();
|
|
|
|
|
|
|
|
for (int i = 0; i < iMax; i++) {
|
2015-01-22 22:14:00 -05:00
|
|
|
waveform_points[i * 2 + 1] = demodAudioData->data[i] * 0.5f;
|
|
|
|
waveform_points[i * 2] = ((double) i / (double) iMax);
|
|
|
|
}
|
|
|
|
|
2015-05-27 23:22:19 -04:00
|
|
|
demodAudioData->busy_update.unlock();
|
|
|
|
|
2015-01-22 22:14:00 -05:00
|
|
|
setStereo(demodAudioData->channels == 2);
|
|
|
|
} else {
|
|
|
|
std::cout << "Incoming Demodulator data empty?" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
glContext->SetCurrent(*this);
|
2015-02-09 20:49:21 -05:00
|
|
|
initGLExtensions();
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
|
|
|
|
2014-12-26 23:28:18 -05:00
|
|
|
glContext->DrawBegin();
|
2015-04-22 22:54:48 -04:00
|
|
|
glContext->Plot(waveform_points, stereo, ppmMode);
|
2014-12-31 21:31:37 -05:00
|
|
|
if (!deviceName.empty()) {
|
|
|
|
glContext->DrawDeviceName(deviceName);
|
|
|
|
}
|
2014-12-26 23:28:18 -05:00
|
|
|
glContext->DrawEnd();
|
2014-11-12 21:55:11 -05:00
|
|
|
|
2014-12-31 21:31:37 -05:00
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeCanvas::OnIdle(wxIdleEvent &event) {
|
2014-11-25 22:51:14 -05:00
|
|
|
Refresh(false);
|
2014-11-12 21:55:11 -05:00
|
|
|
}
|