Skip to content

Commit 2de59ac

Browse files
committed
Added ChannelModes
1 parent 82bd64a commit 2de59ac

File tree

15 files changed

+257
-145
lines changed

15 files changed

+257
-145
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.xxmicloxx</groupId>
77
<artifactId>NoteBlockAPI</artifactId>
8-
<version>1.4.5-SNAPSHOT</version>
8+
<version>1.5.0-SNAPSHOT</version>
99
<name>NoteBlockAPI</name>
1010

1111
<properties>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Layer {
1111

1212
private HashMap<Integer, Note> notesAtTicks = new HashMap<Integer, Note>();
1313
private byte volume = 100;
14+
private int panning = 100;
1415
private String name = "";
1516

1617
/**
@@ -72,4 +73,19 @@ public void setVolume(byte volume) {
7273
this.volume = volume;
7374
}
7475

76+
/**
77+
* Gets the panning of all notes in the Layer
78+
* @return byte representing the panning
79+
*/
80+
public int getPanning() {
81+
return panning;
82+
}
83+
84+
/**
85+
* Sets the panning for all notes in the Layer
86+
* @param panning
87+
*/
88+
public void setPanning(int panning) {
89+
this.panning = panning;
90+
}
7591
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ public class Note {
1010
private byte instrument;
1111
private byte key;
1212
private byte velocity;
13+
private int panning;
1314
private short pitch;
1415

1516
public Note(byte instrument, byte key) {
1617
this(instrument, key, (byte) 100, (byte) 100, (short) 0);
1718
}
1819

19-
public Note(byte instrument, byte key, byte velocity, byte panning, short pitch) {
20+
public Note(byte instrument, byte key, byte velocity, int panning, short pitch) {
2021
this.instrument = instrument;
2122
this.key = key;
2223
this.velocity = velocity;
24+
this.panning = panning;
2325
this.pitch = pitch;
2426
}
2527

@@ -91,4 +93,20 @@ public void setVelocity(byte velocity) {
9193

9294
this.velocity = velocity;
9395
}
96+
97+
/**
98+
* Returns stereo panning of this note
99+
* @return
100+
*/
101+
public int getPanning() {
102+
return panning;
103+
}
104+
105+
/**
106+
* Sets stereo panning of this note
107+
* @param panning
108+
*/
109+
public void setPanning(int panning) {
110+
this.panning = panning;
111+
}
94112
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.Layer;
4+
import com.xxmicloxx.NoteBlockAPI.model.Note;
5+
import com.xxmicloxx.NoteBlockAPI.model.Song;
6+
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
7+
import org.bukkit.Location;
8+
import org.bukkit.entity.Player;
9+
10+
public abstract class ChannelMode {
11+
12+
public abstract void play(Player player, Location location, Song song, Layer layer, Note note,
13+
SoundCategory soundCategory, float volume, float pitch);
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class MonoMode extends ChannelMode {
10+
11+
@Override
12+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
13+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
14+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
15+
16+
if (instrument.getSound() != null) {
17+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, 0);
18+
} else {
19+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, 0);
20+
}
21+
} else {
22+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, 0);
23+
}
24+
}
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class MonoStereoMode extends ChannelMode{
10+
11+
private float distance = 2;
12+
13+
@Override
14+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
15+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
16+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
17+
18+
if (instrument.getSound() != null) {
19+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
20+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, -distance);
21+
} else {
22+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
23+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, -distance);
24+
}
25+
} else {
26+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
27+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, -distance);
28+
}
29+
}
30+
31+
public float getDistance() {
32+
return distance;
33+
}
34+
35+
public void setDistance(float distance) {
36+
this.distance = distance;
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class StereoMode extends ChannelMode {
10+
11+
float maxDistance = 2;
12+
13+
@Override
14+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
15+
float distance = 0;
16+
if (layer.getPanning() == 100){
17+
distance = (note.getPanning() - 100) * maxDistance;
18+
} else {
19+
distance = ((layer.getPanning() - 100 + note.getPanning() - 100) / 200f) * maxDistance;
20+
}
21+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
22+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
23+
24+
if (instrument.getSound() != null) {
25+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
26+
} else {
27+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
28+
}
29+
} else {
30+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
31+
}
32+
}
33+
}

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,7 @@ public void playTick(Player player, int tick) {
7979
* ((1F / 16F) * getDistance());
8080
float pitch = NoteUtils.getPitch(note);
8181

82-
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
83-
CustomInstrument instrument = song.getCustomInstruments()
84-
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
85-
86-
if (instrument.getSound() != null) {
87-
CompatibilityUtils.playSound(player, entity.getLocation(), instrument.getSound(),
88-
this.soundCategory, volume, pitch, false);
89-
} else {
90-
CompatibilityUtils.playSound(player, entity.getLocation(), instrument.getSoundFileName(),
91-
this.soundCategory, volume, pitch, false);
92-
}
93-
} else {
94-
CompatibilityUtils.playSound(player, entity.getLocation(),
95-
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory,
96-
volume, pitch, false);
97-
}
82+
channelMode.play(player, entity.getLocation(), song, layer, note, soundCategory, volume, pitch);
9883

9984
if (isInRange(player)) {
10085
if (!this.playerList.get(player.getUniqueId())) {

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,7 @@ public void playTick(Player player, int tick) {
104104
* ((1F / 16F) * getDistance());
105105
float pitch = NoteUtils.getPitch(note);
106106

107-
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
108-
CustomInstrument instrument = song.getCustomInstruments()
109-
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
110-
111-
if (instrument.getSound() != null) {
112-
CompatibilityUtils.playSound(player, loc,
113-
instrument.getSound(), this.soundCategory, volume, pitch, false);
114-
} else {
115-
CompatibilityUtils.playSound(player, loc,
116-
instrument.getSoundFileName(), this.soundCategory, volume, pitch, false);
117-
}
118-
} else {
119-
CompatibilityUtils.playSound(player, loc,
120-
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory, volume, pitch, false);
121-
}
107+
channelMode.play(player, loc, song, layer, note, soundCategory, volume, pitch);
122108

123109
if (isInRange(player)) {
124110
if (!this.playerList.get(player.getUniqueId())) {

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,7 @@ public void playTick(Player player, int tick) {
9393
* ((1F / 16F) * getDistance());
9494
float pitch = NoteUtils.getPitch(note);
9595

96-
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
97-
CustomInstrument instrument = song.getCustomInstruments()
98-
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
99-
100-
if (instrument.getSound() != null) {
101-
CompatibilityUtils.playSound(player, targetLocation, instrument.getSound(),
102-
this.soundCategory, volume, pitch, false);
103-
} else {
104-
CompatibilityUtils.playSound(player, targetLocation, instrument.getSoundFileName(),
105-
this.soundCategory, volume, pitch, false);
106-
}
107-
} else {
108-
CompatibilityUtils.playSound(player, targetLocation,
109-
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory,
110-
volume, pitch, false);
111-
}
96+
channelMode.play(player, targetLocation, song, layer, note, soundCategory, volume, pitch);
11297

11398
if (isInRange(player)) {
11499
if (!this.playerList.get(player.getUniqueId())) {
@@ -133,7 +118,4 @@ public void playTick(Player player, int tick) {
133118
public boolean isInRange(Player player) {
134119
return player.getLocation().distance(targetLocation) <= getDistance();
135120
}
136-
137-
138-
139121
}

0 commit comments

Comments
 (0)