Skip to content

Commit

Permalink
Documentation, refactor, cleanup, etc.
Browse files Browse the repository at this point in the history
* A shit ton of documentation
* Better comments
* Lots of cleanup
* Some refactoring of methods
* Move FastNoiseLite to its own package outside of the org.wysko
 .midis2jam2 namespace
* Externalize strings for GUIs for i18n
* Remove AdvancedDisplay.java, will bring this back later
* Add locale switching support
* Added UtilsTest for testing utility functions
  • Loading branch information
wyskoj committed Jul 23, 2021
1 parent 73761af commit b08e162
Show file tree
Hide file tree
Showing 142 changed files with 2,680 additions and 1,475 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions build.gradle
Expand Up @@ -85,11 +85,17 @@ dependencies {
implementation 'com.formdev:flatlaf:1.1.2'

implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'

testImplementation(platform('org.junit:junit-bom:5.7.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}

allprojects {
Expand Down
@@ -1,52 +1,4 @@
package org.wysko.midis2jam2.util;// MIT License
//
// Copyright(c) 2020 Jordan Peck (jordan.me2@gmail.com)
// Copyright(c) 2020 Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.0.1
// https://github.com/Auburn/FastNoise

package com.auburn.fastnoiselite;
// To switch between using floats or doubles for input position,
// perform a file-wide replace on the following strings (including /*FNLfloat*/)
// /*FNLfloat*/ float
Expand Down Expand Up @@ -2468,4 +2420,4 @@ public Vector3(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
this.z = z;
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/org/wysko/midis2jam2/CustomTicker.java
Expand Up @@ -41,6 +41,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

@SuppressWarnings("all")
public class CustomTicker {

public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, IOException {
Expand Down
129 changes: 90 additions & 39 deletions src/main/java/org/wysko/midis2jam2/GuiLauncher.java
Expand Up @@ -55,24 +55,53 @@
/**
* @author Jacob Wysko
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "FieldCanBeLocal"})
public class GuiLauncher extends JFrame {

private static final Map<String, String> supportedLocales = new HashMap<>();

static {
supportedLocales.put("English", "en");
supportedLocales.put("Español", "es");
supportedLocales.put("Français", "fr");
}

private static final File SETTINGS_FILE = new File(System.getProperty("user.home"), "midis2jam2.settings");

private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

public GuiLauncher() {
initComponents();
settings = new LauncherSettings();
public static Map<String, String> getSupportedLocales() {
return supportedLocales;
}

public LauncherSettings getSettings() {
return settings;
}

private transient LauncherSettings settings;

public GuiLauncher() {
settings = new LauncherSettings();
}

public static void main(String[] args) throws IOException {

// Initialize GUI
IntelliJTheme.install(GuiLauncher.class.getResourceAsStream("/Material Darker Contrast.theme.json"));

var guiLauncher = new GuiLauncher();

try {
var json = new String(Files.readAllBytes(SETTINGS_FILE.toPath()));
if (json.isBlank()) throw new IllegalStateException();
guiLauncher.settings = new Gson().fromJson(json, LauncherSettings.class);
} catch (Exception e) {
guiLauncher.settings = new LauncherSettings();
guiLauncher.saveSettings();
}
Locale.setDefault(new Locale(guiLauncher.settings.getLocale()));

guiLauncher.initComponents();

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
guiLauncher.pack();
guiLauncher.setLocation(dim.width / 2 - guiLauncher.getSize().width / 2, dim.height / 2 - guiLauncher.getSize().height / 2);
Expand All @@ -81,11 +110,11 @@ public static void main(String[] args) throws IOException {

// Register drag and drop
guiLauncher.midiFilePathTextField.setDropTarget(new DropTarget() {
@SuppressWarnings("unchecked")
@Override
public synchronized void drop(DropTargetDropEvent evt) {
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
//noinspection unchecked
List<File> droppedFiles = (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
guiLauncher.midiFilePathTextField.setText(droppedFiles.get(0).getAbsolutePath());
} catch (Exception ex) {
Expand All @@ -109,13 +138,13 @@ public synchronized void drop(DropTargetDropEvent evt) {

// Check for updates
new Thread(() -> {
Midis2jam2.LOGGER.info("Checking for updates.");
Midis2jam2.getLOGGER().info("Checking for updates.");
try {
final var bundle = ResourceBundle.getBundle("i18n.updater");
var html = Utils.getHTML("https://midis2jam2.xyz/api/update?v=" + getVersion());
var jep = new JEditorPane();
jep.setContentType("text/html");
jep.setText("<html>This version is out of date and is no longer supported. <a " +
"href=\"https://midis2jam2.xyz\">Download the latest version.</a></html>\"");
jep.setText(bundle.getString("warning"));
jep.setEditable(false);
jep.setOpaque(false);
jep.addHyperlinkListener(hle -> {
Expand All @@ -128,14 +157,13 @@ public synchronized void drop(DropTargetDropEvent evt) {
}
});
if (html.contains("Out of")) {
showMessageDialog(guiLauncher, jep,
"Update available", WARNING_MESSAGE);
Midis2jam2.LOGGER.warning("Out of date!");
showMessageDialog(guiLauncher, jep, bundle.getString("update_available"), WARNING_MESSAGE);
Midis2jam2.getLOGGER().warning("Out of date!");
} else {
Midis2jam2.LOGGER.info("Up to date.");
Midis2jam2.getLOGGER().info("Up to date.");
}
} catch (IOException e) {
Midis2jam2.LOGGER.warning("Failed to check for updates.");
Midis2jam2.getLOGGER().warning("Failed to check for updates.");
e.printStackTrace();
}
}).start();
Expand All @@ -145,22 +173,25 @@ public synchronized void drop(DropTargetDropEvent evt) {
guiLauncher.bringToFront();

// Load settings
try {
var json = new String(Files.readAllBytes(SETTINGS_FILE.toPath()));
if (json.isBlank()) throw new IllegalStateException();
guiLauncher.settings = new Gson().fromJson(json, LauncherSettings.class);
} catch (Exception e) {
guiLauncher.settings = new LauncherSettings();
guiLauncher.saveSettings();
} finally {
guiLauncher.reloadSettings();
}
guiLauncher.reloadSettings();


// Launch directly into midis2jam2 if a MIDI file is specified
if (args.length == 1) {
guiLauncher.midiFilePathTextField.setText(args[0]);
guiLauncher.startButtonPressed(null);
}

ResourceBundle.clearCache();
}

/**
* Returns the current version of the program.
*
* @return the current version of the program
*/
public static String getVersion() {
return Utils.resourceToString("/version.txt");
}

private void reloadSettings() {
Expand All @@ -183,12 +214,14 @@ private void reloadSettings() {
fullscreenCheckbox.setSelected(settings.isFullscreen());
setLatencySpinnerFromDeviceDropdown();
legacyEngineCheckbox.setSelected(settings.isLegacyDisplay());

Locale.setDefault(new Locale(settings.getLocale()));
}

/**
* Saves settings, serializing with GSON then writing to the {@link #SETTINGS_FILE}.
*/
private void saveSettings() {
public void saveSettings() {
try (var writer = new FileWriter(SETTINGS_FILE)) {
writer.write(GSON.toJson(settings));
} catch (IOException e) {
Expand Down Expand Up @@ -218,10 +251,6 @@ private JRadioButton getSelectedTransitionRadioButton() {
return button;
}

public static String getVersion() {
return new Scanner(requireNonNull(GuiLauncher.class.getResourceAsStream("/version.txt"))).next();
}

/**
* Prompts the user to load a MIDI file.
*/
Expand Down Expand Up @@ -252,7 +281,6 @@ public String getDescription() {
}
}


/**
* Prompts the user to load a soundfont file.
*/
Expand Down Expand Up @@ -412,13 +440,6 @@ private void startButtonPressed(ActionEvent e) {
this.setCursor(getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}

// private Class<? extends Displays> getDisplayType() {
// if (simpleWindowRadio.isSelected()) return Midis2jam2Display.class;
// else if (hudWindowRadio.isSelected()) return AdvancedDisplay.class;
// Midis2jam2.LOGGER.severe("One of the display types was not pressed!");
// return null;
// }

public void disableAll() {
this.setEnabled(false);
Expand Down Expand Up @@ -453,7 +474,7 @@ private void latencySpinnerStateChanged(ChangeEvent e) {

private void setLatencySpinnerFromDeviceDropdown() {
settings.setLatencyForDevice(
((MidiDevice.Info) midiDeviceDropDown.getSelectedItem()).getName(),
((MidiDevice.Info) requireNonNull(midiDeviceDropDown.getSelectedItem())).getName(),
(int) latencySpinner.getValue()
);
}
Expand All @@ -463,7 +484,7 @@ private void exitMenuItemActionPerformed(ActionEvent e) {
}

private void aboutMenuItemActionPerformed(ActionEvent e) {
About about = new About(this, true);
var about = new About(this, true);
about.setVisible(true);
}

Expand All @@ -472,6 +493,12 @@ private void legacyEngineCheckboxActionPerformed(ActionEvent e) {
saveSettings();
}

private void localeMenuItemActionPerformed(ActionEvent e) {
var localeSelect = new LocaleSelect(this);
localeSelect.setVisible(true);
}

@SuppressWarnings("all")
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
ResourceBundle bundle = ResourceBundle.getBundle("i18n.guilauncher");
Expand All @@ -481,6 +508,7 @@ private void initComponents() {
editSoundFontsMenuItem = new MenuItemResizedIcon();
exitMenuItem = new MenuItemResizedIcon();
menu1 = new JMenu();
localeMenuItem = new MenuItemResizedIcon();
aboutMenuItem = new JMenuItem();
logo = new JLabel();
configurationPanel = new JPanel();
Expand Down Expand Up @@ -560,6 +588,12 @@ private void initComponents() {
{
menu1.setText(bundle.getString("GuiLauncher.menu1.text"));

//---- localeMenuItem ----
localeMenuItem.setText(bundle.getString("GuiLauncher.localeMenuItem.text"));
localeMenuItem.setIcon(new ImageIcon(getClass().getResource("/locale.png")));
localeMenuItem.addActionListener(e -> localeMenuItemActionPerformed(e));
menu1.add(localeMenuItem);

//---- aboutMenuItem ----
aboutMenuItem.setText(bundle.getString("GuiLauncher.aboutMenuItem.text"));
aboutMenuItem.setIcon(new ImageIcon(getClass().getResource("/help.png")));
Expand Down Expand Up @@ -824,20 +858,37 @@ private void initComponents() {

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JMenuBar menuBar1;

private JMenu fileMenu;

private MenuItemResizedIcon openMidiFileMenuItem;

private MenuItemResizedIcon editSoundFontsMenuItem;

private MenuItemResizedIcon exitMenuItem;

private JMenu menu1;

private MenuItemResizedIcon localeMenuItem;

private JMenuItem aboutMenuItem;

private JLabel logo;

private JPanel configurationPanel;

private JLabel midiFileLabel;

private JTextField midiFilePathTextField;

private JResizedIconButton loadMidiFileButton;

private JLabel midiFileHelp;

private JLabel midiDeviceLabel;

private JComboBox<MidiDevice.Info> midiDeviceDropDown;

private JLabel midiDeviceHelp;
private JLabel soundFontLabel;
private JComboBox<String> soundFontPathDropDown;
Expand Down

0 comments on commit b08e162

Please sign in to comment.