Skip to content

Commit

Permalink
Renamed get/set methods in TempoEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Jan 6, 2025
1 parent 7b94208 commit 598535d
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ NoteBlockLib.writeSong(newSong, new File("output.nbs"));
```java
Song mySong = new GenericSong();
mySong.setTitle("My song");
mySong.getTempoEvents().setTempo(0, 10F); // set the tempo to 10 ticks per second
mySong.getTempoEvents().set(0, 10F); // set the tempo to 10 ticks per second
mySong.getNotes().add(0, new Note().setInstrument(MinecraftInstrument.HARP).setNbsKey((byte) 46));
mySong.getNotes().add(5, new Note().setInstrument(MinecraftInstrument.BASS).setNbsKey((byte) 60));
mySong.getNotes().add(8, new Note().setInstrument(MinecraftInstrument.BIT).setNbsKey((byte) 84));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static FutureClientSong readSong(final InputStream is, final String fileN
}

{ // Fill generalized song structure with data
song.getTempoEvents().setTempo(0, 20);
song.getTempoEvents().set(0, 20);
for (Map.Entry<Integer, List<FutureClientNote>> entry : notes.entrySet()) {
for (FutureClientNote futureClientNote : entry.getValue()) {
final Note note = new Note();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static McSpSong readSong(final InputStream is, final String fileName) {
}

{ // Fill generalized song structure with data
song.getTempoEvents().setTempo(0, 10);
song.getTempoEvents().set(0, 10);
for (Map.Entry<Integer, McSpNote[]> entry : notes.entrySet()) {
for (McSpNote mcSpNote : entry.getValue()) {
if (mcSpNote == null) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static McSp2Song readSong(final InputStream is, final String fileName) {
}

{ // Fill generalized song structure with data
song.getTempoEvents().setTempo(0, song.getTempo());
song.getTempoEvents().set(0, song.getTempo());
for (McSp2Layer layer : song.getLayers().values()) {
for (Map.Entry<Integer, McSp2Note> noteEntry : layer.getNotes().entrySet()) {
final McSp2Note mcSp2Note = noteEntry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static MidiSong readSong(final InputStream is, final String fileName) thr
throw new IllegalArgumentException("MIDI sequence has too many ticks");
}

song.getTempoEvents().setTempo(0, (float) (1_000_000D / ((double) MidiDefinitions.DEFAULT_TEMPO_MPQ / sequence.getResolution())));
song.getTempoEvents().set(0, (float) (1_000_000D / ((double) MidiDefinitions.DEFAULT_TEMPO_MPQ / sequence.getResolution())));
final byte[] channelInstruments = new byte[MidiDefinitions.CHANNEL_COUNT];
final byte[] channelVolumes = new byte[MidiDefinitions.CHANNEL_COUNT];
final byte[] channelPans = new byte[MidiDefinitions.CHANNEL_COUNT];
Expand Down Expand Up @@ -123,7 +123,7 @@ public static MidiSong readSong(final InputStream is, final String fileName) thr
if (metaMessage.getType() == META_SET_TEMPO && metaMessage.getData().length == 3) {
final int newMpq = ((metaMessage.getData()[0] & 0xFF) << 16) | ((metaMessage.getData()[1] & 0xFF) << 8) | (metaMessage.getData()[2] & 0xFF);
final double microsPerTick = (double) newMpq / sequence.getResolution();
song.getTempoEvents().setTempo((int) event.getTick(), (float) (1_000_000D / microsPerTick));
song.getTempoEvents().set((int) event.getTick(), (float) (1_000_000D / microsPerTick));
} else if (metaMessage.getType() == META_COPYRIGHT_NOTICE) {
song.setOriginalAuthor(new String(metaMessage.getData(), StandardCharsets.US_ASCII));
} else if (metaMessage.getType() == META_TRACK_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static NbsSong createSong(final Song song) {
final NbsSong newSong = new NbsSong();
newSong.copyGeneralData(song);
newSong.setLength((short) song.getNotes().getLengthInTicks());
newSong.setTempo((short) Math.round(song.getTempoEvents().getTempo(0) * 100F));
newSong.setTempo((short) Math.round(song.getTempoEvents().get(0) * 100F));

for (int tick : song.getNotes().getTicks()) {
final List<Note> notes = song.getNotes().get(tick);
Expand Down Expand Up @@ -80,7 +80,7 @@ public static NbsSong createSong(final Song song) {
newSong.getLayers().put(newSong.getLayers().size(), tempoChangerLayer);

for (int tempoEventTick : song.getTempoEvents().getTicks()) {
final float tps = song.getTempoEvents().getTempo(tempoEventTick);
final float tps = song.getTempoEvents().get(tempoEventTick);
final NbsNote tempoChangerNote = new NbsNote();
tempoChangerNote.setInstrument(instrumentId);
tempoChangerNote.setKey((byte) NbsDefinitions.F_SHARP_4_NBS_KEY);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/raphimc/noteblocklib/format/nbs/NbsIo.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static NbsSong readSong(final InputStream is, final String fileName) thro
customInstrumentMap.put(customInstrument, customInstrument.copy().setPitch((byte) NbsDefinitions.F_SHARP_4_NBS_KEY));
}

song.getTempoEvents().setTempo(0, song.getTempo() / 100F);
song.getTempoEvents().set(0, song.getTempo() / 100F);
for (NbsLayer layer : layers.values()) {
for (Map.Entry<Integer, NbsNote> noteEntry : layer.getNotes().entrySet()) {
final NbsNote nbsNote = noteEntry.getValue();
Expand All @@ -159,7 +159,7 @@ public static NbsSong readSong(final InputStream is, final String fileName) thro
} else {
final NbsCustomInstrument nbsCustomInstrument = customInstruments.get(nbsNote.getInstrument() - song.getVanillaInstrumentCount());
if (song.getVersion() >= 4 && NbsDefinitions.TEMPO_CHANGER_CUSTOM_INSTRUMENT_NAME.equals(nbsCustomInstrument.getName())) {
song.getTempoEvents().setTempo(noteEntry.getKey(), Math.abs(nbsNote.getPitch() / 15F));
song.getTempoEvents().set(noteEntry.getKey(), Math.abs(nbsNote.getPitch() / 15F));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static TxtSong readSong(final InputStream is, final String fileName) thro
}

{ // Fill generalized song structure with data
song.getTempoEvents().setTempo(0, 20);
song.getTempoEvents().set(0, 20);
for (Map.Entry<Integer, List<TxtNote>> entry : notes.entrySet()) {
for (TxtNote txtNote : entry.getValue()) {
final Note note = new Note();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/raphimc/noteblocklib/model/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int tickToMilliseconds(final int tick) {
int lastTick = 0;
float totalMilliseconds = 0;
for (int tempoTick : tempoEventTicks) {
final float tps = this.tempoEvents.getTempo(lastTick);
final float tps = this.tempoEvents.get(lastTick);
final int ticksInSegment = tempoTick - lastTick;
final float segmentMilliseconds = (ticksInSegment / tps) * 1000F;
totalMilliseconds += segmentMilliseconds;
Expand All @@ -76,7 +76,7 @@ public int millisecondsToTick(final int milliseconds) {
int lastTick = 0;
float totalMilliseconds = 0;
for (int tempoTick : tempoEventTicks) {
final float tps = this.tempoEvents.getTempo(lastTick);
final float tps = this.tempoEvents.get(lastTick);
final int ticksInSegment = tempoTick - lastTick;
final float segmentMilliseconds = (ticksInSegment / tps) * 1000F;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/raphimc/noteblocklib/model/TempoEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public TempoEvents() {
this.tempoEvents.put(0, DEFAULT_TEMPO);
}

public float getTempo(final int tick) {
public float get(final int tick) {
return this.tempoEvents.getOrDefault(tick, 0F);
}

public float getEffectiveTempo(final int tick) {
return this.tempoEvents.floorEntry(tick).getValue();
}

public void setTempo(final int tick, final float tempo) {
public void set(final int tick, final float tempo) {
this.tempoEvents.put(tick, tempo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void start() {
public void start(final int delay) {
if (this.isRunning()) this.stop();

this.ticksPerSecond = this.song.getTempoEvents().getTempo(0);
this.ticksPerSecond = this.song.getTempoEvents().get(0);
this.tick = 0;

TimerHack.ensureRunning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SongResampler {
public static void changeTickSpeed(final Song song, final float newTempo) {
precomputeTempoEvents(song); // Ensure song has static tempo

final float divider = song.getTempoEvents().getTempo(0) / newTempo;
final float divider = song.getTempoEvents().get(0) / newTempo;
if (divider == 1F) return;

final Map<Integer, List<Note>> newNotes = new HashMap<>();
Expand All @@ -49,7 +49,7 @@ public static void changeTickSpeed(final Song song, final float newTempo) {
for (Map.Entry<Integer, List<Note>> entry : newNotes.entrySet()) {
song.getNotes().set(entry.getKey(), entry.getValue());
}
song.getTempoEvents().setTempo(0, newTempo);
song.getTempoEvents().set(0, newTempo);
}

/**
Expand All @@ -75,7 +75,7 @@ public static void precomputeTempoEvents(final Song song) {
song.getNotes().set(entry.getKey(), entry.getValue());
}
song.getTempoEvents().clear();
song.getTempoEvents().setTempo(0, newTempo);
song.getTempoEvents().set(0, newTempo);
}

}

0 comments on commit 598535d

Please sign in to comment.