mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-20 12:36:07 -05:00
- New FrequencyControl replaces JFrequencyControl: MHz to 1 Hz, hover a digit and scroll or click its upper/lower half to step it (with carry, clamped to the tuner's range), or type a frequency (e.g. 851.0125) and press Enter. Arrow keys move between digits and step them. Copy/paste supported. - Tuners tab redesigned: tuner list with status pills and configurable columns, Add Tuner menu, and a sectioned editor (header with status, enable switch, spectrum/record/restart; Tuning; Gain; Options; Frequency Correction; collapsible Frequency Limits). - All tuner editors converted to JavaFX with their full set of controls. RSP editors share option bindings in RspTunerEditor. - Add recording and network tuner dialogs converted to JavaFX dialogs. - DiscoveredTunerModel is no longer a Swing table model. - Fixes: FCD Pro gain/phase correction loaded swapped; RSPdx saved the FM notch as the DAB notch and never applied the HDR bandwidth; RSP2 external reference output and network tuner PPM weren't saved; Airspy/HydraSDR gain mode changes now apply the mode's gains. Co-authored-by: denny <dennis.sheirer@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.control;
|
||||
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the frequency control's keyboard and scroll wheel interaction.
|
||||
*/
|
||||
public class FrequencyControlTest
|
||||
{
|
||||
@BeforeAll
|
||||
public static void startToolkit() throws Exception
|
||||
{
|
||||
//Run without a display
|
||||
System.setProperty("glass.platform", "Headless");
|
||||
System.setProperty("prism.order", "sw");
|
||||
CompletableFuture<Void> started = new CompletableFuture<>();
|
||||
|
||||
try
|
||||
{
|
||||
Platform.startup(() -> started.complete(null));
|
||||
}
|
||||
catch(IllegalStateException e)
|
||||
{
|
||||
started.complete(null); //Already started
|
||||
}
|
||||
|
||||
started.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private static <T> T onFx(java.util.concurrent.Callable<T> callable) throws Exception
|
||||
{
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
Platform.runLater(() -> {
|
||||
try
|
||||
{
|
||||
future.complete(callable.call());
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
future.completeExceptionally(t);
|
||||
}
|
||||
});
|
||||
return future.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private static FrequencyControl createControl(List<Long> requests)
|
||||
{
|
||||
FrequencyControl control = new FrequencyControl();
|
||||
control.setRange(24_000_000, 1_766_000_000);
|
||||
control.setFrequency(851_012_500);
|
||||
control.addListener(requests::add);
|
||||
Scene scene = new Scene(new StackPane(control), 400, 120);
|
||||
scene.snapshot(null);
|
||||
return control;
|
||||
}
|
||||
|
||||
private static void type(Node node, String text)
|
||||
{
|
||||
for(char c: text.toCharArray())
|
||||
{
|
||||
node.fireEvent(new KeyEvent(KeyEvent.KEY_TYPED, String.valueOf(c), "", KeyCode.UNDEFINED, false, false,
|
||||
false, false));
|
||||
}
|
||||
}
|
||||
|
||||
private static void press(Node node, KeyCode code)
|
||||
{
|
||||
node.fireEvent(new KeyEvent(KeyEvent.KEY_PRESSED, "", "", code, false, false, false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedEntryAppliedWithEnter() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
long frequency = onFx(() -> {
|
||||
FrequencyControl control = createControl(requests);
|
||||
type(control, "462.5625");
|
||||
assertTrue(control.isEntryActive());
|
||||
assertEquals(851_012_500L, control.getFrequency(), "not applied until Enter");
|
||||
press(control, KeyCode.ENTER);
|
||||
return control.getFrequency();
|
||||
});
|
||||
|
||||
assertEquals(462_562_500L, frequency);
|
||||
assertEquals(List.of(462_562_500L), requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedEntryCancelledWithEscape() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
long frequency = onFx(() -> {
|
||||
FrequencyControl control = createControl(requests);
|
||||
type(control, "155.0");
|
||||
press(control, KeyCode.ESCAPE);
|
||||
return control.getFrequency();
|
||||
});
|
||||
|
||||
assertEquals(851_012_500L, frequency);
|
||||
assertTrue(requests.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outOfRangeEntryRejected() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
long frequency = onFx(() -> {
|
||||
FrequencyControl control = createControl(requests);
|
||||
type(control, "2000");
|
||||
press(control, KeyCode.ENTER);
|
||||
return control.getFrequency();
|
||||
});
|
||||
|
||||
assertEquals(851_012_500L, frequency);
|
||||
assertTrue(requests.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arrowKeysMoveCursorAndStep() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
long frequency = onFx(() -> {
|
||||
FrequencyControl control = createControl(requests);
|
||||
//Cursor starts on the 1 MHz digit: move right to the 100 kHz digit and step up twice
|
||||
assertEquals(6, control.getCursorPosition());
|
||||
press(control, KeyCode.RIGHT);
|
||||
press(control, KeyCode.UP);
|
||||
press(control, KeyCode.UP);
|
||||
//Move left twice to the 10 MHz digit and step down once
|
||||
press(control, KeyCode.LEFT);
|
||||
press(control, KeyCode.LEFT);
|
||||
press(control, KeyCode.DOWN);
|
||||
return control.getFrequency();
|
||||
});
|
||||
|
||||
assertEquals(841_212_500L, frequency);
|
||||
assertEquals(List.of(851_112_500L, 851_212_500L, 841_212_500L), requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scrollWheelStepsDigitUnderMouse() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
long frequency = onFx(() -> {
|
||||
FrequencyControl control = createControl(requests);
|
||||
//Digits are in order from the 1000 MHz digit (position 9) to the 1 Hz digit (position 0)
|
||||
Node digit = control.lookupAll(".frequency-digit").stream().toList().get(9 - 3); //1 kHz digit
|
||||
var bounds = digit.localToScene(digit.getLayoutBounds());
|
||||
//Two wheel notches up, as JFXPanel reports them: 40 per notch with a multiplier of 40
|
||||
digit.fireEvent(new ScrollEvent(ScrollEvent.SCROLL, bounds.getCenterX(), bounds.getCenterY(),
|
||||
bounds.getCenterX(), bounds.getCenterY(), false, false, false, false, false, false, 0, 80, 0, 80,
|
||||
40, 40, ScrollEvent.HorizontalTextScrollUnits.NONE, 0, ScrollEvent.VerticalTextScrollUnits.NONE,
|
||||
0, 0, null));
|
||||
return control.getFrequency();
|
||||
});
|
||||
|
||||
assertEquals(851_014_500L, frequency);
|
||||
assertEquals(List.of(851_014_500L), requests, "one request for both notches");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tunerNotificationUpdatesWithoutRequest() throws Exception
|
||||
{
|
||||
List<Long> requests = new ArrayList<>();
|
||||
FrequencyControl control = onFx(() -> createControl(requests));
|
||||
control.process(SourceEvent.frequencyChange(null, 155_250_000L));
|
||||
long frequency = onFx(control::getFrequency);
|
||||
assertEquals(155_250_000L, frequency);
|
||||
assertTrue(requests.isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.control;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the frequency control's digit arithmetic, parsing and typed entry.
|
||||
*/
|
||||
public class FrequencyEntryTest
|
||||
{
|
||||
@Test
|
||||
public void digits()
|
||||
{
|
||||
long frequency = 851_012_500L;
|
||||
assertEquals(0, FrequencyEntry.getDigit(frequency, 0));
|
||||
assertEquals(5, FrequencyEntry.getDigit(frequency, 2));
|
||||
assertEquals(1, FrequencyEntry.getDigit(frequency, 4));
|
||||
assertEquals(1, FrequencyEntry.getDigit(frequency, 6));
|
||||
assertEquals(8, FrequencyEntry.getDigit(frequency, 8));
|
||||
assertEquals(0, FrequencyEntry.getDigit(frequency, 9));
|
||||
assertTrue(FrequencyEntry.isLeadingZero(frequency, 9));
|
||||
assertFalse(FrequencyEntry.isLeadingZero(frequency, 8));
|
||||
assertFalse(FrequencyEntry.isLeadingZero(0, 6), "1 MHz digit is never a leading zero");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepCarriesAndClamps()
|
||||
{
|
||||
assertEquals(852_000_000L, FrequencyEntry.step(851_900_000L, 5, 1, 1, 2_000_000_000L), "carry into MHz");
|
||||
assertEquals(850_900_000L, FrequencyEntry.step(851_000_000L, 5, -1, 1, 2_000_000_000L), "borrow from MHz");
|
||||
assertEquals(1_766_000_000L, FrequencyEntry.step(1_765_500_000L, 6, 3, 24_000_000L, 1_766_000_000L),
|
||||
"clamp at maximum");
|
||||
assertEquals(24_000_000L, FrequencyEntry.step(25_000_000L, 7, -1, 24_000_000L, 1_766_000_000L),
|
||||
"clamp at minimum");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDigit()
|
||||
{
|
||||
assertEquals(861_012_500L, FrequencyEntry.setDigit(851_012_500L, 7, 6));
|
||||
assertEquals(851_012_509L, FrequencyEntry.setDigit(851_012_500L, 0, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse()
|
||||
{
|
||||
assertEquals(851_012_500L, FrequencyEntry.parse("851.0125"));
|
||||
assertEquals(851_012_500L, FrequencyEntry.parse(" 851.012500 MHz "));
|
||||
assertEquals(851_012_500L, FrequencyEntry.parse("851012500"), "large whole number is Hertz");
|
||||
assertEquals(851_012_500L, FrequencyEntry.parse("851,012,500 Hz"));
|
||||
assertEquals(162_550_000L, FrequencyEntry.parse("162550 kHz"));
|
||||
assertEquals(1_296_000_000L, FrequencyEntry.parse("1.296GHz"));
|
||||
assertEquals(9_999_000_000L, FrequencyEntry.parse("9999"), "4 digit whole number is MHz");
|
||||
assertNull(FrequencyEntry.parse("851.0125005"), "finer than 1 Hz");
|
||||
assertNull(FrequencyEntry.parse("abc"));
|
||||
assertNull(FrequencyEntry.parse("-5"));
|
||||
assertNull(FrequencyEntry.parse(""));
|
||||
assertNull(FrequencyEntry.parse(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void format()
|
||||
{
|
||||
assertEquals("851.012500", FrequencyEntry.format(851_012_500L));
|
||||
assertEquals("0.000001", FrequencyEntry.format(1));
|
||||
assertEquals("1296.000000", FrequencyEntry.format(1_296_000_000L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedEntry()
|
||||
{
|
||||
FrequencyEntry.TypedEntry entry = new FrequencyEntry.TypedEntry();
|
||||
assertTrue(entry.isEmpty());
|
||||
|
||||
for(char c: "0851.0125".toCharArray())
|
||||
{
|
||||
assertTrue(entry.type(c));
|
||||
}
|
||||
|
||||
assertEquals(851_012_500L, entry.getFrequency());
|
||||
assertTrue(entry.isTyped(8), "100 MHz digit typed");
|
||||
assertFalse(entry.isTyped(9), "leading zero isn't counted");
|
||||
assertTrue(entry.isTyped(2), "100 Hz digit typed");
|
||||
assertFalse(entry.isTyped(1), "10 Hz digit implied");
|
||||
assertFalse(entry.type('.'), "second decimal point");
|
||||
|
||||
assertTrue(entry.backspace());
|
||||
assertEquals(851_012_000L, entry.getFrequency());
|
||||
|
||||
entry.clear();
|
||||
|
||||
for(char c: "12345".toCharArray())
|
||||
{
|
||||
entry.type(c);
|
||||
}
|
||||
|
||||
assertEquals(1234_000_000L, entry.getFrequency(), "fifth MHz digit is rejected");
|
||||
|
||||
entry.clear();
|
||||
|
||||
for(char c: ".1234567".toCharArray())
|
||||
{
|
||||
entry.type(c);
|
||||
}
|
||||
|
||||
assertEquals(123_456L, entry.getFrequency(), "seventh fractional digit is rejected");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.source.tuner.ui;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests parsing the simple HTML tuner information that tuner editors provide.
|
||||
*/
|
||||
public class TunerInfoDialogTest
|
||||
{
|
||||
@Test
|
||||
public void parsesHeadingAndKeyValueLines()
|
||||
{
|
||||
TunerInfoDialog.Info info = TunerInfoDialog.parse("<html><h3>RTL-2832 with R820T Tuner</h3>" +
|
||||
"<b>USB ID: </b>0bda:2838<br><b>Serial: </b>00000001<br>No EEPROM Descriptor Available");
|
||||
|
||||
assertEquals("RTL-2832 with R820T Tuner", info.heading());
|
||||
assertEquals(List.of(new TunerInfoDialog.Line("USB ID", "0bda:2838"),
|
||||
new TunerInfoDialog.Line("Serial", "00000001"),
|
||||
new TunerInfoDialog.Line(null, "No EEPROM Descriptor Available")), info.lines());
|
||||
assertEquals("RTL-2832 with R820T Tuner\nUSB ID: 0bda:2838\nSerial: 00000001\nNo EEPROM Descriptor Available\n",
|
||||
info.toText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesMissingHeading()
|
||||
{
|
||||
TunerInfoDialog.Info info = TunerInfoDialog.parse("<b>Host: </b>localhost<br>");
|
||||
assertEquals(null, info.heading());
|
||||
assertEquals(List.of(new TunerInfoDialog.Line("Host", "localhost")), info.lines());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user