public class KaraokeAnalyzer
extends java.lang.Object
This class analyzes the karaoke-related messages of a MIDI sequence. It collects information from it and builds up the karaoke structures used by the player and the info window.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
chosenCharset |
static int |
KARAOKE_LYRICS |
static int |
KARAOKE_TEXT |
private static java.util.HashMap<java.lang.String,java.lang.Object> |
karaokeInfo |
private static java.lang.String |
karaokeMode |
private static boolean |
karLineEnded |
private static long |
karLineTick |
private static java.util.regex.Pattern |
karPattSecond |
private static long |
karPreAlertTicks |
private static java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Long,java.lang.String>> |
lyrics
line begin tick – syllable tick – syllable
|
private static java.util.TreeSet<java.lang.Long> |
lyricsEventTicks
ticks of either lyrics events or pre-alerts
|
private static java.util.TreeMap<java.lang.Long,java.lang.String> |
lyricsFlat
Flat lyrics structure: tick – syllable
|
private static int |
lyricsTrack |
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> |
lyricsTrackCounter |
private static LyricUtil |
lyricUtil |
private static java.util.TreeSet<java.lang.Long> |
markerTicks
tick
|
private static float |
MAX_SYL_SPACE_RATE |
private static java.lang.String |
midiFileCharset |
private static float |
PRE_ALERT_QUARTERS |
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> |
textTrackCounter |
private static boolean |
useLyrics |
Modifier | Constructor and Description |
---|---|
private |
KaraokeAnalyzer()
This class is only used statically so a public constructor is not needed.
|
Modifier and Type | Method and Description |
---|---|
static void |
addEvent(int type,
int track,
long tick,
byte[] content)
Collects karaoke specific information from meta messages and adds the event to the lyrics, if necessary.
|
static void |
chooseLyricsTypeAndTrack()
Decides which meta event type and track number to use for the lyrics.
|
static void |
countEventAndGetSongInfo(int type,
int track,
byte[] content)
Counts the LYRICS or TEXT event by type and track for later determination about what to use for lyrics.
|
static java.lang.String |
getFileCharset()
Returns the last detected charset defined by a lyrics event in the sequence.
|
static java.util.HashMap<java.lang.String,java.lang.Object> |
getKaraokeInfo()
Returns karaoke-related information.
|
static java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Long,java.lang.String>> |
getLyrics()
Returns the tick/line/syllable structure of the lyrics.
|
static java.util.TreeSet<java.lang.Long> |
getLyricsEventTicks()
Returns all ticks where a lyrics event happens (either the lyrics itself for the pre-alert).
|
static java.util.TreeMap<java.lang.Long,java.lang.String> |
getLyricsFlat()
Returns the lyrics as tick/syllable pairs.
|
static java.lang.String |
getLyricsForPlayer(long tick)
Returns the lyrics including formatting to be displayed at the given tick.
|
static void |
init(int resolution,
java.lang.String charset,
java.util.TreeSet<java.lang.Long> analyzerMarkerTicks)
Initializes the internal data structures so that they are ready to be filled with karaoke and lyrics information.
|
static void |
postprocess()
Postprocesses data structures.
|
private static void |
processKaraoke(java.lang.String text,
int type,
long tick,
int track)
Processes the given text as a karaoke meta or lyrics command.
|
static void |
reset()
Resets all information that can be queried in public getter methods.
|
static void |
resetFileCharset()
Resets the character set detected in the sequence.
|
public static final int KARAOKE_TEXT
public static final int KARAOKE_LYRICS
private static final float PRE_ALERT_QUARTERS
private static final float MAX_SYL_SPACE_RATE
private static java.lang.String chosenCharset
private static LyricUtil lyricUtil
private static java.lang.String midiFileCharset
private static java.lang.String karaokeMode
private static long karLineTick
private static boolean karLineEnded
private static long karPreAlertTicks
private static java.util.regex.Pattern karPattSecond
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> textTrackCounter
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> lyricsTrackCounter
private static int lyricsTrack
private static boolean useLyrics
private static java.util.HashMap<java.lang.String,java.lang.Object> karaokeInfo
private static java.util.TreeSet<java.lang.Long> lyricsEventTicks
ticks of either lyrics events or pre-alerts
private static java.util.TreeSet<java.lang.Long> markerTicks
tick
private static java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Long,java.lang.String>> lyrics
line begin tick – syllable tick – syllable
private static java.util.TreeMap<java.lang.Long,java.lang.String> lyricsFlat
Flat lyrics structure: tick – syllable
private KaraokeAnalyzer()
This class is only used statically so a public constructor is not needed.
public static void reset()
Resets all information that can be queried in public getter methods. This is called before a MIDI or MidicaPL file is parsed so that the getters don’t return the information of a former parsing after a later parsing failed.
public static java.util.TreeMap<java.lang.Long,java.lang.String> getLyricsFlat()
Returns the lyrics as tick/syllable pairs.
public static void init(int resolution, java.lang.String charset, java.util.TreeSet<java.lang.Long> analyzerMarkerTicks)
Initializes the internal data structures so that they are ready to be filled with karaoke and lyrics information.
resolution
- The sequence’s resolution in ticks per quarter note.charset
- The charset that has been chosen in the file chooser.analyzerMarkerTicks
- Marker ticks from the SequenceAnalyzer
.public static void resetFileCharset()
Resets the character set detected in the sequence. Called from the SequenceAnalyzer between several parsing runs of the same sequence.
public static java.lang.String getFileCharset()
Returns the last detected charset defined by a lyrics event in the sequence.
public static void chooseLyricsTypeAndTrack()
Decides which meta event type and track number to use for the lyrics.
public static java.util.HashMap<java.lang.String,java.lang.Object> getKaraokeInfo()
Returns karaoke-related information.
Lyrics related fields:
Fields from RP-026 tags:
Simple Soft Karaoke fields:
Special Soft Karaoke fields:
ArrayList<String>
of all contents of @I tagspublic static void countEventAndGetSongInfo(int type, int track, byte[] content)
Counts the LYRICS or TEXT event by type and track for later determination about what to use for lyrics. Also retrieves song and karaoke related fields.
type
- META message type: KARAOKE_TEXT
or KARAOKE_LYRICS
.track
- track number of the META messagecontent
- text content of the META message.public static void addEvent(int type, int track, long tick, byte[] content)
Collects karaoke specific information from meta messages and adds the event to the lyrics, if necessary.
type
- META message type: KARAOKE_TEXT
or KARAOKE_LYRICS
.track
- Track number of the META message.tick
- Tickstamp of the META message.content
- Text content of the META message.private static void processKaraoke(java.lang.String text, int type, long tick, int track)
Processes the given text as a karaoke meta or lyrics command.
text
- The text from the text or lyrics message.type
- The message type (1: text, 2: lyrics).tick
- Tickstamp of the event.track
- Track number of the event.public static void postprocess()
Postprocesses data structures.
public static java.util.TreeMap<java.lang.Long,java.util.TreeMap<java.lang.Long,java.lang.String>> getLyrics()
Returns the tick/line/syllable structure of the lyrics.
public static java.util.TreeSet<java.lang.Long> getLyricsEventTicks()
Returns all ticks where a lyrics event happens (either the lyrics itself for the pre-alert).
public static java.lang.String getLyricsForPlayer(long tick)
Returns the lyrics including formatting to be displayed at the given tick.
tick
- Tickstamp in the MIDI sequence.