Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Aug 7, 2021
1 parent a08443d commit 3e9bc06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
22 changes: 16 additions & 6 deletions zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,50 @@

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);
private static final float SCALE_FACTOR_4 = Short.MAX_VALUE / (255.0f * 4);
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));
}

Expand Down

0 comments on commit 3e9bc06

Please sign in to comment.