repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java | TimeFinder.interpolateTimeFromUpdate | private long interpolateTimeFromUpdate(TrackPositionUpdate lastTrackUpdate, CdjStatus newDeviceUpdate,
BeatGrid beatGrid) {
final int beatNumber = newDeviceUpdate.getBeatNumber();
final boolean noLongerPlaying = !newDeviceUpdate.isPlaying();
// If we have just stopped, see if we are near a cue (assuming that information is available), and if so,
// the best assumption is that the DJ jumped to that cue.
if (lastTrackUpdate.playing && noLongerPlaying) {
final CueList.Entry jumpedTo = findAdjacentCue(newDeviceUpdate, beatGrid);
if (jumpedTo != null) return jumpedTo.cueTime;
}
// Handle the special case where we were not playing either in the previous or current update, but the DJ
// might have jumped to a different place in the track.
if (!lastTrackUpdate.playing) {
if (lastTrackUpdate.beatNumber == beatNumber && noLongerPlaying) { // Haven't moved
return lastTrackUpdate.milliseconds;
} else {
if (noLongerPlaying) { // Have jumped without playing.
if (beatNumber < 0) {
return -1; // We don't know the position any more; weird to get into this state and still have a grid?
}
// As a heuristic, assume we are right before the beat?
return timeOfBeat(beatGrid, beatNumber, newDeviceUpdate);
}
}
}
// One way or another, we are now playing.
long elapsedMillis = (newDeviceUpdate.getTimestamp() - lastTrackUpdate.timestamp) / 1000000;
long moved = Math.round(lastTrackUpdate.pitch * elapsedMillis);
long interpolated = (lastTrackUpdate.reverse)?
(lastTrackUpdate.milliseconds - moved) : lastTrackUpdate.milliseconds + moved;
if (Math.abs(beatGrid.findBeatAtTime(interpolated) - beatNumber) < 2) {
return interpolated; // Our calculations still look plausible
}
// The player has jumped or drifted somewhere unexpected, correct.
if (newDeviceUpdate.isPlayingForwards()) {
return timeOfBeat(beatGrid, beatNumber, newDeviceUpdate);
} else {
return beatGrid.getTimeWithinTrack(Math.min(beatNumber + 1, beatGrid.beatCount));
}
} | java | private long interpolateTimeFromUpdate(TrackPositionUpdate lastTrackUpdate, CdjStatus newDeviceUpdate,
BeatGrid beatGrid) {
final int beatNumber = newDeviceUpdate.getBeatNumber();
final boolean noLongerPlaying = !newDeviceUpdate.isPlaying();
// If we have just stopped, see if we are near a cue (assuming that information is available), and if so,
// the best assumption is that the DJ jumped to that cue.
if (lastTrackUpdate.playing && noLongerPlaying) {
final CueList.Entry jumpedTo = findAdjacentCue(newDeviceUpdate, beatGrid);
if (jumpedTo != null) return jumpedTo.cueTime;
}
// Handle the special case where we were not playing either in the previous or current update, but the DJ
// might have jumped to a different place in the track.
if (!lastTrackUpdate.playing) {
if (lastTrackUpdate.beatNumber == beatNumber && noLongerPlaying) { // Haven't moved
return lastTrackUpdate.milliseconds;
} else {
if (noLongerPlaying) { // Have jumped without playing.
if (beatNumber < 0) {
return -1; // We don't know the position any more; weird to get into this state and still have a grid?
}
// As a heuristic, assume we are right before the beat?
return timeOfBeat(beatGrid, beatNumber, newDeviceUpdate);
}
}
}
// One way or another, we are now playing.
long elapsedMillis = (newDeviceUpdate.getTimestamp() - lastTrackUpdate.timestamp) / 1000000;
long moved = Math.round(lastTrackUpdate.pitch * elapsedMillis);
long interpolated = (lastTrackUpdate.reverse)?
(lastTrackUpdate.milliseconds - moved) : lastTrackUpdate.milliseconds + moved;
if (Math.abs(beatGrid.findBeatAtTime(interpolated) - beatNumber) < 2) {
return interpolated; // Our calculations still look plausible
}
// The player has jumped or drifted somewhere unexpected, correct.
if (newDeviceUpdate.isPlayingForwards()) {
return timeOfBeat(beatGrid, beatNumber, newDeviceUpdate);
} else {
return beatGrid.getTimeWithinTrack(Math.min(beatNumber + 1, beatGrid.beatCount));
}
} | [
"private",
"long",
"interpolateTimeFromUpdate",
"(",
"TrackPositionUpdate",
"lastTrackUpdate",
",",
"CdjStatus",
"newDeviceUpdate",
",",
"BeatGrid",
"beatGrid",
")",
"{",
"final",
"int",
"beatNumber",
"=",
"newDeviceUpdate",
".",
"getBeatNumber",
"(",
")",
";",
"final... | Sanity-check a new non-beat update, make sure we are still interpolating a sensible position, and correct
as needed.
@param lastTrackUpdate the most recent digested update received from a player
@param newDeviceUpdate a new status update from the player
@param beatGrid the beat grid for the track that is playing, in case we have jumped
@return the playback position we believe that player has reached at that point in time | [
"Sanity",
"-",
"check",
"a",
"new",
"non",
"-",
"beat",
"update",
"make",
"sure",
"we",
"are",
"still",
"interpolating",
"a",
"sensible",
"position",
"and",
"correct",
"as",
"needed",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L199-L241 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java | TimeFinder.getTimeFor | public long getTimeFor(int player) {
TrackPositionUpdate update = positions.get(player);
if (update != null) {
return interpolateTimeSinceUpdate(update, System.nanoTime());
}
return -1; // We don't know.
} | java | public long getTimeFor(int player) {
TrackPositionUpdate update = positions.get(player);
if (update != null) {
return interpolateTimeSinceUpdate(update, System.nanoTime());
}
return -1; // We don't know.
} | [
"public",
"long",
"getTimeFor",
"(",
"int",
"player",
")",
"{",
"TrackPositionUpdate",
"update",
"=",
"positions",
".",
"get",
"(",
"player",
")",
";",
"if",
"(",
"update",
"!=",
"null",
")",
"{",
"return",
"interpolateTimeSinceUpdate",
"(",
"update",
",",
... | Get the best guess we have for the current track position on the specified player.
@param player the player number whose position is desired
@return the milliseconds into the track that we believe playback has reached, or -1 if we don't know
@throws IllegalStateException if the TimeFinder is not running | [
"Get",
"the",
"best",
"guess",
"we",
"have",
"for",
"the",
"current",
"track",
"position",
"on",
"the",
"specified",
"player",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L252-L258 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java | TimeFinder.interpolationsDisagree | private boolean interpolationsDisagree(TrackPositionUpdate lastUpdate, TrackPositionUpdate currentUpdate) {
long now = System.nanoTime();
return Math.abs(interpolateTimeSinceUpdate(lastUpdate, now) - interpolateTimeSinceUpdate(currentUpdate, now)) >
slack.get();
} | java | private boolean interpolationsDisagree(TrackPositionUpdate lastUpdate, TrackPositionUpdate currentUpdate) {
long now = System.nanoTime();
return Math.abs(interpolateTimeSinceUpdate(lastUpdate, now) - interpolateTimeSinceUpdate(currentUpdate, now)) >
slack.get();
} | [
"private",
"boolean",
"interpolationsDisagree",
"(",
"TrackPositionUpdate",
"lastUpdate",
",",
"TrackPositionUpdate",
"currentUpdate",
")",
"{",
"long",
"now",
"=",
"System",
".",
"nanoTime",
"(",
")",
";",
"return",
"Math",
".",
"abs",
"(",
"interpolateTimeSinceUpd... | Check whether we have diverged from what we would predict from the last update that was sent to a particular
track position listener.
@param lastUpdate the last update that was sent to the listener
@param currentUpdate the latest update available for the same player
@return {@code true }if the listener will have diverged by more than our permitted amount of slack, and so
should be updated | [
"Check",
"whether",
"we",
"have",
"diverged",
"from",
"what",
"we",
"would",
"predict",
"from",
"the",
"last",
"update",
"that",
"was",
"sent",
"to",
"a",
"particular",
"track",
"position",
"listener",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L363-L367 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java | TimeFinder.stop | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
BeatFinder.getInstance().removeBeatListener(beatListener);
VirtualCdj.getInstance().removeUpdateListener(updateListener);
running.set(false);
positions.clear();
updates.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | java | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
BeatFinder.getInstance().removeBeatListener(beatListener);
VirtualCdj.getInstance().removeUpdateListener(updateListener);
running.set(false);
positions.clear();
updates.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"BeatFinder",
".",
"getInstance",
"(",
")",
".",
"removeBeatListener",
"(",
"beatListener",
")",
";",
... | Stop interpolating playback position for all active players. | [
"Stop",
"interpolating",
"playback",
"position",
"for",
"all",
"active",
"players",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L598-L608 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/DeckReference.java | DeckReference.getDeckReference | public static synchronized DeckReference getDeckReference(int player, int hotCue) {
Map<Integer, DeckReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<Integer, DeckReference>();
instances.put(player, playerMap);
}
DeckReference result = playerMap.get(hotCue);
if (result == null) {
result = new DeckReference(player, hotCue);
playerMap.put(hotCue, result);
}
return result;
} | java | public static synchronized DeckReference getDeckReference(int player, int hotCue) {
Map<Integer, DeckReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<Integer, DeckReference>();
instances.put(player, playerMap);
}
DeckReference result = playerMap.get(hotCue);
if (result == null) {
result = new DeckReference(player, hotCue);
playerMap.put(hotCue, result);
}
return result;
} | [
"public",
"static",
"synchronized",
"DeckReference",
"getDeckReference",
"(",
"int",
"player",
",",
"int",
"hotCue",
")",
"{",
"Map",
"<",
"Integer",
",",
"DeckReference",
">",
"playerMap",
"=",
"instances",
".",
"get",
"(",
"player",
")",
";",
"if",
"(",
... | Get a unique reference to a place where a track is currently loaded in a player.
@param player the player in which the track is loaded
@param hotCue hot cue number in which the track is loaded, or 0 if it is actively loaded on the playback deck
@return the instance that will always represent a reference to the specified player and hot cue | [
"Get",
"a",
"unique",
"reference",
"to",
"a",
"place",
"where",
"a",
"track",
"is",
"currently",
"loaded",
"in",
"a",
"player",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/DeckReference.java#L50-L62 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setDeviceName | public synchronized void setDeviceName(String name) {
if (name.getBytes().length > DEVICE_NAME_LENGTH) {
throw new IllegalArgumentException("name cannot be more than " + DEVICE_NAME_LENGTH + " bytes long");
}
Arrays.fill(announcementBytes, DEVICE_NAME_OFFSET, DEVICE_NAME_LENGTH, (byte)0);
System.arraycopy(name.getBytes(), 0, announcementBytes, DEVICE_NAME_OFFSET, name.getBytes().length);
} | java | public synchronized void setDeviceName(String name) {
if (name.getBytes().length > DEVICE_NAME_LENGTH) {
throw new IllegalArgumentException("name cannot be more than " + DEVICE_NAME_LENGTH + " bytes long");
}
Arrays.fill(announcementBytes, DEVICE_NAME_OFFSET, DEVICE_NAME_LENGTH, (byte)0);
System.arraycopy(name.getBytes(), 0, announcementBytes, DEVICE_NAME_OFFSET, name.getBytes().length);
} | [
"public",
"synchronized",
"void",
"setDeviceName",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
".",
"getBytes",
"(",
")",
".",
"length",
">",
"DEVICE_NAME_LENGTH",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"name cannot be more than \"",
... | Set the name to be used in announcing our presence on the network. The name can be no longer than twenty
bytes, and should be normal ASCII, no Unicode.
@param name the device name to report in our presence announcement packets. | [
"Set",
"the",
"name",
"to",
"be",
"used",
"in",
"announcing",
"our",
"presence",
"on",
"the",
"network",
".",
"The",
"name",
"can",
"be",
"no",
"longer",
"than",
"twenty",
"bytes",
"and",
"should",
"be",
"normal",
"ASCII",
"no",
"Unicode",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L233-L239 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setTempoMaster | private void setTempoMaster(DeviceUpdate newMaster) {
DeviceUpdate oldMaster = tempoMaster.getAndSet(newMaster);
if ((newMaster == null && oldMaster != null) ||
(newMaster != null && ((oldMaster == null) || !newMaster.getAddress().equals(oldMaster.getAddress())))) {
// This is a change in master, so report it to any registered listeners
deliverMasterChangedAnnouncement(newMaster);
}
} | java | private void setTempoMaster(DeviceUpdate newMaster) {
DeviceUpdate oldMaster = tempoMaster.getAndSet(newMaster);
if ((newMaster == null && oldMaster != null) ||
(newMaster != null && ((oldMaster == null) || !newMaster.getAddress().equals(oldMaster.getAddress())))) {
// This is a change in master, so report it to any registered listeners
deliverMasterChangedAnnouncement(newMaster);
}
} | [
"private",
"void",
"setTempoMaster",
"(",
"DeviceUpdate",
"newMaster",
")",
"{",
"DeviceUpdate",
"oldMaster",
"=",
"tempoMaster",
".",
"getAndSet",
"(",
"newMaster",
")",
";",
"if",
"(",
"(",
"newMaster",
"==",
"null",
"&&",
"oldMaster",
"!=",
"null",
")",
"... | Establish a new tempo master, and if it is a change from the existing one, report it to the listeners.
@param newMaster the packet which caused the change of masters, or {@code null} if there is now no master. | [
"Establish",
"a",
"new",
"tempo",
"master",
"and",
"if",
"it",
"is",
"a",
"change",
"from",
"the",
"existing",
"one",
"report",
"it",
"to",
"the",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L266-L273 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setMasterTempo | private void setMasterTempo(double newTempo) {
double oldTempo = Double.longBitsToDouble(masterTempo.getAndSet(Double.doubleToLongBits(newTempo)));
if ((getTempoMaster() != null) && (Math.abs(newTempo - oldTempo) > getTempoEpsilon())) {
// This is a change in tempo, so report it to any registered listeners, and update our metronome if we are synced.
if (isSynced()) {
metronome.setTempo(newTempo);
notifyBeatSenderOfChange();
}
deliverTempoChangedAnnouncement(newTempo);
}
} | java | private void setMasterTempo(double newTempo) {
double oldTempo = Double.longBitsToDouble(masterTempo.getAndSet(Double.doubleToLongBits(newTempo)));
if ((getTempoMaster() != null) && (Math.abs(newTempo - oldTempo) > getTempoEpsilon())) {
// This is a change in tempo, so report it to any registered listeners, and update our metronome if we are synced.
if (isSynced()) {
metronome.setTempo(newTempo);
notifyBeatSenderOfChange();
}
deliverTempoChangedAnnouncement(newTempo);
}
} | [
"private",
"void",
"setMasterTempo",
"(",
"double",
"newTempo",
")",
"{",
"double",
"oldTempo",
"=",
"Double",
".",
"longBitsToDouble",
"(",
"masterTempo",
".",
"getAndSet",
"(",
"Double",
".",
"doubleToLongBits",
"(",
"newTempo",
")",
")",
")",
";",
"if",
"... | Establish a new master tempo, and if it is a change from the existing one, report it to the listeners.
@param newTempo the newly reported master tempo. | [
"Establish",
"a",
"new",
"master",
"tempo",
"and",
"if",
"it",
"is",
"a",
"change",
"from",
"the",
"existing",
"one",
"report",
"it",
"to",
"the",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L319-L329 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.processUpdate | private void processUpdate(DeviceUpdate update) {
updates.put(update.getAddress(), update);
// Keep track of the largest sync number we see.
if (update instanceof CdjStatus) {
int syncNumber = ((CdjStatus)update).getSyncNumber();
if (syncNumber > this.largestSyncCounter.get()) {
this.largestSyncCounter.set(syncNumber);
}
}
// Deal with the tempo master complexities, including handoff to/from us.
if (update.isTempoMaster()) {
final Integer packetYieldingTo = update.getDeviceMasterIsBeingYieldedTo();
if (packetYieldingTo == null) {
// This is a normal, non-yielding master packet. Update our notion of the current master, and,
// if we were yielding, finish that process, updating our sync number appropriately.
if (master.get()) {
if (nextMaster.get() == update.deviceNumber) {
syncCounter.set(largestSyncCounter.get() + 1);
} else {
if (nextMaster.get() == 0xff) {
logger.warn("Saw master asserted by player " + update.deviceNumber +
" when we were not yielding it.");
} else {
logger.warn("Expected to yield master role to player " + nextMaster.get() +
" but saw master asserted by player " + update.deviceNumber);
}
}
}
master.set(false);
nextMaster.set(0xff);
setTempoMaster(update);
setMasterTempo(update.getEffectiveTempo());
} else {
// This is a yielding master packet. If it is us that is being yielded to, take over master.
// Log a message if it was unsolicited, and a warning if it's coming from a different player than
// we asked.
if (packetYieldingTo == getDeviceNumber()) {
if (update.deviceNumber != masterYieldedFrom.get()) {
if (masterYieldedFrom.get() == 0) {
logger.info("Accepting unsolicited Master yield; we must be the only synced device playing.");
} else {
logger.warn("Expected player " + masterYieldedFrom.get() + " to yield master to us, but player " +
update.deviceNumber + " did.");
}
}
master.set(true);
masterYieldedFrom.set(0);
setTempoMaster(null);
setMasterTempo(getTempo());
}
}
} else {
// This update was not acting as a tempo master; if we thought it should be, update our records.
DeviceUpdate oldMaster = getTempoMaster();
if (oldMaster != null && oldMaster.getAddress().equals(update.getAddress())) {
// This device has resigned master status, and nobody else has claimed it so far
setTempoMaster(null);
}
}
deliverDeviceUpdate(update);
} | java | private void processUpdate(DeviceUpdate update) {
updates.put(update.getAddress(), update);
// Keep track of the largest sync number we see.
if (update instanceof CdjStatus) {
int syncNumber = ((CdjStatus)update).getSyncNumber();
if (syncNumber > this.largestSyncCounter.get()) {
this.largestSyncCounter.set(syncNumber);
}
}
// Deal with the tempo master complexities, including handoff to/from us.
if (update.isTempoMaster()) {
final Integer packetYieldingTo = update.getDeviceMasterIsBeingYieldedTo();
if (packetYieldingTo == null) {
// This is a normal, non-yielding master packet. Update our notion of the current master, and,
// if we were yielding, finish that process, updating our sync number appropriately.
if (master.get()) {
if (nextMaster.get() == update.deviceNumber) {
syncCounter.set(largestSyncCounter.get() + 1);
} else {
if (nextMaster.get() == 0xff) {
logger.warn("Saw master asserted by player " + update.deviceNumber +
" when we were not yielding it.");
} else {
logger.warn("Expected to yield master role to player " + nextMaster.get() +
" but saw master asserted by player " + update.deviceNumber);
}
}
}
master.set(false);
nextMaster.set(0xff);
setTempoMaster(update);
setMasterTempo(update.getEffectiveTempo());
} else {
// This is a yielding master packet. If it is us that is being yielded to, take over master.
// Log a message if it was unsolicited, and a warning if it's coming from a different player than
// we asked.
if (packetYieldingTo == getDeviceNumber()) {
if (update.deviceNumber != masterYieldedFrom.get()) {
if (masterYieldedFrom.get() == 0) {
logger.info("Accepting unsolicited Master yield; we must be the only synced device playing.");
} else {
logger.warn("Expected player " + masterYieldedFrom.get() + " to yield master to us, but player " +
update.deviceNumber + " did.");
}
}
master.set(true);
masterYieldedFrom.set(0);
setTempoMaster(null);
setMasterTempo(getTempo());
}
}
} else {
// This update was not acting as a tempo master; if we thought it should be, update our records.
DeviceUpdate oldMaster = getTempoMaster();
if (oldMaster != null && oldMaster.getAddress().equals(update.getAddress())) {
// This device has resigned master status, and nobody else has claimed it so far
setTempoMaster(null);
}
}
deliverDeviceUpdate(update);
} | [
"private",
"void",
"processUpdate",
"(",
"DeviceUpdate",
"update",
")",
"{",
"updates",
".",
"put",
"(",
"update",
".",
"getAddress",
"(",
")",
",",
"update",
")",
";",
"// Keep track of the largest sync number we see.",
"if",
"(",
"update",
"instanceof",
"CdjStat... | Process a device update once it has been received. Track it as the most recent update from its address,
and notify any registered listeners, including master listeners if it results in changes to tracked state,
such as the current master player and tempo. Also handles the Baroque dance of handing off the tempo master
role from or to another device. | [
"Process",
"a",
"device",
"update",
"once",
"it",
"has",
"been",
"received",
".",
"Track",
"it",
"as",
"the",
"most",
"recent",
"update",
"from",
"its",
"address",
"and",
"notify",
"any",
"registered",
"listeners",
"including",
"master",
"listeners",
"if",
"... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L394-L456 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.processBeat | void processBeat(Beat beat) {
if (isRunning() && beat.isTempoMaster()) {
setMasterTempo(beat.getEffectiveTempo());
deliverBeatAnnouncement(beat);
}
} | java | void processBeat(Beat beat) {
if (isRunning() && beat.isTempoMaster()) {
setMasterTempo(beat.getEffectiveTempo());
deliverBeatAnnouncement(beat);
}
} | [
"void",
"processBeat",
"(",
"Beat",
"beat",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
"&&",
"beat",
".",
"isTempoMaster",
"(",
")",
")",
"{",
"setMasterTempo",
"(",
"beat",
".",
"getEffectiveTempo",
"(",
")",
")",
";",
"deliverBeatAnnouncement",
"(",
"... | Process a beat packet, potentially updating the master tempo and sending our listeners a master
beat notification. Does nothing if we are not active. | [
"Process",
"a",
"beat",
"packet",
"potentially",
"updating",
"the",
"master",
"tempo",
"and",
"sending",
"our",
"listeners",
"a",
"master",
"beat",
"notification",
".",
"Does",
"nothing",
"if",
"we",
"are",
"not",
"active",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L462-L467 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.findMatchingAddress | private InterfaceAddress findMatchingAddress(DeviceAnnouncement aDevice, NetworkInterface networkInterface) {
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
if ((address.getBroadcast() != null) &&
Util.sameNetwork(address.getNetworkPrefixLength(), aDevice.getAddress(), address.getAddress())) {
return address;
}
}
return null;
} | java | private InterfaceAddress findMatchingAddress(DeviceAnnouncement aDevice, NetworkInterface networkInterface) {
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
if ((address.getBroadcast() != null) &&
Util.sameNetwork(address.getNetworkPrefixLength(), aDevice.getAddress(), address.getAddress())) {
return address;
}
}
return null;
} | [
"private",
"InterfaceAddress",
"findMatchingAddress",
"(",
"DeviceAnnouncement",
"aDevice",
",",
"NetworkInterface",
"networkInterface",
")",
"{",
"for",
"(",
"InterfaceAddress",
"address",
":",
"networkInterface",
".",
"getInterfaceAddresses",
"(",
")",
")",
"{",
"if",... | Scan a network interface to find if it has an address space which matches the device we are trying to reach.
If so, return the address specification.
@param aDevice the DJ Link device we are trying to communicate with
@param networkInterface the network interface we are testing
@return the address which can be used to communicate with the device on the interface, or null | [
"Scan",
"a",
"network",
"interface",
"to",
"find",
"if",
"it",
"has",
"an",
"address",
"space",
"which",
"matches",
"the",
"device",
"we",
"are",
"trying",
"to",
"reach",
".",
"If",
"so",
"return",
"the",
"address",
"specification",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L477-L485 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.findUnreachablePlayers | public Set<DeviceAnnouncement> findUnreachablePlayers() {
ensureRunning();
Set<DeviceAnnouncement> result = new HashSet<DeviceAnnouncement>();
for (DeviceAnnouncement candidate: DeviceFinder.getInstance().getCurrentDevices()) {
if (!Util.sameNetwork(matchedAddress.getNetworkPrefixLength(), matchedAddress.getAddress(), candidate.getAddress())) {
result.add(candidate);
}
}
return Collections.unmodifiableSet(result);
} | java | public Set<DeviceAnnouncement> findUnreachablePlayers() {
ensureRunning();
Set<DeviceAnnouncement> result = new HashSet<DeviceAnnouncement>();
for (DeviceAnnouncement candidate: DeviceFinder.getInstance().getCurrentDevices()) {
if (!Util.sameNetwork(matchedAddress.getNetworkPrefixLength(), matchedAddress.getAddress(), candidate.getAddress())) {
result.add(candidate);
}
}
return Collections.unmodifiableSet(result);
} | [
"public",
"Set",
"<",
"DeviceAnnouncement",
">",
"findUnreachablePlayers",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"Set",
"<",
"DeviceAnnouncement",
">",
"result",
"=",
"new",
"HashSet",
"<",
"DeviceAnnouncement",
">",
"(",
")",
";",
"for",
"(",
"Devi... | Checks if we can see any players that are on a different network than the one we chose for the Virtual CDJ.
If so, we are not going to be able to communicate with them, and they should all be moved onto a single
network.
@return the device announcements of any players which are on unreachable networks, or hopefully an empty list
@throws IllegalStateException if we are not running | [
"Checks",
"if",
"we",
"can",
"see",
"any",
"players",
"that",
"are",
"on",
"a",
"different",
"network",
"than",
"the",
"one",
"we",
"chose",
"for",
"the",
"Virtual",
"CDJ",
".",
"If",
"so",
"we",
"are",
"not",
"going",
"to",
"be",
"able",
"to",
"comm... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L672-L681 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.stop | public synchronized void stop() {
if (isRunning()) {
try {
setSendingStatus(false);
} catch (Throwable t) {
logger.error("Problem stopping sending status during shutdown", t);
}
DeviceFinder.getInstance().removeIgnoredAddress(socket.get().getLocalAddress());
socket.get().close();
socket.set(null);
broadcastAddress.set(null);
updates.clear();
setTempoMaster(null);
setDeviceNumber((byte)0); // Set up for self-assignment if restarted.
deliverLifecycleAnnouncement(logger, false);
}
} | java | public synchronized void stop() {
if (isRunning()) {
try {
setSendingStatus(false);
} catch (Throwable t) {
logger.error("Problem stopping sending status during shutdown", t);
}
DeviceFinder.getInstance().removeIgnoredAddress(socket.get().getLocalAddress());
socket.get().close();
socket.set(null);
broadcastAddress.set(null);
updates.clear();
setTempoMaster(null);
setDeviceNumber((byte)0); // Set up for self-assignment if restarted.
deliverLifecycleAnnouncement(logger, false);
}
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"try",
"{",
"setSendingStatus",
"(",
"false",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem stopping... | Stop announcing ourselves and listening for status updates. | [
"Stop",
"announcing",
"ourselves",
"and",
"listening",
"for",
"status",
"updates",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L739-L755 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendAnnouncement | private void sendAnnouncement(InetAddress broadcastAddress) {
try {
DatagramPacket announcement = new DatagramPacket(announcementBytes, announcementBytes.length,
broadcastAddress, DeviceFinder.ANNOUNCEMENT_PORT);
socket.get().send(announcement);
Thread.sleep(getAnnounceInterval());
} catch (Throwable t) {
logger.warn("Unable to send announcement packet, shutting down", t);
stop();
}
} | java | private void sendAnnouncement(InetAddress broadcastAddress) {
try {
DatagramPacket announcement = new DatagramPacket(announcementBytes, announcementBytes.length,
broadcastAddress, DeviceFinder.ANNOUNCEMENT_PORT);
socket.get().send(announcement);
Thread.sleep(getAnnounceInterval());
} catch (Throwable t) {
logger.warn("Unable to send announcement packet, shutting down", t);
stop();
}
} | [
"private",
"void",
"sendAnnouncement",
"(",
"InetAddress",
"broadcastAddress",
")",
"{",
"try",
"{",
"DatagramPacket",
"announcement",
"=",
"new",
"DatagramPacket",
"(",
"announcementBytes",
",",
"announcementBytes",
".",
"length",
",",
"broadcastAddress",
",",
"Devic... | Send an announcement packet so the other devices see us as being part of the DJ Link network and send us
updates. | [
"Send",
"an",
"announcement",
"packet",
"so",
"the",
"other",
"devices",
"see",
"us",
"as",
"being",
"part",
"of",
"the",
"DJ",
"Link",
"network",
"and",
"send",
"us",
"updates",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L761-L771 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.deliverMasterChangedAnnouncement | private void deliverMasterChangedAnnouncement(final DeviceUpdate update) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.masterChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering master changed announcement to listener", t);
}
}
} | java | private void deliverMasterChangedAnnouncement(final DeviceUpdate update) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.masterChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering master changed announcement to listener", t);
}
}
} | [
"private",
"void",
"deliverMasterChangedAnnouncement",
"(",
"final",
"DeviceUpdate",
"update",
")",
"{",
"for",
"(",
"final",
"MasterListener",
"listener",
":",
"getMasterListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"masterChanged",
"(",
"update",
... | Send a master changed announcement to all registered master listeners.
@param update the message announcing the new tempo master | [
"Send",
"a",
"master",
"changed",
"announcement",
"to",
"all",
"registered",
"master",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L909-L917 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.deliverTempoChangedAnnouncement | private void deliverTempoChangedAnnouncement(final double tempo) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.tempoChanged(tempo);
} catch (Throwable t) {
logger.warn("Problem delivering tempo changed announcement to listener", t);
}
}
} | java | private void deliverTempoChangedAnnouncement(final double tempo) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.tempoChanged(tempo);
} catch (Throwable t) {
logger.warn("Problem delivering tempo changed announcement to listener", t);
}
}
} | [
"private",
"void",
"deliverTempoChangedAnnouncement",
"(",
"final",
"double",
"tempo",
")",
"{",
"for",
"(",
"final",
"MasterListener",
"listener",
":",
"getMasterListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"tempoChanged",
"(",
"tempo",
")",
"... | Send a tempo changed announcement to all registered master listeners.
@param tempo the new master tempo | [
"Send",
"a",
"tempo",
"changed",
"announcement",
"to",
"all",
"registered",
"master",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L924-L932 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.deliverBeatAnnouncement | private void deliverBeatAnnouncement(final Beat beat) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.newBeat(beat);
} catch (Throwable t) {
logger.warn("Problem delivering master beat announcement to listener", t);
}
}
} | java | private void deliverBeatAnnouncement(final Beat beat) {
for (final MasterListener listener : getMasterListeners()) {
try {
listener.newBeat(beat);
} catch (Throwable t) {
logger.warn("Problem delivering master beat announcement to listener", t);
}
}
} | [
"private",
"void",
"deliverBeatAnnouncement",
"(",
"final",
"Beat",
"beat",
")",
"{",
"for",
"(",
"final",
"MasterListener",
"listener",
":",
"getMasterListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"newBeat",
"(",
"beat",
")",
";",
"}",
"cat... | Send a beat announcement to all registered master listeners.
@param beat the beat sent by the tempo master | [
"Send",
"a",
"beat",
"announcement",
"to",
"all",
"registered",
"master",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L939-L947 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.deliverDeviceUpdate | private void deliverDeviceUpdate(final DeviceUpdate update) {
for (DeviceUpdateListener listener : getUpdateListeners()) {
try {
listener.received(update);
} catch (Throwable t) {
logger.warn("Problem delivering device update to listener", t);
}
}
} | java | private void deliverDeviceUpdate(final DeviceUpdate update) {
for (DeviceUpdateListener listener : getUpdateListeners()) {
try {
listener.received(update);
} catch (Throwable t) {
logger.warn("Problem delivering device update to listener", t);
}
}
} | [
"private",
"void",
"deliverDeviceUpdate",
"(",
"final",
"DeviceUpdate",
"update",
")",
"{",
"for",
"(",
"DeviceUpdateListener",
"listener",
":",
"getUpdateListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"received",
"(",
"update",
")",
";",
"}",
... | Send a device update to all registered update listeners.
@param update the device update that has just arrived | [
"Send",
"a",
"device",
"update",
"to",
"all",
"registered",
"update",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1006-L1014 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.deliverMediaDetailsUpdate | private void deliverMediaDetailsUpdate(final MediaDetails details) {
for (MediaDetailsListener listener : getMediaDetailsListeners()) {
try {
listener.detailsAvailable(details);
} catch (Throwable t) {
logger.warn("Problem delivering media details response to listener", t);
}
}
} | java | private void deliverMediaDetailsUpdate(final MediaDetails details) {
for (MediaDetailsListener listener : getMediaDetailsListeners()) {
try {
listener.detailsAvailable(details);
} catch (Throwable t) {
logger.warn("Problem delivering media details response to listener", t);
}
}
} | [
"private",
"void",
"deliverMediaDetailsUpdate",
"(",
"final",
"MediaDetails",
"details",
")",
"{",
"for",
"(",
"MediaDetailsListener",
"listener",
":",
"getMediaDetailsListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"detailsAvailable",
"(",
"details",
... | Send a media details response to all registered listeners.
@param details the response that has just arrived | [
"Send",
"a",
"media",
"details",
"response",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1072-L1080 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.assembleAndSendPacket | @SuppressWarnings("SameParameterValue")
private void assembleAndSendPacket(Util.PacketType kind, byte[] payload, InetAddress destination, int port) throws IOException {
DatagramPacket packet = Util.buildPacket(kind,
ByteBuffer.wrap(announcementBytes, DEVICE_NAME_OFFSET, DEVICE_NAME_LENGTH).asReadOnlyBuffer(),
ByteBuffer.wrap(payload));
packet.setAddress(destination);
packet.setPort(port);
socket.get().send(packet);
} | java | @SuppressWarnings("SameParameterValue")
private void assembleAndSendPacket(Util.PacketType kind, byte[] payload, InetAddress destination, int port) throws IOException {
DatagramPacket packet = Util.buildPacket(kind,
ByteBuffer.wrap(announcementBytes, DEVICE_NAME_OFFSET, DEVICE_NAME_LENGTH).asReadOnlyBuffer(),
ByteBuffer.wrap(payload));
packet.setAddress(destination);
packet.setPort(port);
socket.get().send(packet);
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"void",
"assembleAndSendPacket",
"(",
"Util",
".",
"PacketType",
"kind",
",",
"byte",
"[",
"]",
"payload",
",",
"InetAddress",
"destination",
",",
"int",
"port",
")",
"throws",
"IOException",
... | Finish the work of building and sending a protocol packet.
@param kind the type of packet to create and send
@param payload the content which will follow our device name in the packet
@param destination where the packet should be sent
@param port the port to which the packet should be sent
@throws IOException if there is a problem sending the packet | [
"Finish",
"the",
"work",
"of",
"building",
"and",
"sending",
"a",
"protocol",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1092-L1100 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendSyncControlCommand | private void sendSyncControlCommand(DeviceUpdate target, byte command) throws IOException {
ensureRunning();
byte[] payload = new byte[SYNC_CONTROL_PAYLOAD.length];
System.arraycopy(SYNC_CONTROL_PAYLOAD, 0, payload, 0, SYNC_CONTROL_PAYLOAD.length);
payload[2] = getDeviceNumber();
payload[8] = getDeviceNumber();
payload[12] = command;
assembleAndSendPacket(Util.PacketType.SYNC_CONTROL, payload, target.getAddress(), BeatFinder.BEAT_PORT);
} | java | private void sendSyncControlCommand(DeviceUpdate target, byte command) throws IOException {
ensureRunning();
byte[] payload = new byte[SYNC_CONTROL_PAYLOAD.length];
System.arraycopy(SYNC_CONTROL_PAYLOAD, 0, payload, 0, SYNC_CONTROL_PAYLOAD.length);
payload[2] = getDeviceNumber();
payload[8] = getDeviceNumber();
payload[12] = command;
assembleAndSendPacket(Util.PacketType.SYNC_CONTROL, payload, target.getAddress(), BeatFinder.BEAT_PORT);
} | [
"private",
"void",
"sendSyncControlCommand",
"(",
"DeviceUpdate",
"target",
",",
"byte",
"command",
")",
"throws",
"IOException",
"{",
"ensureRunning",
"(",
")",
";",
"byte",
"[",
"]",
"payload",
"=",
"new",
"byte",
"[",
"SYNC_CONTROL_PAYLOAD",
".",
"length",
... | Assemble and send a packet that performs sync control, turning a device's sync mode on or off, or telling it
to become the tempo master.
@param target an update from the device whose sync state is to be set
@param command the byte identifying the specific sync command to be sent
@throws IOException if there is a problem sending the command to the device | [
"Assemble",
"and",
"send",
"a",
"packet",
"that",
"performs",
"sync",
"control",
"turning",
"a",
"device",
"s",
"sync",
"mode",
"on",
"or",
"off",
"or",
"telling",
"it",
"to",
"become",
"the",
"tempo",
"master",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1146-L1154 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendSyncModeCommand | public void sendSyncModeCommand(int deviceNumber, boolean synced) throws IOException {
final DeviceUpdate update = getLatestStatusFor(deviceNumber);
if (update == null) {
throw new IllegalArgumentException("Device " + deviceNumber + " not found on network.");
}
sendSyncModeCommand(update, synced);
} | java | public void sendSyncModeCommand(int deviceNumber, boolean synced) throws IOException {
final DeviceUpdate update = getLatestStatusFor(deviceNumber);
if (update == null) {
throw new IllegalArgumentException("Device " + deviceNumber + " not found on network.");
}
sendSyncModeCommand(update, synced);
} | [
"public",
"void",
"sendSyncModeCommand",
"(",
"int",
"deviceNumber",
",",
"boolean",
"synced",
")",
"throws",
"IOException",
"{",
"final",
"DeviceUpdate",
"update",
"=",
"getLatestStatusFor",
"(",
"deviceNumber",
")",
";",
"if",
"(",
"update",
"==",
"null",
")",... | Tell a device to turn sync on or off.
@param deviceNumber the device whose sync state is to be set
@param synced {@code} true if sync should be turned on, else it will be turned off
@throws IOException if there is a problem sending the command to the device
@throws IllegalStateException if the {@code VirtualCdj} is not active
@throws IllegalArgumentException if {@code deviceNumber} is not found on the network | [
"Tell",
"a",
"device",
"to",
"turn",
"sync",
"on",
"or",
"off",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1166-L1172 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.appointTempoMaster | public void appointTempoMaster(int deviceNumber) throws IOException {
final DeviceUpdate update = getLatestStatusFor(deviceNumber);
if (update == null) {
throw new IllegalArgumentException("Device " + deviceNumber + " not found on network.");
}
appointTempoMaster(update);
} | java | public void appointTempoMaster(int deviceNumber) throws IOException {
final DeviceUpdate update = getLatestStatusFor(deviceNumber);
if (update == null) {
throw new IllegalArgumentException("Device " + deviceNumber + " not found on network.");
}
appointTempoMaster(update);
} | [
"public",
"void",
"appointTempoMaster",
"(",
"int",
"deviceNumber",
")",
"throws",
"IOException",
"{",
"final",
"DeviceUpdate",
"update",
"=",
"getLatestStatusFor",
"(",
"deviceNumber",
")",
";",
"if",
"(",
"update",
"==",
"null",
")",
"{",
"throw",
"new",
"Il... | Tell a device to become tempo master.
@param deviceNumber the device we want to take over the role of tempo master
@throws IOException if there is a problem sending the command to the device
@throws IllegalStateException if the {@code VirtualCdj} is not active
@throws IllegalArgumentException if {@code deviceNumber} is not found on the network | [
"Tell",
"a",
"device",
"to",
"become",
"tempo",
"master",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1197-L1203 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendFaderStartCommand | public void sendFaderStartCommand(Set<Integer> deviceNumbersToStart, Set<Integer> deviceNumbersToStop) throws IOException {
ensureRunning();
byte[] payload = new byte[FADER_START_PAYLOAD.length];
System.arraycopy(FADER_START_PAYLOAD, 0, payload, 0, FADER_START_PAYLOAD.length);
payload[2] = getDeviceNumber();
for (int i = 1; i <= 4; i++) {
if (deviceNumbersToStart.contains(i)) {
payload[i + 4] = 0;
}
if (deviceNumbersToStop.contains(i)) {
payload[i + 4] = 1;
}
}
assembleAndSendPacket(Util.PacketType.FADER_START_COMMAND, payload, getBroadcastAddress(), BeatFinder.BEAT_PORT);
} | java | public void sendFaderStartCommand(Set<Integer> deviceNumbersToStart, Set<Integer> deviceNumbersToStop) throws IOException {
ensureRunning();
byte[] payload = new byte[FADER_START_PAYLOAD.length];
System.arraycopy(FADER_START_PAYLOAD, 0, payload, 0, FADER_START_PAYLOAD.length);
payload[2] = getDeviceNumber();
for (int i = 1; i <= 4; i++) {
if (deviceNumbersToStart.contains(i)) {
payload[i + 4] = 0;
}
if (deviceNumbersToStop.contains(i)) {
payload[i + 4] = 1;
}
}
assembleAndSendPacket(Util.PacketType.FADER_START_COMMAND, payload, getBroadcastAddress(), BeatFinder.BEAT_PORT);
} | [
"public",
"void",
"sendFaderStartCommand",
"(",
"Set",
"<",
"Integer",
">",
"deviceNumbersToStart",
",",
"Set",
"<",
"Integer",
">",
"deviceNumbersToStop",
")",
"throws",
"IOException",
"{",
"ensureRunning",
"(",
")",
";",
"byte",
"[",
"]",
"payload",
"=",
"ne... | Broadcast a packet that tells some players to start playing and others to stop. If a player number is in
both sets, it will be told to stop. Numbers outside the range 1 to 4 are ignored.
@param deviceNumbersToStart the players that should start playing if they aren't already
@param deviceNumbersToStop the players that should stop playing
@throws IOException if there is a problem broadcasting the command to the players
@throws IllegalStateException if the {@code VirtualCdj} is not active | [
"Broadcast",
"a",
"packet",
"that",
"tells",
"some",
"players",
"to",
"start",
"playing",
"and",
"others",
"to",
"stop",
".",
"If",
"a",
"player",
"number",
"is",
"in",
"both",
"sets",
"it",
"will",
"be",
"told",
"to",
"stop",
".",
"Numbers",
"outside",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1234-L1250 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendLoadTrackCommand | public void sendLoadTrackCommand(int targetPlayer, int rekordboxId,
int sourcePlayer, CdjStatus.TrackSourceSlot sourceSlot, CdjStatus.TrackType sourceType)
throws IOException {
final DeviceUpdate update = getLatestStatusFor(targetPlayer);
if (update == null) {
throw new IllegalArgumentException("Device " + targetPlayer + " not found on network.");
}
sendLoadTrackCommand(update, rekordboxId, sourcePlayer, sourceSlot, sourceType);
} | java | public void sendLoadTrackCommand(int targetPlayer, int rekordboxId,
int sourcePlayer, CdjStatus.TrackSourceSlot sourceSlot, CdjStatus.TrackType sourceType)
throws IOException {
final DeviceUpdate update = getLatestStatusFor(targetPlayer);
if (update == null) {
throw new IllegalArgumentException("Device " + targetPlayer + " not found on network.");
}
sendLoadTrackCommand(update, rekordboxId, sourcePlayer, sourceSlot, sourceType);
} | [
"public",
"void",
"sendLoadTrackCommand",
"(",
"int",
"targetPlayer",
",",
"int",
"rekordboxId",
",",
"int",
"sourcePlayer",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"sourceSlot",
",",
"CdjStatus",
".",
"TrackType",
"sourceType",
")",
"throws",
"IOException",
"{",
... | Send a packet to the target player telling it to load the specified track from the specified source player.
@param targetPlayer the device number of the player that you want to have load a track
@param rekordboxId the identifier of a track within the source player's rekordbox database
@param sourcePlayer the device number of the player from which the track should be loaded
@param sourceSlot the media slot from which the track should be loaded
@param sourceType the type of track to be loaded
@throws IOException if there is a problem sending the command
@throws IllegalStateException if the {@code VirtualCdj} is not active or the target device cannot be found | [
"Send",
"a",
"packet",
"to",
"the",
"target",
"player",
"telling",
"it",
"to",
"load",
"the",
"specified",
"track",
"from",
"the",
"specified",
"source",
"player",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1306-L1314 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.sendLoadTrackCommand | public void sendLoadTrackCommand(DeviceUpdate target, int rekordboxId,
int sourcePlayer, CdjStatus.TrackSourceSlot sourceSlot, CdjStatus.TrackType sourceType)
throws IOException {
ensureRunning();
byte[] payload = new byte[LOAD_TRACK_PAYLOAD.length];
System.arraycopy(LOAD_TRACK_PAYLOAD, 0, payload, 0, LOAD_TRACK_PAYLOAD.length);
payload[0x02] = getDeviceNumber();
payload[0x05] = getDeviceNumber();
payload[0x09] = (byte)sourcePlayer;
payload[0x0a] = sourceSlot.protocolValue;
payload[0x0b] = sourceType.protocolValue;
Util.numberToBytes(rekordboxId, payload, 0x0d, 4);
assembleAndSendPacket(Util.PacketType.LOAD_TRACK_COMMAND, payload, target.getAddress(), UPDATE_PORT);
} | java | public void sendLoadTrackCommand(DeviceUpdate target, int rekordboxId,
int sourcePlayer, CdjStatus.TrackSourceSlot sourceSlot, CdjStatus.TrackType sourceType)
throws IOException {
ensureRunning();
byte[] payload = new byte[LOAD_TRACK_PAYLOAD.length];
System.arraycopy(LOAD_TRACK_PAYLOAD, 0, payload, 0, LOAD_TRACK_PAYLOAD.length);
payload[0x02] = getDeviceNumber();
payload[0x05] = getDeviceNumber();
payload[0x09] = (byte)sourcePlayer;
payload[0x0a] = sourceSlot.protocolValue;
payload[0x0b] = sourceType.protocolValue;
Util.numberToBytes(rekordboxId, payload, 0x0d, 4);
assembleAndSendPacket(Util.PacketType.LOAD_TRACK_COMMAND, payload, target.getAddress(), UPDATE_PORT);
} | [
"public",
"void",
"sendLoadTrackCommand",
"(",
"DeviceUpdate",
"target",
",",
"int",
"rekordboxId",
",",
"int",
"sourcePlayer",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"sourceSlot",
",",
"CdjStatus",
".",
"TrackType",
"sourceType",
")",
"throws",
"IOException",
"{... | Send a packet to the target device telling it to load the specified track from the specified source player.
@param target an update from the player that you want to have load a track
@param rekordboxId the identifier of a track within the source player's rekordbox database
@param sourcePlayer the device number of the player from which the track should be loaded
@param sourceSlot the media slot from which the track should be loaded
@param sourceType the type of track to be loaded
@throws IOException if there is a problem sending the command
@throws IllegalStateException if the {@code VirtualCdj} is not active | [
"Send",
"a",
"packet",
"to",
"the",
"target",
"device",
"telling",
"it",
"to",
"load",
"the",
"specified",
"track",
"from",
"the",
"specified",
"source",
"player",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1328-L1341 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setSendingStatus | public synchronized void setSendingStatus(boolean send) throws IOException {
if (isSendingStatus() == send) {
return;
}
if (send) { // Start sending status packets.
ensureRunning();
if ((getDeviceNumber() < 1) || (getDeviceNumber() > 4)) {
throw new IllegalStateException("Can only send status when using a standard player number, 1 through 4.");
}
BeatFinder.getInstance().start();
BeatFinder.getInstance().addLifecycleListener(beatFinderLifecycleListener);
final AtomicBoolean stillRunning = new AtomicBoolean(true);
sendingStatus = stillRunning; // Allow other threads to stop us when necessary.
Thread sender = new Thread(null, new Runnable() {
@Override
public void run() {
while (stillRunning.get()) {
sendStatus();
try {
Thread.sleep(getStatusInterval());
} catch (InterruptedException e) {
logger.warn("beat-link VirtualCDJ status sender thread was interrupted; continuing");
}
}
}
}, "beat-link VirtualCdj status sender");
sender.setDaemon(true);
sender.start();
if (isSynced()) { // If we are supposed to be synced, we need to respond to master beats and tempo changes.
addMasterListener(ourSyncMasterListener);
}
if (isPlaying()) { // Start the beat sender too, if we are supposed to be playing.
beatSender.set(new BeatSender(metronome));
}
} else { // Stop sending status packets, and responding to master beats and tempo changes if we were synced.
BeatFinder.getInstance().removeLifecycleListener(beatFinderLifecycleListener);
removeMasterListener(ourSyncMasterListener);
sendingStatus.set(false); // Stop the status sending thread.
sendingStatus = null; // Indicate that we are no longer sending status.
final BeatSender activeSender = beatSender.get(); // And stop the beat sender if we have one.
if (activeSender != null) {
activeSender.shutDown();
beatSender.set(null);
}
}
} | java | public synchronized void setSendingStatus(boolean send) throws IOException {
if (isSendingStatus() == send) {
return;
}
if (send) { // Start sending status packets.
ensureRunning();
if ((getDeviceNumber() < 1) || (getDeviceNumber() > 4)) {
throw new IllegalStateException("Can only send status when using a standard player number, 1 through 4.");
}
BeatFinder.getInstance().start();
BeatFinder.getInstance().addLifecycleListener(beatFinderLifecycleListener);
final AtomicBoolean stillRunning = new AtomicBoolean(true);
sendingStatus = stillRunning; // Allow other threads to stop us when necessary.
Thread sender = new Thread(null, new Runnable() {
@Override
public void run() {
while (stillRunning.get()) {
sendStatus();
try {
Thread.sleep(getStatusInterval());
} catch (InterruptedException e) {
logger.warn("beat-link VirtualCDJ status sender thread was interrupted; continuing");
}
}
}
}, "beat-link VirtualCdj status sender");
sender.setDaemon(true);
sender.start();
if (isSynced()) { // If we are supposed to be synced, we need to respond to master beats and tempo changes.
addMasterListener(ourSyncMasterListener);
}
if (isPlaying()) { // Start the beat sender too, if we are supposed to be playing.
beatSender.set(new BeatSender(metronome));
}
} else { // Stop sending status packets, and responding to master beats and tempo changes if we were synced.
BeatFinder.getInstance().removeLifecycleListener(beatFinderLifecycleListener);
removeMasterListener(ourSyncMasterListener);
sendingStatus.set(false); // Stop the status sending thread.
sendingStatus = null; // Indicate that we are no longer sending status.
final BeatSender activeSender = beatSender.get(); // And stop the beat sender if we have one.
if (activeSender != null) {
activeSender.shutDown();
beatSender.set(null);
}
}
} | [
"public",
"synchronized",
"void",
"setSendingStatus",
"(",
"boolean",
"send",
")",
"throws",
"IOException",
"{",
"if",
"(",
"isSendingStatus",
"(",
")",
"==",
"send",
")",
"{",
"return",
";",
"}",
"if",
"(",
"send",
")",
"{",
"// Start sending status packets."... | Control whether the Virtual CDJ sends status packets to the other players. Most uses of Beat Link will not
require this level of activity. However, if you want to be able to take over the tempo master role, and control
the tempo and beat alignment of other players, you will need to turn on this feature, which also requires that
you are using one of the standard player numbers, 1-4.
@param send if {@code true} we will send status packets, and can participate in (and control) tempo and beat sync
@throws IllegalStateException if the virtual CDJ is not running, or if it is not using a device number in the
range 1 through 4
@throws IOException if there is a problem starting the {@link BeatFinder} | [
"Control",
"whether",
"the",
"Virtual",
"CDJ",
"sends",
"status",
"packets",
"to",
"the",
"other",
"players",
".",
"Most",
"uses",
"of",
"Beat",
"Link",
"will",
"not",
"require",
"this",
"level",
"of",
"activity",
".",
"However",
"if",
"you",
"want",
"to",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1494-L1546 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setPlaying | public void setPlaying(boolean playing) {
if (this.playing.get() == playing) {
return;
}
this.playing.set(playing);
if (playing) {
metronome.jumpToBeat(whereStopped.get().getBeat());
if (isSendingStatus()) { // Need to also start the beat sender.
beatSender.set(new BeatSender(metronome));
}
} else {
final BeatSender activeSender = beatSender.get();
if (activeSender != null) { // We have a beat sender we need to stop.
activeSender.shutDown();
beatSender.set(null);
}
whereStopped.set(metronome.getSnapshot());
}
} | java | public void setPlaying(boolean playing) {
if (this.playing.get() == playing) {
return;
}
this.playing.set(playing);
if (playing) {
metronome.jumpToBeat(whereStopped.get().getBeat());
if (isSendingStatus()) { // Need to also start the beat sender.
beatSender.set(new BeatSender(metronome));
}
} else {
final BeatSender activeSender = beatSender.get();
if (activeSender != null) { // We have a beat sender we need to stop.
activeSender.shutDown();
beatSender.set(null);
}
whereStopped.set(metronome.getSnapshot());
}
} | [
"public",
"void",
"setPlaying",
"(",
"boolean",
"playing",
")",
"{",
"if",
"(",
"this",
".",
"playing",
".",
"get",
"(",
")",
"==",
"playing",
")",
"{",
"return",
";",
"}",
"this",
".",
"playing",
".",
"set",
"(",
"playing",
")",
";",
"if",
"(",
... | Controls whether we report that we are playing. This will only have an impact when we are sending status and
beat packets.
@param playing {@code true} if we should seem to be playing | [
"Controls",
"whether",
"we",
"report",
"that",
"we",
"are",
"playing",
".",
"This",
"will",
"only",
"have",
"an",
"impact",
"when",
"we",
"are",
"sending",
"status",
"and",
"beat",
"packets",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1582-L1603 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.becomeTempoMaster | public synchronized void becomeTempoMaster() throws IOException {
logger.debug("Trying to become master.");
if (!isSendingStatus()) {
throw new IllegalStateException("Must be sending status updates to become the tempo master.");
}
// Is there someone we need to ask to yield to us?
final DeviceUpdate currentMaster = getTempoMaster();
if (currentMaster != null) {
// Send the yield request; we will become master when we get a successful response.
byte[] payload = new byte[MASTER_HANDOFF_REQUEST_PAYLOAD.length];
System.arraycopy(MASTER_HANDOFF_REQUEST_PAYLOAD, 0, payload, 0, MASTER_HANDOFF_REQUEST_PAYLOAD.length);
payload[2] = getDeviceNumber();
payload[8] = getDeviceNumber();
if (logger.isDebugEnabled()) {
logger.debug("Sending master yield request to player " + currentMaster);
}
requestingMasterRoleFromPlayer.set(currentMaster.deviceNumber);
assembleAndSendPacket(Util.PacketType.MASTER_HANDOFF_REQUEST, payload, currentMaster.address, BeatFinder.BEAT_PORT);
} else if (!master.get()) {
// There is no other master, we can just become it immediately.
requestingMasterRoleFromPlayer.set(0);
setMasterTempo(getTempo());
master.set(true);
}
} | java | public synchronized void becomeTempoMaster() throws IOException {
logger.debug("Trying to become master.");
if (!isSendingStatus()) {
throw new IllegalStateException("Must be sending status updates to become the tempo master.");
}
// Is there someone we need to ask to yield to us?
final DeviceUpdate currentMaster = getTempoMaster();
if (currentMaster != null) {
// Send the yield request; we will become master when we get a successful response.
byte[] payload = new byte[MASTER_HANDOFF_REQUEST_PAYLOAD.length];
System.arraycopy(MASTER_HANDOFF_REQUEST_PAYLOAD, 0, payload, 0, MASTER_HANDOFF_REQUEST_PAYLOAD.length);
payload[2] = getDeviceNumber();
payload[8] = getDeviceNumber();
if (logger.isDebugEnabled()) {
logger.debug("Sending master yield request to player " + currentMaster);
}
requestingMasterRoleFromPlayer.set(currentMaster.deviceNumber);
assembleAndSendPacket(Util.PacketType.MASTER_HANDOFF_REQUEST, payload, currentMaster.address, BeatFinder.BEAT_PORT);
} else if (!master.get()) {
// There is no other master, we can just become it immediately.
requestingMasterRoleFromPlayer.set(0);
setMasterTempo(getTempo());
master.set(true);
}
} | [
"public",
"synchronized",
"void",
"becomeTempoMaster",
"(",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Trying to become master.\"",
")",
";",
"if",
"(",
"!",
"isSendingStatus",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
... | Arrange to become the tempo master. Starts a sequence of interactions with the other players that should end
up with us in charge of the group tempo and beat alignment.
@throws IllegalStateException if we are not sending status updates
@throws IOException if there is a problem sending the master yield request | [
"Arrange",
"to",
"become",
"the",
"tempo",
"master",
".",
"Starts",
"a",
"sequence",
"of",
"interactions",
"with",
"the",
"other",
"players",
"that",
"should",
"end",
"up",
"with",
"us",
"in",
"charge",
"of",
"the",
"group",
"tempo",
"and",
"beat",
"alignm... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1670-L1695 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.setSynced | public synchronized void setSynced(boolean sync) {
if (synced.get() != sync) {
// We are changing sync state, so add or remove our master listener as appropriate.
if (sync && isSendingStatus()) {
addMasterListener(ourSyncMasterListener);
} else {
removeMasterListener(ourSyncMasterListener);
}
// Also, if there is a tempo master, and we just got synced, adopt its tempo.
if (!isTempoMaster() && getTempoMaster() != null) {
setTempo(getMasterTempo());
}
}
synced.set(sync);
} | java | public synchronized void setSynced(boolean sync) {
if (synced.get() != sync) {
// We are changing sync state, so add or remove our master listener as appropriate.
if (sync && isSendingStatus()) {
addMasterListener(ourSyncMasterListener);
} else {
removeMasterListener(ourSyncMasterListener);
}
// Also, if there is a tempo master, and we just got synced, adopt its tempo.
if (!isTempoMaster() && getTempoMaster() != null) {
setTempo(getMasterTempo());
}
}
synced.set(sync);
} | [
"public",
"synchronized",
"void",
"setSynced",
"(",
"boolean",
"sync",
")",
"{",
"if",
"(",
"synced",
".",
"get",
"(",
")",
"!=",
"sync",
")",
"{",
"// We are changing sync state, so add or remove our master listener as appropriate.",
"if",
"(",
"sync",
"&&",
"isSen... | Controls whether we are currently staying in sync with the tempo master. Will only be meaningful if we are
sending status packets.
@param sync if {@code true}, our status packets will be tempo and beat aligned with the tempo master | [
"Controls",
"whether",
"we",
"are",
"currently",
"staying",
"in",
"sync",
"with",
"the",
"tempo",
"master",
".",
"Will",
"only",
"be",
"meaningful",
"if",
"we",
"are",
"sending",
"status",
"packets",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1742-L1757 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java | VirtualCdj.jumpToBeat | public synchronized void jumpToBeat(int beat) {
if (beat < 1) {
beat = 1;
} else {
beat = wrapBeat(beat);
}
if (playing.get()) {
metronome.jumpToBeat(beat);
} else {
whereStopped.set(metronome.getSnapshot(metronome.getTimeOfBeat(beat)));
}
} | java | public synchronized void jumpToBeat(int beat) {
if (beat < 1) {
beat = 1;
} else {
beat = wrapBeat(beat);
}
if (playing.get()) {
metronome.jumpToBeat(beat);
} else {
whereStopped.set(metronome.getSnapshot(metronome.getTimeOfBeat(beat)));
}
} | [
"public",
"synchronized",
"void",
"jumpToBeat",
"(",
"int",
"beat",
")",
"{",
"if",
"(",
"beat",
"<",
"1",
")",
"{",
"beat",
"=",
"1",
";",
"}",
"else",
"{",
"beat",
"=",
"wrapBeat",
"(",
"beat",
")",
";",
"}",
"if",
"(",
"playing",
".",
"get",
... | Moves our current playback position to the specified beat; this will be reflected in any status and beat packets
that we are sending. An incoming value less than one will jump us to the first beat.
@param beat the beat that we should pretend to be playing | [
"Moves",
"our",
"current",
"playback",
"position",
"to",
"the",
"specified",
"beat",
";",
"this",
"will",
"be",
"reflected",
"in",
"any",
"status",
"and",
"beat",
"packets",
"that",
"we",
"are",
"sending",
".",
"An",
"incoming",
"value",
"less",
"than",
"o... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1852-L1865 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.getPlaybackState | public Set<PlaybackState> getPlaybackState() {
Set<PlaybackState> result = new HashSet<PlaybackState>(playbackStateMap.values());
return Collections.unmodifiableSet(result);
} | java | public Set<PlaybackState> getPlaybackState() {
Set<PlaybackState> result = new HashSet<PlaybackState>(playbackStateMap.values());
return Collections.unmodifiableSet(result);
} | [
"public",
"Set",
"<",
"PlaybackState",
">",
"getPlaybackState",
"(",
")",
"{",
"Set",
"<",
"PlaybackState",
">",
"result",
"=",
"new",
"HashSet",
"<",
"PlaybackState",
">",
"(",
"playbackStateMap",
".",
"values",
"(",
")",
")",
";",
"return",
"Collections",
... | Look up all recorded playback state information.
@return the playback state recorded for any player
@since 0.5.0 | [
"Look",
"up",
"all",
"recorded",
"playback",
"state",
"information",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L260-L263 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.setPlaybackPosition | private void setPlaybackPosition(long milliseconds) {
PlaybackState oldState = currentSimpleState();
if (oldState != null && oldState.position != milliseconds) {
setPlaybackState(oldState.player, milliseconds, oldState.playing);
}
} | java | private void setPlaybackPosition(long milliseconds) {
PlaybackState oldState = currentSimpleState();
if (oldState != null && oldState.position != milliseconds) {
setPlaybackState(oldState.player, milliseconds, oldState.playing);
}
} | [
"private",
"void",
"setPlaybackPosition",
"(",
"long",
"milliseconds",
")",
"{",
"PlaybackState",
"oldState",
"=",
"currentSimpleState",
"(",
")",
";",
"if",
"(",
"oldState",
"!=",
"null",
"&&",
"oldState",
".",
"position",
"!=",
"milliseconds",
")",
"{",
"set... | Set the current playback position. This method can only be used in situations where the component is
tied to a single player, and therefore always has a single playback position.
Will cause part of the component to be redrawn if the position has
changed. This will be quickly overruled if a player is being monitored, but
can be used in other contexts.
@param milliseconds how far into the track has been played
@see #setPlaybackState | [
"Set",
"the",
"current",
"playback",
"position",
".",
"This",
"method",
"can",
"only",
"be",
"used",
"in",
"situations",
"where",
"the",
"component",
"is",
"tied",
"to",
"a",
"single",
"player",
"and",
"therefore",
"always",
"has",
"a",
"single",
"playback",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L289-L294 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.setPlaying | private void setPlaying(boolean playing) {
PlaybackState oldState = currentSimpleState();
if (oldState != null && oldState.playing != playing) {
setPlaybackState(oldState.player, oldState.position, playing);
}
} | java | private void setPlaying(boolean playing) {
PlaybackState oldState = currentSimpleState();
if (oldState != null && oldState.playing != playing) {
setPlaybackState(oldState.player, oldState.position, playing);
}
} | [
"private",
"void",
"setPlaying",
"(",
"boolean",
"playing",
")",
"{",
"PlaybackState",
"oldState",
"=",
"currentSimpleState",
"(",
")",
";",
"if",
"(",
"oldState",
"!=",
"null",
"&&",
"oldState",
".",
"playing",
"!=",
"playing",
")",
"{",
"setPlaybackState",
... | Set whether the player holding the waveform is playing, which changes the indicator color to white from red.
This method can only be used in situations where the component is tied to a single player, and therefore has
a single playback position.
@param playing if {@code true}, draw the position marker in white, otherwise red
@see #setPlaybackState | [
"Set",
"whether",
"the",
"player",
"holding",
"the",
"waveform",
"is",
"playing",
"which",
"changes",
"the",
"indicator",
"color",
"to",
"white",
"from",
"red",
".",
"This",
"method",
"can",
"only",
"be",
"used",
"in",
"situations",
"where",
"the",
"componen... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L326-L331 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.setMonitoredPlayer | public synchronized void setMonitoredPlayer(final int player) {
if (player < 0) {
throw new IllegalArgumentException("player cannot be negative");
}
clearPlaybackState();
monitoredPlayer.set(player);
if (player > 0) { // Start monitoring the specified player
setPlaybackState(player, 0, false); // Start with default values for required simple state.
VirtualCdj.getInstance().addUpdateListener(updateListener);
MetadataFinder.getInstance().addTrackMetadataListener(metadataListener);
cueList.set(null); // Assume the worst, but see if we have one available next.
if (MetadataFinder.getInstance().isRunning()) {
TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
if (metadata != null) {
cueList.set(metadata.getCueList());
}
}
WaveformFinder.getInstance().addWaveformListener(waveformListener);
if (WaveformFinder.getInstance().isRunning() && WaveformFinder.getInstance().isFindingDetails()) {
waveform.set(WaveformFinder.getInstance().getLatestDetailFor(player));
} else {
waveform.set(null);
}
BeatGridFinder.getInstance().addBeatGridListener(beatGridListener);
if (BeatGridFinder.getInstance().isRunning()) {
beatGrid.set(BeatGridFinder.getInstance().getLatestBeatGridFor(player));
} else {
beatGrid.set(null);
}
try {
TimeFinder.getInstance().start();
if (!animating.getAndSet(true)) {
// Create the thread to update our position smoothly as the track plays
new Thread(new Runnable() {
@Override
public void run() {
while (animating.get()) {
try {
Thread.sleep(33); // Animate at 30 fps
} catch (InterruptedException e) {
logger.warn("Waveform animation thread interrupted; ending");
animating.set(false);
}
setPlaybackPosition(TimeFinder.getInstance().getTimeFor(getMonitoredPlayer()));
}
}
}).start();
}
} catch (Exception e) {
logger.error("Unable to start the TimeFinder to animate the waveform detail view");
animating.set(false);
}
} else { // Stop monitoring any player
animating.set(false);
VirtualCdj.getInstance().removeUpdateListener(updateListener);
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
cueList.set(null);
waveform.set(null);
beatGrid.set(null);
}
if (!autoScroll.get()) {
invalidate();
}
repaint();
} | java | public synchronized void setMonitoredPlayer(final int player) {
if (player < 0) {
throw new IllegalArgumentException("player cannot be negative");
}
clearPlaybackState();
monitoredPlayer.set(player);
if (player > 0) { // Start monitoring the specified player
setPlaybackState(player, 0, false); // Start with default values for required simple state.
VirtualCdj.getInstance().addUpdateListener(updateListener);
MetadataFinder.getInstance().addTrackMetadataListener(metadataListener);
cueList.set(null); // Assume the worst, but see if we have one available next.
if (MetadataFinder.getInstance().isRunning()) {
TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
if (metadata != null) {
cueList.set(metadata.getCueList());
}
}
WaveformFinder.getInstance().addWaveformListener(waveformListener);
if (WaveformFinder.getInstance().isRunning() && WaveformFinder.getInstance().isFindingDetails()) {
waveform.set(WaveformFinder.getInstance().getLatestDetailFor(player));
} else {
waveform.set(null);
}
BeatGridFinder.getInstance().addBeatGridListener(beatGridListener);
if (BeatGridFinder.getInstance().isRunning()) {
beatGrid.set(BeatGridFinder.getInstance().getLatestBeatGridFor(player));
} else {
beatGrid.set(null);
}
try {
TimeFinder.getInstance().start();
if (!animating.getAndSet(true)) {
// Create the thread to update our position smoothly as the track plays
new Thread(new Runnable() {
@Override
public void run() {
while (animating.get()) {
try {
Thread.sleep(33); // Animate at 30 fps
} catch (InterruptedException e) {
logger.warn("Waveform animation thread interrupted; ending");
animating.set(false);
}
setPlaybackPosition(TimeFinder.getInstance().getTimeFor(getMonitoredPlayer()));
}
}
}).start();
}
} catch (Exception e) {
logger.error("Unable to start the TimeFinder to animate the waveform detail view");
animating.set(false);
}
} else { // Stop monitoring any player
animating.set(false);
VirtualCdj.getInstance().removeUpdateListener(updateListener);
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
cueList.set(null);
waveform.set(null);
beatGrid.set(null);
}
if (!autoScroll.get()) {
invalidate();
}
repaint();
} | [
"public",
"synchronized",
"void",
"setMonitoredPlayer",
"(",
"final",
"int",
"player",
")",
"{",
"if",
"(",
"player",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"player cannot be negative\"",
")",
";",
"}",
"clearPlaybackState",
"(",
... | Configures the player whose current track waveforms and status will automatically be reflected. Whenever a new
track is loaded on that player, the waveform and metadata will be updated, and the current playback position and
state of the player will be reflected by the component.
@param player the player number to monitor, or zero if monitoring should stop | [
"Configures",
"the",
"player",
"whose",
"current",
"track",
"waveforms",
"and",
"status",
"will",
"automatically",
"be",
"reflected",
".",
"Whenever",
"a",
"new",
"track",
"is",
"loaded",
"on",
"that",
"player",
"the",
"waveform",
"and",
"metadata",
"will",
"b... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L387-L452 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.getFurthestPlaybackState | public PlaybackState getFurthestPlaybackState() {
PlaybackState result = null;
for (PlaybackState state : playbackStateMap.values()) {
if (result == null || (!result.playing && state.playing) ||
(result.position < state.position) && (state.playing || !result.playing)) {
result = state;
}
}
return result;
} | java | public PlaybackState getFurthestPlaybackState() {
PlaybackState result = null;
for (PlaybackState state : playbackStateMap.values()) {
if (result == null || (!result.playing && state.playing) ||
(result.position < state.position) && (state.playing || !result.playing)) {
result = state;
}
}
return result;
} | [
"public",
"PlaybackState",
"getFurthestPlaybackState",
"(",
")",
"{",
"PlaybackState",
"result",
"=",
"null",
";",
"for",
"(",
"PlaybackState",
"state",
":",
"playbackStateMap",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"result",
"==",
"null",
"||",
"(",... | Look up the playback state that has reached furthest in the track, but give playing players priority over stopped players.
This is used to choose the scroll center when auto-scrolling is active.
@return the playback state, if any, with the highest playing {@link PlaybackState#position} value | [
"Look",
"up",
"the",
"playback",
"state",
"that",
"has",
"reached",
"furthest",
"in",
"the",
"track",
"but",
"give",
"playing",
"players",
"priority",
"over",
"stopped",
"players",
".",
"This",
"is",
"used",
"to",
"choose",
"the",
"scroll",
"center",
"when",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L587-L596 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.getSegmentForX | private int getSegmentForX(int x) {
if (autoScroll.get()) {
int playHead = (x - (getWidth() / 2));
int offset = Util.timeToHalfFrame(getFurthestPlaybackPosition()) / scale.get();
return (playHead + offset) * scale.get();
}
return x * scale.get();
} | java | private int getSegmentForX(int x) {
if (autoScroll.get()) {
int playHead = (x - (getWidth() / 2));
int offset = Util.timeToHalfFrame(getFurthestPlaybackPosition()) / scale.get();
return (playHead + offset) * scale.get();
}
return x * scale.get();
} | [
"private",
"int",
"getSegmentForX",
"(",
"int",
"x",
")",
"{",
"if",
"(",
"autoScroll",
".",
"get",
"(",
")",
")",
"{",
"int",
"playHead",
"=",
"(",
"x",
"-",
"(",
"getWidth",
"(",
")",
"/",
"2",
")",
")",
";",
"int",
"offset",
"=",
"Util",
"."... | Figure out the starting waveform segment that corresponds to the specified coordinate in the window.
@param x the column being drawn
@return the offset into the waveform at the current scale and playback time that should be drawn there | [
"Figure",
"out",
"the",
"starting",
"waveform",
"segment",
"that",
"corresponds",
"to",
"the",
"specified",
"coordinate",
"in",
"the",
"window",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L619-L626 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.getXForBeat | public int getXForBeat(int beat) {
BeatGrid grid = beatGrid.get();
if (grid != null) {
return millisecondsToX(grid.getTimeWithinTrack(beat));
}
return 0;
} | java | public int getXForBeat(int beat) {
BeatGrid grid = beatGrid.get();
if (grid != null) {
return millisecondsToX(grid.getTimeWithinTrack(beat));
}
return 0;
} | [
"public",
"int",
"getXForBeat",
"(",
"int",
"beat",
")",
"{",
"BeatGrid",
"grid",
"=",
"beatGrid",
".",
"get",
"(",
")",
";",
"if",
"(",
"grid",
"!=",
"null",
")",
"{",
"return",
"millisecondsToX",
"(",
"grid",
".",
"getTimeWithinTrack",
"(",
"beat",
"... | Determine the X coordinate within the component at which the specified beat begins.
@param beat the beat number whose position is desired
@return the horizontal position within the component coordinate space where that beat begins
@throws IllegalArgumentException if the beat number exceeds the number of beats in the track. | [
"Determine",
"the",
"X",
"coordinate",
"within",
"the",
"component",
"at",
"which",
"the",
"specified",
"beat",
"begins",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L661-L667 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.millisecondsToX | public int millisecondsToX(long milliseconds) {
if (autoScroll.get()) {
int playHead = (getWidth() / 2) + 2;
long offset = milliseconds - getFurthestPlaybackPosition();
return playHead + (Util.timeToHalfFrame(offset) / scale.get());
}
return Util.timeToHalfFrame(milliseconds) / scale.get();
} | java | public int millisecondsToX(long milliseconds) {
if (autoScroll.get()) {
int playHead = (getWidth() / 2) + 2;
long offset = milliseconds - getFurthestPlaybackPosition();
return playHead + (Util.timeToHalfFrame(offset) / scale.get());
}
return Util.timeToHalfFrame(milliseconds) / scale.get();
} | [
"public",
"int",
"millisecondsToX",
"(",
"long",
"milliseconds",
")",
"{",
"if",
"(",
"autoScroll",
".",
"get",
"(",
")",
")",
"{",
"int",
"playHead",
"=",
"(",
"getWidth",
"(",
")",
"/",
"2",
")",
"+",
"2",
";",
"long",
"offset",
"=",
"milliseconds"... | Converts a time in milliseconds to the appropriate x coordinate for drawing something at that time.
@param milliseconds the time at which something should be drawn
@return the component x coordinate at which it should be drawn | [
"Converts",
"a",
"time",
"in",
"milliseconds",
"to",
"the",
"appropriate",
"x",
"coordinate",
"for",
"drawing",
"something",
"at",
"that",
"time",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L676-L683 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java | WaveformDetailComponent.cueColor | public static Color cueColor(CueList.Entry entry) {
if (entry.hotCueNumber > 0) {
return Color.GREEN;
}
if (entry.isLoop) {
return Color.ORANGE;
}
return Color.RED;
} | java | public static Color cueColor(CueList.Entry entry) {
if (entry.hotCueNumber > 0) {
return Color.GREEN;
}
if (entry.isLoop) {
return Color.ORANGE;
}
return Color.RED;
} | [
"public",
"static",
"Color",
"cueColor",
"(",
"CueList",
".",
"Entry",
"entry",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
">",
"0",
")",
"{",
"return",
"Color",
".",
"GREEN",
";",
"}",
"if",
"(",
"entry",
".",
"isLoop",
")",
"{",
"return",
... | Determine the color to use to draw a cue list entry. Hot cues are green, ordinary memory points are red,
and loops are orange.
@param entry the entry being drawn
@return the color with which it should be represented. | [
"Determine",
"the",
"color",
"to",
"use",
"to",
"draw",
"a",
"cue",
"list",
"entry",
".",
"Hot",
"cues",
"are",
"green",
"ordinary",
"memory",
"points",
"are",
"red",
"and",
"loops",
"are",
"orange",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L698-L706 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceUpdate.java | DeviceUpdate.getPacketBytes | public byte[] getPacketBytes() {
byte[] result = new byte[packetBytes.length];
System.arraycopy(packetBytes, 0, result, 0, packetBytes.length);
return result;
} | java | public byte[] getPacketBytes() {
byte[] result = new byte[packetBytes.length];
System.arraycopy(packetBytes, 0, result, 0, packetBytes.length);
return result;
} | [
"public",
"byte",
"[",
"]",
"getPacketBytes",
"(",
")",
"{",
"byte",
"[",
"]",
"result",
"=",
"new",
"byte",
"[",
"packetBytes",
".",
"length",
"]",
";",
"System",
".",
"arraycopy",
"(",
"packetBytes",
",",
"0",
",",
"result",
",",
"0",
",",
"packetB... | Get the raw data bytes of the device update packet.
@return the data sent by the device to update its status | [
"Get",
"the",
"raw",
"data",
"bytes",
"of",
"the",
"device",
"update",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceUpdate.java#L100-L104 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.buildPacket | public static DatagramPacket buildPacket(PacketType type, ByteBuffer deviceName, ByteBuffer payload) {
ByteBuffer content = ByteBuffer.allocate(0x1f + payload.remaining());
content.put(getMagicHeader());
content.put(type.protocolValue);
content.put(deviceName);
content.put(payload);
return new DatagramPacket(content.array(), content.capacity());
} | java | public static DatagramPacket buildPacket(PacketType type, ByteBuffer deviceName, ByteBuffer payload) {
ByteBuffer content = ByteBuffer.allocate(0x1f + payload.remaining());
content.put(getMagicHeader());
content.put(type.protocolValue);
content.put(deviceName);
content.put(payload);
return new DatagramPacket(content.array(), content.capacity());
} | [
"public",
"static",
"DatagramPacket",
"buildPacket",
"(",
"PacketType",
"type",
",",
"ByteBuffer",
"deviceName",
",",
"ByteBuffer",
"payload",
")",
"{",
"ByteBuffer",
"content",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"0x1f",
"+",
"payload",
".",
"remaining",
"... | Build a standard-format UDP packet for sending to port 50001 or 50002 in the protocol.
@param type the type of packet to create.
@param deviceName the 0x14 (twenty) bytes of the device name to send in the packet.
@param payload the remaining bytes which come after the device name.
@return the packet to send. | [
"Build",
"a",
"standard",
"-",
"format",
"UDP",
"packet",
"for",
"sending",
"to",
"port",
"50001",
"or",
"50002",
"in",
"the",
"protocol",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L176-L183 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.validateHeader | public static PacketType validateHeader(DatagramPacket packet, int port) {
byte[] data = packet.getData();
if (data.length < PACKET_TYPE_OFFSET) {
logger.warn("Packet is too short to be a Pro DJ Link packet; must be at least " + PACKET_TYPE_OFFSET +
" bytes long, was only " + data.length + ".");
return null;
}
if (!getMagicHeader().equals(ByteBuffer.wrap(data, 0, MAGIC_HEADER.length))) {
logger.warn("Packet did not have correct nine-byte header for the Pro DJ Link protocol.");
return null;
}
final Map<Byte, PacketType> portMap = PACKET_TYPE_MAP.get(port);
if (portMap == null) {
logger.warn("Do not know any Pro DJ Link packets that are received on port " + port + ".");
return null;
}
final PacketType result = portMap.get(data[PACKET_TYPE_OFFSET]);
if (result == null) {
logger.warn("Do not know any Pro DJ Link packets received on port " + port + " with type " +
String.format("0x%02x", data[PACKET_TYPE_OFFSET]) + ".");
}
return result;
} | java | public static PacketType validateHeader(DatagramPacket packet, int port) {
byte[] data = packet.getData();
if (data.length < PACKET_TYPE_OFFSET) {
logger.warn("Packet is too short to be a Pro DJ Link packet; must be at least " + PACKET_TYPE_OFFSET +
" bytes long, was only " + data.length + ".");
return null;
}
if (!getMagicHeader().equals(ByteBuffer.wrap(data, 0, MAGIC_HEADER.length))) {
logger.warn("Packet did not have correct nine-byte header for the Pro DJ Link protocol.");
return null;
}
final Map<Byte, PacketType> portMap = PACKET_TYPE_MAP.get(port);
if (portMap == null) {
logger.warn("Do not know any Pro DJ Link packets that are received on port " + port + ".");
return null;
}
final PacketType result = portMap.get(data[PACKET_TYPE_OFFSET]);
if (result == null) {
logger.warn("Do not know any Pro DJ Link packets received on port " + port + " with type " +
String.format("0x%02x", data[PACKET_TYPE_OFFSET]) + ".");
}
return result;
} | [
"public",
"static",
"PacketType",
"validateHeader",
"(",
"DatagramPacket",
"packet",
",",
"int",
"port",
")",
"{",
"byte",
"[",
"]",
"data",
"=",
"packet",
".",
"getData",
"(",
")",
";",
"if",
"(",
"data",
".",
"length",
"<",
"PACKET_TYPE_OFFSET",
")",
"... | Check to see whether a packet starts with the standard header bytes, followed by a known byte identifying it.
If so, return the kind of packet that has been recognized.
@param packet a packet that has just been received
@param port the port on which the packet has been received
@return the type of packet that was recognized, or {@code null} if the packet was not recognized | [
"Check",
"to",
"see",
"whether",
"a",
"packet",
"starts",
"with",
"the",
"standard",
"header",
"bytes",
"followed",
"by",
"a",
"known",
"byte",
"identifying",
"it",
".",
"If",
"so",
"return",
"the",
"kind",
"of",
"packet",
"that",
"has",
"been",
"recognize... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L194-L221 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.bytesToNumber | public static long bytesToNumber(byte[] buffer, int start, int length) {
long result = 0;
for (int index = start; index < start + length; index++) {
result = (result << 8) + unsign(buffer[index]);
}
return result;
} | java | public static long bytesToNumber(byte[] buffer, int start, int length) {
long result = 0;
for (int index = start; index < start + length; index++) {
result = (result << 8) + unsign(buffer[index]);
}
return result;
} | [
"public",
"static",
"long",
"bytesToNumber",
"(",
"byte",
"[",
"]",
"buffer",
",",
"int",
"start",
",",
"int",
"length",
")",
"{",
"long",
"result",
"=",
"0",
";",
"for",
"(",
"int",
"index",
"=",
"start",
";",
"index",
"<",
"start",
"+",
"length",
... | Reconstructs a number that is represented by more than one byte in a network packet in big-endian order.
@param buffer the byte array containing the packet data
@param start the index of the first byte containing a numeric value
@param length the number of bytes making up the value
@return the reconstructed number | [
"Reconstructs",
"a",
"number",
"that",
"is",
"represented",
"by",
"more",
"than",
"one",
"byte",
"in",
"a",
"network",
"packet",
"in",
"big",
"-",
"endian",
"order",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L242-L248 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.bytesToNumberLittleEndian | @SuppressWarnings("SameParameterValue")
public static long bytesToNumberLittleEndian(byte[] buffer, int start, int length) {
long result = 0;
for (int index = start + length - 1; index >= start; index--) {
result = (result << 8) + unsign(buffer[index]);
}
return result;
} | java | @SuppressWarnings("SameParameterValue")
public static long bytesToNumberLittleEndian(byte[] buffer, int start, int length) {
long result = 0;
for (int index = start + length - 1; index >= start; index--) {
result = (result << 8) + unsign(buffer[index]);
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"public",
"static",
"long",
"bytesToNumberLittleEndian",
"(",
"byte",
"[",
"]",
"buffer",
",",
"int",
"start",
",",
"int",
"length",
")",
"{",
"long",
"result",
"=",
"0",
";",
"for",
"(",
"int",
... | Reconstructs a number that is represented by more than one byte in a network packet in little-endian order, for
the very few protocol values that are sent in this quirky way.
@param buffer the byte array containing the packet data
@param start the index of the first byte containing a numeric value
@param length the number of bytes making up the value
@return the reconstructed number | [
"Reconstructs",
"a",
"number",
"that",
"is",
"represented",
"by",
"more",
"than",
"one",
"byte",
"in",
"a",
"network",
"packet",
"in",
"little",
"-",
"endian",
"order",
"for",
"the",
"very",
"few",
"protocol",
"values",
"that",
"are",
"sent",
"in",
"this",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L259-L266 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.numberToBytes | public static void numberToBytes(int number, byte[] buffer, int start, int length) {
for (int index = start + length - 1; index >= start; index--) {
buffer[index] = (byte)(number & 0xff);
number = number >> 8;
}
} | java | public static void numberToBytes(int number, byte[] buffer, int start, int length) {
for (int index = start + length - 1; index >= start; index--) {
buffer[index] = (byte)(number & 0xff);
number = number >> 8;
}
} | [
"public",
"static",
"void",
"numberToBytes",
"(",
"int",
"number",
",",
"byte",
"[",
"]",
"buffer",
",",
"int",
"start",
",",
"int",
"length",
")",
"{",
"for",
"(",
"int",
"index",
"=",
"start",
"+",
"length",
"-",
"1",
";",
"index",
">=",
"start",
... | Writes a number to the specified byte array field, breaking it into its component bytes in big-endian order.
If the number is too large to fit in the specified number of bytes, only the low-order bytes are written.
@param number the number to be written to the array
@param buffer the buffer to which the number should be written
@param start where the high-order byte should be written
@param length how many bytes of the number should be written | [
"Writes",
"a",
"number",
"to",
"the",
"specified",
"byte",
"array",
"field",
"breaking",
"it",
"into",
"its",
"component",
"bytes",
"in",
"big",
"-",
"endian",
"order",
".",
"If",
"the",
"number",
"is",
"too",
"large",
"to",
"fit",
"in",
"the",
"specifie... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L277-L282 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.addressToLong | public static long addressToLong(InetAddress address) {
long result = 0;
for (byte element : address.getAddress()) {
result = (result << 8) + unsign(element);
}
return result;
} | java | public static long addressToLong(InetAddress address) {
long result = 0;
for (byte element : address.getAddress()) {
result = (result << 8) + unsign(element);
}
return result;
} | [
"public",
"static",
"long",
"addressToLong",
"(",
"InetAddress",
"address",
")",
"{",
"long",
"result",
"=",
"0",
";",
"for",
"(",
"byte",
"element",
":",
"address",
".",
"getAddress",
"(",
")",
")",
"{",
"result",
"=",
"(",
"result",
"<<",
"8",
")",
... | Converts the bytes that make up an internet address into the corresponding integer value to make
it easier to perform bit-masking operations on them.
@param address an address whose integer equivalent is desired
@return the integer corresponding to that address | [
"Converts",
"the",
"bytes",
"that",
"make",
"up",
"an",
"internet",
"address",
"into",
"the",
"corresponding",
"integer",
"value",
"to",
"make",
"it",
"easier",
"to",
"perform",
"bit",
"-",
"masking",
"operations",
"on",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L292-L298 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.sameNetwork | public static boolean sameNetwork(int prefixLength, InetAddress address1, InetAddress address2) {
if (logger.isDebugEnabled()) {
logger.debug("Comparing address " + address1.getHostAddress() + " with " + address2.getHostAddress() + ", prefixLength=" + prefixLength);
}
long prefixMask = 0xffffffffL & (-1 << (32 - prefixLength));
return (addressToLong(address1) & prefixMask) == (addressToLong(address2) & prefixMask);
} | java | public static boolean sameNetwork(int prefixLength, InetAddress address1, InetAddress address2) {
if (logger.isDebugEnabled()) {
logger.debug("Comparing address " + address1.getHostAddress() + " with " + address2.getHostAddress() + ", prefixLength=" + prefixLength);
}
long prefixMask = 0xffffffffL & (-1 << (32 - prefixLength));
return (addressToLong(address1) & prefixMask) == (addressToLong(address2) & prefixMask);
} | [
"public",
"static",
"boolean",
"sameNetwork",
"(",
"int",
"prefixLength",
",",
"InetAddress",
"address1",
",",
"InetAddress",
"address2",
")",
"{",
"if",
"(",
"logger",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Comparing addres... | Checks whether two internet addresses are on the same subnet.
@param prefixLength the number of bits within an address that identify the network
@param address1 the first address to be compared
@param address2 the second address to be compared
@return true if both addresses share the same network bits | [
"Checks",
"whether",
"two",
"internet",
"addresses",
"are",
"on",
"the",
"same",
"subnet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L309-L315 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Util.java | Util.writeFully | public static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException {
while (buffer.hasRemaining()) {
channel.write(buffer);
}
} | java | public static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException {
while (buffer.hasRemaining()) {
channel.write(buffer);
}
} | [
"public",
"static",
"void",
"writeFully",
"(",
"ByteBuffer",
"buffer",
",",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"while",
"(",
"buffer",
".",
"hasRemaining",
"(",
")",
")",
"{",
"channel",
".",
"write",
"(",
"buffer",
")",
";"... | Writes the entire remaining contents of the buffer to the channel. May complete in one operation, but the
documentation is vague, so this keeps going until we are sure.
@param buffer the data to be written
@param channel the channel to which we want to write data
@throws IOException if there is a problem writing to the channel | [
"Writes",
"the",
"entire",
"remaining",
"contents",
"of",
"the",
"buffer",
"to",
"the",
"channel",
".",
"May",
"complete",
"in",
"one",
"operation",
"but",
"the",
"documentation",
"is",
"vague",
"so",
"this",
"keeps",
"going",
"until",
"we",
"are",
"sure",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L348-L352 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.getSignatures | public Map<Integer, String> getSignatures() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<Integer, String>(signatures));
} | java | public Map<Integer, String> getSignatures() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<Integer, String>(signatures));
} | [
"public",
"Map",
"<",
"Integer",
",",
"String",
">",
"getSignatures",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",... | Get the signatures that have been computed for all tracks currently loaded in any player for which we have
been able to obtain all necessary metadata.
@return the signatures that uniquely identify the tracks loaded in each player
@throws IllegalStateException if the SignatureFinder is not running | [
"Get",
"the",
"signatures",
"that",
"have",
"been",
"computed",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"for",
"which",
"we",
"have",
"been",
"able",
"to",
"obtain",
"all",
"necessary",
"metadata",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L143-L147 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.checkExistingTracks | private void checkExistingTracks() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Map.Entry<DeckReference, TrackMetadata> entry : MetadataFinder.getInstance().getLoadedTracks().entrySet()) {
if (entry.getKey().hotCue == 0) { // The track is currently loaded in a main player deck
checkIfSignatureReady(entry.getKey().player);
}
}
}
});
} | java | private void checkExistingTracks() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Map.Entry<DeckReference, TrackMetadata> entry : MetadataFinder.getInstance().getLoadedTracks().entrySet()) {
if (entry.getKey().hotCue == 0) { // The track is currently loaded in a main player deck
checkIfSignatureReady(entry.getKey().player);
}
}
}
});
} | [
"private",
"void",
"checkExistingTracks",
"(",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DeckReference",
",",
"Tr... | Send ourselves "updates" about any tracks that were loaded before we started, since we missed them. | [
"Send",
"ourselves",
"updates",
"about",
"any",
"tracks",
"that",
"were",
"loaded",
"before",
"we",
"started",
"since",
"we",
"missed",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L267-L278 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.digestInteger | private void digestInteger(MessageDigest digest, int value) {
byte[] valueBytes = new byte[4];
Util.numberToBytes(value, valueBytes, 0, 4);
digest.update(valueBytes);
} | java | private void digestInteger(MessageDigest digest, int value) {
byte[] valueBytes = new byte[4];
Util.numberToBytes(value, valueBytes, 0, 4);
digest.update(valueBytes);
} | [
"private",
"void",
"digestInteger",
"(",
"MessageDigest",
"digest",
",",
"int",
"value",
")",
"{",
"byte",
"[",
"]",
"valueBytes",
"=",
"new",
"byte",
"[",
"4",
"]",
";",
"Util",
".",
"numberToBytes",
"(",
"value",
",",
"valueBytes",
",",
"0",
",",
"4"... | Helper method to add a Java integer value to a message digest.
@param digest the message digest being built
@param value the integer whose bytes should be included in the digest | [
"Helper",
"method",
"to",
"add",
"a",
"Java",
"integer",
"value",
"to",
"a",
"message",
"digest",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L286-L290 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.computeTrackSignature | public String computeTrackSignature(final String title, final SearchableItem artist, final int duration,
final WaveformDetail waveformDetail, final BeatGrid beatGrid) {
final String safeTitle = (title == null)? "" : title;
final String artistName = (artist == null)? "[no artist]" : artist.label;
try {
// Compute the SHA-1 hash of our fields
MessageDigest digest = MessageDigest.getInstance("SHA1");
digest.update(safeTitle.getBytes("UTF-8"));
digest.update((byte) 0);
digest.update(artistName.getBytes("UTF-8"));
digest.update((byte) 0);
digestInteger(digest, duration);
digest.update(waveformDetail.getData());
for (int i = 1; i <= beatGrid.beatCount; i++) {
digestInteger(digest, beatGrid.getBeatWithinBar(i));
digestInteger(digest, (int)beatGrid.getTimeWithinTrack(i));
}
byte[] result = digest.digest();
// Create a hex string representation of the hash
StringBuilder hex = new StringBuilder(result.length * 2);
for (byte aResult : result) {
hex.append(Integer.toString((aResult & 0xff) + 0x100, 16).substring(1));
}
return hex.toString();
} catch (NullPointerException e) {
logger.info("Returning null track signature because an input element was null.", e);
} catch (NoSuchAlgorithmException e) {
logger.error("Unable to obtain SHA-1 MessageDigest instance for computing track signatures.", e);
} catch (UnsupportedEncodingException e) {
logger.error("Unable to work with UTF-8 string encoding for computing track signatures.", e);
}
return null; // We were unable to compute a signature
} | java | public String computeTrackSignature(final String title, final SearchableItem artist, final int duration,
final WaveformDetail waveformDetail, final BeatGrid beatGrid) {
final String safeTitle = (title == null)? "" : title;
final String artistName = (artist == null)? "[no artist]" : artist.label;
try {
// Compute the SHA-1 hash of our fields
MessageDigest digest = MessageDigest.getInstance("SHA1");
digest.update(safeTitle.getBytes("UTF-8"));
digest.update((byte) 0);
digest.update(artistName.getBytes("UTF-8"));
digest.update((byte) 0);
digestInteger(digest, duration);
digest.update(waveformDetail.getData());
for (int i = 1; i <= beatGrid.beatCount; i++) {
digestInteger(digest, beatGrid.getBeatWithinBar(i));
digestInteger(digest, (int)beatGrid.getTimeWithinTrack(i));
}
byte[] result = digest.digest();
// Create a hex string representation of the hash
StringBuilder hex = new StringBuilder(result.length * 2);
for (byte aResult : result) {
hex.append(Integer.toString((aResult & 0xff) + 0x100, 16).substring(1));
}
return hex.toString();
} catch (NullPointerException e) {
logger.info("Returning null track signature because an input element was null.", e);
} catch (NoSuchAlgorithmException e) {
logger.error("Unable to obtain SHA-1 MessageDigest instance for computing track signatures.", e);
} catch (UnsupportedEncodingException e) {
logger.error("Unable to work with UTF-8 string encoding for computing track signatures.", e);
}
return null; // We were unable to compute a signature
} | [
"public",
"String",
"computeTrackSignature",
"(",
"final",
"String",
"title",
",",
"final",
"SearchableItem",
"artist",
",",
"final",
"int",
"duration",
",",
"final",
"WaveformDetail",
"waveformDetail",
",",
"final",
"BeatGrid",
"beatGrid",
")",
"{",
"final",
"Str... | Calculate the signature by which we can reliably recognize a loaded track.
@param title the track title
@param artist the track artist, or {@code null} if there is no artist
@param duration the duration of the track in seconds
@param waveformDetail the monochrome waveform detail of the track
@param beatGrid the beat grid of the track
@return the SHA-1 hash of all the arguments supplied, or {@code null} if any either {@code waveFormDetail} or {@code beatGrid} were {@code null} | [
"Calculate",
"the",
"signature",
"by",
"which",
"we",
"can",
"reliably",
"recognize",
"a",
"loaded",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L303-L338 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.handleUpdate | private void handleUpdate(final int player) {
final TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
final WaveformDetail waveformDetail = WaveformFinder.getInstance().getLatestDetailFor(player);
final BeatGrid beatGrid = BeatGridFinder.getInstance().getLatestBeatGridFor(player);
if (metadata != null && waveformDetail != null && beatGrid != null) {
final String signature = computeTrackSignature(metadata.getTitle(), metadata.getArtist(),
metadata.getDuration(), waveformDetail, beatGrid);
if (signature != null) {
signatures.put(player, signature);
deliverSignatureUpdate(player, signature);
}
}
} | java | private void handleUpdate(final int player) {
final TrackMetadata metadata = MetadataFinder.getInstance().getLatestMetadataFor(player);
final WaveformDetail waveformDetail = WaveformFinder.getInstance().getLatestDetailFor(player);
final BeatGrid beatGrid = BeatGridFinder.getInstance().getLatestBeatGridFor(player);
if (metadata != null && waveformDetail != null && beatGrid != null) {
final String signature = computeTrackSignature(metadata.getTitle(), metadata.getArtist(),
metadata.getDuration(), waveformDetail, beatGrid);
if (signature != null) {
signatures.put(player, signature);
deliverSignatureUpdate(player, signature);
}
}
} | [
"private",
"void",
"handleUpdate",
"(",
"final",
"int",
"player",
")",
"{",
"final",
"TrackMetadata",
"metadata",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestMetadataFor",
"(",
"player",
")",
";",
"final",
"WaveformDetail",
"waveformDetail"... | We have reason to believe we might have enough information to calculate a signature for the track loaded on a
player. Verify that, and if so, perform the computation and record and report the new signature. | [
"We",
"have",
"reason",
"to",
"believe",
"we",
"might",
"have",
"enough",
"information",
"to",
"calculate",
"a",
"signature",
"for",
"the",
"track",
"loaded",
"on",
"a",
"player",
".",
"Verify",
"that",
"and",
"if",
"so",
"perform",
"the",
"computation",
"... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L344-L356 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java | SignatureFinder.stop | public synchronized void stop () {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
BeatGridFinder.getInstance().removeBeatGridListener(beatGridListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our signatures, on the proper thread, outside our lock
final Set<Integer> dyingSignatures = new HashSet<Integer>(signatures.keySet());
signatures.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Integer player : dyingSignatures) {
deliverSignatureUpdate(player, null);
}
}
});
}
deliverLifecycleAnnouncement(logger, false);
} | java | public synchronized void stop () {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
WaveformFinder.getInstance().removeWaveformListener(waveformListener);
BeatGridFinder.getInstance().removeBeatGridListener(beatGridListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our signatures, on the proper thread, outside our lock
final Set<Integer> dyingSignatures = new HashSet<Integer>(signatures.keySet());
signatures.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (Integer player : dyingSignatures) {
deliverSignatureUpdate(player, null);
}
}
});
}
deliverLifecycleAnnouncement(logger, false);
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"removeTrackMetadataListener",
"(",
"metadataListener",
")",
";",
"WaveformFinder",
".",
"getInstance",
"(... | Stop finding signatures for all active players. | [
"Stop",
"finding",
"signatures",
"for",
"all",
"active",
"players",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SignatureFinder.java#L406-L429 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.expireDevices | private void expireDevices() {
long now = System.currentTimeMillis();
// Make a copy so we don't have to worry about concurrent modification.
Map<InetAddress, DeviceAnnouncement> copy = new HashMap<InetAddress, DeviceAnnouncement>(devices);
for (Map.Entry<InetAddress, DeviceAnnouncement> entry : copy.entrySet()) {
if (now - entry.getValue().getTimestamp() > MAXIMUM_AGE) {
devices.remove(entry.getKey());
deliverLostAnnouncement(entry.getValue());
}
}
if (devices.isEmpty()) {
firstDeviceTime.set(0); // We have lost contact with the Pro DJ Link network, so start over with next device.
}
} | java | private void expireDevices() {
long now = System.currentTimeMillis();
// Make a copy so we don't have to worry about concurrent modification.
Map<InetAddress, DeviceAnnouncement> copy = new HashMap<InetAddress, DeviceAnnouncement>(devices);
for (Map.Entry<InetAddress, DeviceAnnouncement> entry : copy.entrySet()) {
if (now - entry.getValue().getTimestamp() > MAXIMUM_AGE) {
devices.remove(entry.getKey());
deliverLostAnnouncement(entry.getValue());
}
}
if (devices.isEmpty()) {
firstDeviceTime.set(0); // We have lost contact with the Pro DJ Link network, so start over with next device.
}
} | [
"private",
"void",
"expireDevices",
"(",
")",
"{",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"// Make a copy so we don't have to worry about concurrent modification.",
"Map",
"<",
"InetAddress",
",",
"DeviceAnnouncement",
">",
"copy",
"=",
... | Remove any device announcements that are so old that the device seems to have gone away. | [
"Remove",
"any",
"device",
"announcements",
"that",
"are",
"so",
"old",
"that",
"the",
"device",
"seems",
"to",
"have",
"gone",
"away",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L98-L111 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.updateDevices | private void updateDevices(DeviceAnnouncement announcement) {
firstDeviceTime.compareAndSet(0, System.currentTimeMillis());
devices.put(announcement.getAddress(), announcement);
} | java | private void updateDevices(DeviceAnnouncement announcement) {
firstDeviceTime.compareAndSet(0, System.currentTimeMillis());
devices.put(announcement.getAddress(), announcement);
} | [
"private",
"void",
"updateDevices",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"firstDeviceTime",
".",
"compareAndSet",
"(",
"0",
",",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"devices",
".",
"put",
"(",
"announcement",
".",
"getAddress"... | Record a device announcement in the devices map, so we know whe saw it.
@param announcement the announcement to be recorded | [
"Record",
"a",
"device",
"announcement",
"in",
"the",
"devices",
"map",
"so",
"we",
"know",
"whe",
"saw",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L118-L121 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.start | public synchronized void start() throws SocketException {
if (!isRunning()) {
socket.set(new DatagramSocket(ANNOUNCEMENT_PORT));
startTime.set(System.currentTimeMillis());
deliverLifecycleAnnouncement(logger, true);
final byte[] buffer = new byte[512];
final DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
Thread receiver = new Thread(null, new Runnable() {
@Override
public void run() {
boolean received;
while (isRunning()) {
try {
if (getCurrentDevices().isEmpty()) {
socket.get().setSoTimeout(60000); // We have no devices to check for timeout; block for a whole minute to check for shutdown
} else {
socket.get().setSoTimeout(1000); // Check every second to see if a device has vanished
}
socket.get().receive(packet);
received = !ignoredAddresses.contains(packet.getAddress());
} catch (SocketTimeoutException ste) {
received = false;
} catch (IOException e) {
// Don't log a warning if the exception was due to the socket closing at shutdown.
if (isRunning()) {
// We did not expect to have a problem; log a warning and shut down.
logger.warn("Problem reading from DeviceAnnouncement socket, stopping", e);
stop();
}
received = false;
}
try {
if (received && (packet.getLength() == 54)) {
final Util.PacketType kind = Util.validateHeader(packet, ANNOUNCEMENT_PORT);
if (kind == Util.PacketType.DEVICE_KEEP_ALIVE) {
// Looks like the kind of packet we need
if (packet.getLength() < 54) {
logger.warn("Ignoring too-short " + kind.name + " packet; expected 54 bytes, but only got " +
packet.getLength() + ".");
} else {
if (packet.getLength() > 54) {
logger.warn("Processing too-long " + kind.name + " packet; expected 54 bytes, but got " +
packet.getLength() + ".");
}
DeviceAnnouncement announcement = new DeviceAnnouncement(packet);
final boolean foundNewDevice = isDeviceNew(announcement);
updateDevices(announcement);
if (foundNewDevice) {
deliverFoundAnnouncement(announcement);
}
}
}
}
expireDevices();
} catch (Throwable t) {
logger.warn("Problem processing DeviceAnnouncement packet", t);
}
}
}
}, "beat-link DeviceFinder receiver");
receiver.setDaemon(true);
receiver.start();
}
} | java | public synchronized void start() throws SocketException {
if (!isRunning()) {
socket.set(new DatagramSocket(ANNOUNCEMENT_PORT));
startTime.set(System.currentTimeMillis());
deliverLifecycleAnnouncement(logger, true);
final byte[] buffer = new byte[512];
final DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
Thread receiver = new Thread(null, new Runnable() {
@Override
public void run() {
boolean received;
while (isRunning()) {
try {
if (getCurrentDevices().isEmpty()) {
socket.get().setSoTimeout(60000); // We have no devices to check for timeout; block for a whole minute to check for shutdown
} else {
socket.get().setSoTimeout(1000); // Check every second to see if a device has vanished
}
socket.get().receive(packet);
received = !ignoredAddresses.contains(packet.getAddress());
} catch (SocketTimeoutException ste) {
received = false;
} catch (IOException e) {
// Don't log a warning if the exception was due to the socket closing at shutdown.
if (isRunning()) {
// We did not expect to have a problem; log a warning and shut down.
logger.warn("Problem reading from DeviceAnnouncement socket, stopping", e);
stop();
}
received = false;
}
try {
if (received && (packet.getLength() == 54)) {
final Util.PacketType kind = Util.validateHeader(packet, ANNOUNCEMENT_PORT);
if (kind == Util.PacketType.DEVICE_KEEP_ALIVE) {
// Looks like the kind of packet we need
if (packet.getLength() < 54) {
logger.warn("Ignoring too-short " + kind.name + " packet; expected 54 bytes, but only got " +
packet.getLength() + ".");
} else {
if (packet.getLength() > 54) {
logger.warn("Processing too-long " + kind.name + " packet; expected 54 bytes, but got " +
packet.getLength() + ".");
}
DeviceAnnouncement announcement = new DeviceAnnouncement(packet);
final boolean foundNewDevice = isDeviceNew(announcement);
updateDevices(announcement);
if (foundNewDevice) {
deliverFoundAnnouncement(announcement);
}
}
}
}
expireDevices();
} catch (Throwable t) {
logger.warn("Problem processing DeviceAnnouncement packet", t);
}
}
}
}, "beat-link DeviceFinder receiver");
receiver.setDaemon(true);
receiver.start();
}
} | [
"public",
"synchronized",
"void",
"start",
"(",
")",
"throws",
"SocketException",
"{",
"if",
"(",
"!",
"isRunning",
"(",
")",
")",
"{",
"socket",
".",
"set",
"(",
"new",
"DatagramSocket",
"(",
"ANNOUNCEMENT_PORT",
")",
")",
";",
"startTime",
".",
"set",
... | Start listening for device announcements and keeping track of the DJ Link devices visible on the network.
If already listening, has no effect.
@throws SocketException if the socket to listen on port 50000 cannot be created | [
"Start",
"listening",
"for",
"device",
"announcements",
"and",
"keeping",
"track",
"of",
"the",
"DJ",
"Link",
"devices",
"visible",
"on",
"the",
"network",
".",
"If",
"already",
"listening",
"has",
"no",
"effect",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L180-L245 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.stop | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
final Set<DeviceAnnouncement> lastDevices = getCurrentDevices();
socket.get().close();
socket.set(null);
devices.clear();
firstDeviceTime.set(0);
// Report the loss of all our devices, on the proper thread, outside our lock
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeviceAnnouncement announcement : lastDevices) {
deliverLostAnnouncement(announcement);
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | java | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
final Set<DeviceAnnouncement> lastDevices = getCurrentDevices();
socket.get().close();
socket.set(null);
devices.clear();
firstDeviceTime.set(0);
// Report the loss of all our devices, on the proper thread, outside our lock
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeviceAnnouncement announcement : lastDevices) {
deliverLostAnnouncement(announcement);
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"final",
"Set",
"<",
"DeviceAnnouncement",
">",
"lastDevices",
"=",
"getCurrentDevices",
"(",
")",
";"... | Stop listening for device announcements. Also discard any announcements which had been received, and
notify any registered listeners that those devices have been lost. | [
"Stop",
"listening",
"for",
"device",
"announcements",
".",
"Also",
"discard",
"any",
"announcements",
"which",
"had",
"been",
"received",
"and",
"notify",
"any",
"registered",
"listeners",
"that",
"those",
"devices",
"have",
"been",
"lost",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L251-L270 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.deliverFoundAnnouncement | private void deliverFoundAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceFound(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device found announcement to listener", t);
}
}
});
}
} | java | private void deliverFoundAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceFound(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device found announcement to listener", t);
}
}
});
}
} | [
"private",
"void",
"deliverFoundAnnouncement",
"(",
"final",
"DeviceAnnouncement",
"announcement",
")",
"{",
"for",
"(",
"final",
"DeviceAnnouncementListener",
"listener",
":",
"getDeviceAnnouncementListeners",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"... | Send a device found announcement to all registered listeners.
@param announcement the message announcing the new device | [
"Send",
"a",
"device",
"found",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L362-L375 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java | DeviceFinder.deliverLostAnnouncement | private void deliverLostAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceLost(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device lost announcement to listener", t);
}
}
});
}
} | java | private void deliverLostAnnouncement(final DeviceAnnouncement announcement) {
for (final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
listener.deviceLost(announcement);
} catch (Throwable t) {
logger.warn("Problem delivering device lost announcement to listener", t);
}
}
});
}
} | [
"private",
"void",
"deliverLostAnnouncement",
"(",
"final",
"DeviceAnnouncement",
"announcement",
")",
"{",
"for",
"(",
"final",
"DeviceAnnouncementListener",
"listener",
":",
"getDeviceAnnouncementListeners",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(... | Send a device lost announcement to all registered listeners.
@param announcement the last message received from the vanished device | [
"Send",
"a",
"device",
"lost",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/DeviceFinder.java#L382-L395 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.performSetupExchange | private void performSetupExchange() throws IOException {
Message setupRequest = new Message(0xfffffffeL, Message.KnownType.SETUP_REQ, new NumberField(posingAsPlayer, 4));
sendMessage(setupRequest);
Message response = Message.read(is);
if (response.knownType != Message.KnownType.MENU_AVAILABLE) {
throw new IOException("Did not receive message type 0x4000 in response to setup message, got: " + response);
}
if (response.arguments.size() != 2) {
throw new IOException("Did not receive two arguments in response to setup message, got: " + response);
}
final Field player = response.arguments.get(1);
if (!(player instanceof NumberField)) {
throw new IOException("Second argument in response to setup message was not a number: " + response);
}
if (((NumberField)player).getValue() != targetPlayer) {
throw new IOException("Expected to connect to player " + targetPlayer +
", but welcome response identified itself as player " + ((NumberField)player).getValue());
}
} | java | private void performSetupExchange() throws IOException {
Message setupRequest = new Message(0xfffffffeL, Message.KnownType.SETUP_REQ, new NumberField(posingAsPlayer, 4));
sendMessage(setupRequest);
Message response = Message.read(is);
if (response.knownType != Message.KnownType.MENU_AVAILABLE) {
throw new IOException("Did not receive message type 0x4000 in response to setup message, got: " + response);
}
if (response.arguments.size() != 2) {
throw new IOException("Did not receive two arguments in response to setup message, got: " + response);
}
final Field player = response.arguments.get(1);
if (!(player instanceof NumberField)) {
throw new IOException("Second argument in response to setup message was not a number: " + response);
}
if (((NumberField)player).getValue() != targetPlayer) {
throw new IOException("Expected to connect to player " + targetPlayer +
", but welcome response identified itself as player " + ((NumberField)player).getValue());
}
} | [
"private",
"void",
"performSetupExchange",
"(",
")",
"throws",
"IOException",
"{",
"Message",
"setupRequest",
"=",
"new",
"Message",
"(",
"0xfffffffe",
"L",
",",
"Message",
".",
"KnownType",
".",
"SETUP_REQ",
",",
"new",
"NumberField",
"(",
"posingAsPlayer",
","... | Exchanges the initial fully-formed messages which establishes the transaction context for queries to
the dbserver.
@throws IOException if there is a problem during the exchange | [
"Exchanges",
"the",
"initial",
"fully",
"-",
"formed",
"messages",
"which",
"establishes",
"the",
"transaction",
"context",
"for",
"queries",
"to",
"the",
"dbserver",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L117-L135 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.performTeardownExchange | private void performTeardownExchange() throws IOException {
Message teardownRequest = new Message(0xfffffffeL, Message.KnownType.TEARDOWN_REQ);
sendMessage(teardownRequest);
// At this point, the server closes the connection from its end, so we can’t read any more.
} | java | private void performTeardownExchange() throws IOException {
Message teardownRequest = new Message(0xfffffffeL, Message.KnownType.TEARDOWN_REQ);
sendMessage(teardownRequest);
// At this point, the server closes the connection from its end, so we can’t read any more.
} | [
"private",
"void",
"performTeardownExchange",
"(",
")",
"throws",
"IOException",
"{",
"Message",
"teardownRequest",
"=",
"new",
"Message",
"(",
"0xfffffffe",
"L",
",",
"Message",
".",
"KnownType",
".",
"TEARDOWN_REQ",
")",
";",
"sendMessage",
"(",
"teardownRequest... | Exchanges the final messages which politely report our intention to disconnect from the dbserver. | [
"Exchanges",
"the",
"final",
"messages",
"which",
"politely",
"report",
"our",
"intention",
"to",
"disconnect",
"from",
"the",
"dbserver",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L140-L144 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.close | void close() {
try {
performTeardownExchange();
} catch (IOException e) {
logger.warn("Problem reporting our intention to close the dbserver connection", e);
}
try {
channel.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output channel", e);
}
try {
os.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output stream", e);
}
try {
is.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client input stream", e);
}
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client socket", e);
}
} | java | void close() {
try {
performTeardownExchange();
} catch (IOException e) {
logger.warn("Problem reporting our intention to close the dbserver connection", e);
}
try {
channel.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output channel", e);
}
try {
os.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client output stream", e);
}
try {
is.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client input stream", e);
}
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing dbserver client socket", e);
}
} | [
"void",
"close",
"(",
")",
"{",
"try",
"{",
"performTeardownExchange",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem reporting our intention to close the dbserver connection\"",
",",
"e",
")",
";",
"}",
... | Closes the connection to the dbserver. This instance can no longer be used after this action. | [
"Closes",
"the",
"connection",
"to",
"the",
"dbserver",
".",
"This",
"instance",
"can",
"no",
"longer",
"be",
"used",
"after",
"this",
"action",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L160-L186 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.sendField | @SuppressWarnings("SameParameterValue")
private void sendField(Field field) throws IOException {
if (isConnected()) {
try {
field.write(channel);
} catch (IOException e) {
logger.warn("Problem trying to write field to dbserver, closing connection", e);
close();
throw e;
}
return;
}
throw new IOException("sendField() called after dbserver connection was closed");
} | java | @SuppressWarnings("SameParameterValue")
private void sendField(Field field) throws IOException {
if (isConnected()) {
try {
field.write(channel);
} catch (IOException e) {
logger.warn("Problem trying to write field to dbserver, closing connection", e);
close();
throw e;
}
return;
}
throw new IOException("sendField() called after dbserver connection was closed");
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"void",
"sendField",
"(",
"Field",
"field",
")",
"throws",
"IOException",
"{",
"if",
"(",
"isConnected",
"(",
")",
")",
"{",
"try",
"{",
"field",
".",
"write",
"(",
"channel",
")",
";"... | Attempt to send the specified field to the dbserver.
This low-level function is available only to the package itself for use in setting up the connection. It was
previously also used for sending parts of larger-scale messages, but because that sometimes led to them being
fragmented into multiple network packets, and Windows rekordbox cannot handle that, full message sending no
longer uses this method.
@param field the field to be sent
@throws IOException if the field cannot be sent | [
"Attempt",
"to",
"send",
"the",
"specified",
"field",
"to",
"the",
"dbserver",
".",
"This",
"low",
"-",
"level",
"function",
"is",
"available",
"only",
"to",
"the",
"package",
"itself",
"for",
"use",
"in",
"setting",
"up",
"the",
"connection",
".",
"It",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L199-L212 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.sendMessage | private void sendMessage(Message message) throws IOException {
logger.debug("Sending> {}", message);
int totalSize = 0;
for (Field field : message.fields) {
totalSize += field.getBytes().remaining();
}
ByteBuffer combined = ByteBuffer.allocate(totalSize);
for (Field field : message.fields) {
logger.debug("..sending> {}", field);
combined.put(field.getBytes());
}
combined.flip();
Util.writeFully(combined, channel);
} | java | private void sendMessage(Message message) throws IOException {
logger.debug("Sending> {}", message);
int totalSize = 0;
for (Field field : message.fields) {
totalSize += field.getBytes().remaining();
}
ByteBuffer combined = ByteBuffer.allocate(totalSize);
for (Field field : message.fields) {
logger.debug("..sending> {}", field);
combined.put(field.getBytes());
}
combined.flip();
Util.writeFully(combined, channel);
} | [
"private",
"void",
"sendMessage",
"(",
"Message",
"message",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Sending> {}\"",
",",
"message",
")",
";",
"int",
"totalSize",
"=",
"0",
";",
"for",
"(",
"Field",
"field",
":",
"message",
".",
... | Sends a message to the dbserver, first assembling it into a single byte buffer so that it can be sent as
a single packet.
@param message the message to be sent
@throws IOException if there is a problem sending it | [
"Sends",
"a",
"message",
"to",
"the",
"dbserver",
"first",
"assembling",
"it",
"into",
"a",
"single",
"byte",
"buffer",
"so",
"that",
"it",
"can",
"be",
"sent",
"as",
"a",
"single",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L231-L244 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.simpleRequest | public synchronized Message simpleRequest(Message.KnownType requestType, Message.KnownType responseType,
Field... arguments)
throws IOException {
final NumberField transaction = assignTransactionNumber();
final Message request = new Message(transaction, new NumberField(requestType.protocolValue, 2), arguments);
sendMessage(request);
final Message response = Message.read(is);
if (response.transaction.getValue() != transaction.getValue()) {
throw new IOException("Received response with wrong transaction ID. Expected: " + transaction.getValue() +
", got: " + response);
}
if (responseType != null && response.knownType != responseType) {
throw new IOException("Received response with wrong type. Expected: " + responseType +
", got: " + response);
}
return response;
} | java | public synchronized Message simpleRequest(Message.KnownType requestType, Message.KnownType responseType,
Field... arguments)
throws IOException {
final NumberField transaction = assignTransactionNumber();
final Message request = new Message(transaction, new NumberField(requestType.protocolValue, 2), arguments);
sendMessage(request);
final Message response = Message.read(is);
if (response.transaction.getValue() != transaction.getValue()) {
throw new IOException("Received response with wrong transaction ID. Expected: " + transaction.getValue() +
", got: " + response);
}
if (responseType != null && response.knownType != responseType) {
throw new IOException("Received response with wrong type. Expected: " + responseType +
", got: " + response);
}
return response;
} | [
"public",
"synchronized",
"Message",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
"requestType",
",",
"Message",
".",
"KnownType",
"responseType",
",",
"Field",
"...",
"arguments",
")",
"throws",
"IOException",
"{",
"final",
"NumberField",
"transaction",
"=",
... | Send a request that expects a single message as its response, then read and return that response.
@param requestType identifies what kind of request to send
@param responseType identifies the type of response we expect, or {@code null} if we’ll accept anything
@param arguments The argument fields to send in the request
@return the response from the player
@throws IOException if there is a communication problem, or if the response does not have the same transaction
ID as the request. | [
"Send",
"a",
"request",
"that",
"expects",
"a",
"single",
"message",
"as",
"its",
"response",
"then",
"read",
"and",
"return",
"that",
"response",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L345-L361 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java | Client.menuRequestTyped | public synchronized Message menuRequestTyped(Message.KnownType requestType, Message.MenuIdentifier targetMenu,
CdjStatus.TrackSourceSlot slot, CdjStatus.TrackType trackType, Field... arguments)
throws IOException {
if (!menuLock.isHeldByCurrentThread()) {
throw new IllegalStateException("renderMenuItems() cannot be called without first successfully calling tryLockingForMenuOperation()");
}
Field[] combinedArguments = new Field[arguments.length + 1];
combinedArguments[0] = buildRMST(targetMenu, slot, trackType);
System.arraycopy(arguments, 0, combinedArguments, 1, arguments.length);
final Message response = simpleRequest(requestType, Message.KnownType.MENU_AVAILABLE, combinedArguments);
final NumberField reportedRequestType = (NumberField)response.arguments.get(0);
if (reportedRequestType.getValue() != requestType.protocolValue) {
throw new IOException("Menu request did not return result for same type as request; sent type: " +
requestType.protocolValue + ", received type: " + reportedRequestType.getValue() +
", response: " + response);
}
return response;
} | java | public synchronized Message menuRequestTyped(Message.KnownType requestType, Message.MenuIdentifier targetMenu,
CdjStatus.TrackSourceSlot slot, CdjStatus.TrackType trackType, Field... arguments)
throws IOException {
if (!menuLock.isHeldByCurrentThread()) {
throw new IllegalStateException("renderMenuItems() cannot be called without first successfully calling tryLockingForMenuOperation()");
}
Field[] combinedArguments = new Field[arguments.length + 1];
combinedArguments[0] = buildRMST(targetMenu, slot, trackType);
System.arraycopy(arguments, 0, combinedArguments, 1, arguments.length);
final Message response = simpleRequest(requestType, Message.KnownType.MENU_AVAILABLE, combinedArguments);
final NumberField reportedRequestType = (NumberField)response.arguments.get(0);
if (reportedRequestType.getValue() != requestType.protocolValue) {
throw new IOException("Menu request did not return result for same type as request; sent type: " +
requestType.protocolValue + ", received type: " + reportedRequestType.getValue() +
", response: " + response);
}
return response;
} | [
"public",
"synchronized",
"Message",
"menuRequestTyped",
"(",
"Message",
".",
"KnownType",
"requestType",
",",
"Message",
".",
"MenuIdentifier",
"targetMenu",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"Fi... | Send a request for a menu that we will retrieve items from in subsequent requests, when the request must reflect
the actual type of track being asked about.
@param requestType identifies what kind of menu request to send
@param targetMenu the destination for the response to this query
@param slot the media library of interest for this query
@param trackType the type of track for which metadata is being requested, since this affects the request format
@param arguments the additional arguments needed, if any, to complete the request
@return the {@link Message.KnownType#MENU_AVAILABLE} response reporting how many items are available in the menu
@throws IOException if there is a problem communicating, or if the requested menu is not available
@throws IllegalStateException if {@link #tryLockingForMenuOperations(long, TimeUnit)} was not called successfully
before attempting this call | [
"Send",
"a",
"request",
"for",
"a",
"menu",
"that",
"we",
"will",
"retrieve",
"items",
"from",
"in",
"subsequent",
"requests",
"when",
"the",
"request",
"must",
"reflect",
"the",
"actual",
"type",
"of",
"track",
"being",
"asked",
"about",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Client.java#L403-L422 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java | SlotReference.getSlotReference | @SuppressWarnings("WeakerAccess")
public static synchronized SlotReference getSlotReference(int player, CdjStatus.TrackSourceSlot slot) {
Map<CdjStatus.TrackSourceSlot, SlotReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<CdjStatus.TrackSourceSlot, SlotReference>();
instances.put(player, playerMap);
}
SlotReference result = playerMap.get(slot);
if (result == null) {
result = new SlotReference(player, slot);
playerMap.put(slot, result);
}
return result;
} | java | @SuppressWarnings("WeakerAccess")
public static synchronized SlotReference getSlotReference(int player, CdjStatus.TrackSourceSlot slot) {
Map<CdjStatus.TrackSourceSlot, SlotReference> playerMap = instances.get(player);
if (playerMap == null) {
playerMap = new HashMap<CdjStatus.TrackSourceSlot, SlotReference>();
instances.put(player, playerMap);
}
SlotReference result = playerMap.get(slot);
if (result == null) {
result = new SlotReference(player, slot);
playerMap.put(slot, result);
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"static",
"synchronized",
"SlotReference",
"getSlotReference",
"(",
"int",
"player",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
")",
"{",
"Map",
"<",
"CdjStatus",
".",
"TrackSourceSlot",
",",
... | Get a unique reference to a media slot on the network from which tracks can be loaded.
@param player the player in which the slot is found
@param slot the specific type of the slot
@return the instance that will always represent the specified slot
@throws NullPointerException if {@code slot} is {@code null} | [
"Get",
"a",
"unique",
"reference",
"to",
"a",
"media",
"slot",
"on",
"the",
"network",
"from",
"which",
"tracks",
"can",
"be",
"loaded",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java#L56-L69 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java | SlotReference.getSlotReference | @SuppressWarnings("WeakerAccess")
public static SlotReference getSlotReference(DataReference dataReference) {
return getSlotReference(dataReference.player, dataReference.slot);
} | java | @SuppressWarnings("WeakerAccess")
public static SlotReference getSlotReference(DataReference dataReference) {
return getSlotReference(dataReference.player, dataReference.slot);
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"static",
"SlotReference",
"getSlotReference",
"(",
"DataReference",
"dataReference",
")",
"{",
"return",
"getSlotReference",
"(",
"dataReference",
".",
"player",
",",
"dataReference",
".",
"slot",
")",
... | Get a unique reference to the media slot on the network from which the specified data was loaded.
@param dataReference the data whose media slot is of interest
@return the instance that will always represent the slot associated with the specified data | [
"Get",
"a",
"unique",
"reference",
"to",
"the",
"media",
"slot",
"on",
"the",
"network",
"from",
"which",
"the",
"specified",
"data",
"was",
"loaded",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/SlotReference.java#L78-L81 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/Beat.java | Beat.isTempoMaster | @Override
public boolean isTempoMaster() {
DeviceUpdate master = VirtualCdj.getInstance().getTempoMaster();
return (master != null) && master.getAddress().equals(address);
} | java | @Override
public boolean isTempoMaster() {
DeviceUpdate master = VirtualCdj.getInstance().getTempoMaster();
return (master != null) && master.getAddress().equals(address);
} | [
"@",
"Override",
"public",
"boolean",
"isTempoMaster",
"(",
")",
"{",
"DeviceUpdate",
"master",
"=",
"VirtualCdj",
".",
"getInstance",
"(",
")",
".",
"getTempoMaster",
"(",
")",
";",
"return",
"(",
"master",
"!=",
"null",
")",
"&&",
"master",
".",
"getAddr... | Was this beat sent by the current tempo master?
@return {@code true} if the device that sent this beat is the master
@throws IllegalStateException if the {@link VirtualCdj} is not running | [
"Was",
"this",
"beat",
"sent",
"by",
"the",
"current",
"tempo",
"master?"
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Beat.java#L106-L110 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/LifecycleParticipant.java | LifecycleParticipant.deliverLifecycleAnnouncement | protected void deliverLifecycleAnnouncement(final Logger logger, final boolean starting) {
new Thread(new Runnable() {
@Override
public void run() {
for (final LifecycleListener listener : getLifecycleListeners()) {
try {
if (starting) {
listener.started(LifecycleParticipant.this);
} else {
listener.stopped(LifecycleParticipant.this);
}
} catch (Throwable t) {
logger.warn("Problem delivering lifecycle announcement to listener", t);
}
}
}
}, "Lifecycle announcement delivery").start();
} | java | protected void deliverLifecycleAnnouncement(final Logger logger, final boolean starting) {
new Thread(new Runnable() {
@Override
public void run() {
for (final LifecycleListener listener : getLifecycleListeners()) {
try {
if (starting) {
listener.started(LifecycleParticipant.this);
} else {
listener.stopped(LifecycleParticipant.this);
}
} catch (Throwable t) {
logger.warn("Problem delivering lifecycle announcement to listener", t);
}
}
}
}, "Lifecycle announcement delivery").start();
} | [
"protected",
"void",
"deliverLifecycleAnnouncement",
"(",
"final",
"Logger",
"logger",
",",
"final",
"boolean",
"starting",
")",
"{",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(... | Send a lifecycle announcement to all registered listeners.
@param logger the logger to use, so the log entry shows as belonging to the proper subclass.
@param starting will be {@code true} if the DeviceFinder is starting, {@code false} if it is stopping. | [
"Send",
"a",
"lifecycle",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/LifecycleParticipant.java#L69-L86 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java | CrateDigger.mountPath | private String mountPath(CdjStatus.TrackSourceSlot slot) {
switch (slot) {
case SD_SLOT: return "/B/";
case USB_SLOT: return "/C/";
}
throw new IllegalArgumentException("Don't know how to NFS mount filesystem for slot " + slot);
} | java | private String mountPath(CdjStatus.TrackSourceSlot slot) {
switch (slot) {
case SD_SLOT: return "/B/";
case USB_SLOT: return "/C/";
}
throw new IllegalArgumentException("Don't know how to NFS mount filesystem for slot " + slot);
} | [
"private",
"String",
"mountPath",
"(",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
")",
"{",
"switch",
"(",
"slot",
")",
"{",
"case",
"SD_SLOT",
":",
"return",
"\"/B/\"",
";",
"case",
"USB_SLOT",
":",
"return",
"\"/C/\"",
";",
"}",
"throw",
"new",
"Illega... | Return the filesystem path needed to mount the NFS filesystem associated with a particular media slot.
@param slot the slot whose filesystem is desired
@return the path to use in the NFS mount request to access the files mounted in that slot
@throws IllegalArgumentException if it is a slot that we don't know how to handle | [
"Return",
"the",
"filesystem",
"path",
"needed",
"to",
"mount",
"the",
"NFS",
"filesystem",
"associated",
"with",
"a",
"particular",
"media",
"slot",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java#L189-L195 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java | CrateDigger.deliverDatabaseUpdate | private void deliverDatabaseUpdate(SlotReference slot, Database database, boolean available) {
for (final DatabaseListener listener : getDatabaseListeners()) {
try {
if (available) {
listener.databaseMounted(slot, database);
} else {
listener.databaseUnmounted(slot, database);
}
} catch (Throwable t) {
logger.warn("Problem delivering rekordbox database availability update to listener", t);
}
}
} | java | private void deliverDatabaseUpdate(SlotReference slot, Database database, boolean available) {
for (final DatabaseListener listener : getDatabaseListeners()) {
try {
if (available) {
listener.databaseMounted(slot, database);
} else {
listener.databaseUnmounted(slot, database);
}
} catch (Throwable t) {
logger.warn("Problem delivering rekordbox database availability update to listener", t);
}
}
} | [
"private",
"void",
"deliverDatabaseUpdate",
"(",
"SlotReference",
"slot",
",",
"Database",
"database",
",",
"boolean",
"available",
")",
"{",
"for",
"(",
"final",
"DatabaseListener",
"listener",
":",
"getDatabaseListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
... | Send a database announcement to all registered listeners.
@param slot the media slot whose database availability has changed
@param database the database whose relevance has changed
@param available if {@code} true, the database is newly available, otherwise it is no longer relevant | [
"Send",
"a",
"database",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CrateDigger.java#L726-L738 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java | WaveformPreviewComponent.delegatingRepaint | @SuppressWarnings("SameParameterValue")
private void delegatingRepaint(int x, int y, int width, int height) {
final RepaintDelegate delegate = repaintDelegate.get();
if (delegate != null) {
//logger.info("Delegating repaint: " + x + ", " + y + ", " + width + ", " + height);
delegate.repaint(x, y, width, height);
} else {
//logger.info("Normal repaint: " + x + ", " + y + ", " + width + ", " + height);
repaint(x, y, width, height);
}
} | java | @SuppressWarnings("SameParameterValue")
private void delegatingRepaint(int x, int y, int width, int height) {
final RepaintDelegate delegate = repaintDelegate.get();
if (delegate != null) {
//logger.info("Delegating repaint: " + x + ", " + y + ", " + width + ", " + height);
delegate.repaint(x, y, width, height);
} else {
//logger.info("Normal repaint: " + x + ", " + y + ", " + width + ", " + height);
repaint(x, y, width, height);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"void",
"delegatingRepaint",
"(",
"int",
"x",
",",
"int",
"y",
",",
"int",
"width",
",",
"int",
"height",
")",
"{",
"final",
"RepaintDelegate",
"delegate",
"=",
"repaintDelegate",
".",
"ge... | Determine whether we should use the normal repaint process, or delegate that to another component that is
hosting us in a soft-loaded manner to save memory.
@param x the left edge of the region that we want to have redrawn
@param y the top edge of the region that we want to have redrawn
@param width the width of the region that we want to have redrawn
@param height the height of the region that we want to have redrawn | [
"Determine",
"whether",
"we",
"should",
"use",
"the",
"normal",
"repaint",
"process",
"or",
"delegate",
"that",
"to",
"another",
"component",
"that",
"is",
"hosting",
"us",
"in",
"a",
"soft",
"-",
"loaded",
"manner",
"to",
"save",
"memory",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java#L225-L235 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java | WaveformPreviewComponent.updateWaveform | private void updateWaveform(WaveformPreview preview) {
this.preview.set(preview);
if (preview == null) {
waveformImage.set(null);
} else {
BufferedImage image = new BufferedImage(preview.segmentCount, preview.maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, preview.segmentCount, preview.maxHeight);
for (int segment = 0; segment < preview.segmentCount; segment++) {
g.setColor(preview.segmentColor(segment, false));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, false));
if (preview.isColor) { // We have a front color segment to draw on top.
g.setColor(preview.segmentColor(segment, true));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, true));
}
}
waveformImage.set(image);
}
} | java | private void updateWaveform(WaveformPreview preview) {
this.preview.set(preview);
if (preview == null) {
waveformImage.set(null);
} else {
BufferedImage image = new BufferedImage(preview.segmentCount, preview.maxHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, preview.segmentCount, preview.maxHeight);
for (int segment = 0; segment < preview.segmentCount; segment++) {
g.setColor(preview.segmentColor(segment, false));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, false));
if (preview.isColor) { // We have a front color segment to draw on top.
g.setColor(preview.segmentColor(segment, true));
g.drawLine(segment, preview.maxHeight, segment, preview.maxHeight - preview.segmentHeight(segment, true));
}
}
waveformImage.set(image);
}
} | [
"private",
"void",
"updateWaveform",
"(",
"WaveformPreview",
"preview",
")",
"{",
"this",
".",
"preview",
".",
"set",
"(",
"preview",
")",
";",
"if",
"(",
"preview",
"==",
"null",
")",
"{",
"waveformImage",
".",
"set",
"(",
"null",
")",
";",
"}",
"else... | Create an image of the proper size to hold a new waveform preview image and draw it. | [
"Create",
"an",
"image",
"of",
"the",
"proper",
"size",
"to",
"hold",
"a",
"new",
"waveform",
"preview",
"image",
"and",
"draw",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreviewComponent.java#L420-L439 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.getMaxHeight | private int getMaxHeight() {
int result = 0;
for (int i = 0; i < segmentCount; i++) {
result = Math.max(result, segmentHeight(i, false));
}
return result;
} | java | private int getMaxHeight() {
int result = 0;
for (int i = 0; i < segmentCount; i++) {
result = Math.max(result, segmentHeight(i, false));
}
return result;
} | [
"private",
"int",
"getMaxHeight",
"(",
")",
"{",
"int",
"result",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"segmentCount",
";",
"i",
"++",
")",
"{",
"result",
"=",
"Math",
".",
"max",
"(",
"result",
",",
"segmentHeight",
"(... | Scan the segments to find the largest height value present.
@return the largest waveform height anywhere in the preview. | [
"Scan",
"the",
"segments",
"to",
"find",
"the",
"largest",
"height",
"value",
"present",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L110-L116 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.segmentHeight | @SuppressWarnings("WeakerAccess")
public int segmentHeight(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int frontHeight = Util.unsign(bytes.get(base + 5));
if (front) {
return frontHeight;
} else {
return Math.max(frontHeight, Math.max(Util.unsign(bytes.get(base + 3)), Util.unsign(bytes.get(base + 4))));
}
} else {
return getData().get(segment * 2) & 0x1f;
}
} | java | @SuppressWarnings("WeakerAccess")
public int segmentHeight(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int frontHeight = Util.unsign(bytes.get(base + 5));
if (front) {
return frontHeight;
} else {
return Math.max(frontHeight, Math.max(Util.unsign(bytes.get(base + 3)), Util.unsign(bytes.get(base + 4))));
}
} else {
return getData().get(segment * 2) & 0x1f;
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"int",
"segmentHeight",
"(",
"final",
"int",
"segment",
",",
"final",
"boolean",
"front",
")",
"{",
"final",
"ByteBuffer",
"bytes",
"=",
"getData",
"(",
")",
";",
"if",
"(",
"isColor",
")",
"... | Determine the height of the preview given an index into it.
@param segment the index of the waveform preview segment to examine
@param front if {@code true} the height of the front (brighter) segment of a color waveform preview is returned,
otherwise the height of the back (dimmer) segment is returned. Has no effect for blue previews.
@return a value from 0 to 31 representing the height of the waveform at that segment, which may be an average
of a number of values starting there, determined by the scale | [
"Determine",
"the",
"height",
"of",
"the",
"preview",
"given",
"an",
"index",
"into",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L218-L232 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java | WaveformPreview.segmentColor | @SuppressWarnings("WeakerAccess")
public Color segmentColor(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int backHeight = segmentHeight(segment, false);
if (backHeight == 0) {
return Color.BLACK;
}
final int maxLevel = front? 255 : 191;
final int red = Util.unsign(bytes.get(base + 3)) * maxLevel / backHeight;
final int green = Util.unsign(bytes.get(base + 4)) * maxLevel / backHeight;
final int blue = Util.unsign(bytes.get(base + 5)) * maxLevel / backHeight;
return new Color(red, green, blue);
} else {
final int intensity = getData().get(segment * 2 + 1) & 0x07;
return (intensity >= 5) ? INTENSE_COLOR : NORMAL_COLOR;
}
} | java | @SuppressWarnings("WeakerAccess")
public Color segmentColor(final int segment, final boolean front) {
final ByteBuffer bytes = getData();
if (isColor) {
final int base = segment * 6;
final int backHeight = segmentHeight(segment, false);
if (backHeight == 0) {
return Color.BLACK;
}
final int maxLevel = front? 255 : 191;
final int red = Util.unsign(bytes.get(base + 3)) * maxLevel / backHeight;
final int green = Util.unsign(bytes.get(base + 4)) * maxLevel / backHeight;
final int blue = Util.unsign(bytes.get(base + 5)) * maxLevel / backHeight;
return new Color(red, green, blue);
} else {
final int intensity = getData().get(segment * 2 + 1) & 0x07;
return (intensity >= 5) ? INTENSE_COLOR : NORMAL_COLOR;
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"Color",
"segmentColor",
"(",
"final",
"int",
"segment",
",",
"final",
"boolean",
"front",
")",
"{",
"final",
"ByteBuffer",
"bytes",
"=",
"getData",
"(",
")",
";",
"if",
"(",
"isColor",
")",
... | Determine the color of the waveform given an index into it.
@param segment the index of the first waveform byte to examine
@param front if {@code true} the front (brighter) segment of a color waveform preview is returned,
otherwise the back (dimmer) segment is returned. Has no effect for blue previews.
@return the color of the waveform at that segment, which may be based on an average
of a number of values starting there, determined by the scale | [
"Determine",
"the",
"color",
"of",
"the",
"waveform",
"given",
"an",
"index",
"into",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformPreview.java#L244-L262 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/MediaDetails.java | MediaDetails.hasChanged | public boolean hasChanged(MediaDetails originalMedia) {
if (!hashKey().equals(originalMedia.hashKey())) {
throw new IllegalArgumentException("Can't compare media details with different hashKey values");
}
return playlistCount != originalMedia.playlistCount || trackCount != originalMedia.trackCount;
} | java | public boolean hasChanged(MediaDetails originalMedia) {
if (!hashKey().equals(originalMedia.hashKey())) {
throw new IllegalArgumentException("Can't compare media details with different hashKey values");
}
return playlistCount != originalMedia.playlistCount || trackCount != originalMedia.trackCount;
} | [
"public",
"boolean",
"hasChanged",
"(",
"MediaDetails",
"originalMedia",
")",
"{",
"if",
"(",
"!",
"hashKey",
"(",
")",
".",
"equals",
"(",
"originalMedia",
".",
"hashKey",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Can't co... | Check whether the media seems to have changed since a saved version of it was used. We ignore changes in
free space because those probably just reflect history entries being added.
@param originalMedia the media details when information about it was saved
@return true if there have been detectable significant changes to the media since it was saved
@throws IllegalArgumentException if the {@link #hashKey()} values of the media detail objects differ | [
"Check",
"whether",
"the",
"media",
"seems",
"to",
"have",
"changed",
"since",
"a",
"saved",
"version",
"of",
"it",
"was",
"used",
".",
"We",
"ignore",
"changes",
"in",
"free",
"space",
"because",
"those",
"probably",
"just",
"reflect",
"history",
"entries",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/MediaDetails.java#L183-L188 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/BinaryField.java | BinaryField.getValueAsArray | public byte[] getValueAsArray() {
ByteBuffer buffer = getValue();
byte[] result = new byte[buffer.remaining()];
buffer.get(result);
return result;
} | java | public byte[] getValueAsArray() {
ByteBuffer buffer = getValue();
byte[] result = new byte[buffer.remaining()];
buffer.get(result);
return result;
} | [
"public",
"byte",
"[",
"]",
"getValueAsArray",
"(",
")",
"{",
"ByteBuffer",
"buffer",
"=",
"getValue",
"(",
")",
";",
"byte",
"[",
"]",
"result",
"=",
"new",
"byte",
"[",
"buffer",
".",
"remaining",
"(",
")",
"]",
";",
"buffer",
".",
"get",
"(",
"r... | Get the bytes which represent the payload of this field, without the leading type tag and length header, as
a newly-allocated byte array.
@return a new byte array containing a copy of the bytes this field contains | [
"Get",
"the",
"bytes",
"which",
"represent",
"the",
"payload",
"of",
"this",
"field",
"without",
"the",
"leading",
"type",
"tag",
"and",
"length",
"header",
"as",
"a",
"newly",
"-",
"allocated",
"byte",
"array",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/BinaryField.java#L69-L74 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.getHotCueCount | public int getHotCueCount() {
if (rawMessage != null) {
return (int) ((NumberField) rawMessage.arguments.get(5)).getValue();
}
int total = 0;
for (Entry entry : entries) {
if (entry.hotCueNumber > 0) {
++total;
}
}
return total;
} | java | public int getHotCueCount() {
if (rawMessage != null) {
return (int) ((NumberField) rawMessage.arguments.get(5)).getValue();
}
int total = 0;
for (Entry entry : entries) {
if (entry.hotCueNumber > 0) {
++total;
}
}
return total;
} | [
"public",
"int",
"getHotCueCount",
"(",
")",
"{",
"if",
"(",
"rawMessage",
"!=",
"null",
")",
"{",
"return",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"rawMessage",
".",
"arguments",
".",
"get",
"(",
"5",
")",
")",
".",
"getValue",
"(",
")",
"... | Return the number of entries in the cue list that represent hot cues.
@return the number of cue list entries that are hot cues | [
"Return",
"the",
"number",
"of",
"entries",
"in",
"the",
"cue",
"list",
"that",
"represent",
"hot",
"cues",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L42-L53 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.sortEntries | private List<Entry> sortEntries(List<Entry> loadedEntries) {
Collections.sort(loadedEntries, new Comparator<Entry>() {
@Override
public int compare(Entry entry1, Entry entry2) {
int result = (int) (entry1.cuePosition - entry2.cuePosition);
if (result == 0) {
int h1 = (entry1.hotCueNumber != 0) ? 1 : 0;
int h2 = (entry2.hotCueNumber != 0) ? 1 : 0;
result = h1 - h2;
}
return result;
}
});
return Collections.unmodifiableList(loadedEntries);
} | java | private List<Entry> sortEntries(List<Entry> loadedEntries) {
Collections.sort(loadedEntries, new Comparator<Entry>() {
@Override
public int compare(Entry entry1, Entry entry2) {
int result = (int) (entry1.cuePosition - entry2.cuePosition);
if (result == 0) {
int h1 = (entry1.hotCueNumber != 0) ? 1 : 0;
int h2 = (entry2.hotCueNumber != 0) ? 1 : 0;
result = h1 - h2;
}
return result;
}
});
return Collections.unmodifiableList(loadedEntries);
} | [
"private",
"List",
"<",
"Entry",
">",
"sortEntries",
"(",
"List",
"<",
"Entry",
">",
"loadedEntries",
")",
"{",
"Collections",
".",
"sort",
"(",
"loadedEntries",
",",
"new",
"Comparator",
"<",
"Entry",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"int"... | Sorts the entries into the order we want to present them in, which is by position, with hot cues coming after
ordinary memory points if both exist at the same position, which often happens.
@param loadedEntries the unsorted entries we have loaded from a dbserver message, metadata cache, or rekordbox
database export
@return an immutable list of the collections in the proper order | [
"Sorts",
"the",
"entries",
"into",
"the",
"order",
"we",
"want",
"to",
"present",
"them",
"in",
"which",
"is",
"by",
"position",
"with",
"hot",
"cues",
"coming",
"after",
"ordinary",
"memory",
"points",
"if",
"both",
"exist",
"at",
"the",
"same",
"position... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L204-L218 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/CueList.java | CueList.addEntriesFromTag | private void addEntriesFromTag(List<Entry> entries, RekordboxAnlz.CueTag tag) {
for (RekordboxAnlz.CueEntry cueEntry : tag.cues()) { // TODO: Need to figure out how to identify deleted entries to ignore.
if (cueEntry.type() == RekordboxAnlz.CueEntryType.LOOP) {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time()),
Util.timeToHalfFrame(cueEntry.loopTime())));
} else {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time())));
}
}
} | java | private void addEntriesFromTag(List<Entry> entries, RekordboxAnlz.CueTag tag) {
for (RekordboxAnlz.CueEntry cueEntry : tag.cues()) { // TODO: Need to figure out how to identify deleted entries to ignore.
if (cueEntry.type() == RekordboxAnlz.CueEntryType.LOOP) {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time()),
Util.timeToHalfFrame(cueEntry.loopTime())));
} else {
entries.add(new Entry((int)cueEntry.hotCue(), Util.timeToHalfFrame(cueEntry.time())));
}
}
} | [
"private",
"void",
"addEntriesFromTag",
"(",
"List",
"<",
"Entry",
">",
"entries",
",",
"RekordboxAnlz",
".",
"CueTag",
"tag",
")",
"{",
"for",
"(",
"RekordboxAnlz",
".",
"CueEntry",
"cueEntry",
":",
"tag",
".",
"cues",
"(",
")",
")",
"{",
"// TODO: Need t... | Helper method to add cue list entries from a parsed ANLZ cue tag
@param entries the list of entries being accumulated
@param tag the tag whose entries are to be added | [
"Helper",
"method",
"to",
"add",
"cue",
"list",
"entries",
"from",
"a",
"parsed",
"ANLZ",
"cue",
"tag"
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/CueList.java#L226-L235 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final String input, final Configuration configuration)
{
try
{
return process(new StringReader(input), configuration);
}
catch (final IOException e)
{
// This _can never_ happen
return null;
}
} | java | public final static String process(final String input, final Configuration configuration)
{
try
{
return process(new StringReader(input), configuration);
}
catch (final IOException e)
{
// This _can never_ happen
return null;
}
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"String",
"input",
",",
"final",
"Configuration",
"configuration",
")",
"{",
"try",
"{",
"return",
"process",
"(",
"new",
"StringReader",
"(",
"input",
")",
",",
"configuration",
")",
";",
"}",
... | Transforms an input String into HTML using the given Configuration.
@param input
The String to process.
@param configuration
The Configuration.
@return The processed String.
@since 0.7
@see Configuration | [
"Transforms",
"an",
"input",
"String",
"into",
"HTML",
"using",
"the",
"given",
"Configuration",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L97-L108 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final File file, final Configuration configuration) throws IOException
{
final FileInputStream input = new FileInputStream(file);
final String ret = process(input, configuration);
input.close();
return ret;
} | java | public final static String process(final File file, final Configuration configuration) throws IOException
{
final FileInputStream input = new FileInputStream(file);
final String ret = process(input, configuration);
input.close();
return ret;
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"File",
"file",
",",
"final",
"Configuration",
"configuration",
")",
"throws",
"IOException",
"{",
"final",
"FileInputStream",
"input",
"=",
"new",
"FileInputStream",
"(",
"file",
")",
";",
"final",... | Transforms an input file into HTML using the given Configuration.
@param file
The File to process.
@param configuration
the Configuration
@return The processed String.
@throws IOException
if an IO error occurs
@since 0.7
@see Configuration | [
"Transforms",
"an",
"input",
"file",
"into",
"HTML",
"using",
"the",
"given",
"Configuration",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L123-L129 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Processor.java | Processor.process | public final static String process(final File file, final boolean safeMode) throws IOException
{
return process(file, Configuration.builder().setSafeMode(safeMode).build());
} | java | public final static String process(final File file, final boolean safeMode) throws IOException
{
return process(file, Configuration.builder().setSafeMode(safeMode).build());
} | [
"public",
"final",
"static",
"String",
"process",
"(",
"final",
"File",
"file",
",",
"final",
"boolean",
"safeMode",
")",
"throws",
"IOException",
"{",
"return",
"process",
"(",
"file",
",",
"Configuration",
".",
"builder",
"(",
")",
".",
"setSafeMode",
"(",... | Transforms an input file into HTML.
@param file
The File to process.
@param safeMode
Set to <code>true</code> to escape unsafe HTML tags.
@return The processed String.
@throws IOException
if an IO error occurs
@see Configuration#DEFAULT | [
"Transforms",
"an",
"input",
"file",
"into",
"HTML",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Processor.java#L238-L241 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Run.java | Run.main | public static void main(final String[] args) throws IOException
{
// This is just a _hack_ ...
BufferedReader reader = null;
if (args.length == 0)
{
System.err.println("No input file specified.");
System.exit(-1);
}
if (args.length > 1)
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "UTF-8"));
String line = reader.readLine();
while (line != null && !line.startsWith("<!-- ###"))
{
System.out.println(line);
line = reader.readLine();
}
}
System.out.println(Processor.process(new File(args[0])));
if (args.length > 1 && reader != null)
{
String line = reader.readLine();
while (line != null)
{
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
} | java | public static void main(final String[] args) throws IOException
{
// This is just a _hack_ ...
BufferedReader reader = null;
if (args.length == 0)
{
System.err.println("No input file specified.");
System.exit(-1);
}
if (args.length > 1)
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "UTF-8"));
String line = reader.readLine();
while (line != null && !line.startsWith("<!-- ###"))
{
System.out.println(line);
line = reader.readLine();
}
}
System.out.println(Processor.process(new File(args[0])));
if (args.length > 1 && reader != null)
{
String line = reader.readLine();
while (line != null)
{
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
} | [
"public",
"static",
"void",
"main",
"(",
"final",
"String",
"[",
"]",
"args",
")",
"throws",
"IOException",
"{",
"// This is just a _hack_ ...",
"BufferedReader",
"reader",
"=",
"null",
";",
"if",
"(",
"args",
".",
"length",
"==",
"0",
")",
"{",
"System",
... | Static main.
@param args
Program arguments.
@throws IOException
If an IO error occurred. | [
"Static",
"main",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Run.java#L75-L105 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/cmd/CmdLineParser.java | CmdLineParser.parse | public static List<String> parse(final String[] args, final Object... objs) throws IOException
{
final List<String> ret = Colls.list();
final List<Arg> allArgs = Colls.list();
final HashMap<String, Arg> shortArgs = new HashMap<String, Arg>();
final HashMap<String, Arg> longArgs = new HashMap<String, Arg>();
parseArgs(objs, allArgs, shortArgs, longArgs);
for (int i = 0; i < args.length; i++)
{
final String s = args[i];
final Arg a;
if (s.startsWith("--"))
{
a = longArgs.get(s.substring(2));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else if (s.startsWith("-"))
{
a = shortArgs.get(s.substring(1));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else
{
a = null;
ret.add(s);
}
if (a != null)
{
if (a.isSwitch)
{
a.setField("true");
}
else
{
if (i + 1 >= args.length)
{
System.out.println("Missing parameter for: " + s);
}
if (a.isCatchAll())
{
final List<String> ca = Colls.list();
for (++i; i < args.length; ++i)
{
ca.add(args[i]);
}
a.setCatchAll(ca);
}
else
{
++i;
a.setField(args[i]);
}
}
a.setPresent();
}
}
for (final Arg a : allArgs)
{
if (!a.isOk())
{
throw new IOException("Missing mandatory argument: " + a);
}
}
return ret;
} | java | public static List<String> parse(final String[] args, final Object... objs) throws IOException
{
final List<String> ret = Colls.list();
final List<Arg> allArgs = Colls.list();
final HashMap<String, Arg> shortArgs = new HashMap<String, Arg>();
final HashMap<String, Arg> longArgs = new HashMap<String, Arg>();
parseArgs(objs, allArgs, shortArgs, longArgs);
for (int i = 0; i < args.length; i++)
{
final String s = args[i];
final Arg a;
if (s.startsWith("--"))
{
a = longArgs.get(s.substring(2));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else if (s.startsWith("-"))
{
a = shortArgs.get(s.substring(1));
if (a == null)
{
throw new IOException("Unknown switch: " + s);
}
}
else
{
a = null;
ret.add(s);
}
if (a != null)
{
if (a.isSwitch)
{
a.setField("true");
}
else
{
if (i + 1 >= args.length)
{
System.out.println("Missing parameter for: " + s);
}
if (a.isCatchAll())
{
final List<String> ca = Colls.list();
for (++i; i < args.length; ++i)
{
ca.add(args[i]);
}
a.setCatchAll(ca);
}
else
{
++i;
a.setField(args[i]);
}
}
a.setPresent();
}
}
for (final Arg a : allArgs)
{
if (!a.isOk())
{
throw new IOException("Missing mandatory argument: " + a);
}
}
return ret;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"parse",
"(",
"final",
"String",
"[",
"]",
"args",
",",
"final",
"Object",
"...",
"objs",
")",
"throws",
"IOException",
"{",
"final",
"List",
"<",
"String",
">",
"ret",
"=",
"Colls",
".",
"list",
"(",
"... | Parses command line arguments.
@param args
Array of arguments, like the ones provided by
{@code void main(String[] args)}
@param objs
One or more objects with annotated public fields.
@return A {@code List} containing all unparsed arguments (i.e. arguments
that are no switches)
@throws IOException
if a parsing error occurred.
@see CmdArgument | [
"Parses",
"command",
"line",
"arguments",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/cmd/CmdLineParser.java#L312-L390 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readUntil | public final static int readUntil(final StringBuilder out, final String in, final int start, final char end)
{
int pos = start;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
if (ch == end)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readUntil(final StringBuilder out, final String in, final int start, final char end)
{
int pos = start;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
if (ch == end)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readUntil",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"char",
"end",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"while",
"(",
"pos",
"<",
"in",
... | Reads characters until the 'end' character is encountered.
@param out
The StringBuilder to write to.
@param in
The Input String.
@param start
Starting position.
@param end
End characters.
@return The new position or -1 if no 'end' char was found. | [
"Reads",
"characters",
"until",
"the",
"end",
"character",
"is",
"encountered",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L159-L181 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readMdLink | public final static int readMdLink(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
boolean endReached = false;
switch (ch)
{
case '(':
counter++;
break;
case ' ':
if (counter == 1)
{
endReached = true;
}
break;
case ')':
counter--;
if (counter == 0)
{
endReached = true;
}
break;
}
if (endReached)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readMdLink(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (ch == '\\' && pos + 1 < in.length())
{
pos = escape(out, in.charAt(pos + 1), pos);
}
else
{
boolean endReached = false;
switch (ch)
{
case '(':
counter++;
break;
case ' ':
if (counter == 1)
{
endReached = true;
}
break;
case ')':
counter--;
if (counter == 0)
{
endReached = true;
}
break;
}
if (endReached)
{
break;
}
out.append(ch);
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readMdLink",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"int",
"counter",
"=",
"1",
";",
"while",
"(",
"pos",
"<",
... | Reads a markdown link.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Starting position.
@return The new position or -1 if this is no valid markdown link. | [
"Reads",
"a",
"markdown",
"link",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L194-L237 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readMdLinkId | public final static int readMdLinkId(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
boolean endReached = false;
switch (ch)
{
case '\n':
out.append(' ');
break;
case '[':
counter++;
out.append(ch);
break;
case ']':
counter--;
if (counter == 0)
{
endReached = true;
}
else
{
out.append(ch);
}
break;
default:
out.append(ch);
break;
}
if (endReached)
{
break;
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readMdLinkId(final StringBuilder out, final String in, final int start)
{
int pos = start;
int counter = 1;
while (pos < in.length())
{
final char ch = in.charAt(pos);
boolean endReached = false;
switch (ch)
{
case '\n':
out.append(' ');
break;
case '[':
counter++;
out.append(ch);
break;
case ']':
counter--;
if (counter == 0)
{
endReached = true;
}
else
{
out.append(ch);
}
break;
default:
out.append(ch);
break;
}
if (endReached)
{
break;
}
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readMdLinkId",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"int",
"counter",
"=",
"1",
";",
"while",
"(",
"pos",
"<",
... | Reads a markdown link ID.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Starting position.
@return The new position or -1 if this is no valid markdown link ID. | [
"Reads",
"a",
"markdown",
"link",
"ID",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L250-L290 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.readXMLUntil | public final static int readXMLUntil(final StringBuilder out, final String in, final int start, final char... end)
{
int pos = start;
boolean inString = false;
char stringChar = 0;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (inString)
{
if (ch == '\\')
{
out.append(ch);
pos++;
if (pos < in.length())
{
out.append(ch);
pos++;
}
continue;
}
if (ch == stringChar)
{
inString = false;
out.append(ch);
pos++;
continue;
}
}
switch (ch)
{
case '"':
case '\'':
inString = true;
stringChar = ch;
break;
}
if (!inString)
{
boolean endReached = false;
for (int n = 0; n < end.length; n++)
{
if (ch == end[n])
{
endReached = true;
break;
}
}
if (endReached)
{
break;
}
}
out.append(ch);
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | java | public final static int readXMLUntil(final StringBuilder out, final String in, final int start, final char... end)
{
int pos = start;
boolean inString = false;
char stringChar = 0;
while (pos < in.length())
{
final char ch = in.charAt(pos);
if (inString)
{
if (ch == '\\')
{
out.append(ch);
pos++;
if (pos < in.length())
{
out.append(ch);
pos++;
}
continue;
}
if (ch == stringChar)
{
inString = false;
out.append(ch);
pos++;
continue;
}
}
switch (ch)
{
case '"':
case '\'':
inString = true;
stringChar = ch;
break;
}
if (!inString)
{
boolean endReached = false;
for (int n = 0; n < end.length; n++)
{
if (ch == end[n])
{
endReached = true;
break;
}
}
if (endReached)
{
break;
}
}
out.append(ch);
pos++;
}
return (pos == in.length()) ? -1 : pos;
} | [
"public",
"final",
"static",
"int",
"readXMLUntil",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"char",
"...",
"end",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"boolean",
"inString",
"=... | Reads characters until any 'end' character is encountered, ignoring
escape sequences.
@param out
The StringBuilder to write to.
@param in
The Input String.
@param start
Starting position.
@param end
End characters.
@return The new position or -1 if no 'end' char was found. | [
"Reads",
"characters",
"until",
"any",
"end",
"character",
"is",
"encountered",
"ignoring",
"escape",
"sequences",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L377-L435 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.appendCode | public final static void appendCode(final StringBuilder out, final String in, final int start, final int end)
{
for (int i = start; i < end; i++)
{
final char c;
switch (c = in.charAt(i))
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
break;
}
}
} | java | public final static void appendCode(final StringBuilder out, final String in, final int start, final int end)
{
for (int i = start; i < end; i++)
{
final char c;
switch (c = in.charAt(i))
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
break;
}
}
} | [
"public",
"final",
"static",
"void",
"appendCode",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"in",
",",
"final",
"int",
"start",
",",
"final",
"int",
"end",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";"... | Appends the given string encoding special HTML characters.
@param out
The StringBuilder to write to.
@param in
Input String.
@param start
Input String starting position.
@param end
Input String end position. | [
"Appends",
"the",
"given",
"string",
"encoding",
"special",
"HTML",
"characters",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L449-L470 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.appendDecEntity | public final static void appendDecEntity(final StringBuilder out, final char value)
{
out.append("&#");
out.append((int)value);
out.append(';');
} | java | public final static void appendDecEntity(final StringBuilder out, final char value)
{
out.append("&#");
out.append((int)value);
out.append(';');
} | [
"public",
"final",
"static",
"void",
"appendDecEntity",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"char",
"value",
")",
"{",
"out",
".",
"append",
"(",
"\"&#\"",
")",
";",
"out",
".",
"append",
"(",
"(",
"int",
")",
"value",
")",
";",
"out",
... | Append the given char as a decimal HTML entity.
@param out
The StringBuilder to write to.
@param value
The character. | [
"Append",
"the",
"given",
"char",
"as",
"a",
"decimal",
"HTML",
"entity",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L522-L527 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Utils.java | Utils.codeEncode | public final static void codeEncode(final StringBuilder out, final String value, final int offset)
{
for (int i = offset; i < value.length(); i++)
{
final char c = value.charAt(i);
switch (c)
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
}
}
} | java | public final static void codeEncode(final StringBuilder out, final String value, final int offset)
{
for (int i = offset; i < value.length(); i++)
{
final char c = value.charAt(i);
switch (c)
{
case '&':
out.append("&");
break;
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
default:
out.append(c);
}
}
} | [
"public",
"final",
"static",
"void",
"codeEncode",
"(",
"final",
"StringBuilder",
"out",
",",
"final",
"String",
"value",
",",
"final",
"int",
"offset",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"offset",
";",
"i",
"<",
"value",
".",
"length",
"(",
")",
... | Appends the given string to the given StringBuilder, replacing '&',
'<' and '>' by their respective HTML entities.
@param out
The StringBuilder to append to.
@param value
The string to append.
@param offset
The character offset into value from where to start | [
"Appends",
"the",
"given",
"string",
"to",
"the",
"given",
"StringBuilder",
"replacing",
"&",
";",
"<",
";",
"and",
">",
";",
"by",
"their",
"respective",
"HTML",
"entities",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Utils.java#L743-L763 | train |
rjeschke/txtmark | src/main/java/com/github/rjeschke/txtmark/Line.java | Line.countCharsStart | private int countCharsStart(final char ch, final boolean allowSpaces)
{
int count = 0;
for (int i = 0; i < this.value.length(); i++)
{
final char c = this.value.charAt(i);
if (c == ' ' && allowSpaces)
{
continue;
}
if (c == ch)
{
count++;
}
else
{
break;
}
}
return count;
} | java | private int countCharsStart(final char ch, final boolean allowSpaces)
{
int count = 0;
for (int i = 0; i < this.value.length(); i++)
{
final char c = this.value.charAt(i);
if (c == ' ' && allowSpaces)
{
continue;
}
if (c == ch)
{
count++;
}
else
{
break;
}
}
return count;
} | [
"private",
"int",
"countCharsStart",
"(",
"final",
"char",
"ch",
",",
"final",
"boolean",
"allowSpaces",
")",
"{",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"value",
".",
"length",
"(",
")",
";",
... | Counts the amount of 'ch' at the start of this line optionally ignoring
spaces.
@param ch
The char to count.
@param allowSpaces
Whether to allow spaces or not
@return Number of characters found.
@since 0.12 | [
"Counts",
"the",
"amount",
"of",
"ch",
"at",
"the",
"start",
"of",
"this",
"line",
"optionally",
"ignoring",
"spaces",
"."
] | 108cee6b209a362843729c032c2d982625d12d98 | https://github.com/rjeschke/txtmark/blob/108cee6b209a362843729c032c2d982625d12d98/src/main/java/com/github/rjeschke/txtmark/Line.java#L247-L267 | train |
iwgang/SimplifySpan | library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java | SimplifySpanBuild.append | public SimplifySpanBuild append(String text) {
if (TextUtils.isEmpty(text)) return this;
mNormalSizeText.append(text);
mStringBuilder.append(text);
return this;
} | java | public SimplifySpanBuild append(String text) {
if (TextUtils.isEmpty(text)) return this;
mNormalSizeText.append(text);
mStringBuilder.append(text);
return this;
} | [
"public",
"SimplifySpanBuild",
"append",
"(",
"String",
"text",
")",
"{",
"if",
"(",
"TextUtils",
".",
"isEmpty",
"(",
"text",
")",
")",
"return",
"this",
";",
"mNormalSizeText",
".",
"append",
"(",
"text",
")",
";",
"mStringBuilder",
".",
"append",
"(",
... | append normal text
@param text normal text
@return SimplifySpanBuild | [
"append",
"normal",
"text"
] | 34e917cd5497215c8abc07b3d8df187949967283 | https://github.com/iwgang/SimplifySpan/blob/34e917cd5497215c8abc07b3d8df187949967283/library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java#L191-L197 | train |
iwgang/SimplifySpan | library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java | SimplifySpanBuild.appendMultiClickable | public SimplifySpanBuild appendMultiClickable(SpecialClickableUnit specialClickableUnit, Object... specialUnitOrStrings) {
processMultiClickableSpecialUnit(false, specialClickableUnit, specialUnitOrStrings);
return this;
} | java | public SimplifySpanBuild appendMultiClickable(SpecialClickableUnit specialClickableUnit, Object... specialUnitOrStrings) {
processMultiClickableSpecialUnit(false, specialClickableUnit, specialUnitOrStrings);
return this;
} | [
"public",
"SimplifySpanBuild",
"appendMultiClickable",
"(",
"SpecialClickableUnit",
"specialClickableUnit",
",",
"Object",
"...",
"specialUnitOrStrings",
")",
"{",
"processMultiClickableSpecialUnit",
"(",
"false",
",",
"specialClickableUnit",
",",
"specialUnitOrStrings",
")",
... | append multi clickable SpecialUnit or String
@param specialClickableUnit SpecialClickableUnit
@param specialUnitOrStrings Unit Or String
@return | [
"append",
"multi",
"clickable",
"SpecialUnit",
"or",
"String"
] | 34e917cd5497215c8abc07b3d8df187949967283 | https://github.com/iwgang/SimplifySpan/blob/34e917cd5497215c8abc07b3d8df187949967283/library/src/main/java/cn/iwgang/simplifyspan/SimplifySpanBuild.java#L240-L243 | train |
erizet/SignalA | SignalA/src/main/java/com/zsoft/signala/Hubs/HubProxy.java | HubProxy.Invoke | @Override
public void Invoke(final String method, JSONArray args,
HubInvokeCallback callback) {
if (method == null)
{
throw new IllegalArgumentException("method");
}
if (args == null)
{
throw new IllegalArgumentException("args");
}
final String callbackId = mConnection.RegisterCallback(callback);
HubInvocation hubData = new HubInvocation(mHubName, method, args, callbackId);
String value = hubData.Serialize();
mConnection.Send(value, new SendCallback()
{
@Override
public void OnSent(CharSequence messageSent) {
Log.v(TAG, "Invoke of " + method + "sent to " + mHubName);
// callback.OnSent() ??!?!?
}
@Override
public void OnError(Exception ex) {
// TODO Cancel the callback
Log.e(TAG, "Failed to invoke " + method + "on " + mHubName);
mConnection.RemoveCallback(callbackId);
// callback.OnError() ?!?!?
}
});
} | java | @Override
public void Invoke(final String method, JSONArray args,
HubInvokeCallback callback) {
if (method == null)
{
throw new IllegalArgumentException("method");
}
if (args == null)
{
throw new IllegalArgumentException("args");
}
final String callbackId = mConnection.RegisterCallback(callback);
HubInvocation hubData = new HubInvocation(mHubName, method, args, callbackId);
String value = hubData.Serialize();
mConnection.Send(value, new SendCallback()
{
@Override
public void OnSent(CharSequence messageSent) {
Log.v(TAG, "Invoke of " + method + "sent to " + mHubName);
// callback.OnSent() ??!?!?
}
@Override
public void OnError(Exception ex) {
// TODO Cancel the callback
Log.e(TAG, "Failed to invoke " + method + "on " + mHubName);
mConnection.RemoveCallback(callbackId);
// callback.OnError() ?!?!?
}
});
} | [
"@",
"Override",
"public",
"void",
"Invoke",
"(",
"final",
"String",
"method",
",",
"JSONArray",
"args",
",",
"HubInvokeCallback",
"callback",
")",
"{",
"if",
"(",
"method",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"method\"",... | Executes a method on the server asynchronously | [
"Executes",
"a",
"method",
"on",
"the",
"server",
"asynchronously"
] | d33bf49dbcf7249f826c5dbb3411cfe4f5d97dd4 | https://github.com/erizet/SignalA/blob/d33bf49dbcf7249f826c5dbb3411cfe4f5d97dd4/SignalA/src/main/java/com/zsoft/signala/Hubs/HubProxy.java#L34-L70 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.