Skip to content

Commit

Permalink
Added song visualizer (#31)
Browse files Browse the repository at this point in the history
* Added song visualizer window

* Animate keys when they are pressed down

* Use ratio instead of hardcoded sizes

* Fixed rendering issues on Linux/AMD

* Made key colors more vibrant

* Improved keyboard design

* Optimized map lookups

* Improved piano visuals

* Updated ThinGL API usage

* Improved NBS renderer visuals

* Removed MacOS OpenGL natives

* Visualize tempo changes

* Added button to open/close the visualizer window

* Updated ThinGL

---------

Co-authored-by: Lenni0451 <20379977+Lenni0451@users.noreply.github.com>
  • Loading branch information
RaphiMC and Lenni0451 authored Feb 7, 2025
1 parent 33e2b1b commit 145cadc
Show file tree
Hide file tree
Showing 12 changed files with 763 additions and 6 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ dependencies {
include "org.lwjgl:lwjgl-stb:3.3.6:$it"
}
include "net.java.dev.jna:jna:5.16.0"

include("net.raphimc:thingl:0.0.1-20250207.205058-20") {
exclude group: "org.slf4j", module: "slf4j-api"
}
include "org.lwjgl:lwjgl-glfw:3.3.6"
include "org.lwjgl:lwjgl-opengl:3.3.6"
include "org.lwjgl:lwjgl-freetype:3.3.6"
["natives-windows", "natives-windows-arm64", "natives-linux", "natives-linux-arm64"].each {
include "org.lwjgl:lwjgl-glfw:3.3.6:$it"
include "org.lwjgl:lwjgl-opengl:3.3.6:$it"
include "org.lwjgl:lwjgl-freetype:3.3.6:$it"
}
}

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public synchronized void close() {
}

@Override
public synchronized String getStatusLine() {
public String getStatusLine() {
return "Sounds: " + this.audioMixer.getMasterMixSound().getMixedSounds() + " / " + this.maxSounds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public synchronized void close() {
}

@Override
public synchronized String getStatusLine() {
public String getStatusLine() {
int mixedSounds = 0;
for (AudioMixer audioMixer : this.audioMixers) {
mixedSounds += audioMixer.getMasterMixSound().getMixedSounds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.raphimc.noteblocktool.audio.soundsystem.impl.*;
import net.raphimc.noteblocktool.elements.FastScrollPane;
import net.raphimc.noteblocktool.elements.NewLineLabel;
import net.raphimc.noteblocktool.frames.visualizer.VisualizerWindow;
import net.raphimc.noteblocktool.util.SoundSystemSongPlayer;

import javax.swing.*;
Expand All @@ -36,7 +37,8 @@

public class SongPlayerFrame extends JFrame {

private static final String UNAVAILABLE_MESSAGE = "An error occurred while initializing the sound system.\nPlease make sure that your system supports the selected sound system.";
private static final String SOUND_SYSTEM_UNAVAILABLE_MESSAGE = "An error occurred while initializing the sound system.\nPlease make sure that your system supports the selected sound system.";
private static final String VISUALIZER_UNAVAILABLE_MESSAGE = "An error occurred while initializing the visualizer window.\nPlease make sure that your system supports at least OpenGL 4.5.";
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
private static SongPlayerFrame instance;
private static Point lastPosition;
Expand Down Expand Up @@ -76,6 +78,7 @@ public static void close() {
private final JSlider volumeSlider = new JSlider(0, 100, lastVolume);
private final JButton playStopButton = new JButton("Play");
private final JButton pauseResumeButton = new JButton("Pause");
private final JButton openVisualizerButton = new JButton("Open Visualizer");
private final JSlider progressSlider = new JSlider(0, 100, 0);
private final JLabel statusLine = new JLabel(" ");
private final JLabel progressLabel = new JLabel("Current Position: 00:00:00");
Expand Down Expand Up @@ -215,6 +218,21 @@ private void initComponents() {
this.soundSystem.stopSounds();
}
});
buttonPanel.add(this.openVisualizerButton);
this.openVisualizerButton.addActionListener(e -> {
if (VisualizerWindow.getInstance().isVisible()) {
this.openVisualizerButton.setText("Open Visualizer");
VisualizerWindow.getInstance().hide();
} else {
VisualizerWindow.getInstance().open(this.songPlayer, this::toFront, () -> SwingUtilities.invokeLater(() -> this.openVisualizerButton.setText("Open Visualizer")));
if (VisualizerWindow.getInstance().isRenderThreadAlive()) {
this.openVisualizerButton.setText("Close Visualizer");
} else {
JOptionPane.showMessageDialog(this, VISUALIZER_UNAVAILABLE_MESSAGE, "Error", JOptionPane.ERROR_MESSAGE);
this.openVisualizerButton.setEnabled(false);
}
}
});
GBC.create(southPanel).grid(0, gridy++).insets(5, 5, 5, 5).weightx(1).width(2).fill(GBC.HORIZONTAL).add(buttonPanel);

final JPanel statusBar = new JPanel();
Expand All @@ -240,7 +258,7 @@ private boolean initSoundSystem() {
} else if (this.soundSystem == null) {
currentIndex = -1;
} else {
throw new UnsupportedOperationException(UNAVAILABLE_MESSAGE);
throw new UnsupportedOperationException(SOUND_SYSTEM_UNAVAILABLE_MESSAGE);
}

try {
Expand All @@ -261,14 +279,14 @@ private boolean initSoundSystem() {
} else if (this.soundSystemComboBox.getSelectedIndex() == 4) {
this.soundSystem = new XAudio2SoundSystem(soundData, maxSounds);
} else {
throw new UnsupportedOperationException(UNAVAILABLE_MESSAGE);
throw new UnsupportedOperationException(SOUND_SYSTEM_UNAVAILABLE_MESSAGE);
}
}
return this.soundSystem != null;
} catch (Throwable t) {
this.soundSystem = null;
t.printStackTrace();
JOptionPane.showMessageDialog(this, UNAVAILABLE_MESSAGE, "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, SOUND_SYSTEM_UNAVAILABLE_MESSAGE, "Error", JOptionPane.ERROR_MESSAGE);
}
return false;
}
Expand All @@ -285,6 +303,7 @@ public void windowClosing(WindowEvent e) {
public void windowClosed(WindowEvent e) {
SongPlayerFrame.this.songPlayer.stop();
SongPlayerFrame.this.updateTimer.stop();
VisualizerWindow.getInstance().hide();
if (SongPlayerFrame.this.soundSystem != null) SongPlayerFrame.this.soundSystem.close();
}
});
Expand Down
Loading

0 comments on commit 145cadc

Please sign in to comment.