Skip to content

Commit 9bfcd15

Browse files
committed
Updated README
1 parent 50014a4 commit 9bfcd15

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,59 @@ NoteBlockLib.writeSong(nbsSong, new File("output.nbs"));
116116
**Reading a song, changing its sample rate to 10 TPS and writing it back**
117117
```java
118118
Song<?, ?, ?> song = NoteBlockLib.readSong(new File("input.nbs"));
119-
120119
SongResampler.changeTickSpeed(song.getView(), 10F);
121-
122120
Song<?, ?, ?> newSong = NoteBlockLib.createSongFromView(song.getView(), SongFormat.NBS);
123-
// For songs with custom instruments make sure to copy them over to the new song
124-
// ((NbsSong)newSong).getData().setCustomInstruments(((NbsSong)song).getData().getCustomInstruments());
125-
126121
NoteBlockLib.writeSong(newSong, new File("output.nbs"));
127122
```
128123
**Creating a new song and saving it as NBS**
129124
```java
130125
// tick -> list of notes
131126
Map<Integer, List<Note>> notes = new TreeMap<>();
132127
// Add the notes to the song
133-
notes.put(0, Lists.newArrayList(new NbsNote(Instrument.HARP.nbsId(), (byte) 46)));
134-
notes.put(5, Lists.newArrayList(new NbsNote(Instrument.BASS.nbsId(), (byte) 60)));
135-
notes.put(8, Lists.newArrayList(new NbsNote(Instrument.BIT.nbsId(), (byte) 84)));
128+
notes.put(0, Lists.newArrayList(new NbsNote(Instrument.HARP, (byte) 46)));
129+
notes.put(5, Lists.newArrayList(new NbsNote(Instrument.BASS, (byte) 60)));
130+
notes.put(8, Lists.newArrayList(new NbsNote(Instrument.BIT, (byte) 84)));
136131
SongView<Note> mySong = new SongView<>("My song" /*title*/, 10F /*ticks per second*/, notes);
137-
138132
Song<?, ?, ?> nbsSong = NoteBlockLib.createSongFromView(mySong, SongFormat.NBS);
139-
140133
NoteBlockLib.writeSong(nbsSong, new File("C:\\Users\\Koppe\\Desktop\\output.nbs"));
141134
```
142135
**Playing a song**
143-
```java
144-
Song<?, ?, ?> song = NoteBlockLib.readSong(new File("input.nbs"));
145136

146-
// Optionally apply a modification to all notes here (For example to transpose the note keys)
137+
Define a callback class
138+
```java
139+
// Default callback. This callback has a method which receives the already calculated pitch, volume and panning.
140+
// Note: The FullNoteConsumer interface may change over time when new note data is added by one of the formats.
141+
public class MyCallback implements SongPlayerCallback, FullNoteConsumer {
142+
@Override
143+
public void playNote(final Instrument instrument, final float pitch, final float volume, final float panning) {
144+
// This method gets called in real time as the song is played.
145+
System.out.println(instrument + " " + pitch + " " + volume + " " + panning);
146+
}
147+
148+
// There are other methods like playCustomNote, onFinished which can be overridden.
149+
}
147150

148-
SongPlayer player = new SongPlayer(song.getView(), new ISongPlayerCallback() {
151+
// Raw callback. This callback receives the raw Note class. Data like pitch, volume or panning have to be calculated/accessed manually.
152+
public class MyRawCallback implements SongPlayerCallback {
149153
@Override
150154
public void playNote(Note note) {
151-
// This method gets called in real time when the song is played.
152-
// NBS Notes have a fine pitch besides the normal key. To calculate the key which factors that in use the NbsDefinitions class.
155+
// This method gets called in real time as the song is played.
156+
// For an example to calculate the various note data see the FullNoteConsumer class.
153157
System.out.println(note.getInstrument() + " " + note.getKey());
154158
}
155-
159+
156160
// There are other methods like onFinished which can be overridden.
157-
});
161+
}
162+
```
163+
164+
Start playing the song
165+
```java
166+
Song<?, ?, ?> song = NoteBlockLib.readSong(new File("input.nbs"));
167+
168+
// Optionally apply a modification to all notes here (For example to transpose the note keys)
169+
170+
// Create a song player
171+
SongPlayer player = new SongPlayer(song.getView(), new MyCallback());
158172

159173
// Start playing
160174
player.play();

0 commit comments

Comments
 (0)