diff --git a/pom.xml b/pom.xml
index 8deb1d5..8002f05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,19 @@
1.8
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 2.4.2
+
+
+ package
+
+ shade
+
+
+
+
@@ -30,12 +43,22 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+ local-repo
+ file:///${basedir}/repo
+
org.spigotmc
spigot-api
1.12.2-R0.1-SNAPSHOT
+ provided
+
+
+ jouvieje
+ nativebass
+ 1.1.2
\ No newline at end of file
diff --git a/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.jar b/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.jar
new file mode 100644
index 0000000..1ace9f1
Binary files /dev/null and b/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.jar differ
diff --git a/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.pom b/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.pom
new file mode 100644
index 0000000..3f41a59
--- /dev/null
+++ b/repo/jouvieje/nativebass/1.1.2/nativebass-1.1.2.pom
@@ -0,0 +1,9 @@
+
+
+ 4.0.0
+ jouvieje
+ nativebass
+ 1.1.2
+ POM was created from install:install-file
+
diff --git a/repo/jouvieje/nativebass/maven-metadata-local.xml b/repo/jouvieje/nativebass/maven-metadata-local.xml
new file mode 100644
index 0000000..fdb8f65
--- /dev/null
+++ b/repo/jouvieje/nativebass/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+
+
+ jouvieje
+ nativebass
+
+ 1.1.2
+
+ 1.1.2
+
+ 20171110213049
+
+
diff --git a/src/io/github/norbipeti/audiospectrum/Analyzer.java b/src/io/github/norbipeti/audiospectrum/Analyzer.java
new file mode 100644
index 0000000..5f8eed0
--- /dev/null
+++ b/src/io/github/norbipeti/audiospectrum/Analyzer.java
@@ -0,0 +1,160 @@
+package io.github.norbipeti.audiospectrum;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import static jouvieje.bass.Bass.*;
+import static jouvieje.bass.defines.BASS_MUSIC.BASS_MUSIC_RAMP;
+import static jouvieje.bass.defines.BASS_SAMPLE.BASS_SAMPLE_LOOP;
+
+import static jouvieje.bass.defines.BASS_DATA.BASS_DATA_FFT2048;
+import static jouvieje.bass.utils.BufferUtils.newByteBuffer;
+import static jouvieje.bass.utils.BufferUtils.SIZEOF_FLOAT;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import jouvieje.bass.BassInit;
+import jouvieje.bass.exceptions.BassException;
+import jouvieje.bass.structures.HMUSIC;
+import jouvieje.bass.structures.HSTREAM;
+
+public class Analyzer //Based on NativeBass example 'Spectrum'
+{
+ /* display error messages */
+ private final void error(String text, CommandSender sender)
+ {
+ System.out.println(text + " - " + BASS_ErrorGetCode());
+ }
+
+ private final void printfExit(String format, Object... args)
+ {
+ String s = String.format(format, args);
+ System.out.println(s);
+ stop();
+ Bukkit.getPluginManager().disablePlugin(PluginMain.getPlugin(PluginMain.class));
+ }
+
+ private boolean init = false;
+ private boolean deinit = false;
+
+ private int chan;
+
+ public void init()
+ {
+ /*
+ * NativeBass Init
+ */
+ try
+ {
+ BassInit.loadLibraries();
+ } catch (BassException e)
+ {
+ printfExit("NativeBass error! %s\n", e.getMessage());
+ return;
+ }
+
+ /*
+ * Checking NativeBass version
+ */
+ if (BassInit.NATIVEBASS_LIBRARY_VERSION() != BassInit.NATIVEBASS_JAR_VERSION())
+ {
+ printfExit("Error! NativeBass library version (%08x) is different to jar version (%08x)\n",
+ BassInit.NATIVEBASS_LIBRARY_VERSION(), BassInit.NATIVEBASS_JAR_VERSION());
+ return;
+ }
+
+ /* ================================================== */
+
+ init = true;
+ }
+
+ private ByteBuffer buffer;
+ private TimerTask tt;
+
+ public FloatBuffer run(CommandSender sender, String file)
+ {
+ if (!init)
+ {
+ return null;
+ }
+
+ // check the correct BASS was loaded
+ if (((BASS_GetVersion() & 0xFFFF0000) >> 16) != BassInit.BASSVERSION())
+ {
+ printfExit("An incorrect version of BASS.DLL was loaded");
+ return null;
+ }
+
+ // initialize BASS
+ if (!BASS_Init(-1, 44100, 0, null, null))
+ {
+ error("Can't initialize device", sender);
+ stop();
+ return null;
+ }
+ if (!playFile(sender, file))
+ {
+ // start a file playing
+ BASS_Free();
+ stop();
+ return null;
+ }
+ final int size = 1024 * SIZEOF_FLOAT;
+ if (buffer == null || buffer.capacity() < size)
+ buffer = newByteBuffer(size);
+ // setup update timer (50hz)
+ timer.scheduleAtFixedRate(tt = new TimerTask()
+ {
+ @Override
+ public void run()
+ {
+ BASS_ChannelGetData(chan, buffer, BASS_DATA_FFT2048); //Get the FFT data
+ }
+ }, 50, 50);
+ FloatBuffer floats = buffer.asFloatBuffer();
+ return floats;
+ }
+
+ public boolean isRunning()
+ {
+ return deinit;
+ }
+
+ public void stop()
+ {
+ if (!init || deinit)
+ {
+ return;
+ }
+ deinit = true;
+
+ tt.cancel();
+ BASS_Free();
+ }
+
+ private boolean playFile(CommandSender sender, String file)
+ {
+ if (!new File(file).exists())
+ {
+ sender.sendMessage("§cFile not found: " + file);
+ }
+ HSTREAM stream = null;
+ HMUSIC music = null;
+ if ((stream = BASS_StreamCreateFile(false, file, 0, 0, BASS_SAMPLE_LOOP)) == null
+ && (music = BASS_MusicLoad(false, file, 0, 0, BASS_MUSIC_RAMP | BASS_SAMPLE_LOOP, 0)) == null)
+ {
+ error("Can't play file", sender);
+ return false; // Can't load the file
+ }
+
+ chan = (stream != null) ? stream.asInt() : ((music != null) ? music.asInt() : 0);
+
+ BASS_ChannelPlay(chan, false);
+ return true;
+ }
+
+ private Timer timer = new Timer();
+}
diff --git a/src/io/github/norbipeti/audiospectrum/BarsRenderer.java b/src/io/github/norbipeti/audiospectrum/BarsRenderer.java
index 0cc21ca..f0487b9 100644
--- a/src/io/github/norbipeti/audiospectrum/BarsRenderer.java
+++ b/src/io/github/norbipeti/audiospectrum/BarsRenderer.java
@@ -7,18 +7,19 @@ import org.bukkit.map.*;
public class BarsRenderer extends BarsRendererBase
{
- private boolean single = false;
+ private boolean single = true;
public BarsRenderer(int[] bars)
{
super(bars);
+ //System.out.println("black: " + MapPalette.matchColor(Color.black));
+ //System.out.println("BLACK: " + MapPalette.matchColor(Color.BLACK));
}
@SuppressWarnings("deprecation")
@Override
public void render(MapView mv, MapCanvas mc, Player pl)
{ //Width: 8, empty space: 8, count per map: 8
- //if (firstrender ? !(firstrender = !firstrender) : firstrender)
if (firstrender < 4 ? firstrender++ < 4 : false) //Only increment if true
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++)
@@ -35,7 +36,6 @@ public class BarsRenderer extends BarsRendererBase
return;
}
int offsetx = mv.getId() % 2 * 8, offsety = mv.getId() < 2 ? -128 : 0;
- //System.out.println("OX: " + offsetx + " OY: " + offsety + " ID: " + mv.getId());
for (int i = 0; i < 8 && i < count - offsetx; i++)
for (int j = 0; j < 128; j++)
for (int k = 0; k < 8; k++)
diff --git a/src/io/github/norbipeti/audiospectrum/PluginMain.java b/src/io/github/norbipeti/audiospectrum/PluginMain.java
index 39a3cd2..5ec7b94 100644
--- a/src/io/github/norbipeti/audiospectrum/PluginMain.java
+++ b/src/io/github/norbipeti/audiospectrum/PluginMain.java
@@ -12,7 +12,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class PluginMain extends JavaPlugin
{
- private Thread thread;
+ //private Thread thread;
private boolean running = false;
private volatile int[] bars = new int[16];
private BarsRenderer br;
@@ -31,16 +31,13 @@ public class PluginMain extends JavaPlugin
map.getRenderers().clear();
map.addRenderer(br);
}
- thread = new Thread()
- {
- @Override
- public void run()
- {
- PluginMain.this.run(5896);
- }
- };
- running = true;
- thread.start();
+ //thread = new Thread(() -> PluginMain.this.run(5896));
+ //running = true;
+ //thread.start();
+ Analyzer an = new Analyzer();
+ Bukkit.getConsoleSender().sendMessage("§bInitializing analyzer...");
+ an.init(); //TODO: Add command to play music, test
+ Bukkit.getConsoleSender().sendMessage("§bDone!");
}
// Fired when plugin is disabled
@@ -65,8 +62,6 @@ public class PluginMain extends JavaPlugin
while (running)
{
serverSocket.receive(receivePacket);
- //bars[Byte.toUnsignedInt(packet[0])] = Byte.toUnsignedInt(packet[1]);
- //System.out.println("Index: " + Byte.toUnsignedInt(packet[0]) + " Value: " + bars[Byte.toUnsignedInt(packet[0])]);
for (int i = 0; i < packet.length && i < bars.length; i++)
bars[i] = Byte.toUnsignedInt(packet[i]);
}