js8call/plotter.cpp
Jordan Sherer c24e931f09 Squashed commit of the following:
commit 0d6833b23da2519155ee93b98b4144240b356730
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 14:06:47 2019 -0400

    Bump version

commit 17705fcff6a22529f3dec45aa95cad90feb78c63
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 10:36:03 2019 -0400

    Updated configration labeling for idle timeout

commit a9f8aa9549c1c6b62201a6c102d91649ee17b9a5
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 10:07:11 2019 -0400

    Decoder params tests

commit 94e524741020fd8b3925233a189cedf0a8a282cc
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 21:24:23 2019 -0400

    Fixed decoder bug that crashed the software

commit 4fdbfc8d9082e0f52513a5c215489b13558972f9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 21:02:52 2019 -0400

    Decoder params tweak

commit 1e25ac41d442372f09b254d957e0d9e31773254e
Merge: 97a0fb5 552cd7f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 18:17:40 2019 -0400

    Merge branch 'fortran-cleanup' of bitbucket.org:widefido/js8call-private into fortran-cleanup

commit 97a0fb51b37c24e2638400dc5694fc4e988ae4f2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 18:15:25 2019 -0400

    Heartbeat as a mode does not work if slow mode does not work. Tabling this idea for now.

commit 552cd7fe5fc81c712b57b5f3ea79599177e53f69
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 23:35:14 2019 +0000

    js8_params.f90 edited online with Bitbucket

commit 7c9e960b863148a4ecbca4f61584536471623ea2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:28:52 2019 -0400

    Do not randomize offset at startup

commit cff7b90dbb9aada2944e668a9bcf078470af4608
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:20:19 2019 -0400

    Slow label for button

commit 977145dee89ccd7da4d43ce0bc2f9b79243aa200
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:17:36 2019 -0400

    Experimental slow mode

commit 27c128e0b327e1c077a9b49e11750bef2f3c26eb
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 15:26:01 2019 -0400

    HBs are Normal

commit 89792f91abf22dcd7c512bf7362f5e2e1cb36374
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 14:16:27 2019 -0400

    Update heartbeat UI for more clarity

commit f5cebbcdabe37d90b75ca7e8d1675a553e107c83
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 11:58:53 2019 -0400

    Optimize decode params

commit b14003bb34d93f9e93d7d4ad4241d619963c3a65
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 11:30:00 2019 -0400

    Shrink speed column for Joe ;)

commit 35f4446146efc9fd7044af3b56b0b93664238b24
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 10:54:28 2019 -0400

    Fixed fast mode decoder for directed messages

commit 64212acc30dd360348a72b354899a5b0de28aa83
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 10:05:11 2019 -0400

    Simplified decoder callbacks

commit a026766517d282a3fda0258356f6f22fee2a916f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 09:50:33 2019 -0400

    Commentary

commit 9d28b1ff5bd5cda7a04028218a01639e3902bf7b
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 23:33:22 2019 -0400

    Let's experiment with a new UI for HB

commit a013d66d8b8d16cc941a14eb76af2ce23b7bb6d5
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 21:44:26 2019 -0400

    31.25 baud experiment

commit 0671458bf588dd94710c5ba34f20695e13a28d31
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 15:31:43 2019 -0400

    Added basic foundation for slow mode, coming soon.

commit 8b9aed6e29b093e8fb736ebdbdf0fbe12a820e8e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 09:59:08 2019 -0400

    Display SPEED+AUTO

commit 5f5af250c1c5b610e8969b32c01654d3467f0973
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Sep 1 09:45:39 2019 -0400

    Added mode speed option to the activity tables

commit 82fa0335fdd41f0a578149e0211d6307293c739d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 23:14:07 2019 -0400

    Remember mode speed setting

commit 79ec805b223099bb4d552dc612a6c97a8982525e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 21:14:04 2019 -0400

    Remove unused sync vars

commit fc52dfcc320e59f6c7ca58ba277cb70469419587
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 21:12:11 2019 -0400

    Timing delta max

commit 62b8fc5054d3611d40d7441d57d695df594b8446
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 17:14:08 2019 -0400

    Fast modes optionally can use huff encoding for data... we'll see which is best

commit 44c357aff3e1c6687e93fb843917bd420888b397
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 17:03:21 2019 -0400

    Added ability to use a different message packing algorithm for fast modes

commit e075a078eb75509ef690e6c78c0e797ada569b94
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 16:18:14 2019 -0400

    Fixed symbol offset in sync code for turbo mode

commit a130b5d4a594e9bceece003be0ba72abb05a9f90
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 16:09:27 2019 -0400

    Added WPM to menu

commit 98cacab7bfc243492b6dec703d216d378cc3d34d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 23:18:58 2019 -0400

    Key eater

commit eef58e2c88d010c7f3917a111243eae744a425c3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 16:07:31 2019 -0400

    Reorganizing js8dec for better understanding and less confusion between it and JS8b

