id
int32 0
165k
| 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
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
163,900 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.findTrackIdAtOffset | private static int findTrackIdAtOffset(SlotReference slot, Client client, int offset) throws IOException {
Message entry = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot.slot, CdjStatus.TrackType.REKORDBOX, offset, 1).get(0);
if (entry.getMenuItemType() == Message.MenuItemType.UNKNOWN) {
logger.warn("Encountered unrecognized track list entry item type: {}", entry);
}
return (int)((NumberField)entry.arguments.get(1)).getValue();
} | java | private static int findTrackIdAtOffset(SlotReference slot, Client client, int offset) throws IOException {
Message entry = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot.slot, CdjStatus.TrackType.REKORDBOX, offset, 1).get(0);
if (entry.getMenuItemType() == Message.MenuItemType.UNKNOWN) {
logger.warn("Encountered unrecognized track list entry item type: {}", entry);
}
return (int)((NumberField)entry.arguments.get(1)).getValue();
} | [
"private",
"static",
"int",
"findTrackIdAtOffset",
"(",
"SlotReference",
"slot",
",",
"Client",
"client",
",",
"int",
"offset",
")",
"throws",
"IOException",
"{",
"Message",
"entry",
"=",
"client",
".",
"renderMenuItems",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
".",
"slot",
",",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
",",
"offset",
",",
"1",
")",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"entry",
".",
"getMenuItemType",
"(",
")",
"==",
"Message",
".",
"MenuItemType",
".",
"UNKNOWN",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Encountered unrecognized track list entry item type: {}\"",
",",
"entry",
")",
";",
"}",
"return",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"entry",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"}"
] | As part of checking whether a metadata cache can be auto-mounted for a particular media slot, this method
looks up the track at the specified offset within the player's track list, and returns its rekordbox ID.
@param slot the slot being considered for auto-attaching a metadata cache
@param client the connection to the database server on the player holding that slot
@param offset an index into the list of all tracks present in the slot
@throws IOException if there is a problem communicating with the player | [
"As",
"part",
"of",
"checking",
"whether",
"a",
"metadata",
"cache",
"can",
"be",
"auto",
"-",
"mounted",
"for",
"a",
"particular",
"media",
"slot",
"this",
"method",
"looks",
"up",
"the",
"track",
"at",
"the",
"specified",
"offset",
"within",
"the",
"player",
"s",
"track",
"list",
"and",
"returns",
"its",
"rekordbox",
"ID",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L1036-L1042 |
163,901 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.isPacketLongEnough | private boolean isPacketLongEnough(DatagramPacket packet, int expectedLength, String name) {
final int length = packet.getLength();
if (length < expectedLength) {
logger.warn("Ignoring too-short " + name + " packet; expecting " + expectedLength + " bytes and got " +
length + ".");
return false;
}
if (length > expectedLength) {
logger.warn("Processing too-long " + name + " packet; expecting " + expectedLength +
" bytes and got " + length + ".");
}
return true;
} | java | private boolean isPacketLongEnough(DatagramPacket packet, int expectedLength, String name) {
final int length = packet.getLength();
if (length < expectedLength) {
logger.warn("Ignoring too-short " + name + " packet; expecting " + expectedLength + " bytes and got " +
length + ".");
return false;
}
if (length > expectedLength) {
logger.warn("Processing too-long " + name + " packet; expecting " + expectedLength +
" bytes and got " + length + ".");
}
return true;
} | [
"private",
"boolean",
"isPacketLongEnough",
"(",
"DatagramPacket",
"packet",
",",
"int",
"expectedLength",
",",
"String",
"name",
")",
"{",
"final",
"int",
"length",
"=",
"packet",
".",
"getLength",
"(",
")",
";",
"if",
"(",
"length",
"<",
"expectedLength",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Ignoring too-short \"",
"+",
"name",
"+",
"\" packet; expecting \"",
"+",
"expectedLength",
"+",
"\" bytes and got \"",
"+",
"length",
"+",
"\".\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"length",
">",
"expectedLength",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Processing too-long \"",
"+",
"name",
"+",
"\" packet; expecting \"",
"+",
"expectedLength",
"+",
"\" bytes and got \"",
"+",
"length",
"+",
"\".\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Helper method to check that we got the right size packet.
@param packet a packet that has been received
@param expectedLength the number of bytes we expect it to contain
@param name the description of the packet in case we need to report issues with the length
@return {@code true} if enough bytes were received to process the packet | [
"Helper",
"method",
"to",
"check",
"that",
"we",
"got",
"the",
"right",
"size",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L72-L86 |
163,902 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.stop | public synchronized void stop() {
if (isRunning()) {
socket.get().close();
socket.set(null);
deliverLifecycleAnnouncement(logger, false);
}
} | java | public synchronized void stop() {
if (isRunning()) {
socket.get().close();
socket.set(null);
deliverLifecycleAnnouncement(logger, false);
}
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"socket",
".",
"get",
"(",
")",
".",
"close",
"(",
")",
";",
"socket",
".",
"set",
"(",
"null",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | Stop listening for beats. | [
"Stop",
"listening",
"for",
"beats",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L212-L218 |
163,903 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.deliverSyncCommand | private void deliverSyncCommand(byte command) {
for (final SyncListener listener : getSyncListeners()) {
try {
switch (command) {
case 0x01:
listener.becomeMaster();
case 0x10:
listener.setSyncMode(true);
break;
case 0x20:
listener.setSyncMode(false);
break;
}
} catch (Throwable t) {
logger.warn("Problem delivering sync command to listener", t);
}
}
} | java | private void deliverSyncCommand(byte command) {
for (final SyncListener listener : getSyncListeners()) {
try {
switch (command) {
case 0x01:
listener.becomeMaster();
case 0x10:
listener.setSyncMode(true);
break;
case 0x20:
listener.setSyncMode(false);
break;
}
} catch (Throwable t) {
logger.warn("Problem delivering sync command to listener", t);
}
}
} | [
"private",
"void",
"deliverSyncCommand",
"(",
"byte",
"command",
")",
"{",
"for",
"(",
"final",
"SyncListener",
"listener",
":",
"getSyncListeners",
"(",
")",
")",
"{",
"try",
"{",
"switch",
"(",
"command",
")",
"{",
"case",
"0x01",
":",
"listener",
".",
"becomeMaster",
"(",
")",
";",
"case",
"0x10",
":",
"listener",
".",
"setSyncMode",
"(",
"true",
")",
";",
"break",
";",
"case",
"0x20",
":",
"listener",
".",
"setSyncMode",
"(",
"false",
")",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering sync command to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a sync command to all registered listeners.
@param command the byte which identifies the type of sync command we received | [
"Send",
"a",
"sync",
"command",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L344-L365 |
163,904 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.deliverMasterYieldCommand | private void deliverMasterYieldCommand(int toPlayer) {
for (final MasterHandoffListener listener : getMasterHandoffListeners()) {
try {
listener.yieldMasterTo(toPlayer);
} catch (Throwable t) {
logger.warn("Problem delivering master yield command to listener", t);
}
}
} | java | private void deliverMasterYieldCommand(int toPlayer) {
for (final MasterHandoffListener listener : getMasterHandoffListeners()) {
try {
listener.yieldMasterTo(toPlayer);
} catch (Throwable t) {
logger.warn("Problem delivering master yield command to listener", t);
}
}
} | [
"private",
"void",
"deliverMasterYieldCommand",
"(",
"int",
"toPlayer",
")",
"{",
"for",
"(",
"final",
"MasterHandoffListener",
"listener",
":",
"getMasterHandoffListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"yieldMasterTo",
"(",
"toPlayer",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering master yield command to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a master handoff yield command to all registered listeners.
@param toPlayer the device number to which we are being instructed to yield the tempo master role | [
"Send",
"a",
"master",
"handoff",
"yield",
"command",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L423-L431 |
163,905 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.deliverMasterYieldResponse | private void deliverMasterYieldResponse(int fromPlayer, boolean yielded) {
for (final MasterHandoffListener listener : getMasterHandoffListeners()) {
try {
listener.yieldResponse(fromPlayer, yielded);
} catch (Throwable t) {
logger.warn("Problem delivering master yield response to listener", t);
}
}
} | java | private void deliverMasterYieldResponse(int fromPlayer, boolean yielded) {
for (final MasterHandoffListener listener : getMasterHandoffListeners()) {
try {
listener.yieldResponse(fromPlayer, yielded);
} catch (Throwable t) {
logger.warn("Problem delivering master yield response to listener", t);
}
}
} | [
"private",
"void",
"deliverMasterYieldResponse",
"(",
"int",
"fromPlayer",
",",
"boolean",
"yielded",
")",
"{",
"for",
"(",
"final",
"MasterHandoffListener",
"listener",
":",
"getMasterHandoffListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"yieldResponse",
"(",
"fromPlayer",
",",
"yielded",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering master yield response to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a master handoff yield response to all registered listeners.
@param fromPlayer the device number that is responding to our request that it yield the tempo master role to us
@param yielded will be {@code true} if we should now be the tempo master | [
"Send",
"a",
"master",
"handoff",
"yield",
"response",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L439-L447 |
163,906 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.deliverOnAirUpdate | private void deliverOnAirUpdate(Set<Integer> audibleChannels) {
for (final OnAirListener listener : getOnAirListeners()) {
try {
listener.channelsOnAir(audibleChannels);
} catch (Throwable t) {
logger.warn("Problem delivering channels on-air update to listener", t);
}
}
} | java | private void deliverOnAirUpdate(Set<Integer> audibleChannels) {
for (final OnAirListener listener : getOnAirListeners()) {
try {
listener.channelsOnAir(audibleChannels);
} catch (Throwable t) {
logger.warn("Problem delivering channels on-air update to listener", t);
}
}
} | [
"private",
"void",
"deliverOnAirUpdate",
"(",
"Set",
"<",
"Integer",
">",
"audibleChannels",
")",
"{",
"for",
"(",
"final",
"OnAirListener",
"listener",
":",
"getOnAirListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"channelsOnAir",
"(",
"audibleChannels",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering channels on-air update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a channels on-air update to all registered listeners.
@param audibleChannels holds the device numbers of all channels that can currently be heard in the mixer output | [
"Send",
"a",
"channels",
"on",
"-",
"air",
"update",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L505-L513 |
163,907 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/BeatFinder.java | BeatFinder.deliverFaderStartCommand | private void deliverFaderStartCommand(Set<Integer> playersToStart, Set<Integer> playersToStop) {
for (final FaderStartListener listener : getFaderStartListeners()) {
try {
listener.fadersChanged(playersToStart, playersToStop);
} catch (Throwable t) {
logger.warn("Problem delivering fader start command to listener", t);
}
}
} | java | private void deliverFaderStartCommand(Set<Integer> playersToStart, Set<Integer> playersToStop) {
for (final FaderStartListener listener : getFaderStartListeners()) {
try {
listener.fadersChanged(playersToStart, playersToStop);
} catch (Throwable t) {
logger.warn("Problem delivering fader start command to listener", t);
}
}
} | [
"private",
"void",
"deliverFaderStartCommand",
"(",
"Set",
"<",
"Integer",
">",
"playersToStart",
",",
"Set",
"<",
"Integer",
">",
"playersToStop",
")",
"{",
"for",
"(",
"final",
"FaderStartListener",
"listener",
":",
"getFaderStartListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"fadersChanged",
"(",
"playersToStart",
",",
"playersToStop",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering fader start command to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a fader start command to all registered listeners.
@param playersToStart contains the device numbers of all players that should start playing
@param playersToStop contains the device numbers of all players that should stop playing | [
"Send",
"a",
"fader",
"start",
"command",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/BeatFinder.java#L572-L580 |
163,908 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Message.java | Message.write | public void write(WritableByteChannel channel) throws IOException {
logger.debug("Writing> {}", this);
for (Field field : fields) {
field.write(channel);
}
} | java | public void write(WritableByteChannel channel) throws IOException {
logger.debug("Writing> {}", this);
for (Field field : fields) {
field.write(channel);
}
} | [
"public",
"void",
"write",
"(",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Writing> {}\"",
",",
"this",
")",
";",
"for",
"(",
"Field",
"field",
":",
"fields",
")",
"{",
"field",
".",
"write",
"(",
"channel",
")",
";",
"}",
"}"
] | Writes the message to the specified channel, for example when creating metadata cache files.
@param channel the channel to which it should be written
@throws IOException if there is a problem writing to the channel | [
"Writes",
"the",
"message",
"to",
"the",
"specified",
"channel",
"for",
"example",
"when",
"creating",
"metadata",
"cache",
"files",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Message.java#L1068-L1073 |
163,909 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.setFindDetails | public final void setFindDetails(boolean findDetails) {
this.findDetails.set(findDetails);
if (findDetails) {
primeCache(); // Get details for any tracks that were already loaded on players.
} else {
// Inform our listeners, on the proper thread, that the detailed waveforms are no longer available
final Set<DeckReference> dyingCache = new HashSet<DeckReference>(detailHotCache.keySet());
detailHotCache.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingCache) {
deliverWaveformDetailUpdate(deck.player, null);
}
}
});
}
} | java | public final void setFindDetails(boolean findDetails) {
this.findDetails.set(findDetails);
if (findDetails) {
primeCache(); // Get details for any tracks that were already loaded on players.
} else {
// Inform our listeners, on the proper thread, that the detailed waveforms are no longer available
final Set<DeckReference> dyingCache = new HashSet<DeckReference>(detailHotCache.keySet());
detailHotCache.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingCache) {
deliverWaveformDetailUpdate(deck.player, null);
}
}
});
}
} | [
"public",
"final",
"void",
"setFindDetails",
"(",
"boolean",
"findDetails",
")",
"{",
"this",
".",
"findDetails",
".",
"set",
"(",
"findDetails",
")",
";",
"if",
"(",
"findDetails",
")",
"{",
"primeCache",
"(",
")",
";",
"// Get details for any tracks that were already loaded on players.",
"}",
"else",
"{",
"// Inform our listeners, on the proper thread, that the detailed waveforms are no longer available",
"final",
"Set",
"<",
"DeckReference",
">",
"dyingCache",
"=",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"detailHotCache",
".",
"keySet",
"(",
")",
")",
";",
"detailHotCache",
".",
"clear",
"(",
")",
";",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"DeckReference",
"deck",
":",
"dyingCache",
")",
"{",
"deliverWaveformDetailUpdate",
"(",
"deck",
".",
"player",
",",
"null",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Set whether we should retrieve the waveform details in addition to the waveform previews.
@param findDetails if {@code true}, both types of waveform will be retrieved, if {@code false} only previews
will be retrieved | [
"Set",
"whether",
"we",
"should",
"retrieve",
"the",
"waveform",
"details",
"in",
"addition",
"to",
"the",
"waveform",
"previews",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L57-L74 |
163,910 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.setColorPreferred | public final void setColorPreferred(boolean preferColor) {
if (this.preferColor.compareAndSet(!preferColor, preferColor) && isRunning()) {
stop();
try {
start();
} catch (Exception e) {
logger.error("Unexplained exception restarting; we had been running already!", e);
}
}
} | java | public final void setColorPreferred(boolean preferColor) {
if (this.preferColor.compareAndSet(!preferColor, preferColor) && isRunning()) {
stop();
try {
start();
} catch (Exception e) {
logger.error("Unexplained exception restarting; we had been running already!", e);
}
}
} | [
"public",
"final",
"void",
"setColorPreferred",
"(",
"boolean",
"preferColor",
")",
"{",
"if",
"(",
"this",
".",
"preferColor",
".",
"compareAndSet",
"(",
"!",
"preferColor",
",",
"preferColor",
")",
"&&",
"isRunning",
"(",
")",
")",
"{",
"stop",
"(",
")",
";",
"try",
"{",
"start",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unexplained exception restarting; we had been running already!\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] | Set whether we should obtain color versions of waveforms and previews when they are available. This will only
affect waveforms loaded after the setting has been changed. If this changes the setting, and we were running,
stop and restart in order to flush and reload the correct waveform versions.
@param preferColor if {@code true}, the full-color versions of waveforms will be requested, if {@code false}
only the older blue versions will be retrieved | [
"Set",
"whether",
"we",
"should",
"obtain",
"color",
"versions",
"of",
"waveforms",
"and",
"previews",
"when",
"they",
"are",
"available",
".",
"This",
"will",
"only",
"affect",
"waveforms",
"loaded",
"after",
"the",
"setting",
"has",
"been",
"changed",
".",
"If",
"this",
"changes",
"the",
"setting",
"and",
"we",
"were",
"running",
"stop",
"and",
"restart",
"in",
"order",
"to",
"flush",
"and",
"reload",
"the",
"correct",
"waveform",
"versions",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L100-L109 |
163,911 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.clearDeckPreview | private void clearDeckPreview(TrackMetadataUpdate update) {
if (previewHotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverWaveformPreviewUpdate(update.player, null);
}
} | java | private void clearDeckPreview(TrackMetadataUpdate update) {
if (previewHotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverWaveformPreviewUpdate(update.player, null);
}
} | [
"private",
"void",
"clearDeckPreview",
"(",
"TrackMetadataUpdate",
"update",
")",
"{",
"if",
"(",
"previewHotCache",
".",
"remove",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
")",
"!=",
"null",
")",
"{",
"deliverWaveformPreviewUpdate",
"(",
"update",
".",
"player",
",",
"null",
")",
";",
"}",
"}"
] | We have received an update that invalidates the waveform preview for a player, so clear it and alert
any listeners if this represents a change. This does not affect the hot cues; they will stick around until the
player loads a new track that overwrites one or more of them.
@param update the update which means we have no waveform preview for the associated player | [
"We",
"have",
"received",
"an",
"update",
"that",
"invalidates",
"the",
"waveform",
"preview",
"for",
"a",
"player",
"so",
"clear",
"it",
"and",
"alert",
"any",
"listeners",
"if",
"this",
"represents",
"a",
"change",
".",
"This",
"does",
"not",
"affect",
"the",
"hot",
"cues",
";",
"they",
"will",
"stick",
"around",
"until",
"the",
"player",
"loads",
"a",
"new",
"track",
"that",
"overwrites",
"one",
"or",
"more",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L219-L223 |
163,912 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.clearDeckDetail | private void clearDeckDetail(TrackMetadataUpdate update) {
if (detailHotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverWaveformDetailUpdate(update.player, null);
}
} | java | private void clearDeckDetail(TrackMetadataUpdate update) {
if (detailHotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverWaveformDetailUpdate(update.player, null);
}
} | [
"private",
"void",
"clearDeckDetail",
"(",
"TrackMetadataUpdate",
"update",
")",
"{",
"if",
"(",
"detailHotCache",
".",
"remove",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
")",
"!=",
"null",
")",
"{",
"deliverWaveformDetailUpdate",
"(",
"update",
".",
"player",
",",
"null",
")",
";",
"}",
"}"
] | We have received an update that invalidates the waveform detail for a player, so clear it and alert
any listeners if this represents a change. This does not affect the hot cues; they will stick around until the
player loads a new track that overwrites one or more of them.
@param update the update which means we have no waveform preview for the associated player | [
"We",
"have",
"received",
"an",
"update",
"that",
"invalidates",
"the",
"waveform",
"detail",
"for",
"a",
"player",
"so",
"clear",
"it",
"and",
"alert",
"any",
"listeners",
"if",
"this",
"represents",
"a",
"change",
".",
"This",
"does",
"not",
"affect",
"the",
"hot",
"cues",
";",
"they",
"will",
"stick",
"around",
"until",
"the",
"player",
"loads",
"a",
"new",
"track",
"that",
"overwrites",
"one",
"or",
"more",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L232-L236 |
163,913 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.clearWaveforms | private void clearWaveforms(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(previewHotCache.keySet())) {
if (deck.player == player) {
previewHotCache.remove(deck);
if (deck.hotCue == 0) {
deliverWaveformPreviewUpdate(player, null); // Inform listeners that preview is gone.
}
}
}
// Again iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(detailHotCache.keySet())) {
if (deck.player == player) {
detailHotCache.remove(deck);
if (deck.hotCue == 0) {
deliverWaveformDetailUpdate(player, null); // Inform listeners that detail is gone.
}
}
}
} | java | private void clearWaveforms(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(previewHotCache.keySet())) {
if (deck.player == player) {
previewHotCache.remove(deck);
if (deck.hotCue == 0) {
deliverWaveformPreviewUpdate(player, null); // Inform listeners that preview is gone.
}
}
}
// Again iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(detailHotCache.keySet())) {
if (deck.player == player) {
detailHotCache.remove(deck);
if (deck.hotCue == 0) {
deliverWaveformDetailUpdate(player, null); // Inform listeners that detail is gone.
}
}
}
} | [
"private",
"void",
"clearWaveforms",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"final",
"int",
"player",
"=",
"announcement",
".",
"getNumber",
"(",
")",
";",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
":",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"previewHotCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"deck",
".",
"player",
"==",
"player",
")",
"{",
"previewHotCache",
".",
"remove",
"(",
"deck",
")",
";",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverWaveformPreviewUpdate",
"(",
"player",
",",
"null",
")",
";",
"// Inform listeners that preview is gone.",
"}",
"}",
"}",
"// Again iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
":",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"detailHotCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"deck",
".",
"player",
"==",
"player",
")",
"{",
"detailHotCache",
".",
"remove",
"(",
"deck",
")",
";",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverWaveformDetailUpdate",
"(",
"player",
",",
"null",
")",
";",
"// Inform listeners that detail is gone.",
"}",
"}",
"}",
"}"
] | We have received notification that a device is no longer on the network, so clear out all its waveforms.
@param announcement the packet which reported the device’s disappearance | [
"We",
"have",
"received",
"notification",
"that",
"a",
"device",
"is",
"no",
"longer",
"on",
"the",
"network",
"so",
"clear",
"out",
"all",
"its",
"waveforms",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L255-L275 |
163,914 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.updatePreview | private void updatePreview(TrackMetadataUpdate update, WaveformPreview preview) {
previewHotCache.put(DeckReference.getDeckReference(update.player, 0), preview); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
previewHotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), preview);
}
}
}
deliverWaveformPreviewUpdate(update.player, preview);
} | java | private void updatePreview(TrackMetadataUpdate update, WaveformPreview preview) {
previewHotCache.put(DeckReference.getDeckReference(update.player, 0), preview); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
previewHotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), preview);
}
}
}
deliverWaveformPreviewUpdate(update.player, preview);
} | [
"private",
"void",
"updatePreview",
"(",
"TrackMetadataUpdate",
"update",
",",
"WaveformPreview",
"preview",
")",
"{",
"previewHotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
",",
"preview",
")",
";",
"// Main deck",
"if",
"(",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
"!=",
"null",
")",
"{",
"// Update the cache with any hot cues in this track as well",
"for",
"(",
"CueList",
".",
"Entry",
"entry",
":",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
".",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
"!=",
"0",
")",
"{",
"previewHotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"entry",
".",
"hotCueNumber",
")",
",",
"preview",
")",
";",
"}",
"}",
"}",
"deliverWaveformPreviewUpdate",
"(",
"update",
".",
"player",
",",
"preview",
")",
";",
"}"
] | We have obtained a waveform preview for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this waveform preview
@param preview the waveform preview which we retrieved | [
"We",
"have",
"obtained",
"a",
"waveform",
"preview",
"for",
"a",
"device",
"so",
"store",
"it",
"and",
"alert",
"any",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L283-L293 |
163,915 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.updateDetail | private void updateDetail(TrackMetadataUpdate update, WaveformDetail detail) {
detailHotCache.put(DeckReference.getDeckReference(update.player, 0), detail); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
detailHotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), detail);
}
}
}
deliverWaveformDetailUpdate(update.player, detail);
} | java | private void updateDetail(TrackMetadataUpdate update, WaveformDetail detail) {
detailHotCache.put(DeckReference.getDeckReference(update.player, 0), detail); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
detailHotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), detail);
}
}
}
deliverWaveformDetailUpdate(update.player, detail);
} | [
"private",
"void",
"updateDetail",
"(",
"TrackMetadataUpdate",
"update",
",",
"WaveformDetail",
"detail",
")",
"{",
"detailHotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
",",
"detail",
")",
";",
"// Main deck",
"if",
"(",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
"!=",
"null",
")",
"{",
"// Update the cache with any hot cues in this track as well",
"for",
"(",
"CueList",
".",
"Entry",
"entry",
":",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
".",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
"!=",
"0",
")",
"{",
"detailHotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"entry",
".",
"hotCueNumber",
")",
",",
"detail",
")",
";",
"}",
"}",
"}",
"deliverWaveformDetailUpdate",
"(",
"update",
".",
"player",
",",
"detail",
")",
";",
"}"
] | We have obtained waveform detail for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this waveform detail
@param detail the waveform detail which we retrieved | [
"We",
"have",
"obtained",
"waveform",
"detail",
"for",
"a",
"device",
"so",
"store",
"it",
"and",
"alert",
"any",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L301-L311 |
163,916 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.getLoadedPreviews | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, WaveformPreview> getLoadedPreviews() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, WaveformPreview>(previewHotCache));
} | java | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, WaveformPreview> getLoadedPreviews() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, WaveformPreview>(previewHotCache));
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"Map",
"<",
"DeckReference",
",",
"WaveformPreview",
">",
"getLoadedPreviews",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"DeckReference",
",",
"WaveformPreview",
">",
"(",
"previewHotCache",
")",
")",
";",
"}"
] | Get the waveform previews available for all tracks currently loaded in any player, either on the play deck, or
in a hot cue.
@return the previews associated with all current players, including for any tracks loaded in their hot cue slots
@throws IllegalStateException if the WaveformFinder is not running | [
"Get",
"the",
"waveform",
"previews",
"available",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"either",
"on",
"the",
"play",
"deck",
"or",
"in",
"a",
"hot",
"cue",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L321-L326 |
163,917 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.getLoadedDetails | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, WaveformDetail> getLoadedDetails() {
ensureRunning();
if (!isFindingDetails()) {
throw new IllegalStateException("WaveformFinder is not configured to find waveform details.");
}
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, WaveformDetail>(detailHotCache));
} | java | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, WaveformDetail> getLoadedDetails() {
ensureRunning();
if (!isFindingDetails()) {
throw new IllegalStateException("WaveformFinder is not configured to find waveform details.");
}
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, WaveformDetail>(detailHotCache));
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"Map",
"<",
"DeckReference",
",",
"WaveformDetail",
">",
"getLoadedDetails",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"if",
"(",
"!",
"isFindingDetails",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"WaveformFinder is not configured to find waveform details.\"",
")",
";",
"}",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"DeckReference",
",",
"WaveformDetail",
">",
"(",
"detailHotCache",
")",
")",
";",
"}"
] | Get the waveform details available for all tracks currently loaded in any player, either on the play deck, or
in a hot cue.
@return the details associated with all current players, including for any tracks loaded in their hot cue slots
@throws IllegalStateException if the WaveformFinder is not running or requesting waveform details | [
"Get",
"the",
"waveform",
"details",
"available",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"either",
"on",
"the",
"play",
"deck",
"or",
"in",
"a",
"hot",
"cue",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L336-L344 |
163,918 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.requestPreviewInternal | private WaveformPreview requestPreviewInternal(final DataReference trackReference, final boolean failIfPassive) {
// First check if we are using cached data for this slot
MetadataCache cache = MetadataFinder.getInstance().getMetadataCache(SlotReference.getSlotReference(trackReference));
if (cache != null) {
return cache.getWaveformPreview(null, trackReference);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = MetadataFinder.getInstance().getMediaDetailsFor(trackReference.getSlotReference());
if (sourceDetails != null) {
final WaveformPreview provided = MetadataFinder.getInstance().allMetadataProviders.getWaveformPreview(sourceDetails, trackReference);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (MetadataFinder.getInstance().isPassive() && failIfPassive && trackReference.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// We have to actually request the preview using the dbserver protocol.
ConnectionManager.ClientTask<WaveformPreview> task = new ConnectionManager.ClientTask<WaveformPreview>() {
@Override
public WaveformPreview useClient(Client client) throws Exception {
return getWaveformPreview(trackReference.rekordboxId, SlotReference.getSlotReference(trackReference), client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(trackReference.player, task, "requesting waveform preview");
} catch (Exception e) {
logger.error("Problem requesting waveform preview, returning null", e);
}
return null;
} | java | private WaveformPreview requestPreviewInternal(final DataReference trackReference, final boolean failIfPassive) {
// First check if we are using cached data for this slot
MetadataCache cache = MetadataFinder.getInstance().getMetadataCache(SlotReference.getSlotReference(trackReference));
if (cache != null) {
return cache.getWaveformPreview(null, trackReference);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = MetadataFinder.getInstance().getMediaDetailsFor(trackReference.getSlotReference());
if (sourceDetails != null) {
final WaveformPreview provided = MetadataFinder.getInstance().allMetadataProviders.getWaveformPreview(sourceDetails, trackReference);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (MetadataFinder.getInstance().isPassive() && failIfPassive && trackReference.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// We have to actually request the preview using the dbserver protocol.
ConnectionManager.ClientTask<WaveformPreview> task = new ConnectionManager.ClientTask<WaveformPreview>() {
@Override
public WaveformPreview useClient(Client client) throws Exception {
return getWaveformPreview(trackReference.rekordboxId, SlotReference.getSlotReference(trackReference), client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(trackReference.player, task, "requesting waveform preview");
} catch (Exception e) {
logger.error("Problem requesting waveform preview, returning null", e);
}
return null;
} | [
"private",
"WaveformPreview",
"requestPreviewInternal",
"(",
"final",
"DataReference",
"trackReference",
",",
"final",
"boolean",
"failIfPassive",
")",
"{",
"// First check if we are using cached data for this slot",
"MetadataCache",
"cache",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMetadataCache",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"trackReference",
")",
")",
";",
"if",
"(",
"cache",
"!=",
"null",
")",
"{",
"return",
"cache",
".",
"getWaveformPreview",
"(",
"null",
",",
"trackReference",
")",
";",
"}",
"// Then see if any registered metadata providers can offer it for us.",
"final",
"MediaDetails",
"sourceDetails",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMediaDetailsFor",
"(",
"trackReference",
".",
"getSlotReference",
"(",
")",
")",
";",
"if",
"(",
"sourceDetails",
"!=",
"null",
")",
"{",
"final",
"WaveformPreview",
"provided",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"allMetadataProviders",
".",
"getWaveformPreview",
"(",
"sourceDetails",
",",
"trackReference",
")",
";",
"if",
"(",
"provided",
"!=",
"null",
")",
"{",
"return",
"provided",
";",
"}",
"}",
"// At this point, unless we are allowed to actively request the data, we are done. We can always actively",
"// request tracks from rekordbox.",
"if",
"(",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"isPassive",
"(",
")",
"&&",
"failIfPassive",
"&&",
"trackReference",
".",
"slot",
"!=",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"COLLECTION",
")",
"{",
"return",
"null",
";",
"}",
"// We have to actually request the preview using the dbserver protocol.",
"ConnectionManager",
".",
"ClientTask",
"<",
"WaveformPreview",
">",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"WaveformPreview",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"WaveformPreview",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"return",
"getWaveformPreview",
"(",
"trackReference",
".",
"rekordboxId",
",",
"SlotReference",
".",
"getSlotReference",
"(",
"trackReference",
")",
",",
"client",
")",
";",
"}",
"}",
";",
"try",
"{",
"return",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"trackReference",
".",
"player",
",",
"task",
",",
"\"requesting waveform preview\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem requesting waveform preview, returning null\"",
",",
"e",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Ask the specified player for the waveform preview in the specified slot with the specified rekordbox ID,
using cached media instead if it is available, and possibly giving up if we are in passive mode.
@param trackReference uniquely identifies the desired waveform preview
@param failIfPassive will prevent the request from taking place if we are in passive mode, so that automatic
waveform updates will use available caches only
@return the waveform preview found, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"waveform",
"preview",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"using",
"cached",
"media",
"instead",
"if",
"it",
"is",
"available",
"and",
"possibly",
"giving",
"up",
"if",
"we",
"are",
"in",
"passive",
"mode",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L410-L447 |
163,919 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.requestWaveformPreviewFrom | public WaveformPreview requestWaveformPreviewFrom(final DataReference dataReference) {
ensureRunning();
for (WaveformPreview cached : previewHotCache.values()) {
if (cached.dataReference.equals(dataReference)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestPreviewInternal(dataReference, false);
} | java | public WaveformPreview requestWaveformPreviewFrom(final DataReference dataReference) {
ensureRunning();
for (WaveformPreview cached : previewHotCache.values()) {
if (cached.dataReference.equals(dataReference)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestPreviewInternal(dataReference, false);
} | [
"public",
"WaveformPreview",
"requestWaveformPreviewFrom",
"(",
"final",
"DataReference",
"dataReference",
")",
"{",
"ensureRunning",
"(",
")",
";",
"for",
"(",
"WaveformPreview",
"cached",
":",
"previewHotCache",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"cached",
".",
"dataReference",
".",
"equals",
"(",
"dataReference",
")",
")",
"{",
"// Found a hot cue hit, use it.",
"return",
"cached",
";",
"}",
"}",
"return",
"requestPreviewInternal",
"(",
"dataReference",
",",
"false",
")",
";",
"}"
] | Ask the specified player for the specified waveform preview from the specified media slot, first checking if we
have a cached copy.
@param dataReference uniquely identifies the desired waveform preview
@return the preview, if it was found, or {@code null}
@throws IllegalStateException if the WaveformFinder is not running | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"specified",
"waveform",
"preview",
"from",
"the",
"specified",
"media",
"slot",
"first",
"checking",
"if",
"we",
"have",
"a",
"cached",
"copy",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L459-L467 |
163,920 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.getWaveformPreview | WaveformPreview getWaveformPreview(int rekordboxId, SlotReference slot, Client client)
throws IOException {
final NumberField idField = new NumberField(rekordboxId);
// First try to get the NXS2-style color waveform if we are supposed to.
if (preferColor.get()) {
try {
Message response = client.simpleRequest(Message.KnownType.ANLZ_TAG_REQ, Message.KnownType.ANLZ_TAG,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField,
new NumberField(Message.ANLZ_FILE_TAG_COLOR_WAVEFORM_PREVIEW), new NumberField(Message.ALNZ_FILE_TYPE_EXT));
return new WaveformPreview(new DataReference(slot, rekordboxId), response);
} catch (Exception e) {
logger.info("No color waveform preview available for slot " + slot + ", id " + rekordboxId + "; requesting blue version.", e);
}
}
Message response = client.simpleRequest(Message.KnownType.WAVE_PREVIEW_REQ, Message.KnownType.WAVE_PREVIEW,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot), NumberField.WORD_1,
idField, NumberField.WORD_0);
return new WaveformPreview(new DataReference(slot, rekordboxId), response);
} | java | WaveformPreview getWaveformPreview(int rekordboxId, SlotReference slot, Client client)
throws IOException {
final NumberField idField = new NumberField(rekordboxId);
// First try to get the NXS2-style color waveform if we are supposed to.
if (preferColor.get()) {
try {
Message response = client.simpleRequest(Message.KnownType.ANLZ_TAG_REQ, Message.KnownType.ANLZ_TAG,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField,
new NumberField(Message.ANLZ_FILE_TAG_COLOR_WAVEFORM_PREVIEW), new NumberField(Message.ALNZ_FILE_TYPE_EXT));
return new WaveformPreview(new DataReference(slot, rekordboxId), response);
} catch (Exception e) {
logger.info("No color waveform preview available for slot " + slot + ", id " + rekordboxId + "; requesting blue version.", e);
}
}
Message response = client.simpleRequest(Message.KnownType.WAVE_PREVIEW_REQ, Message.KnownType.WAVE_PREVIEW,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot), NumberField.WORD_1,
idField, NumberField.WORD_0);
return new WaveformPreview(new DataReference(slot, rekordboxId), response);
} | [
"WaveformPreview",
"getWaveformPreview",
"(",
"int",
"rekordboxId",
",",
"SlotReference",
"slot",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"final",
"NumberField",
"idField",
"=",
"new",
"NumberField",
"(",
"rekordboxId",
")",
";",
"// First try to get the NXS2-style color waveform if we are supposed to.",
"if",
"(",
"preferColor",
".",
"get",
"(",
")",
")",
"{",
"try",
"{",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"ANLZ_TAG_REQ",
",",
"Message",
".",
"KnownType",
".",
"ANLZ_TAG",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
".",
"slot",
")",
",",
"idField",
",",
"new",
"NumberField",
"(",
"Message",
".",
"ANLZ_FILE_TAG_COLOR_WAVEFORM_PREVIEW",
")",
",",
"new",
"NumberField",
"(",
"Message",
".",
"ALNZ_FILE_TYPE_EXT",
")",
")",
";",
"return",
"new",
"WaveformPreview",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"rekordboxId",
")",
",",
"response",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"info",
"(",
"\"No color waveform preview available for slot \"",
"+",
"slot",
"+",
"\", id \"",
"+",
"rekordboxId",
"+",
"\"; requesting blue version.\"",
",",
"e",
")",
";",
"}",
"}",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"WAVE_PREVIEW_REQ",
",",
"Message",
".",
"KnownType",
".",
"WAVE_PREVIEW",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"DATA",
",",
"slot",
".",
"slot",
")",
",",
"NumberField",
".",
"WORD_1",
",",
"idField",
",",
"NumberField",
".",
"WORD_0",
")",
";",
"return",
"new",
"WaveformPreview",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"rekordboxId",
")",
",",
"response",
")",
";",
"}"
] | Requests the waveform preview for a specific track ID, given a connection to a player that has already been
set up.
@param rekordboxId the track whose waveform preview is desired
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved waveform preview, or {@code null} if none was available
@throws IOException if there is a communication problem | [
"Requests",
"the",
"waveform",
"preview",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L480-L502 |
163,921 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.requestWaveformDetailFrom | public WaveformDetail requestWaveformDetailFrom(final DataReference dataReference) {
ensureRunning();
for (WaveformDetail cached : detailHotCache.values()) {
if (cached.dataReference.equals(dataReference)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestDetailInternal(dataReference, false);
} | java | public WaveformDetail requestWaveformDetailFrom(final DataReference dataReference) {
ensureRunning();
for (WaveformDetail cached : detailHotCache.values()) {
if (cached.dataReference.equals(dataReference)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestDetailInternal(dataReference, false);
} | [
"public",
"WaveformDetail",
"requestWaveformDetailFrom",
"(",
"final",
"DataReference",
"dataReference",
")",
"{",
"ensureRunning",
"(",
")",
";",
"for",
"(",
"WaveformDetail",
"cached",
":",
"detailHotCache",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"cached",
".",
"dataReference",
".",
"equals",
"(",
"dataReference",
")",
")",
"{",
"// Found a hot cue hit, use it.",
"return",
"cached",
";",
"}",
"}",
"return",
"requestDetailInternal",
"(",
"dataReference",
",",
"false",
")",
";",
"}"
] | Ask the specified player for the specified waveform detail from the specified media slot, first checking if we
have a cached copy.
@param dataReference uniquely identifies the desired waveform detail
@return the waveform detail, if it was found, or {@code null}
@throws IllegalStateException if the WaveformFinder is not running | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"specified",
"waveform",
"detail",
"from",
"the",
"specified",
"media",
"slot",
"first",
"checking",
"if",
"we",
"have",
"a",
"cached",
"copy",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L563-L571 |
163,922 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.getWaveformDetail | WaveformDetail getWaveformDetail(int rekordboxId, SlotReference slot, Client client)
throws IOException {
final NumberField idField = new NumberField(rekordboxId);
// First try to get the NXS2-style color waveform if we are supposed to.
if (preferColor.get()) {
try {
Message response = client.simpleRequest(Message.KnownType.ANLZ_TAG_REQ, Message.KnownType.ANLZ_TAG,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField,
new NumberField(Message.ANLZ_FILE_TAG_COLOR_WAVEFORM_DETAIL), new NumberField(Message.ALNZ_FILE_TYPE_EXT));
return new WaveformDetail(new DataReference(slot, rekordboxId), response);
} catch (Exception e) {
logger.info("No color waveform available for slot " + slot + ", id " + rekordboxId + "; requesting blue version.", e);
}
}
Message response = client.simpleRequest(Message.KnownType.WAVE_DETAIL_REQ, Message.KnownType.WAVE_DETAIL,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField, NumberField.WORD_0);
return new WaveformDetail(new DataReference(slot, rekordboxId), response);
} | java | WaveformDetail getWaveformDetail(int rekordboxId, SlotReference slot, Client client)
throws IOException {
final NumberField idField = new NumberField(rekordboxId);
// First try to get the NXS2-style color waveform if we are supposed to.
if (preferColor.get()) {
try {
Message response = client.simpleRequest(Message.KnownType.ANLZ_TAG_REQ, Message.KnownType.ANLZ_TAG,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField,
new NumberField(Message.ANLZ_FILE_TAG_COLOR_WAVEFORM_DETAIL), new NumberField(Message.ALNZ_FILE_TYPE_EXT));
return new WaveformDetail(new DataReference(slot, rekordboxId), response);
} catch (Exception e) {
logger.info("No color waveform available for slot " + slot + ", id " + rekordboxId + "; requesting blue version.", e);
}
}
Message response = client.simpleRequest(Message.KnownType.WAVE_DETAIL_REQ, Message.KnownType.WAVE_DETAIL,
client.buildRMST(Message.MenuIdentifier.MAIN_MENU, slot.slot), idField, NumberField.WORD_0);
return new WaveformDetail(new DataReference(slot, rekordboxId), response);
} | [
"WaveformDetail",
"getWaveformDetail",
"(",
"int",
"rekordboxId",
",",
"SlotReference",
"slot",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"final",
"NumberField",
"idField",
"=",
"new",
"NumberField",
"(",
"rekordboxId",
")",
";",
"// First try to get the NXS2-style color waveform if we are supposed to.",
"if",
"(",
"preferColor",
".",
"get",
"(",
")",
")",
"{",
"try",
"{",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"ANLZ_TAG_REQ",
",",
"Message",
".",
"KnownType",
".",
"ANLZ_TAG",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
".",
"slot",
")",
",",
"idField",
",",
"new",
"NumberField",
"(",
"Message",
".",
"ANLZ_FILE_TAG_COLOR_WAVEFORM_DETAIL",
")",
",",
"new",
"NumberField",
"(",
"Message",
".",
"ALNZ_FILE_TYPE_EXT",
")",
")",
";",
"return",
"new",
"WaveformDetail",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"rekordboxId",
")",
",",
"response",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"info",
"(",
"\"No color waveform available for slot \"",
"+",
"slot",
"+",
"\", id \"",
"+",
"rekordboxId",
"+",
"\"; requesting blue version.\"",
",",
"e",
")",
";",
"}",
"}",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"WAVE_DETAIL_REQ",
",",
"Message",
".",
"KnownType",
".",
"WAVE_DETAIL",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
".",
"slot",
")",
",",
"idField",
",",
"NumberField",
".",
"WORD_0",
")",
";",
"return",
"new",
"WaveformDetail",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"rekordboxId",
")",
",",
"response",
")",
";",
"}"
] | Requests the waveform detail for a specific track ID, given a connection to a player that has already been
set up.
@param rekordboxId the track whose waveform detail is desired
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved waveform detail, or {@code null} if none was available
@throws IOException if there is a communication problem | [
"Requests",
"the",
"waveform",
"detail",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L584-L603 |
163,923 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.deliverWaveformPreviewUpdate | private void deliverWaveformPreviewUpdate(final int player, final WaveformPreview preview) {
final Set<WaveformListener> listeners = getWaveformListeners();
if (!listeners.isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final WaveformPreviewUpdate update = new WaveformPreviewUpdate(player, preview);
for (final WaveformListener listener : listeners) {
try {
listener.previewChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering waveform preview update to listener", t);
}
}
}
});
}
} | java | private void deliverWaveformPreviewUpdate(final int player, final WaveformPreview preview) {
final Set<WaveformListener> listeners = getWaveformListeners();
if (!listeners.isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final WaveformPreviewUpdate update = new WaveformPreviewUpdate(player, preview);
for (final WaveformListener listener : listeners) {
try {
listener.previewChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering waveform preview update to listener", t);
}
}
}
});
}
} | [
"private",
"void",
"deliverWaveformPreviewUpdate",
"(",
"final",
"int",
"player",
",",
"final",
"WaveformPreview",
"preview",
")",
"{",
"final",
"Set",
"<",
"WaveformListener",
">",
"listeners",
"=",
"getWaveformListeners",
"(",
")",
";",
"if",
"(",
"!",
"listeners",
".",
"isEmpty",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"final",
"WaveformPreviewUpdate",
"update",
"=",
"new",
"WaveformPreviewUpdate",
"(",
"player",
",",
"preview",
")",
";",
"for",
"(",
"final",
"WaveformListener",
"listener",
":",
"listeners",
")",
"{",
"try",
"{",
"listener",
".",
"previewChanged",
"(",
"update",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering waveform preview update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Send a waveform preview update announcement to all registered listeners.
@param player the player whose waveform preview has changed
@param preview the new waveform preview, if any | [
"Send",
"a",
"waveform",
"preview",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L671-L689 |
163,924 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.deliverWaveformDetailUpdate | private void deliverWaveformDetailUpdate(final int player, final WaveformDetail detail) {
if (!getWaveformListeners().isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final WaveformDetailUpdate update = new WaveformDetailUpdate(player, detail);
for (final WaveformListener listener : getWaveformListeners()) {
try {
listener.detailChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering waveform detail update to listener", t);
}
}
}
});
}
} | java | private void deliverWaveformDetailUpdate(final int player, final WaveformDetail detail) {
if (!getWaveformListeners().isEmpty()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final WaveformDetailUpdate update = new WaveformDetailUpdate(player, detail);
for (final WaveformListener listener : getWaveformListeners()) {
try {
listener.detailChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering waveform detail update to listener", t);
}
}
}
});
}
} | [
"private",
"void",
"deliverWaveformDetailUpdate",
"(",
"final",
"int",
"player",
",",
"final",
"WaveformDetail",
"detail",
")",
"{",
"if",
"(",
"!",
"getWaveformListeners",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"final",
"WaveformDetailUpdate",
"update",
"=",
"new",
"WaveformDetailUpdate",
"(",
"player",
",",
"detail",
")",
";",
"for",
"(",
"final",
"WaveformListener",
"listener",
":",
"getWaveformListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"detailChanged",
"(",
"update",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering waveform detail update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Send a waveform detail update announcement to all registered listeners.
@param player the player whose waveform detail has changed
@param detail the new waveform detail, if any | [
"Send",
"a",
"waveform",
"detail",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L697-L714 |
163,925 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.primeCache | private void primeCache() {
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
handleUpdate(new TrackMetadataUpdate(entry.getKey().player, entry.getValue()));
}
}
}
});
} | java | private void primeCache() {
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
handleUpdate(new TrackMetadataUpdate(entry.getKey().player, entry.getValue()));
}
}
}
});
} | [
"private",
"void",
"primeCache",
"(",
")",
"{",
"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",
"handleUpdate",
"(",
"new",
"TrackMetadataUpdate",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"player",
",",
"entry",
".",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
] | Send ourselves "updates" about any tracks that were loaded before we started, or before we were requesting
details, since we missed them. | [
"Send",
"ourselves",
"updates",
"about",
"any",
"tracks",
"that",
"were",
"loaded",
"before",
"we",
"started",
"or",
"before",
"we",
"were",
"requesting",
"details",
"since",
"we",
"missed",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L823-L834 |
163,926 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java | WaveformFinder.stop | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our waveforms, on the proper thread, outside our lock
final Set<DeckReference> dyingPreviewCache = new HashSet<DeckReference>(previewHotCache.keySet());
previewHotCache.clear();
final Set<DeckReference> dyingDetailCache = new HashSet<DeckReference>(detailHotCache.keySet());
detailHotCache.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingPreviewCache) { // Report the loss of our previews.
if (deck.hotCue == 0) {
deliverWaveformPreviewUpdate(deck.player, null);
}
}
for (DeckReference deck : dyingDetailCache) { // Report the loss of our details.
if (deck.hotCue == 0) {
deliverWaveformDetailUpdate(deck.player, null);
}
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | java | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our waveforms, on the proper thread, outside our lock
final Set<DeckReference> dyingPreviewCache = new HashSet<DeckReference>(previewHotCache.keySet());
previewHotCache.clear();
final Set<DeckReference> dyingDetailCache = new HashSet<DeckReference>(detailHotCache.keySet());
detailHotCache.clear();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingPreviewCache) { // Report the loss of our previews.
if (deck.hotCue == 0) {
deliverWaveformPreviewUpdate(deck.player, null);
}
}
for (DeckReference deck : dyingDetailCache) { // Report the loss of our details.
if (deck.hotCue == 0) {
deliverWaveformDetailUpdate(deck.player, null);
}
}
}
});
deliverLifecycleAnnouncement(logger, false);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"removeTrackMetadataListener",
"(",
"metadataListener",
")",
";",
"running",
".",
"set",
"(",
"false",
")",
";",
"pendingUpdates",
".",
"clear",
"(",
")",
";",
"queueHandler",
".",
"interrupt",
"(",
")",
";",
"queueHandler",
"=",
"null",
";",
"// Report the loss of our waveforms, on the proper thread, outside our lock",
"final",
"Set",
"<",
"DeckReference",
">",
"dyingPreviewCache",
"=",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"previewHotCache",
".",
"keySet",
"(",
")",
")",
";",
"previewHotCache",
".",
"clear",
"(",
")",
";",
"final",
"Set",
"<",
"DeckReference",
">",
"dyingDetailCache",
"=",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"detailHotCache",
".",
"keySet",
"(",
")",
")",
";",
"detailHotCache",
".",
"clear",
"(",
")",
";",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"DeckReference",
"deck",
":",
"dyingPreviewCache",
")",
"{",
"// Report the loss of our previews.",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverWaveformPreviewUpdate",
"(",
"deck",
".",
"player",
",",
"null",
")",
";",
"}",
"}",
"for",
"(",
"DeckReference",
"deck",
":",
"dyingDetailCache",
")",
"{",
"// Report the loss of our details.",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverWaveformDetailUpdate",
"(",
"deck",
".",
"player",
",",
"null",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | Stop finding waveforms for all active players. | [
"Stop",
"finding",
"waveforms",
"for",
"all",
"active",
"players",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L877-L908 |
163,927 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.clearArt | private void clearArt(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverAlbumArtUpdate(player, null); // Inform listeners that the artwork is gone.
}
}
}
// Again iterate over a copy to avoid concurrent modification issues
for (DataReference art : new HashSet<DataReference>(artCache.keySet())) {
if (art.player == player) {
artCache.remove(art);
}
}
} | java | private void clearArt(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverAlbumArtUpdate(player, null); // Inform listeners that the artwork is gone.
}
}
}
// Again iterate over a copy to avoid concurrent modification issues
for (DataReference art : new HashSet<DataReference>(artCache.keySet())) {
if (art.player == player) {
artCache.remove(art);
}
}
} | [
"private",
"void",
"clearArt",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"final",
"int",
"player",
"=",
"announcement",
".",
"getNumber",
"(",
")",
";",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
":",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"hotCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"deck",
".",
"player",
"==",
"player",
")",
"{",
"hotCache",
".",
"remove",
"(",
"deck",
")",
";",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverAlbumArtUpdate",
"(",
"player",
",",
"null",
")",
";",
"// Inform listeners that the artwork is gone.",
"}",
"}",
"}",
"// Again iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DataReference",
"art",
":",
"new",
"HashSet",
"<",
"DataReference",
">",
"(",
"artCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"art",
".",
"player",
"==",
"player",
")",
"{",
"artCache",
".",
"remove",
"(",
"art",
")",
";",
"}",
"}",
"}"
] | We have received notification that a device is no longer on the network, so clear out its artwork.
@param announcement the packet which reported the device’s disappearance | [
"We",
"have",
"received",
"notification",
"that",
"a",
"device",
"is",
"no",
"longer",
"on",
"the",
"network",
"so",
"clear",
"out",
"its",
"artwork",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L152-L169 |
163,928 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.updateArt | private void updateArt(TrackMetadataUpdate update, AlbumArt art) {
hotCache.put(DeckReference.getDeckReference(update.player, 0), art); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), art);
}
}
}
deliverAlbumArtUpdate(update.player, art);
} | java | private void updateArt(TrackMetadataUpdate update, AlbumArt art) {
hotCache.put(DeckReference.getDeckReference(update.player, 0), art); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), art);
}
}
}
deliverAlbumArtUpdate(update.player, art);
} | [
"private",
"void",
"updateArt",
"(",
"TrackMetadataUpdate",
"update",
",",
"AlbumArt",
"art",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
",",
"art",
")",
";",
"// Main deck",
"if",
"(",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
"!=",
"null",
")",
"{",
"// Update the cache with any hot cues in this track as well",
"for",
"(",
"CueList",
".",
"Entry",
"entry",
":",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
".",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
"!=",
"0",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"entry",
".",
"hotCueNumber",
")",
",",
"art",
")",
";",
"}",
"}",
"}",
"deliverAlbumArtUpdate",
"(",
"update",
".",
"player",
",",
"art",
")",
";",
"}"
] | We have obtained album art for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this art
@param art the album art which we retrieved | [
"We",
"have",
"obtained",
"album",
"art",
"for",
"a",
"device",
"so",
"store",
"it",
"and",
"alert",
"any",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L177-L187 |
163,929 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.getLoadedArt | public Map<DeckReference, AlbumArt> getLoadedArt() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, AlbumArt>(hotCache));
} | java | public Map<DeckReference, AlbumArt> getLoadedArt() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, AlbumArt>(hotCache));
} | [
"public",
"Map",
"<",
"DeckReference",
",",
"AlbumArt",
">",
"getLoadedArt",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"DeckReference",
",",
"AlbumArt",
">",
"(",
"hotCache",
")",
")",
";",
"}"
] | Get the art available for all tracks currently loaded in any player, either on the play deck, or in a hot cue.
@return the album art associated with all current players, including for any tracks loaded in their hot cue slots
@throws IllegalStateException if the ArtFinder is not running | [
"Get",
"the",
"art",
"available",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"either",
"on",
"the",
"play",
"deck",
"or",
"in",
"a",
"hot",
"cue",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L196-L200 |
163,930 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.requestArtworkInternal | private AlbumArt requestArtworkInternal(final DataReference artReference, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this slot.
MetadataCache cache = MetadataFinder.getInstance().getMetadataCache(SlotReference.getSlotReference(artReference));
if (cache != null) {
final AlbumArt result = cache.getAlbumArt(null, artReference);
if (result != null) {
artCache.put(artReference, result);
}
return result;
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = MetadataFinder.getInstance().getMediaDetailsFor(artReference.getSlotReference());
if (sourceDetails != null) {
final AlbumArt provided = MetadataFinder.getInstance().allMetadataProviders.getAlbumArt(sourceDetails, artReference);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (MetadataFinder.getInstance().isPassive() && failIfPassive && artReference.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// We have to actually request the art using the dbserver protocol.
ConnectionManager.ClientTask<AlbumArt> task = new ConnectionManager.ClientTask<AlbumArt>() {
@Override
public AlbumArt useClient(Client client) throws Exception {
return getArtwork(artReference.rekordboxId, SlotReference.getSlotReference(artReference), trackType, client);
}
};
try {
AlbumArt artwork = ConnectionManager.getInstance().invokeWithClientSession(artReference.player, task, "requesting artwork");
if (artwork != null) { // Our cache file load or network request succeeded, so add to the level 2 cache.
artCache.put(artReference, artwork);
}
return artwork;
} catch (Exception e) {
logger.error("Problem requesting album art, returning null", e);
}
return null;
} | java | private AlbumArt requestArtworkInternal(final DataReference artReference, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this slot.
MetadataCache cache = MetadataFinder.getInstance().getMetadataCache(SlotReference.getSlotReference(artReference));
if (cache != null) {
final AlbumArt result = cache.getAlbumArt(null, artReference);
if (result != null) {
artCache.put(artReference, result);
}
return result;
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = MetadataFinder.getInstance().getMediaDetailsFor(artReference.getSlotReference());
if (sourceDetails != null) {
final AlbumArt provided = MetadataFinder.getInstance().allMetadataProviders.getAlbumArt(sourceDetails, artReference);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (MetadataFinder.getInstance().isPassive() && failIfPassive && artReference.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// We have to actually request the art using the dbserver protocol.
ConnectionManager.ClientTask<AlbumArt> task = new ConnectionManager.ClientTask<AlbumArt>() {
@Override
public AlbumArt useClient(Client client) throws Exception {
return getArtwork(artReference.rekordboxId, SlotReference.getSlotReference(artReference), trackType, client);
}
};
try {
AlbumArt artwork = ConnectionManager.getInstance().invokeWithClientSession(artReference.player, task, "requesting artwork");
if (artwork != null) { // Our cache file load or network request succeeded, so add to the level 2 cache.
artCache.put(artReference, artwork);
}
return artwork;
} catch (Exception e) {
logger.error("Problem requesting album art, returning null", e);
}
return null;
} | [
"private",
"AlbumArt",
"requestArtworkInternal",
"(",
"final",
"DataReference",
"artReference",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"final",
"boolean",
"failIfPassive",
")",
"{",
"// First check if we are using cached data for this slot.",
"MetadataCache",
"cache",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMetadataCache",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"artReference",
")",
")",
";",
"if",
"(",
"cache",
"!=",
"null",
")",
"{",
"final",
"AlbumArt",
"result",
"=",
"cache",
".",
"getAlbumArt",
"(",
"null",
",",
"artReference",
")",
";",
"if",
"(",
"result",
"!=",
"null",
")",
"{",
"artCache",
".",
"put",
"(",
"artReference",
",",
"result",
")",
";",
"}",
"return",
"result",
";",
"}",
"// Then see if any registered metadata providers can offer it for us.",
"final",
"MediaDetails",
"sourceDetails",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMediaDetailsFor",
"(",
"artReference",
".",
"getSlotReference",
"(",
")",
")",
";",
"if",
"(",
"sourceDetails",
"!=",
"null",
")",
"{",
"final",
"AlbumArt",
"provided",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"allMetadataProviders",
".",
"getAlbumArt",
"(",
"sourceDetails",
",",
"artReference",
")",
";",
"if",
"(",
"provided",
"!=",
"null",
")",
"{",
"return",
"provided",
";",
"}",
"}",
"// At this point, unless we are allowed to actively request the data, we are done. We can always actively",
"// request tracks from rekordbox.",
"if",
"(",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"isPassive",
"(",
")",
"&&",
"failIfPassive",
"&&",
"artReference",
".",
"slot",
"!=",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"COLLECTION",
")",
"{",
"return",
"null",
";",
"}",
"// We have to actually request the art using the dbserver protocol.",
"ConnectionManager",
".",
"ClientTask",
"<",
"AlbumArt",
">",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"AlbumArt",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"AlbumArt",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"return",
"getArtwork",
"(",
"artReference",
".",
"rekordboxId",
",",
"SlotReference",
".",
"getSlotReference",
"(",
"artReference",
")",
",",
"trackType",
",",
"client",
")",
";",
"}",
"}",
";",
"try",
"{",
"AlbumArt",
"artwork",
"=",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"artReference",
".",
"player",
",",
"task",
",",
"\"requesting artwork\"",
")",
";",
"if",
"(",
"artwork",
"!=",
"null",
")",
"{",
"// Our cache file load or network request succeeded, so add to the level 2 cache.",
"artCache",
".",
"put",
"(",
"artReference",
",",
"artwork",
")",
";",
"}",
"return",
"artwork",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem requesting album art, returning null\"",
",",
"e",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Ask the specified player for the album art in the specified slot with the specified rekordbox ID,
using cached media instead if it is available, and possibly giving up if we are in passive mode.
@param artReference uniquely identifies the desired album art
@param trackType the kind of track that owns the art
@param failIfPassive will prevent the request from taking place if we are in passive mode, so that automatic
artwork updates will use available caches only
@return the album art found, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"album",
"art",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"using",
"cached",
"media",
"instead",
"if",
"it",
"is",
"available",
"and",
"possibly",
"giving",
"up",
"if",
"we",
"are",
"in",
"passive",
"mode",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L280-L326 |
163,931 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.requestArtworkFrom | public AlbumArt requestArtworkFrom(final DataReference artReference, final CdjStatus.TrackType trackType) {
ensureRunning();
AlbumArt artwork = findArtInMemoryCaches(artReference); // First check the in-memory artwork caches.
if (artwork == null) {
artwork = requestArtworkInternal(artReference, trackType, false);
}
return artwork;
} | java | public AlbumArt requestArtworkFrom(final DataReference artReference, final CdjStatus.TrackType trackType) {
ensureRunning();
AlbumArt artwork = findArtInMemoryCaches(artReference); // First check the in-memory artwork caches.
if (artwork == null) {
artwork = requestArtworkInternal(artReference, trackType, false);
}
return artwork;
} | [
"public",
"AlbumArt",
"requestArtworkFrom",
"(",
"final",
"DataReference",
"artReference",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
")",
"{",
"ensureRunning",
"(",
")",
";",
"AlbumArt",
"artwork",
"=",
"findArtInMemoryCaches",
"(",
"artReference",
")",
";",
"// First check the in-memory artwork caches.",
"if",
"(",
"artwork",
"==",
"null",
")",
"{",
"artwork",
"=",
"requestArtworkInternal",
"(",
"artReference",
",",
"trackType",
",",
"false",
")",
";",
"}",
"return",
"artwork",
";",
"}"
] | Ask the specified player for the specified artwork from the specified media slot, first checking if we have a
cached copy.
@param artReference uniquely identifies the desired artwork
@param trackType the kind of track that owns the artwork
@return the artwork, if it was found, or {@code null}
@throws IllegalStateException if the ArtFinder is not running | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"specified",
"artwork",
"from",
"the",
"specified",
"media",
"slot",
"first",
"checking",
"if",
"we",
"have",
"a",
"cached",
"copy",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L339-L346 |
163,932 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.getArtwork | AlbumArt getArtwork(int artworkId, SlotReference slot, CdjStatus.TrackType trackType, Client client)
throws IOException {
// Send the artwork request
Message response = client.simpleRequest(Message.KnownType.ALBUM_ART_REQ, Message.KnownType.ALBUM_ART,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot, trackType), new NumberField((long)artworkId));
// Create an image from the response bytes
return new AlbumArt(new DataReference(slot, artworkId), ((BinaryField)response.arguments.get(3)).getValue());
} | java | AlbumArt getArtwork(int artworkId, SlotReference slot, CdjStatus.TrackType trackType, Client client)
throws IOException {
// Send the artwork request
Message response = client.simpleRequest(Message.KnownType.ALBUM_ART_REQ, Message.KnownType.ALBUM_ART,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot, trackType), new NumberField((long)artworkId));
// Create an image from the response bytes
return new AlbumArt(new DataReference(slot, artworkId), ((BinaryField)response.arguments.get(3)).getValue());
} | [
"AlbumArt",
"getArtwork",
"(",
"int",
"artworkId",
",",
"SlotReference",
"slot",
",",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"// Send the artwork request",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"ALBUM_ART_REQ",
",",
"Message",
".",
"KnownType",
".",
"ALBUM_ART",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"DATA",
",",
"slot",
".",
"slot",
",",
"trackType",
")",
",",
"new",
"NumberField",
"(",
"(",
"long",
")",
"artworkId",
")",
")",
";",
"// Create an image from the response bytes",
"return",
"new",
"AlbumArt",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"artworkId",
")",
",",
"(",
"(",
"BinaryField",
")",
"response",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
")",
";",
"}"
] | Request the artwork with a particular artwork ID, given a connection to a player that has already been set up.
@param artworkId identifies the album art to retrieve
@param slot the slot identifier from which the associated track was loaded
@param trackType the kind of track that owns the artwork
@param client the dbserver client that is communicating with the appropriate player
@return the track's artwork, or null if none is available
@throws IOException if there is a problem communicating with the player | [
"Request",
"the",
"artwork",
"with",
"a",
"particular",
"artwork",
"ID",
"given",
"a",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L360-L369 |
163,933 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.findArtInMemoryCaches | private AlbumArt findArtInMemoryCaches(DataReference artReference) {
// First see if we can find the new track in the hot cache as a hot cue
for (AlbumArt cached : hotCache.values()) {
if (cached.artReference.equals(artReference)) { // Found a hot cue hit, use it.
return cached;
}
}
// Not in the hot cache, see if it is in our LRU cache
return artCache.get(artReference);
} | java | private AlbumArt findArtInMemoryCaches(DataReference artReference) {
// First see if we can find the new track in the hot cache as a hot cue
for (AlbumArt cached : hotCache.values()) {
if (cached.artReference.equals(artReference)) { // Found a hot cue hit, use it.
return cached;
}
}
// Not in the hot cache, see if it is in our LRU cache
return artCache.get(artReference);
} | [
"private",
"AlbumArt",
"findArtInMemoryCaches",
"(",
"DataReference",
"artReference",
")",
"{",
"// First see if we can find the new track in the hot cache as a hot cue",
"for",
"(",
"AlbumArt",
"cached",
":",
"hotCache",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"cached",
".",
"artReference",
".",
"equals",
"(",
"artReference",
")",
")",
"{",
"// Found a hot cue hit, use it.",
"return",
"cached",
";",
"}",
"}",
"// Not in the hot cache, see if it is in our LRU cache",
"return",
"artCache",
".",
"get",
"(",
"artReference",
")",
";",
"}"
] | Look for the specified album art in both the hot cache of loaded tracks and the longer-lived LRU cache.
@param artReference uniquely identifies the desired album art
@return the art, if it was found in one of our caches, or {@code null} | [
"Look",
"for",
"the",
"specified",
"album",
"art",
"in",
"both",
"the",
"hot",
"cache",
"of",
"loaded",
"tracks",
"and",
"the",
"longer",
"-",
"lived",
"LRU",
"cache",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L383-L393 |
163,934 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java | ArtFinder.deliverAlbumArtUpdate | private void deliverAlbumArtUpdate(int player, AlbumArt art) {
if (!getAlbumArtListeners().isEmpty()) {
final AlbumArtUpdate update = new AlbumArtUpdate(player, art);
for (final AlbumArtListener listener : getAlbumArtListeners()) {
try {
listener.albumArtChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering album art update to listener", t);
}
}
}
} | java | private void deliverAlbumArtUpdate(int player, AlbumArt art) {
if (!getAlbumArtListeners().isEmpty()) {
final AlbumArtUpdate update = new AlbumArtUpdate(player, art);
for (final AlbumArtListener listener : getAlbumArtListeners()) {
try {
listener.albumArtChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering album art update to listener", t);
}
}
}
} | [
"private",
"void",
"deliverAlbumArtUpdate",
"(",
"int",
"player",
",",
"AlbumArt",
"art",
")",
"{",
"if",
"(",
"!",
"getAlbumArtListeners",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"AlbumArtUpdate",
"update",
"=",
"new",
"AlbumArtUpdate",
"(",
"player",
",",
"art",
")",
";",
"for",
"(",
"final",
"AlbumArtListener",
"listener",
":",
"getAlbumArtListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"albumArtChanged",
"(",
"update",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering album art update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}"
] | Send an album art update announcement to all registered listeners. | [
"Send",
"an",
"album",
"art",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L450-L462 |
163,935 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/AlbumArt.java | AlbumArt.getImage | public BufferedImage getImage() {
ByteBuffer artwork = getRawBytes();
artwork.rewind();
byte[] imageBytes = new byte[artwork.remaining()];
artwork.get(imageBytes);
try {
return ImageIO.read(new ByteArrayInputStream(imageBytes));
} catch (IOException e) {
logger.error("Weird! Caught exception creating image from artwork bytes", e);
return null;
}
} | java | public BufferedImage getImage() {
ByteBuffer artwork = getRawBytes();
artwork.rewind();
byte[] imageBytes = new byte[artwork.remaining()];
artwork.get(imageBytes);
try {
return ImageIO.read(new ByteArrayInputStream(imageBytes));
} catch (IOException e) {
logger.error("Weird! Caught exception creating image from artwork bytes", e);
return null;
}
} | [
"public",
"BufferedImage",
"getImage",
"(",
")",
"{",
"ByteBuffer",
"artwork",
"=",
"getRawBytes",
"(",
")",
";",
"artwork",
".",
"rewind",
"(",
")",
";",
"byte",
"[",
"]",
"imageBytes",
"=",
"new",
"byte",
"[",
"artwork",
".",
"remaining",
"(",
")",
"]",
";",
"artwork",
".",
"get",
"(",
"imageBytes",
")",
";",
"try",
"{",
"return",
"ImageIO",
".",
"read",
"(",
"new",
"ByteArrayInputStream",
"(",
"imageBytes",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Weird! Caught exception creating image from artwork bytes\"",
",",
"e",
")",
";",
"return",
"null",
";",
"}",
"}"
] | Given the byte buffer containing album art, build an actual image from it for easy rendering.
@return the newly-created image, ready to be drawn | [
"Given",
"the",
"byte",
"buffer",
"containing",
"album",
"art",
"build",
"an",
"actual",
"image",
"from",
"it",
"for",
"easy",
"rendering",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/AlbumArt.java#L52-L63 |
163,936 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.findTrackSourceSlot | private TrackSourceSlot findTrackSourceSlot() {
TrackSourceSlot result = TRACK_SOURCE_SLOT_MAP.get(packetBytes[41]);
if (result == null) {
return TrackSourceSlot.UNKNOWN;
}
return result;
} | java | private TrackSourceSlot findTrackSourceSlot() {
TrackSourceSlot result = TRACK_SOURCE_SLOT_MAP.get(packetBytes[41]);
if (result == null) {
return TrackSourceSlot.UNKNOWN;
}
return result;
} | [
"private",
"TrackSourceSlot",
"findTrackSourceSlot",
"(",
")",
"{",
"TrackSourceSlot",
"result",
"=",
"TRACK_SOURCE_SLOT_MAP",
".",
"get",
"(",
"packetBytes",
"[",
"41",
"]",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"TrackSourceSlot",
".",
"UNKNOWN",
";",
"}",
"return",
"result",
";",
"}"
] | Determine the enum value corresponding to the track source slot found in the packet.
@return the proper value | [
"Determine",
"the",
"enum",
"value",
"corresponding",
"to",
"the",
"track",
"source",
"slot",
"found",
"in",
"the",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L489-L495 |
163,937 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.findTrackType | private TrackType findTrackType() {
TrackType result = TRACK_TYPE_MAP.get(packetBytes[42]);
if (result == null) {
return TrackType.UNKNOWN;
}
return result;
} | java | private TrackType findTrackType() {
TrackType result = TRACK_TYPE_MAP.get(packetBytes[42]);
if (result == null) {
return TrackType.UNKNOWN;
}
return result;
} | [
"private",
"TrackType",
"findTrackType",
"(",
")",
"{",
"TrackType",
"result",
"=",
"TRACK_TYPE_MAP",
".",
"get",
"(",
"packetBytes",
"[",
"42",
"]",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"TrackType",
".",
"UNKNOWN",
";",
"}",
"return",
"result",
";",
"}"
] | Determine the enum value corresponding to the track type found in the packet.
@return the proper value | [
"Determine",
"the",
"enum",
"value",
"corresponding",
"to",
"the",
"track",
"type",
"found",
"in",
"the",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L502-L508 |
163,938 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.findPlayState1 | private PlayState1 findPlayState1() {
PlayState1 result = PLAY_STATE_1_MAP.get(packetBytes[123]);
if (result == null) {
return PlayState1.UNKNOWN;
}
return result;
} | java | private PlayState1 findPlayState1() {
PlayState1 result = PLAY_STATE_1_MAP.get(packetBytes[123]);
if (result == null) {
return PlayState1.UNKNOWN;
}
return result;
} | [
"private",
"PlayState1",
"findPlayState1",
"(",
")",
"{",
"PlayState1",
"result",
"=",
"PLAY_STATE_1_MAP",
".",
"get",
"(",
"packetBytes",
"[",
"123",
"]",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"PlayState1",
".",
"UNKNOWN",
";",
"}",
"return",
"result",
";",
"}"
] | Determine the enum value corresponding to the first play state found in the packet.
@return the proper value | [
"Determine",
"the",
"enum",
"value",
"corresponding",
"to",
"the",
"first",
"play",
"state",
"found",
"in",
"the",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L515-L521 |
163,939 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.findPlayState3 | private PlayState3 findPlayState3() {
PlayState3 result = PLAY_STATE_3_MAP.get(packetBytes[157]);
if (result == null) {
return PlayState3.UNKNOWN;
}
return result;
} | java | private PlayState3 findPlayState3() {
PlayState3 result = PLAY_STATE_3_MAP.get(packetBytes[157]);
if (result == null) {
return PlayState3.UNKNOWN;
}
return result;
} | [
"private",
"PlayState3",
"findPlayState3",
"(",
")",
"{",
"PlayState3",
"result",
"=",
"PLAY_STATE_3_MAP",
".",
"get",
"(",
"packetBytes",
"[",
"157",
"]",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"PlayState3",
".",
"UNKNOWN",
";",
"}",
"return",
"result",
";",
"}"
] | Determine the enum value corresponding to the third play state found in the packet.
@return the proper value | [
"Determine",
"the",
"enum",
"value",
"corresponding",
"to",
"the",
"third",
"play",
"state",
"found",
"in",
"the",
"packet",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L550-L556 |
163,940 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.isPlaying | @SuppressWarnings("WeakerAccess")
public boolean isPlaying() {
if (packetBytes.length >= 212) {
return (packetBytes[STATUS_FLAGS] & PLAYING_FLAG) > 0;
} else {
final PlayState1 state = getPlayState1();
return state == PlayState1.PLAYING || state == PlayState1.LOOPING ||
(state == PlayState1.SEARCHING && getPlayState2() == PlayState2.MOVING);
}
} | java | @SuppressWarnings("WeakerAccess")
public boolean isPlaying() {
if (packetBytes.length >= 212) {
return (packetBytes[STATUS_FLAGS] & PLAYING_FLAG) > 0;
} else {
final PlayState1 state = getPlayState1();
return state == PlayState1.PLAYING || state == PlayState1.LOOPING ||
(state == PlayState1.SEARCHING && getPlayState2() == PlayState2.MOVING);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"boolean",
"isPlaying",
"(",
")",
"{",
"if",
"(",
"packetBytes",
".",
"length",
">=",
"212",
")",
"{",
"return",
"(",
"packetBytes",
"[",
"STATUS_FLAGS",
"]",
"&",
"PLAYING_FLAG",
")",
">",
"0",
";",
"}",
"else",
"{",
"final",
"PlayState1",
"state",
"=",
"getPlayState1",
"(",
")",
";",
"return",
"state",
"==",
"PlayState1",
".",
"PLAYING",
"||",
"state",
"==",
"PlayState1",
".",
"LOOPING",
"||",
"(",
"state",
"==",
"PlayState1",
".",
"SEARCHING",
"&&",
"getPlayState2",
"(",
")",
"==",
"PlayState2",
".",
"MOVING",
")",
";",
"}",
"}"
] | Was the CDJ playing a track when this update was sent?
@return true if the play flag was set, or, if this seems to be a non-nexus player, if <em>P<sub>1</sub></em>
has a value corresponding to a playing state. | [
"Was",
"the",
"CDJ",
"playing",
"a",
"track",
"when",
"this",
"update",
"was",
"sent?"
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L719-L728 |
163,941 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/CdjStatus.java | CdjStatus.formatCueCountdown | @SuppressWarnings("WeakerAccess")
public String formatCueCountdown() {
int count = getCueCountdown();
if (count == 511) {
return "--.-";
}
if ((count >= 1) && (count <= 256)) {
int bars = (count - 1) / 4;
int beats = ((count - 1) % 4) + 1;
return String.format("%02d.%d", bars, beats);
}
if (count == 0) {
return "00.0";
}
return "??.?";
} | java | @SuppressWarnings("WeakerAccess")
public String formatCueCountdown() {
int count = getCueCountdown();
if (count == 511) {
return "--.-";
}
if ((count >= 1) && (count <= 256)) {
int bars = (count - 1) / 4;
int beats = ((count - 1) % 4) + 1;
return String.format("%02d.%d", bars, beats);
}
if (count == 0) {
return "00.0";
}
return "??.?";
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"String",
"formatCueCountdown",
"(",
")",
"{",
"int",
"count",
"=",
"getCueCountdown",
"(",
")",
";",
"if",
"(",
"count",
"==",
"511",
")",
"{",
"return",
"\"--.-\"",
";",
"}",
"if",
"(",
"(",
"count",
">=",
"1",
")",
"&&",
"(",
"count",
"<=",
"256",
")",
")",
"{",
"int",
"bars",
"=",
"(",
"count",
"-",
"1",
")",
"/",
"4",
";",
"int",
"beats",
"=",
"(",
"(",
"count",
"-",
"1",
")",
"%",
"4",
")",
"+",
"1",
";",
"return",
"String",
".",
"format",
"(",
"\"%02d.%d\"",
",",
"bars",
",",
"beats",
")",
";",
"}",
"if",
"(",
"count",
"==",
"0",
")",
"{",
"return",
"\"00.0\"",
";",
"}",
"return",
"\"??.?\"",
";",
"}"
] | Format a cue countdown indicator in the same way as the CDJ would at this point in the track.
@return the value that the CDJ would display to indicate the distance to the next cue
@see #getCueCountdown() | [
"Format",
"a",
"cue",
"countdown",
"indicator",
"in",
"the",
"same",
"way",
"as",
"the",
"CDJ",
"would",
"at",
"this",
"point",
"in",
"the",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/CdjStatus.java#L1011-L1030 |
163,942 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.clearDeck | private void clearDeck(TrackMetadataUpdate update) {
if (hotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverBeatGridUpdate(update.player, null);
}
} | java | private void clearDeck(TrackMetadataUpdate update) {
if (hotCache.remove(DeckReference.getDeckReference(update.player, 0)) != null) {
deliverBeatGridUpdate(update.player, null);
}
} | [
"private",
"void",
"clearDeck",
"(",
"TrackMetadataUpdate",
"update",
")",
"{",
"if",
"(",
"hotCache",
".",
"remove",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
")",
"!=",
"null",
")",
"{",
"deliverBeatGridUpdate",
"(",
"update",
".",
"player",
",",
"null",
")",
";",
"}",
"}"
] | We have received an update that invalidates the beat grid for a player, so clear it and alert
any listeners if this represents a change. This does not affect the hot cues; they will stick around until the
player loads a new track that overwrites one or more of them.
@param update the update which means we have no beat grid for the associated player | [
"We",
"have",
"received",
"an",
"update",
"that",
"invalidates",
"the",
"beat",
"grid",
"for",
"a",
"player",
"so",
"clear",
"it",
"and",
"alert",
"any",
"listeners",
"if",
"this",
"represents",
"a",
"change",
".",
"This",
"does",
"not",
"affect",
"the",
"hot",
"cues",
";",
"they",
"will",
"stick",
"around",
"until",
"the",
"player",
"loads",
"a",
"new",
"track",
"that",
"overwrites",
"one",
"or",
"more",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L131-L135 |
163,943 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.clearBeatGrids | private void clearBeatGrids(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverBeatGridUpdate(player, null); // Inform listeners the beat grid is gone.
}
}
}
} | java | private void clearBeatGrids(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverBeatGridUpdate(player, null); // Inform listeners the beat grid is gone.
}
}
}
} | [
"private",
"void",
"clearBeatGrids",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"final",
"int",
"player",
"=",
"announcement",
".",
"getNumber",
"(",
")",
";",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
":",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"hotCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"deck",
".",
"player",
"==",
"player",
")",
"{",
"hotCache",
".",
"remove",
"(",
"deck",
")",
";",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverBeatGridUpdate",
"(",
"player",
",",
"null",
")",
";",
"// Inform listeners the beat grid is gone.",
"}",
"}",
"}",
"}"
] | We have received notification that a device is no longer on the network, so clear out all its beat grids.
@param announcement the packet which reported the device’s disappearance | [
"We",
"have",
"received",
"notification",
"that",
"a",
"device",
"is",
"no",
"longer",
"on",
"the",
"network",
"so",
"clear",
"out",
"all",
"its",
"beat",
"grids",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L142-L153 |
163,944 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.updateBeatGrid | private void updateBeatGrid(TrackMetadataUpdate update, BeatGrid beatGrid) {
hotCache.put(DeckReference.getDeckReference(update.player, 0), beatGrid); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), beatGrid);
}
}
}
deliverBeatGridUpdate(update.player, beatGrid);
} | java | private void updateBeatGrid(TrackMetadataUpdate update, BeatGrid beatGrid) {
hotCache.put(DeckReference.getDeckReference(update.player, 0), beatGrid); // Main deck
if (update.metadata.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : update.metadata.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.player, entry.hotCueNumber), beatGrid);
}
}
}
deliverBeatGridUpdate(update.player, beatGrid);
} | [
"private",
"void",
"updateBeatGrid",
"(",
"TrackMetadataUpdate",
"update",
",",
"BeatGrid",
"beatGrid",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"0",
")",
",",
"beatGrid",
")",
";",
"// Main deck",
"if",
"(",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
"!=",
"null",
")",
"{",
"// Update the cache with any hot cues in this track as well",
"for",
"(",
"CueList",
".",
"Entry",
"entry",
":",
"update",
".",
"metadata",
".",
"getCueList",
"(",
")",
".",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
"!=",
"0",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"player",
",",
"entry",
".",
"hotCueNumber",
")",
",",
"beatGrid",
")",
";",
"}",
"}",
"}",
"deliverBeatGridUpdate",
"(",
"update",
".",
"player",
",",
"beatGrid",
")",
";",
"}"
] | We have obtained a beat grid for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this beat grid
@param beatGrid the beat grid which we retrieved | [
"We",
"have",
"obtained",
"a",
"beat",
"grid",
"for",
"a",
"device",
"so",
"store",
"it",
"and",
"alert",
"any",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L161-L171 |
163,945 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.getLoadedBeatGrids | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, BeatGrid> getLoadedBeatGrids() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, BeatGrid>(hotCache));
} | java | @SuppressWarnings("WeakerAccess")
public Map<DeckReference, BeatGrid> getLoadedBeatGrids() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, BeatGrid>(hotCache));
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"Map",
"<",
"DeckReference",
",",
"BeatGrid",
">",
"getLoadedBeatGrids",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"DeckReference",
",",
"BeatGrid",
">",
"(",
"hotCache",
")",
")",
";",
"}"
] | Get the beat grids available for all tracks currently loaded in any player, either on the play deck, or
in a hot cue.
@return the beat grids associated with all current players, including for any tracks loaded in their hot cue slots
@throws IllegalStateException if the BeatGridFinder is not running | [
"Get",
"the",
"beat",
"grids",
"available",
"for",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"either",
"on",
"the",
"play",
"deck",
"or",
"in",
"a",
"hot",
"cue",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L181-L186 |
163,946 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.requestBeatGridFrom | public BeatGrid requestBeatGridFrom(final DataReference track) {
for (BeatGrid cached : hotCache.values()) {
if (cached.dataReference.equals(track)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestBeatGridInternal(track, false);
} | java | public BeatGrid requestBeatGridFrom(final DataReference track) {
for (BeatGrid cached : hotCache.values()) {
if (cached.dataReference.equals(track)) { // Found a hot cue hit, use it.
return cached;
}
}
return requestBeatGridInternal(track, false);
} | [
"public",
"BeatGrid",
"requestBeatGridFrom",
"(",
"final",
"DataReference",
"track",
")",
"{",
"for",
"(",
"BeatGrid",
"cached",
":",
"hotCache",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"cached",
".",
"dataReference",
".",
"equals",
"(",
"track",
")",
")",
"{",
"// Found a hot cue hit, use it.",
"return",
"cached",
";",
"}",
"}",
"return",
"requestBeatGridInternal",
"(",
"track",
",",
"false",
")",
";",
"}"
] | Ask the specified player for the beat grid of the track in the specified slot with the specified rekordbox ID,
first checking if we have a cache we can use instead.
@param track uniquely identifies the track whose beat grid is desired
@return the beat grid, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"the",
"beat",
"grid",
"of",
"the",
"track",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"first",
"checking",
"if",
"we",
"have",
"a",
"cache",
"we",
"can",
"use",
"instead",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L278-L285 |
163,947 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.getBeatGrid | BeatGrid getBeatGrid(int rekordboxId, SlotReference slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.BEAT_GRID_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.BEAT_GRID) {
return new BeatGrid(new DataReference(slot, rekordboxId), response);
}
logger.error("Unexpected response type when requesting beat grid: {}", response);
return null;
} | java | BeatGrid getBeatGrid(int rekordboxId, SlotReference slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.BEAT_GRID_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot.slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.BEAT_GRID) {
return new BeatGrid(new DataReference(slot, rekordboxId), response);
}
logger.error("Unexpected response type when requesting beat grid: {}", response);
return null;
} | [
"BeatGrid",
"getBeatGrid",
"(",
"int",
"rekordboxId",
",",
"SlotReference",
"slot",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"BEAT_GRID_REQ",
",",
"null",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"DATA",
",",
"slot",
".",
"slot",
")",
",",
"new",
"NumberField",
"(",
"rekordboxId",
")",
")",
";",
"if",
"(",
"response",
".",
"knownType",
"==",
"Message",
".",
"KnownType",
".",
"BEAT_GRID",
")",
"{",
"return",
"new",
"BeatGrid",
"(",
"new",
"DataReference",
"(",
"slot",
",",
"rekordboxId",
")",
",",
"response",
")",
";",
"}",
"logger",
".",
"error",
"(",
"\"Unexpected response type when requesting beat grid: {}\"",
",",
"response",
")",
";",
"return",
"null",
";",
"}"
] | Requests the beat grid for a specific track ID, given a connection to a player that has already been set up.
@param rekordboxId the track of interest
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved beat grid, or {@code null} if there was none available
@throws IOException if there is a communication problem | [
"Requests",
"the",
"beat",
"grid",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L298-L307 |
163,948 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.deliverBeatGridUpdate | private void deliverBeatGridUpdate(int player, BeatGrid beatGrid) {
if (!getBeatGridListeners().isEmpty()) {
final BeatGridUpdate update = new BeatGridUpdate(player, beatGrid);
for (final BeatGridListener listener : getBeatGridListeners()) {
try {
listener.beatGridChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering beat grid update to listener", t);
}
}
}
} | java | private void deliverBeatGridUpdate(int player, BeatGrid beatGrid) {
if (!getBeatGridListeners().isEmpty()) {
final BeatGridUpdate update = new BeatGridUpdate(player, beatGrid);
for (final BeatGridListener listener : getBeatGridListeners()) {
try {
listener.beatGridChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering beat grid update to listener", t);
}
}
}
} | [
"private",
"void",
"deliverBeatGridUpdate",
"(",
"int",
"player",
",",
"BeatGrid",
"beatGrid",
")",
"{",
"if",
"(",
"!",
"getBeatGridListeners",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"BeatGridUpdate",
"update",
"=",
"new",
"BeatGridUpdate",
"(",
"player",
",",
"beatGrid",
")",
";",
"for",
"(",
"final",
"BeatGridListener",
"listener",
":",
"getBeatGridListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"beatGridChanged",
"(",
"update",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering beat grid update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}"
] | Send a beat grid update announcement to all registered listeners.
@param player the player whose beat grid information has changed
@param beatGrid the new beat grid associated with that player, if any | [
"Send",
"a",
"beat",
"grid",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L372-L384 |
163,949 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java | BeatGridFinder.stop | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our previews, on the proper thread, and outside our lock.
final Set<DeckReference> dyingCache = new HashSet<DeckReference>(hotCache.keySet());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingCache) {
if (deck.hotCue == 0) {
deliverBeatGridUpdate(deck.player, null);
}
}
}
});
hotCache.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | java | @SuppressWarnings("WeakerAccess")
public synchronized void stop() {
if (isRunning()) {
MetadataFinder.getInstance().removeTrackMetadataListener(metadataListener);
running.set(false);
pendingUpdates.clear();
queueHandler.interrupt();
queueHandler = null;
// Report the loss of our previews, on the proper thread, and outside our lock.
final Set<DeckReference> dyingCache = new HashSet<DeckReference>(hotCache.keySet());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeckReference deck : dyingCache) {
if (deck.hotCue == 0) {
deliverBeatGridUpdate(deck.player, null);
}
}
}
});
hotCache.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"removeTrackMetadataListener",
"(",
"metadataListener",
")",
";",
"running",
".",
"set",
"(",
"false",
")",
";",
"pendingUpdates",
".",
"clear",
"(",
")",
";",
"queueHandler",
".",
"interrupt",
"(",
")",
";",
"queueHandler",
"=",
"null",
";",
"// Report the loss of our previews, on the proper thread, and outside our lock.",
"final",
"Set",
"<",
"DeckReference",
">",
"dyingCache",
"=",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"hotCache",
".",
"keySet",
"(",
")",
")",
";",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"DeckReference",
"deck",
":",
"dyingCache",
")",
"{",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverBeatGridUpdate",
"(",
"deck",
".",
"player",
",",
"null",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"hotCache",
".",
"clear",
"(",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | Stop finding beat grids for all active players. | [
"Stop",
"finding",
"beat",
"grids",
"for",
"all",
"active",
"players",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L502-L526 |
163,950 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java | TimeFinder.interpolateTimeSinceUpdate | private long interpolateTimeSinceUpdate(TrackPositionUpdate update, long currentTimestamp) {
if (!update.playing) {
return update.milliseconds;
}
long elapsedMillis = (currentTimestamp - update.timestamp) / 1000000;
long moved = Math.round(update.pitch * elapsedMillis);
if (update.reverse) {
return update.milliseconds - moved;
}
return update.milliseconds + moved;
} | java | private long interpolateTimeSinceUpdate(TrackPositionUpdate update, long currentTimestamp) {
if (!update.playing) {
return update.milliseconds;
}
long elapsedMillis = (currentTimestamp - update.timestamp) / 1000000;
long moved = Math.round(update.pitch * elapsedMillis);
if (update.reverse) {
return update.milliseconds - moved;
}
return update.milliseconds + moved;
} | [
"private",
"long",
"interpolateTimeSinceUpdate",
"(",
"TrackPositionUpdate",
"update",
",",
"long",
"currentTimestamp",
")",
"{",
"if",
"(",
"!",
"update",
".",
"playing",
")",
"{",
"return",
"update",
".",
"milliseconds",
";",
"}",
"long",
"elapsedMillis",
"=",
"(",
"currentTimestamp",
"-",
"update",
".",
"timestamp",
")",
"/",
"1000000",
";",
"long",
"moved",
"=",
"Math",
".",
"round",
"(",
"update",
".",
"pitch",
"*",
"elapsedMillis",
")",
";",
"if",
"(",
"update",
".",
"reverse",
")",
"{",
"return",
"update",
".",
"milliseconds",
"-",
"moved",
";",
"}",
"return",
"update",
".",
"milliseconds",
"+",
"moved",
";",
"}"
] | Figure out, based on how much time has elapsed since we received an update, and the playback position,
speed, and direction at the time of that update, where the player will be now.
@param update the most recent update received from a player
@param currentTimestamp the nanosecond timestamp representing when we want to interpolate the track's position
@return the playback position we believe that player has reached now | [
"Figure",
"out",
"based",
"on",
"how",
"much",
"time",
"has",
"elapsed",
"since",
"we",
"received",
"an",
"update",
"and",
"the",
"playback",
"position",
"speed",
"and",
"direction",
"at",
"the",
"time",
"of",
"that",
"update",
"where",
"the",
"player",
"will",
"be",
"now",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L151-L161 |
163,951 | 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",
"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",
")",
")",
";",
"}",
"}"
] | 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 |
163,952 | 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",
",",
"System",
".",
"nanoTime",
"(",
")",
")",
";",
"}",
"return",
"-",
"1",
";",
"// We don't know.",
"}"
] | 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 |
163,953 | 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",
"(",
"interpolateTimeSinceUpdate",
"(",
"lastUpdate",
",",
"now",
")",
"-",
"interpolateTimeSinceUpdate",
"(",
"currentUpdate",
",",
"now",
")",
")",
">",
"slack",
".",
"get",
"(",
")",
";",
"}"
] | 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 |
163,954 | 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",
")",
";",
"VirtualCdj",
".",
"getInstance",
"(",
")",
".",
"removeUpdateListener",
"(",
"updateListener",
")",
";",
"running",
".",
"set",
"(",
"false",
")",
";",
"positions",
".",
"clear",
"(",
")",
";",
"updates",
".",
"clear",
"(",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | 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 |
163,955 | 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",
"(",
"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",
";",
"}"
] | 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 |
163,956 | 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 \"",
"+",
"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",
")",
";",
"}"
] | 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 |
163,957 | 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",
")",
"||",
"(",
"newMaster",
"!=",
"null",
"&&",
"(",
"(",
"oldMaster",
"==",
"null",
")",
"||",
"!",
"newMaster",
".",
"getAddress",
"(",
")",
".",
"equals",
"(",
"oldMaster",
".",
"getAddress",
"(",
")",
")",
")",
")",
")",
"{",
"// This is a change in master, so report it to any registered listeners",
"deliverMasterChangedAnnouncement",
"(",
"newMaster",
")",
";",
"}",
"}"
] | 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 |
163,958 | 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",
"(",
"(",
"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",
")",
";",
"}",
"}"
] | 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 |
163,959 | 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",
"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",
")",
";",
"}"
] | 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",
"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",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L394-L456 |
163,960 | 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",
"(",
"beat",
")",
";",
"}",
"}"
] | 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 |
163,961 | 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",
"(",
"(",
"address",
".",
"getBroadcast",
"(",
")",
"!=",
"null",
")",
"&&",
"Util",
".",
"sameNetwork",
"(",
"address",
".",
"getNetworkPrefixLength",
"(",
")",
",",
"aDevice",
".",
"getAddress",
"(",
")",
",",
"address",
".",
"getAddress",
"(",
")",
")",
")",
"{",
"return",
"address",
";",
"}",
"}",
"return",
"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.
@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 |
163,962 | 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",
"(",
"DeviceAnnouncement",
"candidate",
":",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"getCurrentDevices",
"(",
")",
")",
"{",
"if",
"(",
"!",
"Util",
".",
"sameNetwork",
"(",
"matchedAddress",
".",
"getNetworkPrefixLength",
"(",
")",
",",
"matchedAddress",
".",
"getAddress",
"(",
")",
",",
"candidate",
".",
"getAddress",
"(",
")",
")",
")",
"{",
"result",
".",
"add",
"(",
"candidate",
")",
";",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"result",
")",
";",
"}"
] | 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",
"communicate",
"with",
"them",
"and",
"they",
"should",
"all",
"be",
"moved",
"onto",
"a",
"single",
"network",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L672-L681 |
163,963 | 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 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",
")",
";",
"}",
"}"
] | 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 |
163,964 | 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",
",",
"DeviceFinder",
".",
"ANNOUNCEMENT_PORT",
")",
";",
"socket",
".",
"get",
"(",
")",
".",
"send",
"(",
"announcement",
")",
";",
"Thread",
".",
"sleep",
"(",
"getAnnounceInterval",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Unable to send announcement packet, shutting down\"",
",",
"t",
")",
";",
"stop",
"(",
")",
";",
"}",
"}"
] | 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 |
163,965 | 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",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering master changed announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | 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 |
163,966 | 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",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering tempo changed announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | 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 |
163,967 | 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",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering master beat announcement to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | 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 |
163,968 | 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",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering device update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | 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 |
163,969 | 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",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering media details response to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | 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 |
163,970 | 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",
"{",
"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",
")",
";",
"}"
] | 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 |
163,971 | 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",
"]",
";",
"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",
")",
";",
"}"
] | 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 |
163,972 | 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",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Device \"",
"+",
"deviceNumber",
"+",
"\" not found on network.\"",
")",
";",
"}",
"sendSyncModeCommand",
"(",
"update",
",",
"synced",
")",
";",
"}"
] | 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 |
163,973 | 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",
"IllegalArgumentException",
"(",
"\"Device \"",
"+",
"deviceNumber",
"+",
"\" not found on network.\"",
")",
";",
"}",
"appointTempoMaster",
"(",
"update",
")",
";",
"}"
] | 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 |
163,974 | 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",
"=",
"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",
")",
";",
"}"
] | 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",
"the",
"range",
"1",
"to",
"4",
"are",
"ignored",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1234-L1250 |
163,975 | 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",
"{",
"final",
"DeviceUpdate",
"update",
"=",
"getLatestStatusFor",
"(",
"targetPlayer",
")",
";",
"if",
"(",
"update",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Device \"",
"+",
"targetPlayer",
"+",
"\" not found on network.\"",
")",
";",
"}",
"sendLoadTrackCommand",
"(",
"update",
",",
"rekordboxId",
",",
"sourcePlayer",
",",
"sourceSlot",
",",
"sourceType",
")",
";",
"}"
] | 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 |
163,976 | 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",
"{",
"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",
")",
";",
"}"
] | 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 |
163,977 | 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.",
"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",
")",
";",
"}",
"}",
"}"
] | 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",
"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",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1494-L1546 |
163,978 | 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",
"(",
"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",
"(",
")",
")",
";",
"}",
"}"
] | 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 |
163,979 | 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",
"(",
"\"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",
")",
";",
"}",
"}"
] | 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",
"alignment",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1670-L1695 |
163,980 | 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",
"&&",
"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",
")",
";",
"}"
] | 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 |
163,981 | 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",
"(",
")",
")",
"{",
"metronome",
".",
"jumpToBeat",
"(",
"beat",
")",
";",
"}",
"else",
"{",
"whereStopped",
".",
"set",
"(",
"metronome",
".",
"getSnapshot",
"(",
"metronome",
".",
"getTimeOfBeat",
"(",
"beat",
")",
")",
")",
";",
"}",
"}"
] | 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",
"one",
"will",
"jump",
"us",
"to",
"the",
"first",
"beat",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/VirtualCdj.java#L1852-L1865 |
163,982 | 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",
".",
"unmodifiableSet",
"(",
"result",
")",
";",
"}"
] | 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 |
163,983 | 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",
")",
"{",
"setPlaybackState",
"(",
"oldState",
".",
"player",
",",
"milliseconds",
",",
"oldState",
".",
"playing",
")",
";",
"}",
"}"
] | 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",
"position",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L289-L294 |
163,984 | 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",
"(",
"oldState",
".",
"player",
",",
"oldState",
".",
"position",
",",
"playing",
")",
";",
"}",
"}"
] | 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",
"component",
"is",
"tied",
"to",
"a",
"single",
"player",
"and",
"therefore",
"has",
"a",
"single",
"playback",
"position",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L326-L331 |
163,985 | 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",
"(",
")",
";",
"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",
"(",
")",
";",
"}"
] | 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",
"be",
"updated",
"and",
"the",
"current",
"playback",
"position",
"and",
"state",
"of",
"the",
"player",
"will",
"be",
"reflected",
"by",
"the",
"component",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L387-L452 |
163,986 | 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",
"||",
"(",
"!",
"result",
".",
"playing",
"&&",
"state",
".",
"playing",
")",
"||",
"(",
"result",
".",
"position",
"<",
"state",
".",
"position",
")",
"&&",
"(",
"state",
".",
"playing",
"||",
"!",
"result",
".",
"playing",
")",
")",
"{",
"result",
"=",
"state",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | 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",
"auto",
"-",
"scrolling",
"is",
"active",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetailComponent.java#L587-L596 |
163,987 | 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",
".",
"timeToHalfFrame",
"(",
"getFurthestPlaybackPosition",
"(",
")",
")",
"/",
"scale",
".",
"get",
"(",
")",
";",
"return",
"(",
"playHead",
"+",
"offset",
")",
"*",
"scale",
".",
"get",
"(",
")",
";",
"}",
"return",
"x",
"*",
"scale",
".",
"get",
"(",
")",
";",
"}"
] | 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 |
163,988 | 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",
")",
")",
";",
"}",
"return",
"0",
";",
"}"
] | 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 |
163,989 | 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",
"-",
"getFurthestPlaybackPosition",
"(",
")",
";",
"return",
"playHead",
"+",
"(",
"Util",
".",
"timeToHalfFrame",
"(",
"offset",
")",
"/",
"scale",
".",
"get",
"(",
")",
")",
";",
"}",
"return",
"Util",
".",
"timeToHalfFrame",
"(",
"milliseconds",
")",
"/",
"scale",
".",
"get",
"(",
")",
";",
"}"
] | 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 |
163,990 | 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",
"Color",
".",
"ORANGE",
";",
"}",
"return",
"Color",
".",
"RED",
";",
"}"
] | 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 |
163,991 | 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",
",",
"packetBytes",
".",
"length",
")",
";",
"return",
"result",
";",
"}"
] | 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 |
163,992 | 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",
"(",
")",
")",
";",
"content",
".",
"put",
"(",
"getMagicHeader",
"(",
")",
")",
";",
"content",
".",
"put",
"(",
"type",
".",
"protocolValue",
")",
";",
"content",
".",
"put",
"(",
"deviceName",
")",
";",
"content",
".",
"put",
"(",
"payload",
")",
";",
"return",
"new",
"DatagramPacket",
"(",
"content",
".",
"array",
"(",
")",
",",
"content",
".",
"capacity",
"(",
")",
")",
";",
"}"
] | 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 |
163,993 | 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",
")",
"{",
"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",
";",
"}"
] | 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",
"recognized",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L194-L221 |
163,994 | 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",
";",
"index",
"++",
")",
"{",
"result",
"=",
"(",
"result",
"<<",
"8",
")",
"+",
"unsign",
"(",
"buffer",
"[",
"index",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
] | 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 |
163,995 | 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",
"index",
"=",
"start",
"+",
"length",
"-",
"1",
";",
"index",
">=",
"start",
";",
"index",
"--",
")",
"{",
"result",
"=",
"(",
"result",
"<<",
"8",
")",
"+",
"unsign",
"(",
"buffer",
"[",
"index",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
] | 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",
"quirky",
"way",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L259-L266 |
163,996 | 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",
";",
"index",
"--",
")",
"{",
"buffer",
"[",
"index",
"]",
"=",
"(",
"byte",
")",
"(",
"number",
"&",
"0xff",
")",
";",
"number",
"=",
"number",
">>",
"8",
";",
"}",
"}"
] | 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",
"specified",
"number",
"of",
"bytes",
"only",
"the",
"low",
"-",
"order",
"bytes",
"are",
"written",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/Util.java#L277-L282 |
163,997 | 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",
")",
"+",
"unsign",
"(",
"element",
")",
";",
"}",
"return",
"result",
";",
"}"
] | 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 |
163,998 | 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 address \"",
"+",
"address1",
".",
"getHostAddress",
"(",
")",
"+",
"\" with \"",
"+",
"address2",
".",
"getHostAddress",
"(",
")",
"+",
"\", prefixLength=\"",
"+",
"prefixLength",
")",
";",
"}",
"long",
"prefixMask",
"=",
"0xffffffff",
"",
"L",
"&",
"(",
"-",
"1",
"<<",
"(",
"32",
"-",
"prefixLength",
")",
")",
";",
"return",
"(",
"addressToLong",
"(",
"address1",
")",
"&",
"prefixMask",
")",
"==",
"(",
"addressToLong",
"(",
"address2",
")",
"&",
"prefixMask",
")",
";",
"}"
] | 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 |
163,999 | 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 |
Subsets and Splits