diff --git a/src/main/java/sh/ball/audio/ShapeAudioPlayer.java b/src/main/java/sh/ball/audio/ShapeAudioPlayer.java index 050c7c6..45d8fde 100644 --- a/src/main/java/sh/ball/audio/ShapeAudioPlayer.java +++ b/src/main/java/sh/ball/audio/ShapeAudioPlayer.java @@ -33,7 +33,7 @@ public class ShapeAudioPlayer implements AudioPlayer> { private static final int BUFFER_SIZE = 10; private static final boolean BIG_ENDIAN = false; - private static final double MIN_LENGTH_INCREMENT = 0.0000000001; + private static final double MIN_LENGTH_INCREMENT = 0.000001; // MIDI private final short[][] keyTargetVolumes = new short[MidiNote.NUM_CHANNELS][128]; diff --git a/src/main/java/sh/ball/gui/Gui.java b/src/main/java/sh/ball/gui/Gui.java index dec3ccb..bc2b45a 100644 --- a/src/main/java/sh/ball/gui/Gui.java +++ b/src/main/java/sh/ball/gui/Gui.java @@ -175,6 +175,7 @@ public class Gui extends Application { public void launchMainApplication(MainController controller, String projectPath, Boolean muted) throws Exception { scene.setRoot(root); + controller.initialiseAudioEngine(); controller.openProject(projectPath); if (muted) { controller.setVolume(0); diff --git a/src/main/java/sh/ball/gui/controller/MainController.java b/src/main/java/sh/ball/gui/controller/MainController.java index 1734c9e..f8f777b 100644 --- a/src/main/java/sh/ball/gui/controller/MainController.java +++ b/src/main/java/sh/ball/gui/controller/MainController.java @@ -194,22 +194,8 @@ public class MainController implements Initializable, FrequencyListener, MidiLis @FXML private ComboBox audioSampleComboBox; - public MainController() { - FrameSource> frames = new ShapeFrameSource(List.of(new Vector2())); - openFiles.add(new byte[0]); - frameSources.add(frames); - sampleParsers.add(null); - frameSourcePaths.add("Empty file"); - currentFrameSource = 0; - this.producer = new FrameProducer<>(audioPlayer, frames); - if (defaultDevice == null) { - throw new RuntimeException("No default audio device found!"); - } - this.sampleRate = defaultDevice.sampleRate(); - } // initialises midiButtonMap by mapping MIDI logo SVGs to the slider that they // control if they are selected. - private Map initializeMidiButtonMap() { Map midiMap = new HashMap<>(); subControllers().forEach(controller -> midiMap.putAll(controller.getMidiButtonMap())); @@ -349,7 +335,6 @@ public class MainController implements Initializable, FrequencyListener, MidiLis }); } - objController.setAudioProducer(producer); generalController.setMainController(this); luaController.setMainController(this); @@ -532,32 +517,6 @@ public class MainController implements Initializable, FrequencyListener, MidiLis }); brightnessSlider.valueProperty().addListener((e, old, brightness) -> audioPlayer.setBrightness(brightness.doubleValue())); - - objController.updateObjectRotateSpeed(); - - executor.submit(producer); - Gui.midiCommunicator.addListener(this); - AudioInput audioInput = new JavaAudioInput(); - if (audioInput.isAvailable()) { - audioInput.addListener(this); - new Thread(audioInput).start(); - } else { - for (CheckBox checkBox : micCheckBoxes()) { - if (checkBox != null) { - checkBox.setDisable(true); - } - } - } - - luaController.updateLuaVariables(); - - objectServer = new ObjectServer(this::enableObjectServerRendering, this::disableObjectServerRendering); - new Thread(objectServer).start(); - - webSocketServer = new ByteWebSocketServer(); - webSocketServer.start(); - this.buffer = new byte[FRAME_SIZE * SOSCI_NUM_VERTICES * SOSCI_VERTEX_SIZE]; - new Thread(() -> sendAudioDataToWebSocket(webSocketServer)).start(); } public void setLuaVariable(String variableName, Object value) { @@ -1459,6 +1418,48 @@ public class MainController implements Initializable, FrequencyListener, MidiLis effectsController.setVolume(volume); } + public void initialiseAudioEngine() { + FrameSource> frames = new ShapeFrameSource(List.of(new Vector2())); + openFiles.add(new byte[0]); + frameSources.add(frames); + sampleParsers.add(null); + frameSourcePaths.add("Empty file"); + currentFrameSource = 0; + producer = new FrameProducer<>(audioPlayer, frames); + objController.setAudioProducer(producer); + + if (defaultDevice == null) { + throw new RuntimeException("No default audio device found!"); + } + sampleRate = defaultDevice.sampleRate(); + + objController.updateObjectRotateSpeed(); + + executor.submit(producer); + Gui.midiCommunicator.addListener(this); + AudioInput audioInput = new JavaAudioInput(); + if (audioInput.isAvailable()) { + audioInput.addListener(this); + new Thread(audioInput).start(); + } else { + for (CheckBox checkBox : micCheckBoxes()) { + if (checkBox != null) { + checkBox.setDisable(true); + } + } + } + + luaController.updateLuaVariables(); + + objectServer = new ObjectServer(this::enableObjectServerRendering, this::disableObjectServerRendering); + new Thread(objectServer).start(); + + webSocketServer = new ByteWebSocketServer(); + webSocketServer.start(); + this.buffer = new byte[FRAME_SIZE * SOSCI_NUM_VERTICES * SOSCI_VERTEX_SIZE]; + new Thread(() -> sendAudioDataToWebSocket(webSocketServer)).start(); + } + private record PrintableSlider(Slider slider) { @Override public String toString() { diff --git a/src/main/java/sh/ball/oscilloscope/ByteWebSocketServer.java b/src/main/java/sh/ball/oscilloscope/ByteWebSocketServer.java index 15be6f9..5a67027 100644 --- a/src/main/java/sh/ball/oscilloscope/ByteWebSocketServer.java +++ b/src/main/java/sh/ball/oscilloscope/ByteWebSocketServer.java @@ -8,6 +8,9 @@ import java.net.InetSocketAddress; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; + +import static sh.ball.gui.Gui.logger; public class ByteWebSocketServer extends WebSocketServer { @@ -26,6 +29,7 @@ public class ByteWebSocketServer extends WebSocketServer { sock.send(bytes); } catch (Exception e) { conns.remove(sock); + logger.log(Level.SEVERE, e.getMessage(), e); } } } diff --git a/src/main/resources/CHANGELOG.md b/src/main/resources/CHANGELOG.md index 69cda17..b9b70ab 100644 --- a/src/main/resources/CHANGELOG.md +++ b/src/main/resources/CHANGELOG.md @@ -7,6 +7,8 @@ - Shows last 20 previously opened projects - These can be clicked on to open a previous project - Allow any font that has been installed on your machine to be used with text files + - Change font by selecting a font from the drop-down under View > Text File Font + - Change font style (i.e. plain, bold, italic) by selecting a font style from the drop-down under View > Text File Font Style - 1.26.4