commit 08c14f966e1cda836ca90a8bd1ccd5ae68ec8dd7
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 14:20:52 2019 -0400

    Do no expose relay and messaging to fast and turbo modes

commit c605a31c266866f78eb043812af837ead6442ede
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 12:02:41 2019 -0400

    Do not allow mode speed changes if transmitting

commit add062e657a5215f9a4a1ae3ee82063aa85cf0e4
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 23:02:31 2019 -0400

    Fixed bug where tones were not generated with the correct costas arrays...causing really poor synchronization and failed decodes. I'm surprised it worked at all :P

commit cd492b5dd9fd62b5518a5711a1ef8ec522ea08fe
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 21:56:45 2019 -0400

    Back to 20 baud. It has the best decodability, imho

commit a2266cd00b8bd14c77bdbc8fc18818689e969858
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 14:27:29 2019 -0400

    Back to 20 baud with some decoder optimizations

commit 86413042e75873585bcb40236da67f2d64870859
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 23:04:47 2019 -0400

    Try 24 baud

commit a6704162b37d1c0704f43a64ab6b8a0a6e3c1cba
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 17:09:12 2019 -0400

    Fixed legacy compiler issue with mode text

commit 2fdbcc12e5f0c8cc8062c745af0930db4472cd9c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 10:17:23 2019 -0400

    Function for determining current mode

commit 82e70345baa665418a51307f0309f2b7dcb3d3b7
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 09:59:26 2019 -0400

    Don't write the log

commit d3380e01676537f4bab9a05932cb5a59de3cf45f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 09:59:03 2019 -0400

    Fixed issues with turbo decode with partial sync code

commit c2a8ebb8f305e67fcb2597d25e062663722a0d73
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 03:30:02 2019 -0400

    Working through better decoding of fast modes

commit 7ca93f8c6a7970559577c9dfd833eb92a1b91a0c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 23:23:34 2019 -0400

    Trying for better TX/RX delays

commit b99271b4feaa7e41c7b88219cb3c7d43dbe7b48d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:57:02 2019 -0400

    Added flags to easily enable/disable the faster modes

commit 32d913a7f7d3deb6a8d66651d51673ec451d2500
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:43:20 2019 -0400

    Added mode button

commit c7cc90548591638bfc5a4a8895036dd67b155aaa
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:17:42 2019 -0400

    Updated start delay for the modes

commit b91dc63f92101cd8b6adbf9de588c4ffd10bfc10
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:55:57 2019 -0400

    Late threshold for turbo mode is 1/2 the delay

commit 09ec95fab1307e65aa9bd462d60525afd2a770fe
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:52:55 2019 -0400

    Renamed mode menu items

commit a4e5a9ed9bce66c625e4df1182cd3c91a6ba44dd
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:50:45 2019 -0400

    Only enable networking and autoreply for normal JS8

commit fc558d5823c46fc5d3dc651610b7af43e7519165
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:14:12 2019 -0400

    Fixed spot button tooltip

commit 9a9965d543540a2d215bcbfff34934846afe507a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 10:04:31 2019 -0400

    Working selectable decoder

commit 4a9cdbc52dae1d857c102d8777f1aded4fac87bb
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 20:53:30 2019 -0400

    Mode menu selection of the submodes. Turbo decoder disabled right now. Naming to be determined

commit a3acbf7c243f7aa740c229ae178fffa528e68933
Merge: 8ea554d daa8cc2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 13:29:14 2019 -0400

    Merge branch 'ft8call-develop' into fortran-cleanup

commit 8ea554d79904c9b2f3ccf1027bf4d41fb25e6fe3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 09:53:21 2019 -0400

    Use indx variable instead of computed

commit 067e65500328133f921b172e515babbcc0df831b
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 22:41:00 2019 -0400

    Make it easier to flip between modes

commit a544a7635201072f3ea20483353edf2e79dc813d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 21:18:46 2019 -0400

    Fixed sync issues with multi costas. Added log statements for future debugging

commit a8f3ead932017ae7d98fdb9a779bf3bb44bd395d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 15:54:59 2019 -0400

    Playing around with different costas arrays

commit fa89fe11a15d26abadd5102c8980620cfeffccd9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 15:51:45 2019 -0400

    Added reference to 7x7 costas arrays

commit 2417ebed6139534214f76ce94bdf1f54a966760a
Merge: 6011f1e 32fcabd
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 23:41:39 2019 -0400

    Merge branch 'ft8call-develop' into fortran-cleanup

commit 6011f1e807b1814399477d3c172db46831a090c6
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 23:35:42 2019 -0400

    Back to 10 baud. Update late threshold to be computed to 3/4 dead air time.

commit 41d3995861226f7208b2773430010a48abc125c1
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 15:36:12 2019 -0400

    Trying out 20 baud

commit a8d77e9e5b98f3f0bf19f68b53199b5952e8aaad
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 15:23:36 2019 -0400

    Fixed up sync quarter symbol constant

commit 7050722436b9c629ea00649e6b3c81d7af7be82a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 14:43:48 2019 -0400

    Computed symbol stop

commit f130fe87abdccbabd2e71f2771b789c7f46d57ca
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 20:56:59 2019 -0400

    Added reference to 7x7 costas arrays

commit 53e91858f5a4e9ce78c38ef65c77e87f1903c058
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 16:34:51 2019 -0400

    Back to 10 baud

commit 1ae79d566ebd9a40ad3cf4a07977ef0e09615d91
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 15:14:41 2019 -0400

    Testing 31.25 baud

commit 7e033c28ae090d6c3f5a63fa651ee51c3243d61c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 15:14:17 2019 -0400

    Experimenting with a few different baudrates

commit 050e24ad3a040924ded6d641004ae63da47e4251
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 12:25:50 2019 -0400

    Added ldpcsim for js8

commit d309a75d860e39737dec732560432a191290b258
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 22 22:42:11 2019 -0400

    Experimental submode switching

commit 74f72bb24a22631b8b69942ea0633bb0564b8aa3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 22 22:41:53 2019 -0400

    Allow switching decoders based on submode

commit f8740a23b27e80fa53350e140d4638a27cd6e975
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 23:43:18 2019 -0400

    Initial spike of js8 fortran code

commit 31625316639f79246b4a2e3d0cea4507bf0547f9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 23:09:00 2019 -0400

    Remove fix contest message

commit c0e0862afa8ae2d47e9577562399b8c9bc929c6a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 21:05:05 2019 -0400

    Cleanup unused text files and batch files

commit 1b3aa55869f0c310e6c911a7cbb3fe269bc7421a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 21:00:38 2019 -0400

    Removed fast_decode and dx

commit 49e5cabff25c13620a9d2c6fc6ddd4988f1be217
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 20:54:39 2019 -0400

    Cleaning up msk stuff

commit 8bde6f391f4b23d2a2e9d55685d96bc647a462f6
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 20:44:39 2019 -0400

    Initial cleanup pass of qra, ftrsd, and wsprd
2019-09-05 14:07:24 -04:00

819 lines
22 KiB
C++

#include "plotter.h"
#include <math.h>
#include <QDebug>
#include "commons.h"
#include "moc_plotter.cpp"
#include <fstream>
#include <iostream>
#include "DriftingDateTime.h"
#include "varicode.h"
#define MAX_SCREENSIZE 2048
extern "C" {
void flat4_(float swide[], int* iz, int* nflatten);
void plotsave_(float swide[], int* m_w , int* m_h1, int* irow);
}
CPlotter::CPlotter(QWidget *parent) : //CPlotter Constructor
QFrame {parent},
m_set_freq_action {new QAction {tr ("&Set Rx && Tx Offset"), this}},
m_bScaleOK {false},
m_bReference {false},
m_bReference0 {false},
m_fSpan {2000.0},
m_plotZero {0},
m_plotGain {0},
m_plot2dGain {0},
m_plot2dZero {0},
m_nSubMode {0},
m_turbo {false},
m_Running {false},
m_paintEventBusy {false},
m_fftBinWidth {1500.0/2048.0},
m_dialFreq {0.},
m_sum {},
m_dBStepSize {10},
m_FreqUnits {1},
m_hdivs {HORZ_DIVS},
m_line {0},
m_fSample {12000},
m_nsps {6912},
m_Percent2DScreen {0}, //percent of screen used for 2D display
m_Percent2DScreen0 {0},
m_rxFreq {1020},
m_txFreq {0},
m_startFreq {0},
m_lastMouseX {-1},
m_menuOpen {false}
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setFocusPolicy(Qt::StrongFocus);
setAttribute(Qt::WA_PaintOnScreen,false);
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, false);
setAttribute(Qt::WA_NoSystemBackground, true);
m_bReplot=false;
setMouseTracking(true);
}
CPlotter::~CPlotter() { } // Destructor
QSize CPlotter::minimumSizeHint() const
{
return QSize(50, 50);
}
QSize CPlotter::sizeHint() const
{
return QSize(180, 180);
}
void CPlotter::resizeEvent(QResizeEvent* ) //resizeEvent()
{
if(!size().isValid()) return;
if( m_Size != size() or (m_bReference != m_bReference0) or
m_Percent2DScreen != m_Percent2DScreen0) {
m_Size = size();
m_w = m_Size.width();
m_h = m_Size.height();
m_h2 = m_Percent2DScreen*m_h/100.0;
if(m_h2>m_h-30) m_h2=m_h-30;
if(m_bReference) m_h2=m_h-30;
if(m_h2<1) m_h2=1;
m_h1=m_h-m_h2;
// m_line=0;
m_DialOverlayPixmap = QPixmap(m_Size.width(), m_h);
m_DialOverlayPixmap.fill(Qt::transparent);
m_HoverOverlayPixmap = QPixmap(m_Size.width(), m_h);
m_HoverOverlayPixmap.fill(Qt::transparent);
m_2DPixmap = QPixmap(m_Size.width(), m_h2);
m_2DPixmap.fill(Qt::black);
m_WaterfallPixmap = QPixmap(m_Size.width(), m_h1);
m_OverlayPixmap = QPixmap(m_Size.width(), m_h2);
m_OverlayPixmap.fill(Qt::black);
m_WaterfallPixmap.fill(Qt::black);
m_2DPixmap.fill(Qt::black);
m_ScalePixmap = QPixmap(m_w,30);
m_ScalePixmap.fill(Qt::white);
m_Percent2DScreen0 = m_Percent2DScreen;
}
DrawOverlay();
}
void CPlotter::paintEvent(QPaintEvent *) // paintEvent()
{
if(m_paintEventBusy) return;
m_paintEventBusy=true;
QPainter painter(this);
painter.drawPixmap(0,0,m_ScalePixmap);
painter.drawPixmap(0,30,m_WaterfallPixmap);
painter.drawPixmap(0,m_h1,m_2DPixmap);
int x = XfromFreq(m_rxFreq);
painter.drawPixmap(x,0,m_DialOverlayPixmap);
if(m_lastMouseX >= 0 && m_lastMouseX != x){
painter.drawPixmap(m_lastMouseX, 0, m_HoverOverlayPixmap);
}
m_paintEventBusy=false;
}
void CPlotter::draw(float swide[], bool bScroll, bool bRed)
{
int j,j0;
static int ktop=0;
float y,y2,ymin;
double fac = sqrt(m_binsPerPixel*m_waterfallAvg/15.0);
double gain = fac*pow(10.0,0.015*m_plotGain);
double gain2d = pow(10.0,0.02*(m_plot2dGain));
if(m_bReference != m_bReference0) resizeEvent(NULL);
m_bReference0=m_bReference;
//move current data down one line (must do this before attaching a QPainter object)
if(bScroll and !m_bReplot) m_WaterfallPixmap.scroll(0,1,0,0,m_w,m_h1);
QPainter painter1(&m_WaterfallPixmap);
m_2DPixmap = m_OverlayPixmap.copy(0,0,m_w,m_h2);
QPainter painter2D(&m_2DPixmap);
if(!painter2D.isActive()) return;
QFont Font("Arial");
Font.setPointSize(12);
Font.setWeight(QFont::Normal);
painter2D.setFont(Font);
if(m_bLinearAvg) {
painter2D.setPen(Qt::yellow);
} else if(m_bReference) {
painter2D.setPen(Qt::blue);
} else {
painter2D.setPen(Qt::green);
}
static QPoint LineBuf[MAX_SCREENSIZE];
static QPoint LineBuf2[MAX_SCREENSIZE];
j=0;
j0=int(m_startFreq/m_fftBinWidth + 0.5);
int iz=XfromFreq(5000.0);
int jz=iz*m_binsPerPixel;
m_fMax=FreqfromX(iz);
if(bScroll and swide[0]<1.e29) {
flat4_(swide,&iz,&m_Flatten);
if(!m_bReplot) flat4_(&dec_data.savg[j0],&jz,&m_Flatten);
}
ymin=1.e30;
if(swide[0]>1.e29 and swide[0]< 1.5e30) painter1.setPen(Qt::green); // horizontal line
if(swide[0]>1.4e30) painter1.setPen(Qt::yellow);
if(!m_bReplot) {
m_j=0;
int irow=-1;
plotsave_(swide,&m_w,&m_h1,&irow);
}
for(int i=0; i<iz; i++) {
y=swide[i];
if(y<ymin) ymin=y;
int y1 = 10.0*gain*y + m_plotZero;
if (y1<0) y1=0;
if (y1>254) y1=254;
if (swide[i]<1.e29) painter1.setPen(g_ColorTbl[y1]);
painter1.drawPoint(i,m_j);
}
m_line++;
float y2min=1.e30;
float y2max=-1.e30;
for(int i=0; i<iz; i++) {
y=swide[i] - ymin;
y2=0;
if(m_bCurrent) y2 = gain2d*y + m_plot2dZero; //Current
if(bScroll) {
float sum=0.0;
int j=j0+m_binsPerPixel*i;
for(int k=0; k<m_binsPerPixel; k++) {
sum+=dec_data.savg[j++];
}
m_sum[i]=sum;
}
if(m_bCumulative) y2=gain2d*(m_sum[i]/m_binsPerPixel + m_plot2dZero);
if(m_Flatten==0) y2 += 15; //### could do better! ###
if(m_bLinearAvg) { //Linear Avg (yellow)
float sum=0.0;
int j=j0+m_binsPerPixel*i;
for(int k=0; k<m_binsPerPixel; k++) {
sum+=spectra_.syellow[j++];
}
y2=gain2d*sum/m_binsPerPixel + m_plot2dZero;
}
if(m_bReference) { //Reference (red)
float df_ref=12000.0/6912.0;
int j=FreqfromX(i)/df_ref + 0.5;
y2=spectra_.ref[j] + m_plot2dZero;
// if(gain2d>1.5) y2=spectra_.filter[j] + m_plot2dZero;
}
if(i==iz-1) {
painter2D.drawPolyline(LineBuf,j);
if(m_mode=="QRA64") {
painter2D.setPen(Qt::red);
painter2D.drawPolyline(LineBuf2,ktop);
}
}
LineBuf[j].setX(i);
LineBuf[j].setY(int(0.9*m_h2-y2*m_h2/70.0));
if(y2<y2min) y2min=y2;
if(y2>y2max) y2max=y2;
j++;
}
if(m_bReplot) return;
if(swide[0]>1.0e29) m_line=0;
if(m_line == painter1.fontMetrics ().height ()) {
painter1.setPen(Qt::white);
QString t;
qint64 ms = DriftingDateTime::currentMSecsSinceEpoch() % 86400000;
int n=(ms/1000) % m_TRperiod;
QDateTime t1=DriftingDateTime::currentDateTimeUtc().addSecs(-n);
if(m_TRperiod < 60) {
t=t1.toString("hh:mm:ss") + " " + m_rxBand;
} else {
t=t1.toString("hh:mm") + " " + m_rxBand;
}
painter1.drawText (5, painter1.fontMetrics ().ascent (), t);
}
if(m_mode=="JT4" or m_mode=="QRA64") {
QPen pen3(Qt::yellow); //Mark freqs of JT4 single-tone msgs
painter2D.setPen(pen3);
Font.setWeight(QFont::Bold);
painter2D.setFont(Font);
int x1=XfromFreq(m_rxFreq);
y=0.2*m_h2;
painter2D.drawText(x1-4,y,"T");
x1=XfromFreq(m_rxFreq+250);
painter2D.drawText(x1-4,y,"M");
x1=XfromFreq(m_rxFreq+500);
painter2D.drawText(x1-4,y,"R");
x1=XfromFreq(m_rxFreq+750);
painter2D.drawText(x1-4,y,"73");
}
if(bRed) {
std::ifstream f;
f.open(m_redFile.toLatin1());
if(f) {
int x,y;
float freq,sync;
float slimit=6.0;
QPen pen0(Qt::red,1);
painter1.setPen(pen0);
for(int i=0; i<99999; i++) {
f >> freq >> sync;
if(f.eof()) break;
x=XfromFreq(freq);
y=(sync-slimit)*3.0;
if(y>0) {
if(y>15.0) y=15.0;
if(x>=0 and x<=m_w) {
painter1.setPen(pen0);
painter1.drawLine(x,0,x,y);
}
}
}
f.close();
}
// m_bDecodeFinished=false;
}
update(); //trigger a new paintEvent
m_bScaleOK=true;
}
void CPlotter::drawRed(int ia, int ib, float swide[])
{
m_ia=ia;
m_ib=ib;
draw(swide,false,true);
}
void CPlotter::replot()
{
float swide[m_w];
m_bReplot=true;
for(int irow=0; irow<m_h1; irow++) {
m_j=irow;
plotsave_(swide,&m_w,&m_h1,&irow);
draw(swide,false,false);
}
update(); //trigger a new paintEvent
m_bReplot=false;
}
void CPlotter::DrawOverlay() //DrawOverlay()
{
if(m_OverlayPixmap.isNull()) return;
if(m_WaterfallPixmap.isNull()) return;
int w = m_WaterfallPixmap.width();
int x,y,x1,x2,x3,x4,x5,x6;
float pixperdiv;
double df = m_binsPerPixel*m_fftBinWidth;
QRect rect;
QPen penOrange(QColor(255,165,0),3);
QPen penBlue(QColor(149, 165, 166), 3); //Mark Tol range with green line
QPen penGreen(Qt::green, 3); //Mark Tol range with green line
QPen penRed(Qt::red, 3); //Mark Tx freq with red
QPen penYellow(QColor(243, 156, 18), 3); //Mark band block freq with this pen
QPainter painter(&m_OverlayPixmap);
painter.initFrom(this);
QLinearGradient gradient(0, 0, 0 ,m_h2); //fill background with gradient
gradient.setColorAt(1, Qt::black);
gradient.setColorAt(0, Qt::darkBlue);
painter.setBrush(gradient);
painter.drawRect(0, 0, m_w, m_h2);
painter.setBrush(Qt::SolidPattern);
m_fSpan = w*df;
// int n=m_fSpan/10;
m_freqPerDiv=10;
if(m_fSpan>100) m_freqPerDiv=20;
if(m_fSpan>250) m_freqPerDiv=50;
if(m_fSpan>500) m_freqPerDiv=100;
if(m_fSpan>1000) m_freqPerDiv=200;
if(m_fSpan>2500) m_freqPerDiv=500;
pixperdiv = m_freqPerDiv/df;
m_hdivs = w*df/m_freqPerDiv + 1.9999;
float xx0=float(m_startFreq)/float(m_freqPerDiv);
xx0=xx0-int(xx0);
int x0=xx0*pixperdiv+0.5;
for( int i=1; i<m_hdivs; i++) { //draw vertical grids
x = (int)((float)i*pixperdiv ) - x0;
if(x >= 0 and x<=m_w) {
painter.setPen(QPen(Qt::white, 1,Qt::DotLine));
painter.drawLine(x, 0, x , m_h2);
}
}
pixperdiv = (float)m_h2 / (float)VERT_DIVS;
painter.setPen(QPen(Qt::white, 1,Qt::DotLine));
for( int i=1; i<VERT_DIVS; i++) { //draw horizontal grids
y = (int)( (float)i*pixperdiv );
painter.drawLine(0, y, w, y);
}
QRect rect0;
QPainter painter0(&m_ScalePixmap);
painter0.initFrom(this);
//create Font to use for scales
QFont Font("Arial");
Font.setPointSize(12);
Font.setWeight(QFont::Normal);
painter0.setFont(Font);
painter0.setPen(Qt::black);
if(m_binsPerPixel < 1) m_binsPerPixel=1;
m_hdivs = w*df/m_freqPerDiv + 0.9999;
m_ScalePixmap.fill(Qt::white);
painter0.drawRect(0, 0, w, 30);
MakeFrequencyStrs();
//draw tick marks on upper scale
pixperdiv = m_freqPerDiv/df;
for( int i=0; i<m_hdivs; i++) { //major ticks
x = (int)((m_xOffset+i)*pixperdiv );
painter0.drawLine(x,18,x,30);
}
int minor=5;
if(m_freqPerDiv==200) minor=4;
for( int i=1; i<minor*m_hdivs; i++) { //minor ticks
x = i*pixperdiv/minor;
painter0.drawLine(x,22,x,30);
}
//draw frequency values
for( int i=0; i<=m_hdivs; i++) {
x = (int)((m_xOffset+i)*pixperdiv - pixperdiv/2);
if(int(x+pixperdiv/2) > 70) {
rect0.setRect(x,0, (int)pixperdiv, 20);
painter0.drawText(rect0, Qt::AlignHCenter|Qt::AlignVCenter,m_HDivText[i]);
}
}
float bw = 0;
if(m_nSubMode == Varicode::JS8CallNormal){
bw = 8.0*(double)RX_SAMPLE_RATE/(double)JS8A_SYMBOL_SAMPLES;
}
else if(m_nSubMode == Varicode::JS8CallFast){
bw = 8.0*(double)RX_SAMPLE_RATE/(double)JS8B_SYMBOL_SAMPLES;
}
else if(m_nSubMode == Varicode::JS8CallTurbo){
bw = 8.0*(double)RX_SAMPLE_RATE/(double)JS8C_SYMBOL_SAMPLES;
}
else if(m_nSubMode == Varicode::JS8CallUltra){
bw = 8.0*(double)RX_SAMPLE_RATE/(double)JS8D_SYMBOL_SAMPLES;
}
painter0.setPen(penGreen);
if(m_dialFreq>10.13 and m_dialFreq< 10.15 and m_mode.mid(0,4)!="WSPR") {
float f1=1.0e6*(10.1401 - m_dialFreq);
float f2=f1+200.0;
x1=XfromFreq(f1);
x2=XfromFreq(f2);
if(x1<=m_w and x2>=0) {
painter0.setPen(penOrange); //Mark WSPR sub-band orange
painter0.drawLine(x1,9,x2,9);
}
}
x1=XfromFreq(0);
x2=XfromFreq(500);
if(x1<=m_w and x2>0) {
painter0.setPen(penYellow); //Mark bottom of sub-band
painter0.drawLine(x1+1,26,x2-2,26);
painter0.drawLine(x1+1,28,x2-2,28);
}
x1=XfromFreq(3500);
x2=m_w;
if(x1<=m_w and x2>0) {
painter0.setPen(penYellow); //Mark top of sub-band
painter0.drawLine(x1+1,26,x2-2,26);
painter0.drawLine(x1+1,28,x2-2,28);
}
x1=XfromFreq(500);
x2=XfromFreq(1000);
if(x1<=m_w and x2>0) {
painter0.setPen(penBlue); //Mark ping range
painter0.drawLine(x1+1,26,x2-2,26);
painter0.drawLine(x1+1,28,x2-2,28);
}
if(m_mode=="FT8"){
int fwidth=XfromFreq(m_rxFreq+bw)-XfromFreq(m_rxFreq);
#if TEST_FOX_WAVE_GEN
int offset=XfromFreq(m_rxFreq+bw+TEST_FOX_WAVE_GEN_OFFSET)-XfromFreq(m_rxFreq+bw) + 4; // + 4 for the line padding
#endif
QPainter overPainter(&m_DialOverlayPixmap);
overPainter.initFrom(this);
overPainter.setCompositionMode(QPainter::CompositionMode_Source);
overPainter.fillRect(0, 0, m_Size.width(), m_h, Qt::transparent);
QPen thinRed(Qt::red, 1);
overPainter.setPen(thinRed);
overPainter.drawLine(0, 30, 0, m_h); // first slot, left line
overPainter.drawLine(fwidth + 1, 30, fwidth + 1, m_h); // first slot, right line
#if TEST_FOX_WAVE_GEN
if(m_turbo){
for(int i = 1; i < TEST_FOX_WAVE_GEN_SLOTS; i++){
overPainter.drawLine(i*(fwidth + offset), 30, i*(fwidth + offset), m_h); // n slot, left line
overPainter.drawLine(i*(fwidth + offset) + fwidth + 2, 30, i*(fwidth + offset) + fwidth + 2, m_h); // n slot, right line
}
}
#endif
overPainter.setPen(penRed);
overPainter.drawLine(0, 26, fwidth, 26); // first slot, top bar
overPainter.drawLine(0, 28, fwidth, 28); // first slot, top bar 2
#if TEST_FOX_WAVE_GEN
if(m_turbo){
for(int i = 1; i < TEST_FOX_WAVE_GEN_SLOTS; i++){
overPainter.drawLine(i*(fwidth + offset) + 1, 26, i*(fwidth + offset) + fwidth + 1, 26); // n slot, top bar
overPainter.drawLine(i*(fwidth + offset) + 1, 28, i*(fwidth + offset) + fwidth + 1, 28); // n slot, top bar 2
}
}
#endif
QPainter hoverPainter(&m_HoverOverlayPixmap);
hoverPainter.initFrom(this);
hoverPainter.setCompositionMode(QPainter::CompositionMode_Source);
hoverPainter.fillRect(0, 0, m_Size.width(), m_h, Qt::transparent);
hoverPainter.setPen(QPen(Qt::white));
hoverPainter.drawLine(0, 30, 0, m_h); // first slot, left line hover
hoverPainter.drawLine(fwidth, 30, fwidth, m_h); // first slot, right line hover
#if TEST_FOX_WAVE_GEN
if(m_turbo){
for(int i = 1; i < TEST_FOX_WAVE_GEN_SLOTS; i++){
hoverPainter.drawLine(i*(fwidth + offset), 30, i*(fwidth + offset), m_h); // n slot, left line
hoverPainter.drawLine(i*(fwidth + offset) + fwidth + 2, 30, i*(fwidth + offset) + fwidth + 2, m_h); // n slot, right line
}
}
#endif
#if DRAW_FREQ_OVERLAY
int f = FreqfromX(m_lastMouseX);
hoverPainter.setFont(Font);
hoverPainter.drawText(fwidth + 5, m_h, QString("%1").arg(f));
#endif
}
}
void CPlotter::MakeFrequencyStrs() //MakeFrequencyStrs
{
int f=(m_startFreq+m_freqPerDiv-1)/m_freqPerDiv;
f*=m_freqPerDiv;
m_xOffset=float(f-m_startFreq)/m_freqPerDiv;
for(int i=0; i<=m_hdivs; i++) {
m_HDivText[i].setNum(f);
f+=m_freqPerDiv;
}
}
int CPlotter::XfromFreq(float f) //XfromFreq()
{
// float w = m_WaterfallPixmap.width();
int x = int(m_w * (f - m_startFreq)/m_fSpan + 0.5);
if(x<0 ) return 0;
if(x>m_w) return m_w;
return x;
}
float CPlotter::FreqfromX(int x) //FreqfromX()
{
return float(m_startFreq + x*m_binsPerPixel*m_fftBinWidth);
}
void CPlotter::SetRunningState(bool running) //SetRunningState()
{
m_Running = running;
}
void CPlotter::setPlotZero(int plotZero) //setPlotZero()
{
m_plotZero=plotZero;
}
int CPlotter::plotZero() //PlotZero()
{
return m_plotZero;
}
void CPlotter::setPlotGain(int plotGain) //setPlotGain()
{
m_plotGain=plotGain;
}
int CPlotter::plotGain() //plotGain()
{
return m_plotGain;
}
int CPlotter::plot2dGain() //plot2dGain
{
return m_plot2dGain;
}
void CPlotter::setPlot2dGain(int n) //setPlot2dGain
{
m_plot2dGain=n;
update();
}
int CPlotter::plot2dZero() //plot2dZero
{
return m_plot2dZero;
}
void CPlotter::setPlot2dZero(int plot2dZero) //setPlot2dZero
{
m_plot2dZero=plot2dZero;
}
void CPlotter::setStartFreq(int f) //SetStartFreq()
{
m_startFreq=f;
resizeEvent(NULL);
update();
}
int CPlotter::startFreq() //startFreq()
{
return m_startFreq;
}
int CPlotter::plotWidth(){return m_WaterfallPixmap.width();} //plotWidth
void CPlotter::UpdateOverlay() {DrawOverlay();} //UpdateOverlay
void CPlotter::setDataFromDisk(bool b) {m_dataFromDisk=b;} //setDataFromDisk
void CPlotter::setRxRange(int fMin) //setRxRange
{
m_fMin=fMin;
}
void CPlotter::setBinsPerPixel(int n) //setBinsPerPixel
{
m_binsPerPixel = n;
DrawOverlay(); //Redraw scales and ticks
update(); //trigger a new paintEvent}
}
int CPlotter::binsPerPixel() //binsPerPixel
{
return m_binsPerPixel;
}
void CPlotter::setWaterfallAvg(int n) //setNavg
{
m_waterfallAvg = n;
}
void CPlotter::setRxFreq (int x) //setRxFreq
{
m_rxFreq = x; // x is freq in Hz
DrawOverlay();
update();
}
int CPlotter::rxFreq() {return m_rxFreq;} //rxFreq
void CPlotter::leaveEvent(QEvent *event)
{
m_lastMouseX = -1;
}
void CPlotter::wheelEvent(QWheelEvent *event){
auto delta = event->angleDelta();
if(delta.isNull()){
event->ignore();
return;
}
int newFreq = rxFreq();
int dir = delta.y() > 0 ? 1 : -1;
bool ctrl = (event->modifiers() & Qt::ControlModifier);
if(ctrl){
newFreq += dir;
} else {
newFreq = newFreq/10*10 + dir*10;
}
emit setFreq1 (newFreq, newFreq);
}
void CPlotter::mouseMoveEvent (QMouseEvent * event)
{
int x = event->x();
if(x < 0) x = 0;
if(x>m_Size.width()) x = m_Size.width();
m_lastMouseX = x;
#if DRAW_FREQ_OVERLAY
DrawOverlay();
#endif
update();
event->ignore();
}
void CPlotter::mouseReleaseEvent (QMouseEvent * event)
{
if (Qt::LeftButton == event->button ()) {
int x=event->x();
if(x<0) x=0;
if(x>m_Size.width()) x=m_Size.width();
bool ctrl = (event->modifiers() & Qt::ControlModifier);
bool shift = (event->modifiers() & Qt::ShiftModifier);
int newFreq = int(FreqfromX(x)+0.5);
int oldTxFreq = m_txFreq;
int oldRxFreq = m_rxFreq;
if (ctrl) {
emit setFreq1 (newFreq, newFreq);
} else if (shift) {
emit setFreq1 (oldRxFreq, newFreq);
} else {
emit setFreq1(newFreq,oldTxFreq);
}
int n=1;
if(ctrl) n+=100;
emit freezeDecode1(n);
}
else {
event->ignore (); // let parent handle
}
}
void CPlotter::mouseDoubleClickEvent (QMouseEvent * event)
{
if (Qt::LeftButton == event->button ()) {
bool ctrl = (event->modifiers() & Qt::ControlModifier);
int n=2;
if(ctrl) n+=100;
emit freezeDecode1(n);
}
else {
event->ignore (); // let parent handle
}
}
void CPlotter::setNsps(int ntrperiod, int nsps) //setNsps
{
m_TRperiod=ntrperiod;
m_nsps=nsps;
m_fftBinWidth=1500.0/2048.0;
if(m_nsps==15360) m_fftBinWidth=1500.0/2048.0;
if(m_nsps==40960) m_fftBinWidth=1500.0/6144.0;
if(m_nsps==82944) m_fftBinWidth=1500.0/12288.0;
if(m_nsps==252000) m_fftBinWidth=1500.0/32768.0;
DrawOverlay(); //Redraw scales and ticks
update(); //trigger a new paintEvent}
}
void CPlotter::setTxFreq(int n) //setTxFreq
{
m_txFreq=n;
DrawOverlay();
update();
}
void CPlotter::setMode(QString mode) //setMode
{
m_mode=mode;
}
void CPlotter::setSubMode(int n) //setSubMode
{
m_nSubMode=n;
}
void CPlotter::setModeTx(QString modeTx) //setModeTx
{
m_modeTx=modeTx;
}
int CPlotter::Fmax()
{
return m_fMax;
}
void CPlotter::setDialFreq(double d)
{
m_dialFreq=d;
DrawOverlay();
update();
}
void CPlotter::setRxBand(QString band)
{
m_rxBand=band;
DrawOverlay();
update();
}
void CPlotter::setTurbo(bool turbo)
{
m_turbo=turbo;
DrawOverlay();
update();
}
void CPlotter::setFlatten(bool b1, bool b2)
{
m_Flatten=0;
if(b1) m_Flatten=1;
if(b2) m_Flatten=2;
}
void CPlotter::setTol(int n) //setTol()
{
m_tol=n;
DrawOverlay();
}
void CPlotter::setColours(QVector<QColor> const& cl)
{
g_ColorTbl = cl;
}
void CPlotter::SetPercent2DScreen(int percent)
{
m_Percent2DScreen=percent;
resizeEvent(NULL);
update();
}
void CPlotter::setVHF(bool bVHF)
{
m_bVHF=bVHF;
}
void CPlotter::setRedFile(QString fRed)
{
m_redFile=fRed;
}