Added freq to MP3 names, added 800Hz to new CW bookmarks, refactored.

This commit is contained in:
Marat Fayzullin 2024-11-02 23:55:19 -04:00
parent 3b581f84e7
commit d89c8f6147
6 changed files with 106 additions and 77 deletions

View File

@ -334,7 +334,8 @@ AudioEngine.prototype.startRecording = function() {
if (!this.recording) { if (!this.recording) {
var date = new Date(Date.now()).toISOString().slice(2,19) var date = new Date(Date.now()).toISOString().slice(2,19)
.replaceAll('-','').replaceAll(':','').replaceAll('T','-'); .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; this.recording = true;
} }
}; };

View File

@ -10,8 +10,8 @@ function BookmarkBar() {
me.$container.find('.bookmark').removeClass('selected'); me.$container.find('.bookmark').removeClass('selected');
var b = $bookmark.data(); var b = $bookmark.data();
if (!b || !b.frequency || !b.modulation) return; if (!b || !b.frequency || !b.modulation) return;
me.getDemodulator().set_offset_frequency(b.frequency - center_freq); UI.setFrequency(b.frequency);
me.getDemodulatorPanel().setMode(b.modulation, b.underlying); UI.setModulation(b.modulation, b.underlying);
$bookmark.addClass('selected'); $bookmark.addClass('selected');
stopScanner(); stopScanner();
}); });
@ -106,25 +106,21 @@ BookmarkBar.prototype.render = function(){
BookmarkBar.prototype.showEditDialog = function(bookmark) { BookmarkBar.prototype.showEditDialog = function(bookmark) {
if (!bookmark) { if (!bookmark) {
var mode1 = this.getDemodulator().get_secondary_demod() var freq = UI.getFrequency();
var mode2 = this.getDemodulator().get_modulation(); var mode1 = UI.getModulation();
if (!mode2) mode2 = ''; var mode2 = UI.getUnderlying();
if (!mode1) { if (!!mode1 && !!mode2) {
// if no secondary demod, use the primary one
mode1 = mode2;
mode2 = '';
} else {
// check for default underlying demod // check for default underlying demod
var m = Modes.findByModulation(mode1); var m = Modes.findByModulation(mode1);
if (m && m.underlying.indexOf(mode2) == 0) mode2 = ''; if (m && m.underlying.indexOf(mode2) == 0) mode2 = '';
} }
bookmark = { bookmark = {
name: '', name : '',
frequency: center_freq + this.getDemodulator().get_offset_frequency(), frequency : mode1 === 'cw'? freq + 800 : freq,
modulation: mode1, modulation : mode1,
underlying: mode2, underlying : mode2,
description: '', description : '',
scannable : this.modesToScan.indexOf(mode1) >= 0 scannable : this.modesToScan.indexOf(mode1) >= 0
} }
} }
this.$dialog.bookmarkDialog().setValues(bookmark); this.$dialog.bookmarkDialog().setValues(bookmark);
@ -186,14 +182,6 @@ BookmarkBar.prototype.storeBookmark = function() {
me.$dialog.hide(); me.$dialog.hide();
}; };
BookmarkBar.prototype.getDemodulatorPanel = function() {
return $('#openwebrx-panel-receiver').demodulatorPanel();
};
BookmarkBar.prototype.getDemodulator = function() {
return this.getDemodulatorPanel().getDemodulator();
};
BookmarkBar.prototype.getAllBookmarks = function() { BookmarkBar.prototype.getAllBookmarks = function() {
var sb = this.bookmarks['server']; var sb = this.bookmarks['server'];
var lb = this.bookmarks['local']; var lb = this.bookmarks['local'];

View File

@ -585,7 +585,7 @@ function HdrMetaPanel(el) {
$select.hide(); $select.hide();
$select.on("change", function() { $select.on("change", function() {
var id = parseInt($(this).val()); 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 = $('<select id="dab-service-id"></select>'); this.$select = $('<select id="dab-service-id"></select>');
this.$select.on("change", function() { this.$select.on("change", function() {
me.service_id = parseInt($(this).val()); me.service_id = parseInt($(this).val());
$('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setAudioServiceId(me.service_id); UI.getDemodulator().setAudioServiceId(me.service_id);
}); });
var $container = $( var $container = $(
'<div class="dab-container">' + '<div class="dab-container">' +

View File

@ -11,9 +11,8 @@ Scanner.prototype.tuneBookmark = function(b) {
//console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation); //console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation);
// Tune to the bookmark frequency // Tune to the bookmark frequency
var panel = $('#openwebrx-panel-receiver').demodulatorPanel(); UI.setFrequency(b.frequency);
panel.getDemodulator().set_offset_frequency(b.frequency - center_freq); UI.setModulation(b.modulation, b.underlying);
panel.setMode(b.modulation, b.underlying);
// Done // Done
return true; return true;

View File

@ -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 // Volume Controls
// //

View File

@ -60,9 +60,7 @@ function zoomOutTotal() {
function tuneBySteps(steps) { function tuneBySteps(steps) {
steps = Math.round(steps); steps = Math.round(steps);
if (steps != 0) { if (steps != 0) {
var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); UI.setOffsetFrequency(UI.getOffsetFrequency() + steps * tuning_step);
var f = demodulator.get_offset_frequency();
demodulator.set_offset_frequency(f + steps * tuning_step);
} }
} }
@ -76,8 +74,7 @@ function tuneBySquelch(dir) {
var squelch = $slider.val() - 13.0; var squelch = $slider.val() - 13.0;
// Start from the current offset within the waterfall // Start from the current offset within the waterfall
var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); var f = UI.getOffsetFrequency();
var f = demodulator.get_offset_frequency();
// Scan up or down the waterfall // Scan up or down the waterfall
dir = tuning_step * (dir>=0? 1 : -1); dir = tuning_step * (dir>=0? 1 : -1);
@ -86,7 +83,7 @@ function tuneBySquelch(dir) {
if (i < 0 || i >= wf_data.length) { if (i < 0 || i >= wf_data.length) {
break; break;
} else if (wf_data[i] >= squelch) { } else if (wf_data[i] >= squelch) {
demodulator.set_offset_frequency(f); UI.setOffsetFrequency(f);
break; break;
} }
} }
@ -109,7 +106,7 @@ function monitorLevels(data) {
function jumpBySteps(steps) { function jumpBySteps(steps) {
steps = Math.round(steps); steps = Math.round(steps);
if (steps != 0) { if (steps != 0) {
var key = $('#openwebrx-panel-receiver').demodulatorPanel().getMagicKey(); var key = UI.getDemodulatorPanel().getMagicKey();
var f = center_freq + steps * bandwidth / 4; var f = center_freq + steps * bandwidth / 4;
ws.send(JSON.stringify({ ws.send(JSON.stringify({
"type": "setfrequency", "params": { "frequency": f, "key": key } "type": "setfrequency", "params": { "frequency": f, "key": key }
@ -179,11 +176,7 @@ function typeInAnimation(element, timeout, what, onFinish) {
// ======================================================== // ========================================================
function getDemodulators() { function getDemodulators() {
return [ return [ UI.getDemodulator() ].filter(function(d) { return !!d; });
$('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator()
].filter(function(d) {
return !!d;
});
} }
function mkenvelopes(visible_range) //called from mkscale function mkenvelopes(visible_range) //called from mkscale
@ -285,7 +278,7 @@ function scale_canvas_mousemove(evt) {
function frequency_container_mousemove(evt) { function frequency_container_mousemove(evt) {
var frequency = center_freq + scale_offset_freq_from_px(evt.pageX); 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) { function scale_canvas_end_drag(x) {
@ -520,21 +513,6 @@ function resize_scale() {
bookmarks.position(); 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) { function format_frequency(format, freq_hz, pre_divide, decimals) {
var out = format.replace("{x}", (freq_hz / pre_divide).toFixed(decimals)); var out = format.replace("{x}", (freq_hz / pre_divide).toFixed(decimals));
var at = out.indexOf(".") + 4; var at = out.indexOf(".") + 4;
@ -711,7 +689,7 @@ function canvas_mousemove(evt) {
if (!waterfall_setup_done) return; if (!waterfall_setup_done) return;
var relativeX = get_relative_x(evt); var relativeX = get_relative_x(evt);
if (!canvas_mouse_down) { if (!canvas_mouse_down) {
$('#openwebrx-panel-receiver').demodulatorPanel().setMouseFrequency(canvas_get_frequency(relativeX)); UI.getDemodulatorPanel().setMouseFrequency(UI.getFrequency(relativeX));
} else { } else {
if (!canvas_drag && Math.abs(evt.pageX - canvas_drag_start_x) > canvas_drag_min_delta) { if (!canvas_drag && Math.abs(evt.pageX - canvas_drag_start_x) > canvas_drag_min_delta) {
canvas_drag = true; canvas_drag = true;
@ -751,16 +729,12 @@ function canvas_mouseup(evt) {
var relativeX = get_relative_x(evt); var relativeX = get_relative_x(evt);
if (!canvas_drag) { if (!canvas_drag) {
var demodulator = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); var f = UI.getOffsetFrequency(relativeX);
var f = canvas_get_freq_offset(relativeX);
// For CW, move offset 800Hz below the actual carrier // For CW, move offset 800Hz below the actual carrier
if (demodulator.get_modulation() === 'cw') { if (UI.getModulation() === 'cw') f = f - 800;
f = f - 800; UI.setOffsetFrequency(f);
}
demodulator.set_offset_frequency(f);
stopScanner(); stopScanner();
} } else {
else {
canvas_end_drag(); canvas_end_drag();
} }
canvas_mouse_down = false; canvas_mouse_down = false;
@ -838,7 +812,7 @@ function zoom_step(out, where, onscreen) {
if (out) --zoom_level; if (out) --zoom_level;
else ++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()); //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; zoom_center_where = onscreen;
//console.log(zoom_center_where, zoom_center_rel, where); //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; if (!(level >= 0 && level <= zoom_levels.length - 1)) return;
level = parseInt(level); level = parseInt(level);
zoom_level = 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 = $('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator(); var demodulator = UI.getDemodulator();
zoom_center_rel = demodulator != null? demodulator.get_offset_frequency() : 0; 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 zoom_center_where = 0.5 + (zoom_center_rel / bandwidth); //this is a kind of hack
resize_canvases(true); resize_canvases(true);
@ -940,11 +914,14 @@ function on_ws_recv(evt) {
waterfall_init(); waterfall_init();
var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel(); var demodulatorPanel = UI.getDemodulatorPanel();
demodulatorPanel.setCenterFrequency(center_freq); demodulatorPanel.setCenterFrequency(center_freq);
demodulatorPanel.setInitialParams(initial_demodulator_params); demodulatorPanel.setInitialParams(initial_demodulator_params);
if ('squelch_auto_margin' in config) if ('squelch_auto_margin' in config)
demodulatorPanel.setSquelchMargin(config['squelch_auto_margin']); demodulatorPanel.setSquelchMargin(config['squelch_auto_margin']);
bookmarks.loadLocalBookmarks(); bookmarks.loadLocalBookmarks();
if ('sdr_id' in config || 'profile_id' in config) { if ('sdr_id' in config || 'profile_id' in config) {
@ -963,7 +940,7 @@ function on_ws_recv(evt) {
} }
if ('tuning_precision' in config) if ('tuning_precision' in config)
$('#openwebrx-panel-receiver').demodulatorPanel().setTuningPrecision(config['tuning_precision']); demodulatorPanel.setTuningPrecision(config['tuning_precision']);
if ('tuning_step' in config) { if ('tuning_step' in config) {
tuning_step_default = config['tuning_step']; tuning_step_default = config['tuning_step'];
@ -1072,7 +1049,7 @@ function on_ws_recv(evt) {
var $overlay = $('#openwebrx-error-overlay'); var $overlay = $('#openwebrx-error-overlay');
$overlay.find('.errormessage').text(json['value']); $overlay.find('.errormessage').text(json['value']);
$overlay.show(); $overlay.show();
$("#openwebrx-panel-receiver").demodulatorPanel().stopDemodulator(); UI.getDemodulatorPanel().stopDemodulator();
break; break;
case "demodulator_error": case "demodulator_error":
divlog(json['value'], true); divlog(json['value'], true);
@ -1242,7 +1219,7 @@ function onAudioStart(apiType){
var reconnect_timeout = false; var reconnect_timeout = false;
function on_ws_closed() { function on_ws_closed() {
var demodulatorPanel = $("#openwebrx-panel-receiver").demodulatorPanel(); var demodulatorPanel = UI.getDemodulatorPanel();
demodulatorPanel.stopDemodulator(); demodulatorPanel.stopDemodulator();
demodulatorPanel.resetInitialParams(); demodulatorPanel.resetInitialParams();
if (reconnect_timeout) { if (reconnect_timeout) {
@ -1496,7 +1473,7 @@ function update_dmr_timeslot_filtering() {
}).toArray().reduce(function (acc, v) { }).toArray().reduce(function (acc, v) {
return acc | v; return acc | v;
}, 0); }, 0);
$('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setDmrFilter(filter); UI.getDemodulator().setDmrFilter(filter);
} }
function hideOverlay() { function hideOverlay() {
@ -1760,7 +1737,7 @@ function secondary_demod_update_channel_freq_from_event(evt) {
if (!secondary_demod_waiting_for_set) { if (!secondary_demod_waiting_for_set) {
secondary_demod_waiting_for_set = true; secondary_demod_waiting_for_set = true;
window.setTimeout(function () { 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; secondary_demod_waiting_for_set = false;
}, },
50 50
@ -1819,7 +1796,7 @@ function secondary_demod_waterfall_set_zoom(low_cut, high_cut) {
function sdr_profile_changed() { function sdr_profile_changed() {
var value = $('#openwebrx-sdr-profiles-listbox').val(); var value = $('#openwebrx-sdr-profiles-listbox').val();
var key = $('#openwebrx-panel-receiver').demodulatorPanel().getMagicKey(); var key = UI.getDemodulatorPanel().getMagicKey();
ws.send(JSON.stringify({ ws.send(JSON.stringify({
"type": "selectprofile", "params": { "profile": value, "key": key } "type": "selectprofile", "params": { "profile": value, "key": key }
})); }));