| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/channelmarker.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-26 09:58:07 +02:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | QRgb ChannelMarker::m_colorTable[] = { | 
					
						
							|  |  |  | 	qRgb(0xc0, 0x00, 0x00), | 
					
						
							|  |  |  | 	qRgb(0x00, 0xc0, 0x00), | 
					
						
							|  |  |  | 	qRgb(0x00, 0x00, 0xc0), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qRgb(0xc0, 0xc0, 0x00), | 
					
						
							|  |  |  | 	qRgb(0xc0, 0x00, 0xc0), | 
					
						
							|  |  |  | 	qRgb(0x00, 0xc0, 0xc0), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qRgb(0xc0, 0x60, 0x00), | 
					
						
							|  |  |  | 	qRgb(0xc0, 0x00, 0x60), | 
					
						
							|  |  |  | 	qRgb(0x60, 0x00, 0xc0), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qRgb(0x60, 0x00, 0x00), | 
					
						
							|  |  |  | 	qRgb(0x00, 0x60, 0x00), | 
					
						
							|  |  |  | 	qRgb(0x00, 0x00, 0x60), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qRgb(0x60, 0x60, 0x00), | 
					
						
							|  |  |  | 	qRgb(0x60, 0x00, 0x60), | 
					
						
							|  |  |  | 	qRgb(0x00, 0x60, 0x60), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	0 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | int ChannelMarker::m_nextColor = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ChannelMarker::ChannelMarker(QObject* parent) : | 
					
						
							|  |  |  | 	QObject(parent), | 
					
						
							|  |  |  | 	m_centerFrequency(0), | 
					
						
							|  |  |  | 	m_bandwidth(0), | 
					
						
							| 
									
										
										
										
											2017-03-16 11:49:14 +01:00
										 |  |  |     m_oppositeBandwidth(0), | 
					
						
							| 
									
										
										
										
											2015-05-12 21:50:02 +02:00
										 |  |  | 	m_lowCutoff(0), | 
					
						
							| 
									
										
										
										
											2015-05-11 03:27:31 +02:00
										 |  |  | 	m_sidebands(dsb), | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_visible(false), | 
					
						
							| 
									
										
										
										
											2015-05-11 11:03:01 +02:00
										 |  |  | 	m_highlighted(false), | 
					
						
							| 
									
										
										
										
											2017-03-16 00:39:49 +01:00
										 |  |  | 	m_color(m_colorTable[m_nextColor]), | 
					
						
							| 
									
										
										
										
											2017-08-23 23:43:11 +02:00
										 |  |  | 	m_movable(true), | 
					
						
							| 
									
										
										
										
											2017-08-26 06:38:28 +02:00
										 |  |  | 	m_fScaleDisplayType(FScaleDisplay_freq) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	++m_nextColor; | 
					
						
							|  |  |  | 	if(m_colorTable[m_nextColor] == 0) | 
					
						
							|  |  |  | 		m_nextColor = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | void ChannelMarker::emitChangedByAPI() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     emit changedByAPI(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void ChannelMarker::setTitle(const QString& title) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_title = title; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ChannelMarker::setCenterFrequency(int centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_centerFrequency = centerFrequency; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ChannelMarker::setCenterFrequencyByCursor(int centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  |     emit changedByCursor(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ChannelMarker::setBandwidth(int bandwidth) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_bandwidth = bandwidth; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 11:49:14 +01:00
										 |  |  | void ChannelMarker::setOppositeBandwidth(int bandwidth) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_oppositeBandwidth = bandwidth; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  |     emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2017-03-16 11:49:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-12 21:50:02 +02:00
										 |  |  | void ChannelMarker::setLowCutoff(int lowCutoff) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_lowCutoff = lowCutoff; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2015-05-12 21:50:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 03:27:31 +02:00
										 |  |  | void ChannelMarker::setSidebands(sidebands_t sidebands) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_sidebands = sidebands; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2015-05-11 03:27:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void ChannelMarker::setVisible(bool visible) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_visible = visible; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 11:03:01 +02:00
										 |  |  | void ChannelMarker::setHighlighted(bool highlighted) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_highlighted = highlighted; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ChannelMarker::setHighlightedByCursor(bool highlighted) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_highlighted = highlighted; | 
					
						
							|  |  |  |     emit highlightedByCursor(); | 
					
						
							| 
									
										
										
										
											2015-05-11 11:03:01 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void ChannelMarker::setColor(const QColor& color) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_color = color; | 
					
						
							| 
									
										
										
										
											2017-11-14 00:06:42 +01:00
										 |  |  | 	emit changedByAPI(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-23 23:43:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 09:58:07 +02:00
										 |  |  | void ChannelMarker::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     setTitle("Channel"); | 
					
						
							|  |  |  |     setCenterFrequency(0); | 
					
						
							|  |  |  |     setColor(Qt::white); | 
					
						
							|  |  |  |     setFrequencyScaleDisplayType(FScaleDisplay_freq); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray ChannelMarker::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SimpleSerializer s(1); | 
					
						
							|  |  |  |     s.writeS32(1, getCenterFrequency()); | 
					
						
							|  |  |  |     s.writeU32(2, getColor().rgb()); | 
					
						
							|  |  |  |     s.writeString(3, getTitle()); | 
					
						
							|  |  |  |     s.writeS32(7, (int) getFrequencyScaleDisplayType()); | 
					
						
							|  |  |  |     return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ChannelMarker::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(!d.isValid()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(d.getVersion() == 1) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         quint32 u32tmp; | 
					
						
							|  |  |  |         qint32 tmp; | 
					
						
							|  |  |  |         QString strtmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         blockSignals(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readS32(1, &tmp, 0); | 
					
						
							|  |  |  |         setCenterFrequency(tmp); | 
					
						
							|  |  |  |         if(d.readU32(2, &u32tmp)) { | 
					
						
							|  |  |  |             setColor(u32tmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         d.readString(3, &strtmp, "Channel"); | 
					
						
							|  |  |  |         setTitle(strtmp); | 
					
						
							|  |  |  |         d.readS32(7, &tmp, 0); | 
					
						
							| 
									
										
										
										
											2018-02-22 03:04:42 +01:00
										 |  |  |         if ((tmp >= 0) && (tmp < FScaleDisplay_none)) { | 
					
						
							| 
									
										
										
										
											2017-08-26 09:58:07 +02:00
										 |  |  |             setFrequencyScaleDisplayType((frequencyScaleDisplay_t) tmp); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             setFrequencyScaleDisplayType(FScaleDisplay_freq); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         blockSignals(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |