From 09d1bd81ef1c85181b5deeb207b3aeaaf813052a Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Sat, 2 Nov 2024 22:57:56 -0400 Subject: [PATCH] Adding 800 to new CW bookmarks, refactored frequency functions. --- htdocs/lib/BookmarkBar.js | 13 +++++----- htdocs/lib/UI.js | 54 +++++++++++++++++++++++++++------------ htdocs/openwebrx.js | 23 +++-------------- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index 5c448e0a..9104639d 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -106,6 +106,7 @@ BookmarkBar.prototype.render = function(){ BookmarkBar.prototype.showEditDialog = function(bookmark) { if (!bookmark) { + var freq = UI.getFrequency(); var mode1 = UI.getModulation(); var mode2 = UI.getUnderlying(); if (!!mode1 && !!mode2) { @@ -114,12 +115,12 @@ BookmarkBar.prototype.showEditDialog = function(bookmark) { if (m && m.underlying.indexOf(mode2) == 0) mode2 = ''; } bookmark = { - name: '', - frequency: UI.getFrequency(), - modulation: mode1, - underlying: mode2, - description: '', - scannable : this.modesToScan.indexOf(mode1) >= 0 + name : '', + frequency : mode1 === 'cw'? freq + 800 : freq, + modulation : mode1, + underlying : mode2, + description : '', + scannable : this.modesToScan.indexOf(mode1) >= 0 } } this.$dialog.bookmarkDialog().setValues(bookmark); diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index ea4fb749..2981f100 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -67,7 +67,7 @@ UI.loadSettings = function() { }; // -// Frequency and Modulation Controls +// Modulation Controls // UI.getDemodulatorPanel = function() { @@ -78,22 +78,6 @@ UI.getDemodulator = function() { return this.getDemodulatorPanel().getDemodulator(); } -UI.getOffsetFrequency = function() { - return this.getDemodulator().get_offset_frequency(); -}; - -UI.setOffsetFrequency = function(offset) { - return this.getDemodulator().set_offset_frequency(offset); -}; - -UI.getFrequency = function() { - return center_freq + this.getOffsetFrequency(); -}; - -UI.setFrequency = function(freq) { - return this.setOffsetFrequency(freq - center_freq); -}; - UI.getModulation = function() { var mode1 = this.getDemodulator().get_secondary_demod(); var mode2 = this.getDemodulator().get_modulation(); @@ -110,6 +94,42 @@ UI.setModulation = function(mode, underlying) { this.getDemodulatorPanel().setMode(mode, underlying); }; +// +// Frequency Controls +// + +UI.getOffsetFrequency = function(x) { + if (typeof(x) === 'undefined') { + // No argument: return currently tuned offset + return this.getDemodulator().get_offset_frequency(); + } else { + // Pointer position: return offset under pointer + // Use rounded absolute frequency to get offset + return this.getFrequency(x) - center_freq; + } +}; + +UI.getFrequency = function(x) { + if (typeof(x) === 'undefined') { + // No argument: return currently tuned frequency + return center_freq + this.getOffsetFrequency(); + } else { + // Pointer position: return frequency under pointer + x = x / canvas_container.clientWidth; + x = center_freq + (bandwidth * x) - (bandwidth / 2); + return tuning_step>0? + Math.round(x / tuning_step) * tuning_step : Math.round(x); + } +}; + +UI.setOffsetFrequency = function(offset) { + return this.getDemodulator().set_offset_frequency(offset); +}; + +UI.setFrequency = function(freq) { + return this.setOffsetFrequency(freq - center_freq); +}; + // // Volume Controls // diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 3a697528..2bf3cccb 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -513,21 +513,6 @@ function resize_scale() { bookmarks.position(); } -function canvas_get_freq_offset(relativeX) { - var rel = (relativeX / canvas_container.clientWidth); - var off = (bandwidth * rel) - (bandwidth / 2); - - return tuning_step>0? - Math.round(off / tuning_step) * tuning_step : Math.round(off); -} - -function canvas_get_frequency(relativeX) { - var f = center_freq + canvas_get_freq_offset(relativeX); - - return tuning_step>0? Math.round(f / tuning_step) * tuning_step : f; -} - - function format_frequency(format, freq_hz, pre_divide, decimals) { var out = format.replace("{x}", (freq_hz / pre_divide).toFixed(decimals)); var at = out.indexOf(".") + 4; @@ -704,7 +689,7 @@ function canvas_mousemove(evt) { if (!waterfall_setup_done) return; var relativeX = get_relative_x(evt); if (!canvas_mouse_down) { - UI.getDemodulatorPanel().setMouseFrequency(canvas_get_frequency(relativeX)); + UI.getDemodulatorPanel().setMouseFrequency(UI.getFrequency(relativeX)); } else { if (!canvas_drag && Math.abs(evt.pageX - canvas_drag_start_x) > canvas_drag_min_delta) { canvas_drag = true; @@ -744,7 +729,7 @@ function canvas_mouseup(evt) { var relativeX = get_relative_x(evt); if (!canvas_drag) { - var f = canvas_get_freq_offset(relativeX); + var f = UI.getOffsetFrequency(relativeX); // For CW, move offset 800Hz below the actual carrier if (UI.getModulation() === 'cw') f = f - 800; UI.setOffsetFrequency(f); @@ -827,7 +812,7 @@ function zoom_step(out, where, onscreen) { if (out) --zoom_level; else ++zoom_level; - zoom_center_rel = canvas_get_freq_offset(where); + zoom_center_rel = UI.getOffsetFrequency(where); //console.log("zoom_step || zlevel: "+zoom_level.toString()+" zlevel_val: "+zoom_levels[zoom_level].toString()+" zoom_center_rel: "+zoom_center_rel.toString()); zoom_center_where = onscreen; //console.log(zoom_center_where, zoom_center_rel, where); @@ -841,7 +826,7 @@ function zoom_set(level) { if (!(level >= 0 && level <= zoom_levels.length - 1)) return; level = parseInt(level); zoom_level = level; - //zoom_center_rel=canvas_get_freq_offset(-canvases[0].offsetLeft+waterfallWidth()/2); //zoom to screen center instead of demod envelope + //zoom_center_rel=UI.getOffsetFrequency(-canvases[0].offsetLeft+waterfallWidth()/2); //zoom to screen center instead of demod envelope var demodulator = UI.getDemodulator(); zoom_center_rel = demodulator != null? demodulator.get_offset_frequency() : 0; zoom_center_where = 0.5 + (zoom_center_rel / bandwidth); //this is a kind of hack