From d89c8f6147c3656cc63cad63be30b6edbaf2e555 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Sat, 2 Nov 2024 23:55:19 -0400 Subject: [PATCH] Added freq to MP3 names, added 800Hz to new CW bookmarks, refactored. --- htdocs/lib/AudioEngine.js | 3 +- htdocs/lib/BookmarkBar.js | 36 +++++++------------- htdocs/lib/MetaPanel.js | 4 +-- htdocs/lib/Scanner.js | 5 ++- htdocs/lib/UI.js | 64 +++++++++++++++++++++++++++++++++++ htdocs/openwebrx.js | 71 +++++++++++++-------------------------- 6 files changed, 106 insertions(+), 77 deletions(-) diff --git a/htdocs/lib/AudioEngine.js b/htdocs/lib/AudioEngine.js index 7bd5d3eb..9b075d5f 100644 --- a/htdocs/lib/AudioEngine.js +++ b/htdocs/lib/AudioEngine.js @@ -334,7 +334,8 @@ AudioEngine.prototype.startRecording = function() { if (!this.recording) { var date = new Date(Date.now()).toISOString().slice(2,19) .replaceAll('-','').replaceAll(':','').replaceAll('T','-'); - this.mp3fileName = "REC-" + date + ".mp3"; + var freq = Math.round(UI.getFrequency() / 1000); + this.mp3fileName = "REC-" + date + '-' + freq + ".mp3"; this.recording = true; } }; diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index be387ccf..9104639d 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -10,8 +10,8 @@ function BookmarkBar() { me.$container.find('.bookmark').removeClass('selected'); var b = $bookmark.data(); if (!b || !b.frequency || !b.modulation) return; - me.getDemodulator().set_offset_frequency(b.frequency - center_freq); - me.getDemodulatorPanel().setMode(b.modulation, b.underlying); + UI.setFrequency(b.frequency); + UI.setModulation(b.modulation, b.underlying); $bookmark.addClass('selected'); stopScanner(); }); @@ -106,25 +106,21 @@ BookmarkBar.prototype.render = function(){ BookmarkBar.prototype.showEditDialog = function(bookmark) { if (!bookmark) { - var mode1 = this.getDemodulator().get_secondary_demod() - var mode2 = this.getDemodulator().get_modulation(); - if (!mode2) mode2 = ''; - if (!mode1) { - // if no secondary demod, use the primary one - mode1 = mode2; - mode2 = ''; - } else { + var freq = UI.getFrequency(); + var mode1 = UI.getModulation(); + var mode2 = UI.getUnderlying(); + if (!!mode1 && !!mode2) { // check for default underlying demod var m = Modes.findByModulation(mode1); if (m && m.underlying.indexOf(mode2) == 0) mode2 = ''; } bookmark = { - name: '', - frequency: center_freq + this.getDemodulator().get_offset_frequency(), - 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); @@ -186,14 +182,6 @@ BookmarkBar.prototype.storeBookmark = function() { me.$dialog.hide(); }; -BookmarkBar.prototype.getDemodulatorPanel = function() { - return $('#openwebrx-panel-receiver').demodulatorPanel(); -}; - -BookmarkBar.prototype.getDemodulator = function() { - return this.getDemodulatorPanel().getDemodulator(); -}; - BookmarkBar.prototype.getAllBookmarks = function() { var sb = this.bookmarks['server']; var lb = this.bookmarks['local']; diff --git a/htdocs/lib/MetaPanel.js b/htdocs/lib/MetaPanel.js index 5c483a53..bd745163 100644 --- a/htdocs/lib/MetaPanel.js +++ b/htdocs/lib/MetaPanel.js @@ -585,7 +585,7 @@ function HdrMetaPanel(el) { $select.hide(); $select.on("change", function() { var id = parseInt($(this).val()); - $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setAudioServiceId(id); + UI.getDemodulator().setAudioServiceId(id); }); } @@ -639,7 +639,7 @@ function DabMetaPanel(el) { this.$select = $(''); this.$select.on("change", function() { me.service_id = parseInt($(this).val()); - $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setAudioServiceId(me.service_id); + UI.getDemodulator().setAudioServiceId(me.service_id); }); var $container = $( '
' + diff --git a/htdocs/lib/Scanner.js b/htdocs/lib/Scanner.js index 2e9201cf..309f3803 100644 --- a/htdocs/lib/Scanner.js +++ b/htdocs/lib/Scanner.js @@ -11,9 +11,8 @@ Scanner.prototype.tuneBookmark = function(b) { //console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation); // Tune to the bookmark frequency - var panel = $('#openwebrx-panel-receiver').demodulatorPanel(); - panel.getDemodulator().set_offset_frequency(b.frequency - center_freq); - panel.setMode(b.modulation, b.underlying); + UI.setFrequency(b.frequency); + UI.setModulation(b.modulation, b.underlying); // Done return true; diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index ea199f61..2981f100 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -66,6 +66,70 @@ UI.loadSettings = function() { } }; +// +// Modulation Controls +// + +UI.getDemodulatorPanel = function() { + return $('#openwebrx-panel-receiver').demodulatorPanel(); +}; + +UI.getDemodulator = function() { + return this.getDemodulatorPanel().getDemodulator(); +} + +UI.getModulation = function() { + var mode1 = this.getDemodulator().get_secondary_demod(); + var mode2 = this.getDemodulator().get_modulation(); + return !!mode1? mode1 : !mode2? '' : mode2; +}; + +UI.getUnderlying = function() { + var mode1 = this.getDemodulator().get_secondary_demod(); + var mode2 = this.getDemodulator().get_modulation(); + return !mode1? '' : !mode2? '' : mode2; +}; + +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 e08dd436..2bf3cccb 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -60,9 +60,7 @@ function zoomOutTotal() { function tuneBySteps(steps) { steps = Math.round(steps); if (steps != 0) { - var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); - var f = demodulator.get_offset_frequency(); - demodulator.set_offset_frequency(f + steps * tuning_step); + UI.setOffsetFrequency(UI.getOffsetFrequency() + steps * tuning_step); } } @@ -76,8 +74,7 @@ function tuneBySquelch(dir) { var squelch = $slider.val() - 13.0; // Start from the current offset within the waterfall - var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); - var f = demodulator.get_offset_frequency(); + var f = UI.getOffsetFrequency(); // Scan up or down the waterfall dir = tuning_step * (dir>=0? 1 : -1); @@ -86,7 +83,7 @@ function tuneBySquelch(dir) { if (i < 0 || i >= wf_data.length) { break; } else if (wf_data[i] >= squelch) { - demodulator.set_offset_frequency(f); + UI.setOffsetFrequency(f); break; } } @@ -109,7 +106,7 @@ function monitorLevels(data) { function jumpBySteps(steps) { steps = Math.round(steps); if (steps != 0) { - var key = $('#openwebrx-panel-receiver').demodulatorPanel().getMagicKey(); + var key = UI.getDemodulatorPanel().getMagicKey(); var f = center_freq + steps * bandwidth / 4; ws.send(JSON.stringify({ "type": "setfrequency", "params": { "frequency": f, "key": key } @@ -179,11 +176,7 @@ function typeInAnimation(element, timeout, what, onFinish) { // ======================================================== function getDemodulators() { - return [ - $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator() - ].filter(function(d) { - return !!d; - }); + return [ UI.getDemodulator() ].filter(function(d) { return !!d; }); } function mkenvelopes(visible_range) //called from mkscale @@ -285,7 +278,7 @@ function scale_canvas_mousemove(evt) { function frequency_container_mousemove(evt) { var frequency = center_freq + scale_offset_freq_from_px(evt.pageX); - $('#openwebrx-panel-receiver').demodulatorPanel().setMouseFrequency(frequency); + UI.getDemodulatorPanel().setMouseFrequency(frequency); } function scale_canvas_end_drag(x) { @@ -520,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; @@ -711,7 +689,7 @@ function canvas_mousemove(evt) { if (!waterfall_setup_done) return; var relativeX = get_relative_x(evt); if (!canvas_mouse_down) { - $('#openwebrx-panel-receiver').demodulatorPanel().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; @@ -751,16 +729,12 @@ function canvas_mouseup(evt) { var relativeX = get_relative_x(evt); if (!canvas_drag) { - var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); - var f = canvas_get_freq_offset(relativeX); + var f = UI.getOffsetFrequency(relativeX); // For CW, move offset 800Hz below the actual carrier - if (demodulator.get_modulation() === 'cw') { - f = f - 800; - } - demodulator.set_offset_frequency(f); + if (UI.getModulation() === 'cw') f = f - 800; + UI.setOffsetFrequency(f); stopScanner(); - } - else { + } else { canvas_end_drag(); } canvas_mouse_down = false; @@ -838,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); @@ -852,8 +826,8 @@ 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 - var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); + //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 resize_canvases(true); @@ -940,11 +914,14 @@ function on_ws_recv(evt) { waterfall_init(); - var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel(); + var demodulatorPanel = UI.getDemodulatorPanel(); + demodulatorPanel.setCenterFrequency(center_freq); demodulatorPanel.setInitialParams(initial_demodulator_params); + if ('squelch_auto_margin' in config) demodulatorPanel.setSquelchMargin(config['squelch_auto_margin']); + bookmarks.loadLocalBookmarks(); if ('sdr_id' in config || 'profile_id' in config) { @@ -963,7 +940,7 @@ function on_ws_recv(evt) { } if ('tuning_precision' in config) - $('#openwebrx-panel-receiver').demodulatorPanel().setTuningPrecision(config['tuning_precision']); + demodulatorPanel.setTuningPrecision(config['tuning_precision']); if ('tuning_step' in config) { tuning_step_default = config['tuning_step']; @@ -1072,7 +1049,7 @@ function on_ws_recv(evt) { var $overlay = $('#openwebrx-error-overlay'); $overlay.find('.errormessage').text(json['value']); $overlay.show(); - $("#openwebrx-panel-receiver").demodulatorPanel().stopDemodulator(); + UI.getDemodulatorPanel().stopDemodulator(); break; case "demodulator_error": divlog(json['value'], true); @@ -1242,7 +1219,7 @@ function onAudioStart(apiType){ var reconnect_timeout = false; function on_ws_closed() { - var demodulatorPanel = $("#openwebrx-panel-receiver").demodulatorPanel(); + var demodulatorPanel = UI.getDemodulatorPanel(); demodulatorPanel.stopDemodulator(); demodulatorPanel.resetInitialParams(); if (reconnect_timeout) { @@ -1496,7 +1473,7 @@ function update_dmr_timeslot_filtering() { }).toArray().reduce(function (acc, v) { return acc | v; }, 0); - $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setDmrFilter(filter); + UI.getDemodulator().setDmrFilter(filter); } function hideOverlay() { @@ -1760,7 +1737,7 @@ function secondary_demod_update_channel_freq_from_event(evt) { if (!secondary_demod_waiting_for_set) { secondary_demod_waiting_for_set = true; window.setTimeout(function () { - $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().set_secondary_offset_freq(Math.floor(secondary_demod_channel_freq)); + UI.getDemodulator().set_secondary_offset_freq(Math.floor(secondary_demod_channel_freq)); secondary_demod_waiting_for_set = false; }, 50 @@ -1819,7 +1796,7 @@ function secondary_demod_waterfall_set_zoom(low_cut, high_cut) { function sdr_profile_changed() { var value = $('#openwebrx-sdr-profiles-listbox').val(); - var key = $('#openwebrx-panel-receiver').demodulatorPanel().getMagicKey(); + var key = UI.getDemodulatorPanel().getMagicKey(); ws.send(JSON.stringify({ "type": "selectprofile", "params": { "profile": value, "key": key } }));