From 3e9bc06c8cf54d40e5085bbbbfe7111e4dd3cee6 Mon Sep 17 00:00:00 2001 From: Igor Maznitsa Date: Sat, 7 Aug 2021 15:12:49 +0300 Subject: [PATCH] refactoring --- .../com/igormaznitsa/zxpoly/MainForm.java | 22 ++++++++++++++----- .../zxpoly/components/Motherboard.java | 2 +- .../zxpoly/components/snd/MixerUtils.java | 19 ++++++++-------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java index 38179743..7ca8cca5 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java @@ -74,6 +74,7 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.IntStream; import static com.igormaznitsa.z80.Utils.toHex; import static com.igormaznitsa.z80.Utils.toHexByte; @@ -2655,12 +2656,21 @@ private void formWindowClosing(WindowEvent evt) { } private void menuLoadDriveMenuSelected(MenuEvent evt) { - final JMenuItem[] disks = new JMenuItem[]{this.menuFileSelectDiskA, this.menuFileSelectDiskB, - this.menuFileSelectDiskC, this.menuFileSelectDiskD}; - for (int i = 0; i < 4; i++) { - final TrDosDisk disk = this.board.getBetaDiskInterface().getDiskInDrive(i); - disks[i].setIcon(disk == null ? null : ICO_MDISK); - } + final JMenuItem[] menuItems = new JMenuItem[]{ + this.menuFileSelectDiskA, this.menuFileSelectDiskB, + this.menuFileSelectDiskC, this.menuFileSelectDiskD + }; + IntStream.range(0, 4).forEach(index -> { + final TrDosDisk diskInDrive = this.board.getBetaDiskInterface().getDiskInDrive(index); + final JMenuItem diskMenuItem = menuItems[index]; + if (diskInDrive == null) { + diskMenuItem.setIcon(null); + diskMenuItem.setToolTipText(null); + } else { + diskMenuItem.setIcon(ICO_MDISK); + diskMenuItem.setToolTipText(diskInDrive.getSrcFile() == null ? null : diskInDrive.getSrcFile().getAbsolutePath()); + } + }); } private void menuOptionsEnableTrapMouseActionPerformed(ActionEvent evt) { diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/Motherboard.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/Motherboard.java index dc0a277a..6f0ca860 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/Motherboard.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/Motherboard.java @@ -501,7 +501,7 @@ public int step(final boolean tstatesIntReached, final int feValue = this.video.getPortFE(); final int levelTapeOut = AMPLITUDE_16[((feValue >> 3) & 1) == 0 ? 0 : 14]; final int levelSpeaker = AMPLITUDE_16[((feValue >> 4) & 1) == 0 ? 0 : 15]; - final int levelTapeIn = AMPLITUDE_16[this.keyboard.isTapeIn() ? 4 : 0]; + final int levelTapeIn = AMPLITUDE_16[this.keyboard.isTapeIn() ? 6 : 0]; final int mixedLevels = Math.min(AMPLITUDE_16[15], levelSpeaker + levelTapeIn + levelTapeOut); diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/snd/MixerUtils.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/snd/MixerUtils.java index 3ea87aeb..ab3dec3a 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/snd/MixerUtils.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/components/snd/MixerUtils.java @@ -2,8 +2,7 @@ public abstract class MixerUtils { - private static final float FACTOR_MIDDLE = 0.5f; - private static final float FACTOR_MAIN = 0.6f; + private static final float MIX_COEFF_MIDDLE = 0.7f; private static final float SCALE_FACTOR_6 = Short.MAX_VALUE / (255.0f * 6); private static final float SCALE_FACTOR_5 = Short.MAX_VALUE / (255.0f * 5); @@ -11,42 +10,42 @@ public abstract class MixerUtils { private static final float SCALE_FACTOR_3 = Short.MAX_VALUE / (255.0f * 3); protected static int scaleLeft6(final int left, final int middle) { - final float mixed = left * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = left + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_6)); } protected static int scaleRight6(final int right, final int middle) { - final float mixed = right * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = right + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_6)); } protected static int scaleLeft5(final int left, final int middle) { - final float mixed = left * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = left + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_5)); } protected static int scaleRight5(final int right, final int middle) { - final float mixed = right * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = right + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_5)); } protected static int scaleLeft4(final int left, final int middle) { - final float mixed = left * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = left + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_4)); } protected static int scaleRight4(final int right, final int middle) { - final float mixed = right * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = right + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_4)); } protected static int scaleLeft3(final int left, final int middle) { - final float mixed = left * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = left + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_3)); } protected static int scaleRight3(final int right, final int middle) { - final float mixed = right * FACTOR_MAIN + middle * FACTOR_MIDDLE; + final float mixed = right + middle * MIX_COEFF_MIDDLE; return Math.min(Short.MAX_VALUE, Math.round(mixed * SCALE_FACTOR_3)); }