Added velocity threshold
This commit is contained in:
parent
3d2f89e10f
commit
92a982b2f0
7 changed files with 61 additions and 13 deletions
|
@ -54,6 +54,7 @@ public class CommandProcessor {
|
||||||
commands.add(new toggleFakePlayerCommand());
|
commands.add(new toggleFakePlayerCommand());
|
||||||
commands.add(new setStageTypeCommand());
|
commands.add(new setStageTypeCommand());
|
||||||
commands.add(new toggleMovementCommand());
|
commands.add(new toggleMovementCommand());
|
||||||
|
commands.add(new setVelocityThresholdCommand());
|
||||||
commands.add(new toggleAutoCleanup());
|
commands.add(new toggleAutoCleanup());
|
||||||
commands.add(new cleanupLastStageCommand());
|
commands.add(new cleanupLastStageCommand());
|
||||||
commands.add(new announcementCommand());
|
commands.add(new announcementCommand());
|
||||||
|
@ -950,6 +951,40 @@ public class CommandProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class setVelocityThresholdCommand extends Command {
|
||||||
|
public String getName() {
|
||||||
|
return "setVelocityThreshold";
|
||||||
|
}
|
||||||
|
public String[] getAliases() {
|
||||||
|
return new String[]{"velocityThreshold", "threshold"};
|
||||||
|
}
|
||||||
|
public String[] getSyntax() {
|
||||||
|
return new String[] {"<number>"};
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return "Sets the minimum velocity below which notes won't be played (applies to midi and nbs). This must be a number from 0 to 100. For song items, the threshold is baked in upon item creation.";
|
||||||
|
}
|
||||||
|
public boolean processCommand(String args) {
|
||||||
|
if (args.length() > 0) {
|
||||||
|
try {
|
||||||
|
int threshold = Integer.parseInt(args);
|
||||||
|
if (threshold < 0 || threshold > 100) {
|
||||||
|
SongPlayer.addChatMessage("§cVelocity threshold must be a value between 0 and 100");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Config.getConfig().velocityThreshold = threshold;
|
||||||
|
SongPlayer.addChatMessage("§6Set velocity threshold to " + threshold);
|
||||||
|
Config.saveConfigWithErrorHandling();
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class toggleAutoCleanup extends Command {
|
private static class toggleAutoCleanup extends Command {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "toggleAutoCleanup";
|
return "toggleAutoCleanup";
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class Config {
|
||||||
public Stage.StageType stageType = Stage.StageType.DEFAULT;
|
public Stage.StageType stageType = Stage.StageType.DEFAULT;
|
||||||
public boolean swing = false;
|
public boolean swing = false;
|
||||||
public boolean rotate = false;
|
public boolean rotate = false;
|
||||||
|
public int velocityThreshold = 0;
|
||||||
public boolean doAnnouncement = false;
|
public boolean doAnnouncement = false;
|
||||||
public String announcementMessage = "&6Now playing: &3[name]";
|
public String announcementMessage = "&6Now playing: &3[name]";
|
||||||
public boolean autoCleanup = false;
|
public boolean autoCleanup = false;
|
||||||
|
|
|
@ -90,18 +90,19 @@ public class MidiConverter {
|
||||||
instrumentIds[sm.getChannel()] = sm.getData1();
|
instrumentIds[sm.getChannel()] = sm.getData1();
|
||||||
}
|
}
|
||||||
else if (sm.getCommand() == NOTE_ON) {
|
else if (sm.getCommand() == NOTE_ON) {
|
||||||
if (sm.getData2() == 0) continue;
|
|
||||||
int pitch = sm.getData1();
|
int pitch = sm.getData1();
|
||||||
|
int velocity = sm.getData2();
|
||||||
|
if (velocity == 0) continue; // Just ignore notes with velocity 0
|
||||||
long deltaTick = event.getTick() - prevTick;
|
long deltaTick = event.getTick() - prevTick;
|
||||||
prevTick = event.getTick();
|
prevTick = event.getTick();
|
||||||
microTime += (mpq/tpq) * deltaTick;
|
microTime += (mpq/tpq) * deltaTick;
|
||||||
|
|
||||||
Note note;
|
Note note;
|
||||||
if (sm.getChannel() == 9) {
|
if (sm.getChannel() == 9) {
|
||||||
note = getMidiPercussionNote(pitch, microTime);
|
note = getMidiPercussionNote(pitch, velocity, microTime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
note = getMidiInstrumentNote(instrumentIds[sm.getChannel()], pitch, microTime);
|
note = getMidiInstrumentNote(instrumentIds[sm.getChannel()], pitch, velocity, microTime);
|
||||||
}
|
}
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
song.add(note);
|
song.add(note);
|
||||||
|
@ -141,7 +142,7 @@ public class MidiConverter {
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, long microTime) {
|
public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, int velocity, long microTime) {
|
||||||
com.github.hhhzzzsss.songplayer.song.Instrument instrument = null;
|
com.github.hhhzzzsss.songplayer.song.Instrument instrument = null;
|
||||||
com.github.hhhzzzsss.songplayer.song.Instrument[] instrumentList = instrumentMap.get(midiInstrument);
|
com.github.hhhzzzsss.songplayer.song.Instrument[] instrumentList = instrumentMap.get(midiInstrument);
|
||||||
if (instrumentList != null) {
|
if (instrumentList != null) {
|
||||||
|
@ -161,15 +162,15 @@ public class MidiConverter {
|
||||||
int noteId = pitch + instrument.instrumentId*25;
|
int noteId = pitch + instrument.instrumentId*25;
|
||||||
long time = microTime / 1000L;
|
long time = microTime / 1000L;
|
||||||
|
|
||||||
return new Note(noteId, time);
|
return new Note(noteId, time, velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Note getMidiPercussionNote(int midiPitch, long microTime) {
|
private static Note getMidiPercussionNote(int midiPitch, int velocity, long microTime) {
|
||||||
if (percussionMap.containsKey(midiPitch)) {
|
if (percussionMap.containsKey(midiPitch)) {
|
||||||
int noteId = percussionMap.get(midiPitch);
|
int noteId = percussionMap.get(midiPitch);
|
||||||
long time = microTime / 1000L;
|
long time = microTime / 1000L;
|
||||||
|
|
||||||
return new Note(noteId, time);
|
return new Note(noteId, time, velocity);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class NBSConverter {
|
||||||
|
|
||||||
int pitch = note.key-33;
|
int pitch = note.key-33;
|
||||||
int noteId = pitch + instrument.instrumentId*25;
|
int noteId = pitch + instrument.instrumentId*25;
|
||||||
song.add(new Note(noteId, getMilliTime(note.tick, tempo)));
|
song.add(new Note(noteId, getMilliTime(note.tick, tempo), layerVolume));
|
||||||
}
|
}
|
||||||
|
|
||||||
song.length = song.get(song.size()-1).time + 50;
|
song.length = song.get(song.size()-1).time + 50;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.hhhzzzsss.songplayer.conversion;
|
package com.github.hhhzzzsss.songplayer.conversion;
|
||||||
|
|
||||||
|
import com.github.hhhzzzsss.songplayer.Config;
|
||||||
import com.github.hhhzzzsss.songplayer.Util;
|
import com.github.hhhzzzsss.songplayer.Util;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Note;
|
import com.github.hhhzzzsss.songplayer.song.Note;
|
||||||
import com.github.hhhzzzsss.songplayer.song.Song;
|
import com.github.hhhzzzsss.songplayer.song.Song;
|
||||||
|
@ -81,7 +82,7 @@ public class SPConverter {
|
||||||
|
|
||||||
song.sort();
|
song.sort();
|
||||||
long prevTime = 0;
|
long prevTime = 0;
|
||||||
for (Note note : song.notes) {
|
for (Note note : song.notes) if (note.velocity >= Config.getConfig().velocityThreshold) {
|
||||||
writeShort(os, note.noteId);
|
writeShort(os, note.noteId);
|
||||||
writeVarLong(os, note.time - prevTime);
|
writeVarLong(os, note.time - prevTime);
|
||||||
prevTime = note.time;
|
prevTime = note.time;
|
||||||
|
|
|
@ -400,10 +400,12 @@ public class SongHandler {
|
||||||
currentSong.advanceTime();
|
currentSong.advanceTime();
|
||||||
while (currentSong.reachedNextNote()) {
|
while (currentSong.reachedNextNote()) {
|
||||||
Note note = currentSong.getNextNote();
|
Note note = currentSong.getNextNote();
|
||||||
BlockPos bp = stage.noteblockPositions.get(note.noteId);
|
if (note.velocity >= Config.getConfig().velocityThreshold) {
|
||||||
if (bp != null) {
|
BlockPos bp = stage.noteblockPositions.get(note.noteId);
|
||||||
attackBlock(bp);
|
if (bp != null) {
|
||||||
somethingPlayed = true;
|
attackBlock(bp);
|
||||||
|
somethingPlayed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (somethingPlayed) {
|
if (somethingPlayed) {
|
||||||
|
|
|
@ -3,9 +3,17 @@ package com.github.hhhzzzsss.songplayer.song;
|
||||||
public class Note implements Comparable<Note> {
|
public class Note implements Comparable<Note> {
|
||||||
public int noteId;
|
public int noteId;
|
||||||
public long time;
|
public long time;
|
||||||
|
public int velocity;
|
||||||
public Note(int note, long time) {
|
public Note(int note, long time) {
|
||||||
this.noteId = note;
|
this.noteId = note;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
this.velocity = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Note(int note, long time, int velocity) {
|
||||||
|
this.noteId = note;
|
||||||
|
this.time = time;
|
||||||
|
this.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue