-
Notifications
You must be signed in to change notification settings - Fork 12
The API
#The API The MidiPlayer plugin has a simple API that allows you to create your own plugins that are going to play custom music.
MidiPlayerMain is the plugin main class. You should start by obtaining an instance of it. You can do it by calling MidiPlayerMain.getInstance();
or any other method you see fit.
public class MidiPlayerMain extends JavaPlugin {
public static MidiPlayerMain getInstance();
public MusicPlayer getMusicPlayer();
}
Use getInstance()
to obtain an instance of the plugin main class.
Use getMusicPlayer()
to obtain an instance of the music player class.
To play music you need to use the MusicPlayer class. It is responsible for playing all the tracks.
public class MusicPlayer {
public void playTrack(BaseTrack track);
public void removeTrack(BaseTrack track);
}
Use playTrack(BaseTrack track)
to start playing music from the track
.
Use removeTrack(BaseTrack track)
to stop playing music from track
.
If the track is not looped it will by automatically removed from the MusicPlayer
when its finished. When the track is looped you need to remove it manually using removeTrack
to stop it.
To load midi files you need to use the MidiParser class. It provides only one static method that loads and parses the MIDI file.
public class MidiParser {
public static NoteTrack loadFile(File midiFile);
}
The result of the loadFile(File midiFile)
is a instance of NoteTrack. This class will contain all the loaded notes or error message why MidiPlayer was unable to load the provided file.
public class NoteTrack {
public String getMessage();
public NoteFrame[] getNotes();
public boolean isError();
}
Use isError()
to check if the result is an error or valid note entry.
Use getMessage()
to get the error message.
Use getNotes()
to get the loaded notes.
In order to play music you need to create a track class. You can use the basic, abstract BaseTrack or any of the more specific child classes.
public abstract class BaseTrack {
public BaseTrack(NoteFrame[] notes, boolean loop);
public final void rewind();
protected abstract Player[] getPlayers();
protected abstract Location getLocation();
public void play(long delta);
public boolean isFinished();
}
The BaseTrack(NoteFrame[] notes, boolean loop)
sets the notes and the loop flag of the BaseTrack.
The rewind()
rewinds the track to its beginning. You should use this if you want to play the track again after it has finished or want to play it from the start for some reason.
The getPlayers()
provides the list of players that should hear the track.
The getLocation()
provides the location from with the sound is emitted. If this is set to null MidiPlayer will set play the sound from the position of each player that hears the sound individually.
The play(long delta)
is used by MusicPlayer to play next notes.
The isFinished()
determines if the track has ended.
Sub classes:
- GlobalTrack - A global track that is heard for all players on the server,
- BasePlayerTrack - Abstract track that is heard only for provided list of players,
- PlayerTrack - A global track that is heard only for the provided list of players,
- LocationTrack - A track that is heard only for the provided list of players from a specified location.