Skip to content

Commit 82bd64a

Browse files
committed
Added support for per note volume #38
1 parent 6ac9dbb commit 82bd64a

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>org.spigotmc</groupId>
3131
<artifactId>spigot-api</artifactId>
32-
<version>1.14-R0.1-SNAPSHOT</version>
32+
<version>1.15.2-R0.1-SNAPSHOT</version>
3333
<scope>provided</scope>
3434
</dependency>
3535
<dependency>

src/main/java/com/xxmicloxx/NoteBlockAPI/model/Note.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Note {
99

1010
private byte instrument;
1111
private byte key;
12-
12+
private byte velocity;
1313
private short pitch;
1414

1515
public Note(byte instrument, byte key) {
@@ -19,6 +19,7 @@ public Note(byte instrument, byte key) {
1919
public Note(byte instrument, byte key, byte velocity, byte panning, short pitch) {
2020
this.instrument = instrument;
2121
this.key = key;
22+
this.velocity = velocity;
2223
this.pitch = pitch;
2324
}
2425

@@ -36,19 +37,58 @@ public void setInstrument(byte instrument) {
3637
this.instrument = instrument;
3738
}
3839

40+
/**
41+
* Returns note key number (Minecraft key 0 corresponds to key 33)
42+
* @return
43+
*/
3944
public byte getKey() {
4045
return key;
4146
}
4247

48+
/**
49+
* Sets note key number (Minecraft key 0 corresponds to key 33)
50+
* @param key
51+
*/
4352
public void setKey(byte key) {
4453
this.key = key;
4554
}
4655

56+
/**
57+
* Returns note pitch.
58+
* 100 = 1 key
59+
* 1200 = 1 octave
60+
* @return
61+
*/
4762
public short getPitch() {
4863
return pitch;
4964
}
5065

66+
/**
67+
* Sets note pitch.
68+
* 100 = 1 key
69+
* 1200 = 1 octave
70+
* @param pitch note pitch
71+
*/
5172
public void setPitch(short pitch) {
5273
this.pitch = pitch;
5374
}
75+
76+
/**
77+
* Returns note velocity (volume)
78+
* @return
79+
*/
80+
public byte getVelocity() {
81+
return velocity;
82+
}
83+
84+
/**
85+
* Sets note velocity (volume)
86+
* @param velocity number from 0 - 100
87+
*/
88+
public void setVelocity(byte velocity) {
89+
if (velocity < 0) velocity = 0;
90+
if (velocity > 100) velocity = 100;
91+
92+
this.velocity = velocity;
93+
}
5494
}

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/EntitySongPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void playTick(Player player, int tick) {
7575
Note note = layer.getNote(tick);
7676
if (note == null) continue;
7777

78-
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
78+
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
7979
* ((1F / 16F) * getDistance());
8080
float pitch = NoteUtils.getPitch(note);
8181

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/NoteBlockSongPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void playTick(Player player, int tick) {
100100
player.playNote(loc, InstrumentUtils.getBukkitInstrument(note.getInstrument()),
101101
new org.bukkit.Note(note.getKey() - 33));
102102

103-
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
103+
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
104104
* ((1F / 16F) * getDistance());
105105
float pitch = NoteUtils.getPitch(note);
106106

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/PositionSongPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void playTick(Player player, int tick) {
8989
Note note = layer.getNote(tick);
9090
if (note == null) continue;
9191

92-
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
92+
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
9393
* ((1F / 16F) * getDistance());
9494
float pitch = NoteUtils.getPitch(note);
9595

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/RadioSongPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void playTick(Player player, int tick) {
5656
continue;
5757
}
5858

59-
float volume = (layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F;
59+
float volume = (layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F;
6060
float pitch = NoteUtils.getPitch(note);
6161

6262
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {

0 commit comments

Comments
 (0)