Added release version checker
This commit is contained in:
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
Binary file not shown.
@@ -1 +1 @@
|
||||
version=0.3.8
|
||||
version=0.3.9
|
||||
|
||||
@@ -149,7 +149,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
|
||||
JPanel statusBar;
|
||||
|
||||
JLabel statusLabel;
|
||||
NoiseFloor noiseFloorLabel;
|
||||
|
||||
JScrollPane mainScroll;
|
||||
|
||||
@@ -767,11 +767,13 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
centralPanel.add(sampleControl, BorderLayout.SOUTH);
|
||||
|
||||
statusBar = new JPanel();
|
||||
statusBar.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
statusBar.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
add(statusBar, BorderLayout.SOUTH);
|
||||
|
||||
statusLabel = new JLabel("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
statusBar.add(statusLabel);
|
||||
noiseFloorLabel = new NoiseFloor();
|
||||
|
||||
statusBar.add(noiseFloorLabel);
|
||||
// statusBar.add(Box.createHorizontalStrut(2));
|
||||
statusBar.add(queueMonitor);
|
||||
|
||||
buildToolbar(centralPanel);
|
||||
@@ -1010,6 +1012,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
Options.savePreferences();
|
||||
}
|
||||
|
||||
queueJob(new VersionChecker());
|
||||
|
||||
}
|
||||
|
||||
void bindKeys(JComponent component) {
|
||||
@@ -2328,7 +2332,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
|
||||
bookTree.expandPath(new TreePath(book.getPath()));
|
||||
|
||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -2586,7 +2590,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
|
||||
bookTree.expandPath(new TreePath(book.getPath()));
|
||||
|
||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||
book.setIcon(Icons.book);
|
||||
}
|
||||
|
||||
@@ -2659,7 +2663,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
Debug.trace();
|
||||
roomNoise.stopRecording();
|
||||
centralPanel.setFlash(false);
|
||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||
}
|
||||
}, 5000); // 5 seconds of recording
|
||||
}
|
||||
@@ -4194,7 +4198,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
}
|
||||
}
|
||||
if (orphans.getChildCount() == 0) {
|
||||
try {
|
||||
bookTreeModel.removeNodeFromParent(orphans);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
// Biquad.java
|
||||
//
|
||||
// Created by Nigel Redmon on 11/24/12
|
||||
// EarLevel Engineering: earlevel.com
|
||||
// Copyright 2012 Nigel Redmon
|
||||
// Translated to Java 2019 Majenko Technologies
|
||||
//
|
||||
// For a complete explanation of the Biquad code:
|
||||
// http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
|
||||
//
|
||||
// License:
|
||||
//
|
||||
// This source code is provided as is, without warranty.
|
||||
// You may copy and distribute verbatim copies of this document.
|
||||
// You may modify and use this source code to create binary code
|
||||
// for your own purposes, free or commercial.
|
||||
//
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Biquad implements Effect {
|
||||
|
||||
@@ -450,7 +450,10 @@ public class Book extends BookTreeNode {
|
||||
public void run() {
|
||||
if (AudiobookRecorder.window == null) return;
|
||||
if (AudiobookRecorder.window.bookTreeModel == null) return;
|
||||
try {
|
||||
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,40 +1,16 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
/**
|
||||
* @author Orlando Selenu
|
||||
*
|
||||
*/
|
||||
public class FFT {
|
||||
/**
|
||||
* The Fast Fourier Transform (generic version, with NO optimizations).
|
||||
*
|
||||
* @param inputReal
|
||||
* an array of length n, the real part
|
||||
* @param inputImag
|
||||
* an array of length n, the imaginary part
|
||||
* @param DIRECT
|
||||
* TRUE = direct transform, FALSE = inverse transform
|
||||
* @return a new array of length 2n
|
||||
*/
|
||||
public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||
boolean DIRECT) {
|
||||
// - n is the dimension of the problem
|
||||
// - nu is its logarithm in base e
|
||||
public static double[] fft(final double[] inputReal, double[] inputImag, boolean DIRECT) {
|
||||
int n = inputReal.length;
|
||||
|
||||
// If n is a power of 2, then ld is an integer (_without_ decimals)
|
||||
double ld = Math.log(n) / Math.log(2.0);
|
||||
|
||||
// Here I check if n is a power of 2. If exist decimals in ld, I quit
|
||||
// from the function returning null.
|
||||
if (((int) ld) - ld != 0) {
|
||||
System.out.println("The number of elements is not a power of 2.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Declaration and initialization of the variables
|
||||
// ld should be an integer, actually, so I don't lose any information in
|
||||
// the cast
|
||||
int nu = (int) ld;
|
||||
int n2 = n / 2;
|
||||
int nu1 = nu - 1;
|
||||
@@ -42,22 +18,18 @@ public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||
double[] xImag = new double[n];
|
||||
double tReal, tImag, p, arg, c, s;
|
||||
|
||||
// Here I check if I'm going to do the direct transform or the inverse
|
||||
// transform.
|
||||
double constant;
|
||||
if (DIRECT)
|
||||
if (DIRECT) {
|
||||
constant = -2 * Math.PI;
|
||||
else
|
||||
} else {
|
||||
constant = 2 * Math.PI;
|
||||
}
|
||||
|
||||
// I don't want to overwrite the input arrays, so here I copy them. This
|
||||
// choice adds \Theta(2n) to the complexity.
|
||||
for (int i = 0; i < n; i++) {
|
||||
xReal[i] = inputReal[i];
|
||||
xImag[i] = inputImag[i];
|
||||
}
|
||||
|
||||
// First phase - calculation
|
||||
int k = 0;
|
||||
for (int l = 1; l <= nu; l++) {
|
||||
while (k < n) {
|
||||
@@ -82,7 +54,6 @@ public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||
n2 /= 2;
|
||||
}
|
||||
|
||||
// Second phase - recombination
|
||||
k = 0;
|
||||
int r;
|
||||
while (k < n) {
|
||||
@@ -98,24 +69,16 @@ public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||
k++;
|
||||
}
|
||||
|
||||
// Here I have to mix xReal and xImag to have an array (yes, it should
|
||||
// be possible to do this stuff in the earlier parts of the code, but
|
||||
// it's here to readibility).
|
||||
double[] newArray = new double[xReal.length * 2];
|
||||
double radice = 1 / Math.sqrt(n);
|
||||
for (int i = 0; i < newArray.length; i += 2) {
|
||||
int i2 = i / 2;
|
||||
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
||||
// to normalize the output while I'm copying the elements.
|
||||
newArray[i] = xReal[i2] * radice;
|
||||
newArray[i + 1] = xImag[i2] * radice;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference bitreverse function.
|
||||
*/
|
||||
private static int bitreverseReference(int j, int nu) {
|
||||
int j2;
|
||||
int j1 = j;
|
||||
|
||||
@@ -14,10 +14,6 @@ public class KVPair<K,V> implements Comparable {
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
// if (o instanceof KVPair) {
|
||||
// KVPair ko = (KVPair)o;
|
||||
// return key.compareTo(ko.key);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
|
||||
public class NoiseFloor extends JPanel {
|
||||
|
||||
int noiseFloor = 0;
|
||||
|
||||
public NoiseFloor() {
|
||||
super();
|
||||
noiseFloor = 0;
|
||||
}
|
||||
|
||||
public void setNoiseFloor(int n) {
|
||||
noiseFloor = n;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(128, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMaximumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
Rectangle size = g.getClipBounds();
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, size.width - 1, size.height - 1);
|
||||
g.setColor(new Color(10, 10, 10));
|
||||
g.drawRect(0, 0, size.width - 1, size.height - 1);
|
||||
g.setFont(getFont());
|
||||
|
||||
g.setColor(getForeground());
|
||||
g.drawString("Noise Floor: " + noiseFloor + "dB", 6, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,3 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Majenko Technologies
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Majenko Technologies nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
80
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
80
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.lang.Runnable;
|
||||
import java.net.URL;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
import org.json.JSONObject;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class VersionChecker implements Runnable {
|
||||
public VersionChecker() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL("https://api.github.com/repos/MajenkoProjects/AudiobookRecorder/releases/latest");
|
||||
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
|
||||
String inputLine;
|
||||
StringBuilder jsonData = new StringBuilder();
|
||||
|
||||
while ((inputLine = br.readLine()) != null) {
|
||||
jsonData.append(inputLine);
|
||||
}
|
||||
|
||||
br.close();
|
||||
|
||||
JSONObject job = new JSONObject(jsonData.toString());
|
||||
|
||||
String installed = AudiobookRecorder.config.getProperty("version");
|
||||
String available = job.getString("tag_name");
|
||||
if (available.startsWith("v")) {
|
||||
available = available.substring(1);
|
||||
}
|
||||
String website = job.getString("html_url");
|
||||
|
||||
|
||||
String[] installedParts = installed.split("\\.");
|
||||
String[] availableParts = available.split("\\.");
|
||||
// Must be x.y.z
|
||||
|
||||
System.err.println(installedParts.length);
|
||||
System.err.println(availableParts.length);
|
||||
|
||||
if (installedParts.length != 3) return;
|
||||
if (availableParts.length != 3) return;
|
||||
|
||||
// Convert to xxxyyyzzz
|
||||
String installedVersion = String.format("%03d%03d%03d", Utils.s2i(installedParts[0]), Utils.s2i(installedParts[1]), Utils.s2i(installedParts[2]));
|
||||
String availableVersion = String.format("%03d%03d%03d", Utils.s2i(availableParts[0]), Utils.s2i(availableParts[1]), Utils.s2i(availableParts[2]));
|
||||
|
||||
if (Utils.s2i(installedVersion) >= Utils.s2i(availableVersion)) return;
|
||||
|
||||
System.err.println("Version installed: " + installed);
|
||||
System.err.println("Version available: " + available);
|
||||
System.err.println("URL: " + website);
|
||||
|
||||
JButton upgrade = new JButton("A new version is available.");
|
||||
upgrade.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
Utils.browse(website);
|
||||
}
|
||||
});
|
||||
|
||||
AudiobookRecorder.window.statusBar.add(upgrade);
|
||||
AudiobookRecorder.window.statusBar.revalidate();
|
||||
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user