Package org.deepsymmetry.beatlink.data
Class BeatGrid
- java.lang.Object
-
- org.deepsymmetry.beatlink.data.BeatGrid
-
public class BeatGrid extends Object
Provides information about each beat in a track: the number of milliseconds after the start of the track that the beat occurs, and where the beat falls within a measure.- Author:
- James Elliott
-
-
Field Summary
Fields Modifier and Type Field Description intbeatCountThe number of beats in the track.DataReferencedataReferenceThe unique identifier that was used to request this beat grid.
-
Constructor Summary
Constructors Constructor Description BeatGrid(DataReference reference, int[] beatWithinBarValues, long[] timeWithinTrackValues)Constructor for use by an external cache system.BeatGrid(DataReference reference, ByteBuffer buffer)Constructor for reading from a cache file.BeatGrid(DataReference reference, Message message)Constructor for when reading from the network.BeatGrid(DataReference reference, org.deepsymmetry.cratedigger.pdb.RekordboxAnlz anlzFile)Constructor for when fetched from Crate Digger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intfindBeatAtTime(long milliseconds)Finds the beat in which the specified track position falls.intgetBeatWithinBar(int beatNumber)Returns the musical count of the specified beat, represented by Bb in Figure 11 of the Packet Analysis document.ByteBuffergetRawData()Get the raw bytes of the beat grid as it was read over the network.longgetTimeWithinTrack(int beatNumber)Returns the time at which the specified beat falls within the track.StringtoString()
-
-
-
Field Detail
-
dataReference
public final DataReference dataReference
The unique identifier that was used to request this beat grid.
-
beatCount
public final int beatCount
The number of beats in the track.
-
-
Constructor Detail
-
BeatGrid
public BeatGrid(DataReference reference, Message message)
Constructor for when reading from the network.- Parameters:
reference- the unique database reference that was used to request this waveform detailmessage- the response that contained the beat grid data
-
BeatGrid
public BeatGrid(DataReference reference, ByteBuffer buffer)
Constructor for reading from a cache file.- Parameters:
reference- the unique database reference that was used to request this waveform detailbuffer- the raw bytes representing the beat grid
-
BeatGrid
public BeatGrid(DataReference reference, org.deepsymmetry.cratedigger.pdb.RekordboxAnlz anlzFile)
Constructor for when fetched from Crate Digger.- Parameters:
reference- the unique database reference that was used to request this waveform detailanlzFile- the parsed rekordbox track analysis file containing the waveform preview
-
BeatGrid
public BeatGrid(DataReference reference, int[] beatWithinBarValues, long[] timeWithinTrackValues)
Constructor for use by an external cache system.- Parameters:
reference- the unique database reference that was used to request this waveform detailbeatWithinBarValues- the musical time on which each beat in the grid fallstimeWithinTrackValues- the time, in milliseconds, at which each beat occurs in the track
-
-
Method Detail
-
getRawData
public ByteBuffer getRawData()
Get the raw bytes of the beat grid as it was read over the network. This can be used to analyze fields that have not yet been reliably understood, and is also used for storing the beat grid in a cache file. This is not available when the beat grid was loaded by Crate Digger.- Returns:
- the bytes that make up the beat grid
-
getTimeWithinTrack
public long getTimeWithinTrack(int beatNumber)
Returns the time at which the specified beat falls within the track. Beat 0 means we are before the first beat (e.g. ready to play the track), so we return 0.- Parameters:
beatNumber- the beat number desired, must fall within the range 1..beatCount- Returns:
- the number of milliseconds into the track at which the specified beat occurs
- Throws:
IllegalArgumentException- ifnumberis less than 0 or greater thanbeatCount
-
getBeatWithinBar
public int getBeatWithinBar(int beatNumber)
Returns the musical count of the specified beat, represented by Bb in Figure 11 of the Packet Analysis document. A number from 1 to 4, where 1 is the down beat, or the start of a new measure.- Parameters:
beatNumber- the number of the beat of interest, must fall within the range 1..beatCount- Returns:
- where that beat falls in a bar of music
- Throws:
IllegalArgumentException- ifnumberis less than 1 or greater thanbeatCount
-
findBeatAtTime
public int findBeatAtTime(long milliseconds)
Finds the beat in which the specified track position falls.- Parameters:
milliseconds- how long the track has been playing- Returns:
- the beat number represented by that time, or -1 if the time is before the first beat
-
-