repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.readResponseWithExpectedSize | @SuppressWarnings("SameParameterValue")
private byte[] readResponseWithExpectedSize(InputStream is, int size, String description) throws IOException {
byte[] result = receiveBytes(is);
if (result.length != size) {
logger.warn("Expected " + size + " bytes while reading " + description + " response, received " + result.length);
}
return result;
} | java | @SuppressWarnings("SameParameterValue")
private byte[] readResponseWithExpectedSize(InputStream is, int size, String description) throws IOException {
byte[] result = receiveBytes(is);
if (result.length != size) {
logger.warn("Expected " + size + " bytes while reading " + description + " response, received " + result.length);
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"byte",
"[",
"]",
"readResponseWithExpectedSize",
"(",
"InputStream",
"is",
",",
"int",
"size",
",",
"String",
"description",
")",
"throws",
"IOException",
"{",
"byte",
"[",
"]",
"result",
"... | Receive an expected number of bytes from the player, logging a warning if we get a different number of them.
@param is the input stream associated with the player metadata socket.
@param size the number of bytes we expect to receive.
@param description the type of response being processed, for use in the warning message.
@return the bytes read.
@throws IOException if there is a problem reading the response. | [
"Receive",
"an",
"expected",
"number",
"of",
"bytes",
"from",
"the",
"player",
"logging",
"a",
"warning",
"if",
"we",
"get",
"a",
"different",
"number",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L362-L369 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.closeIdleClients | private synchronized void closeIdleClients() {
List<Client> candidates = new LinkedList<Client>(openClients.values());
logger.debug("Scanning for idle clients; " + candidates.size() + " candidates.");
for (Client client : candidates) {
if ((useCounts.get(client) < 1) &&
((timestamps.get(client) + idleLimit.get() * 1000) <= System.currentTimeMillis())) {
logger.debug("Idle time reached for unused client {}", client);
closeClient(client);
}
}
} | java | private synchronized void closeIdleClients() {
List<Client> candidates = new LinkedList<Client>(openClients.values());
logger.debug("Scanning for idle clients; " + candidates.size() + " candidates.");
for (Client client : candidates) {
if ((useCounts.get(client) < 1) &&
((timestamps.get(client) + idleLimit.get() * 1000) <= System.currentTimeMillis())) {
logger.debug("Idle time reached for unused client {}", client);
closeClient(client);
}
}
} | [
"private",
"synchronized",
"void",
"closeIdleClients",
"(",
")",
"{",
"List",
"<",
"Client",
">",
"candidates",
"=",
"new",
"LinkedList",
"<",
"Client",
">",
"(",
"openClients",
".",
"values",
"(",
")",
")",
";",
"logger",
".",
"debug",
"(",
"\"Scanning fo... | Finds any clients which are not currently in use, and which have been idle for longer than the
idle timeout, and closes them. | [
"Finds",
"any",
"clients",
"which",
"are",
"not",
"currently",
"in",
"use",
"and",
"which",
"have",
"been",
"idle",
"for",
"longer",
"than",
"the",
"idle",
"timeout",
"and",
"closes",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L440-L450 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.start | public synchronized void start() throws SocketException {
if (!isRunning()) {
DeviceFinder.getInstance().addLifecycleListener(lifecycleListener);
DeviceFinder.getInstance().addDeviceAnnouncementListener(announcementListener);
DeviceFinder.getInstance().start();
for (DeviceAnnouncement device: DeviceFinder.getInstance().getCurrentDevices()) {
requestPlayerDBServerPort(device);
}
new Thread(null, new Runnable() {
@Override
public void run() {
while (isRunning()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.warn("Interrupted sleeping to close idle dbserver clients");
}
closeIdleClients();
}
logger.info("Idle dbserver client closer shutting down.");
}
}, "Idle dbserver client closer").start();
running.set(true);
deliverLifecycleAnnouncement(logger, true);
}
} | java | public synchronized void start() throws SocketException {
if (!isRunning()) {
DeviceFinder.getInstance().addLifecycleListener(lifecycleListener);
DeviceFinder.getInstance().addDeviceAnnouncementListener(announcementListener);
DeviceFinder.getInstance().start();
for (DeviceAnnouncement device: DeviceFinder.getInstance().getCurrentDevices()) {
requestPlayerDBServerPort(device);
}
new Thread(null, new Runnable() {
@Override
public void run() {
while (isRunning()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.warn("Interrupted sleeping to close idle dbserver clients");
}
closeIdleClients();
}
logger.info("Idle dbserver client closer shutting down.");
}
}, "Idle dbserver client closer").start();
running.set(true);
deliverLifecycleAnnouncement(logger, true);
}
} | [
"public",
"synchronized",
"void",
"start",
"(",
")",
"throws",
"SocketException",
"{",
"if",
"(",
"!",
"isRunning",
"(",
")",
")",
"{",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"addLifecycleListener",
"(",
"lifecycleListener",
")",
";",
"DeviceFinder... | Start offering shared dbserver sessions.
@throws SocketException if there is a problem opening connections | [
"Start",
"offering",
"shared",
"dbserver",
"sessions",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L457-L484 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.stop | public synchronized void stop() {
if (isRunning()) {
running.set(false);
DeviceFinder.getInstance().removeDeviceAnnouncementListener(announcementListener);
dbServerPorts.clear();
for (Client client : openClients.values()) {
try {
client.close();
} catch (Exception e) {
logger.warn("Problem closing " + client + " when stopping", e);
}
}
openClients.clear();
useCounts.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | java | public synchronized void stop() {
if (isRunning()) {
running.set(false);
DeviceFinder.getInstance().removeDeviceAnnouncementListener(announcementListener);
dbServerPorts.clear();
for (Client client : openClients.values()) {
try {
client.close();
} catch (Exception e) {
logger.warn("Problem closing " + client + " when stopping", e);
}
}
openClients.clear();
useCounts.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"running",
".",
"set",
"(",
"false",
")",
";",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"removeDeviceAnnouncementListener",
"(",
"announcementListe... | Stop offering shared dbserver sessions. | [
"Stop",
"offering",
"shared",
"dbserver",
"sessions",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L489-L505 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildSearchableItem | private SearchableItem buildSearchableItem(Message menuItem) {
return new SearchableItem((int) ((NumberField) menuItem.arguments.get(1)).getValue(),
((StringField) menuItem.arguments.get(3)).getValue());
} | java | private SearchableItem buildSearchableItem(Message menuItem) {
return new SearchableItem((int) ((NumberField) menuItem.arguments.get(1)).getValue(),
((StringField) menuItem.arguments.get(3)).getValue());
} | [
"private",
"SearchableItem",
"buildSearchableItem",
"(",
"Message",
"menuItem",
")",
"{",
"return",
"new",
"SearchableItem",
"(",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
... | Creates a searchable item that represents a metadata field found for a track.
@param menuItem the rendered menu item containing the searchable metadata field
@return the searchable metadata field | [
"Creates",
"a",
"searchable",
"item",
"that",
"represents",
"a",
"metadata",
"field",
"found",
"for",
"a",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L156-L159 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildColorItem | private ColorItem buildColorItem(Message menuItem) {
final int colorId = (int) ((NumberField) menuItem.arguments.get(1)).getValue();
final String label = ((StringField) menuItem.arguments.get(3)).getValue();
return buildColorItem(colorId, label);
} | java | private ColorItem buildColorItem(Message menuItem) {
final int colorId = (int) ((NumberField) menuItem.arguments.get(1)).getValue();
final String label = ((StringField) menuItem.arguments.get(3)).getValue();
return buildColorItem(colorId, label);
} | [
"private",
"ColorItem",
"buildColorItem",
"(",
"Message",
"menuItem",
")",
"{",
"final",
"int",
"colorId",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",... | Creates a color item that represents a color field found for a track based on a dbserver message.
@param menuItem the rendered menu item containing the color metadata field
@return the color metadata field | [
"Creates",
"a",
"color",
"item",
"that",
"represents",
"a",
"color",
"field",
"found",
"for",
"a",
"track",
"based",
"on",
"a",
"dbserver",
"message",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L168-L172 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildColorItem | private ColorItem buildColorItem(int colorId, String label) {
Color color;
String colorName;
switch (colorId) {
case 0:
color = new Color(0, 0, 0, 0);
colorName = "No Color";
break;
case 1:
color = Color.PINK;
colorName = "Pink";
break;
case 2:
color = Color.RED;
colorName = "Red";
break;
case 3:
color = Color.ORANGE;
colorName = "Orange";
break;
case 4:
color = Color.YELLOW;
colorName = "Yellow";
break;
case 5:
color = Color.GREEN;
colorName = "Green";
break;
case 6:
color = Color.CYAN;
colorName = "Aqua";
break;
case 7:
color = Color.BLUE;
colorName = "Blue";
break;
case 8:
color = new Color(128, 0, 128);
colorName = "Purple";
break;
default:
color = new Color(0, 0, 0, 0);
colorName = "Unknown Color";
}
return new ColorItem(colorId, label, color, colorName);
} | java | private ColorItem buildColorItem(int colorId, String label) {
Color color;
String colorName;
switch (colorId) {
case 0:
color = new Color(0, 0, 0, 0);
colorName = "No Color";
break;
case 1:
color = Color.PINK;
colorName = "Pink";
break;
case 2:
color = Color.RED;
colorName = "Red";
break;
case 3:
color = Color.ORANGE;
colorName = "Orange";
break;
case 4:
color = Color.YELLOW;
colorName = "Yellow";
break;
case 5:
color = Color.GREEN;
colorName = "Green";
break;
case 6:
color = Color.CYAN;
colorName = "Aqua";
break;
case 7:
color = Color.BLUE;
colorName = "Blue";
break;
case 8:
color = new Color(128, 0, 128);
colorName = "Purple";
break;
default:
color = new Color(0, 0, 0, 0);
colorName = "Unknown Color";
}
return new ColorItem(colorId, label, color, colorName);
} | [
"private",
"ColorItem",
"buildColorItem",
"(",
"int",
"colorId",
",",
"String",
"label",
")",
"{",
"Color",
"color",
";",
"String",
"colorName",
";",
"switch",
"(",
"colorId",
")",
"{",
"case",
"0",
":",
"color",
"=",
"new",
"Color",
"(",
"0",
",",
"0"... | Creates a color item that represents a color field fond for a track.
@param colorId the key of the color as found in the database
@param label the corresponding color label as found in the database (or sent in the dbserver message)
@return the color metadata field | [
"Creates",
"a",
"color",
"item",
"that",
"represents",
"a",
"color",
"field",
"fond",
"for",
"a",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L182-L227 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.parseMetadataItem | private void parseMetadataItem(Message item) {
switch (item.getMenuItemType()) {
case TRACK_TITLE:
title = ((StringField) item.arguments.get(3)).getValue();
artworkId = (int) ((NumberField) item.arguments.get(8)).getValue();
break;
case ARTIST:
artist = buildSearchableItem(item);
break;
case ORIGINAL_ARTIST:
originalArtist = buildSearchableItem(item);
break;
case REMIXER:
remixer = buildSearchableItem(item);
case ALBUM_TITLE:
album = buildSearchableItem(item);
break;
case LABEL:
label = buildSearchableItem(item);
break;
case DURATION:
duration = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case TEMPO:
tempo = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case COMMENT:
comment = ((StringField) item.arguments.get(3)).getValue();
break;
case KEY:
key = buildSearchableItem(item);
break;
case RATING:
rating = (int) ((NumberField)item.arguments.get(1)).getValue();
break;
case COLOR_NONE:
case COLOR_AQUA:
case COLOR_BLUE:
case COLOR_GREEN:
case COLOR_ORANGE:
case COLOR_PINK:
case COLOR_PURPLE:
case COLOR_RED:
case COLOR_YELLOW:
color = buildColorItem(item);
break;
case GENRE:
genre = buildSearchableItem(item);
break;
case DATE_ADDED:
dateAdded = ((StringField) item.arguments.get(3)).getValue();
break;
case YEAR:
year = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case BIT_RATE:
bitRate = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
default:
logger.warn("Ignoring track metadata item with unknown type: {}", item);
}
} | java | private void parseMetadataItem(Message item) {
switch (item.getMenuItemType()) {
case TRACK_TITLE:
title = ((StringField) item.arguments.get(3)).getValue();
artworkId = (int) ((NumberField) item.arguments.get(8)).getValue();
break;
case ARTIST:
artist = buildSearchableItem(item);
break;
case ORIGINAL_ARTIST:
originalArtist = buildSearchableItem(item);
break;
case REMIXER:
remixer = buildSearchableItem(item);
case ALBUM_TITLE:
album = buildSearchableItem(item);
break;
case LABEL:
label = buildSearchableItem(item);
break;
case DURATION:
duration = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case TEMPO:
tempo = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case COMMENT:
comment = ((StringField) item.arguments.get(3)).getValue();
break;
case KEY:
key = buildSearchableItem(item);
break;
case RATING:
rating = (int) ((NumberField)item.arguments.get(1)).getValue();
break;
case COLOR_NONE:
case COLOR_AQUA:
case COLOR_BLUE:
case COLOR_GREEN:
case COLOR_ORANGE:
case COLOR_PINK:
case COLOR_PURPLE:
case COLOR_RED:
case COLOR_YELLOW:
color = buildColorItem(item);
break;
case GENRE:
genre = buildSearchableItem(item);
break;
case DATE_ADDED:
dateAdded = ((StringField) item.arguments.get(3)).getValue();
break;
case YEAR:
year = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case BIT_RATE:
bitRate = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
default:
logger.warn("Ignoring track metadata item with unknown type: {}", item);
}
} | [
"private",
"void",
"parseMetadataItem",
"(",
"Message",
"item",
")",
"{",
"switch",
"(",
"item",
".",
"getMenuItemType",
"(",
")",
")",
"{",
"case",
"TRACK_TITLE",
":",
"title",
"=",
"(",
"(",
"StringField",
")",
"item",
".",
"arguments",
".",
"get",
"("... | Processes one of the menu responses that jointly constitute the track metadata, updating our
fields accordingly.
@param item the menu response to be considered | [
"Processes",
"one",
"of",
"the",
"menu",
"responses",
"that",
"jointly",
"constitute",
"the",
"track",
"metadata",
"updating",
"our",
"fields",
"accordingly",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L350-L427 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.getRawData | @SuppressWarnings("WeakerAccess")
public ByteBuffer getRawData() {
if (rawData != null) {
rawData.rewind();
return rawData.slice();
}
return null;
} | java | @SuppressWarnings("WeakerAccess")
public ByteBuffer getRawData() {
if (rawData != null) {
rawData.rewind();
return rawData.slice();
}
return null;
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"ByteBuffer",
"getRawData",
"(",
")",
"{",
"if",
"(",
"rawData",
"!=",
"null",
")",
"{",
"rawData",
".",
"rewind",
"(",
")",
";",
"return",
"rawData",
".",
"slice",
"(",
")",
";",
"}",
"r... | Get the raw bytes of the beat grid as it was read over the network. This can be used to analyze fields
that have not yet been reliably understood, and is also used for storing the beat grid in a cache file.
This is not available when the beat grid was loaded by Crate Digger.
@return the bytes that make up the beat grid | [
"Get",
"the",
"raw",
"bytes",
"of",
"the",
"beat",
"grid",
"as",
"it",
"was",
"read",
"over",
"the",
"network",
".",
"This",
"can",
"be",
"used",
"to",
"analyze",
"fields",
"that",
"have",
"not",
"yet",
"been",
"reliably",
"understood",
"and",
"is",
"a... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L37-L44 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.findTag | private RekordboxAnlz.BeatGridTag findTag(RekordboxAnlz anlzFile) {
for (RekordboxAnlz.TaggedSection section : anlzFile.sections()) {
if (section.body() instanceof RekordboxAnlz.BeatGridTag) {
return (RekordboxAnlz.BeatGridTag) section.body();
}
}
throw new IllegalArgumentException("No beat grid found inside analysis file " + anlzFile);
} | java | private RekordboxAnlz.BeatGridTag findTag(RekordboxAnlz anlzFile) {
for (RekordboxAnlz.TaggedSection section : anlzFile.sections()) {
if (section.body() instanceof RekordboxAnlz.BeatGridTag) {
return (RekordboxAnlz.BeatGridTag) section.body();
}
}
throw new IllegalArgumentException("No beat grid found inside analysis file " + anlzFile);
} | [
"private",
"RekordboxAnlz",
".",
"BeatGridTag",
"findTag",
"(",
"RekordboxAnlz",
"anlzFile",
")",
"{",
"for",
"(",
"RekordboxAnlz",
".",
"TaggedSection",
"section",
":",
"anlzFile",
".",
"sections",
"(",
")",
")",
"{",
"if",
"(",
"section",
".",
"body",
"(",... | Helper function to find the beat grid section in a rekordbox track analysis file.
@param anlzFile the file that was downloaded from the player
@return the section containing the beat grid | [
"Helper",
"function",
"to",
"find",
"the",
"beat",
"grid",
"section",
"in",
"a",
"rekordbox",
"track",
"analysis",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L101-L108 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.beatOffset | private int beatOffset(int beatNumber) {
if (beatCount == 0) {
throw new IllegalStateException("There are no beats in this beat grid.");
}
if (beatNumber < 1 || beatNumber > beatCount) {
throw new IndexOutOfBoundsException("beatNumber (" + beatNumber + ") must be between 1 and " + beatCount);
}
return beatNumber - 1;
} | java | private int beatOffset(int beatNumber) {
if (beatCount == 0) {
throw new IllegalStateException("There are no beats in this beat grid.");
}
if (beatNumber < 1 || beatNumber > beatCount) {
throw new IndexOutOfBoundsException("beatNumber (" + beatNumber + ") must be between 1 and " + beatCount);
}
return beatNumber - 1;
} | [
"private",
"int",
"beatOffset",
"(",
"int",
"beatNumber",
")",
"{",
"if",
"(",
"beatCount",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"There are no beats in this beat grid.\"",
")",
";",
"}",
"if",
"(",
"beatNumber",
"<",
"1",
"||",
... | Calculate where within the beat grid array the information for the specified beat can be found.
Yes, this is a super simple calculation; the main point of the method is to provide a nice exception
when the beat is out of bounds.
@param beatNumber the beat desired
@return the offset of the start of our cache arrays for information about that beat | [
"Calculate",
"where",
"within",
"the",
"beat",
"grid",
"array",
"the",
"information",
"for",
"the",
"specified",
"beat",
"can",
"be",
"found",
".",
"Yes",
"this",
"is",
"a",
"super",
"simple",
"calculation",
";",
"the",
"main",
"point",
"of",
"the",
"metho... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L159-L167 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.findBeatAtTime | @SuppressWarnings("WeakerAccess")
public int findBeatAtTime(long milliseconds) {
int found = Arrays.binarySearch(timeWithinTrackValues, milliseconds);
if (found >= 0) { // An exact match, just change 0-based array index to 1-based beat number
return found + 1;
} else if (found == -1) { // We are before the first beat
return found;
} else { // We are after some beat, report its beat number
return -(found + 1);
}
} | java | @SuppressWarnings("WeakerAccess")
public int findBeatAtTime(long milliseconds) {
int found = Arrays.binarySearch(timeWithinTrackValues, milliseconds);
if (found >= 0) { // An exact match, just change 0-based array index to 1-based beat number
return found + 1;
} else if (found == -1) { // We are before the first beat
return found;
} else { // We are after some beat, report its beat number
return -(found + 1);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"int",
"findBeatAtTime",
"(",
"long",
"milliseconds",
")",
"{",
"int",
"found",
"=",
"Arrays",
".",
"binarySearch",
"(",
"timeWithinTrackValues",
",",
"milliseconds",
")",
";",
"if",
"(",
"found",
... | Finds the beat in which the specified track position falls.
@param milliseconds how long the track has been playing
@return the beat number represented by that time, or -1 if the time is before the first beat | [
"Finds",
"the",
"beat",
"in",
"which",
"the",
"specified",
"track",
"position",
"falls",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L208-L218 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestTrackMenuFrom | public List<Message> requestTrackMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
return MetadataFinder.getInstance().getFullTrackList(slotReference.slot, client, sortOrder);
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting track menu");
} | java | public List<Message> requestTrackMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
return MetadataFinder.getInstance().getFullTrackList(slotReference.slot, client, sortOrder);
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting track menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestTrackMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">>",
"task",
"... | Ask the specified player for a Track menu.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@return the entries in the track menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"a",
"Track",
"menu",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L179-L190 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestArtistMenuFrom | public List<Message> requestArtistMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Artist menu.");
Message response = client.menuRequest(Message.KnownType.ARTIST_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
new NumberField(sortOrder));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.REKORDBOX, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting artist menu");
} | java | public List<Message> requestArtistMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Artist menu.");
Message response = client.menuRequest(Message.KnownType.ARTIST_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
new NumberField(sortOrder));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.REKORDBOX, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting artist menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestArtistMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">>",
"task",
... | Ask the specified player for an Artist menu.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@return the entries in the artist menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"an",
"Artist",
"menu",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L204-L226 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestFolderMenuFrom | public List<Message> requestFolderMenuFrom(final SlotReference slotReference, final int sortOrder, final int folderId)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Key menu.");
Message response = client.menuRequestTyped(Message.KnownType.FOLDER_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
CdjStatus.TrackType.UNANALYZED, new NumberField(sortOrder), new NumberField(folderId), new NumberField(0xffffff));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.UNANALYZED, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting folder menu");
} | java | public List<Message> requestFolderMenuFrom(final SlotReference slotReference, final int sortOrder, final int folderId)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Key menu.");
Message response = client.menuRequestTyped(Message.KnownType.FOLDER_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
CdjStatus.TrackType.UNANALYZED, new NumberField(sortOrder), new NumberField(folderId), new NumberField(0xffffff));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.UNANALYZED, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting folder menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestFolderMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
",",
"final",
"int",
"folderId",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",... | Ask the specified player for a Folder menu for exploring its raw filesystem.
This is a request for unanalyzed items, so we do a typed menu request.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@param folderId identifies the folder whose contents should be listed, use -1 to get the root folder
@return the entries in the folder menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"a",
"Folder",
"menu",
"for",
"exploring",
"its",
"raw",
"filesystem",
".",
"This",
"is",
"a",
"request",
"for",
"unanalyzed",
"items",
"so",
"we",
"do",
"a",
"typed",
"menu",
"request",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L1575-L1597 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java | Field.read | public static Field read(DataInputStream is) throws IOException {
final byte tag = is.readByte();
final Field result;
switch (tag) {
case 0x0f:
case 0x10:
case 0x11:
result = new NumberField(tag, is);
break;
case 0x14:
result = new BinaryField(is);
break;
case 0x26:
result = new StringField(is);
break;
default:
throw new IOException("Unable to read a field with type tag " + tag);
}
logger.debug("..received> {}", result);
return result;
} | java | public static Field read(DataInputStream is) throws IOException {
final byte tag = is.readByte();
final Field result;
switch (tag) {
case 0x0f:
case 0x10:
case 0x11:
result = new NumberField(tag, is);
break;
case 0x14:
result = new BinaryField(is);
break;
case 0x26:
result = new StringField(is);
break;
default:
throw new IOException("Unable to read a field with type tag " + tag);
}
logger.debug("..received> {}", result);
return result;
} | [
"public",
"static",
"Field",
"read",
"(",
"DataInputStream",
"is",
")",
"throws",
"IOException",
"{",
"final",
"byte",
"tag",
"=",
"is",
".",
"readByte",
"(",
")",
";",
"final",
"Field",
"result",
";",
"switch",
"(",
"tag",
")",
"{",
"case",
"0x0f",
":... | Read a field from the supplied stream, starting with the tag that identifies the type, and reading enough
to collect the corresponding value.
@param is the stream on which a type tag is expected to be the next byte, followed by the field value.
@return the field that was found on the stream.
@throws IOException if there is a problem reading the field. | [
"Read",
"a",
"field",
"from",
"the",
"supplied",
"stream",
"starting",
"with",
"the",
"tag",
"that",
"identifies",
"the",
"type",
"and",
"reading",
"enough",
"to",
"collect",
"the",
"corresponding",
"value",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java#L63-L87 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java | Field.write | public void write(WritableByteChannel channel) throws IOException {
logger.debug("..writing> {}", this);
Util.writeFully(getBytes(), channel);
} | java | public void write(WritableByteChannel channel) throws IOException {
logger.debug("..writing> {}", this);
Util.writeFully(getBytes(), channel);
} | [
"public",
"void",
"write",
"(",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"..writing> {}\"",
",",
"this",
")",
";",
"Util",
".",
"writeFully",
"(",
"getBytes",
"(",
")",
",",
"channel",
")",
";",
"}... | Write the field to the specified channel.
@param channel the channel to which it should be written
@throws IOException if there is a problem writing to the channel | [
"Write",
"the",
"field",
"to",
"the",
"specified",
"channel",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java#L113-L116 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataFrom | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final CdjStatus status) {
if (status.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK || status.getRekordboxId() == 0) {
return null;
}
final DataReference track = new DataReference(status.getTrackSourcePlayer(), status.getTrackSourceSlot(),
status.getRekordboxId());
return requestMetadataFrom(track, status.getTrackType());
} | java | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final CdjStatus status) {
if (status.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK || status.getRekordboxId() == 0) {
return null;
}
final DataReference track = new DataReference(status.getTrackSourcePlayer(), status.getTrackSourceSlot(),
status.getRekordboxId());
return requestMetadataFrom(track, status.getTrackType());
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"TrackMetadata",
"requestMetadataFrom",
"(",
"final",
"CdjStatus",
"status",
")",
"{",
"if",
"(",
"status",
".",
"getTrackSourceSlot",
"(",
")",
"==",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"NO_TR... | Given a status update from a CDJ, find the metadata for the track that it has loaded, if any. If there is
an appropriate metadata cache, will use that, otherwise makes a query to the players dbserver.
@param status the CDJ status update that will be used to determine the loaded track and ask the appropriate
player for metadata about it
@return the metadata that was obtained, if any | [
"Given",
"a",
"status",
"update",
"from",
"a",
"CDJ",
"find",
"the",
"metadata",
"for",
"the",
"track",
"that",
"it",
"has",
"loaded",
"if",
"any",
".",
"If",
"there",
"is",
"an",
"appropriate",
"metadata",
"cache",
"will",
"use",
"that",
"otherwise",
"m... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L52-L60 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataFrom | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final DataReference track, final CdjStatus.TrackType trackType) {
return requestMetadataInternal(track, trackType, false);
} | java | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final DataReference track, final CdjStatus.TrackType trackType) {
return requestMetadataInternal(track, trackType, false);
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"TrackMetadata",
"requestMetadataFrom",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
")",
"{",
"return",
"requestMetadataInternal",
"(",
"track",
",",... | Ask the specified player for metadata about the track in the specified slot with the specified rekordbox ID,
unless we have a metadata cache available for the specified media slot, in which case that will be used instead.
@param track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@return the metadata, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"metadata",
"about",
"the",
"track",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"unless",
"we",
"have",
"a",
"metadata",
"cache",
"available",
"for",
"the",
"specified",
"media",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L73-L76 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataInternal | private TrackMetadata requestMetadataInternal(final DataReference track, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this request.
MetadataCache cache = getMetadataCache(SlotReference.getSlotReference(track));
if (cache != null && trackType == CdjStatus.TrackType.REKORDBOX) {
return cache.getTrackMetadata(null, track);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = getMediaDetailsFor(track.getSlotReference());
if (sourceDetails != null) {
final TrackMetadata provided = allMetadataProviders.getTrackMetadata(sourceDetails, track);
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 (passive.get() && failIfPassive && track.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// Use the dbserver protocol implementation to request the metadata.
ConnectionManager.ClientTask<TrackMetadata> task = new ConnectionManager.ClientTask<TrackMetadata>() {
@Override
public TrackMetadata useClient(Client client) throws Exception {
return queryMetadata(track, trackType, client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(track.player, task, "requesting metadata");
} catch (Exception e) {
logger.error("Problem requesting metadata, returning null", e);
}
return null;
} | java | private TrackMetadata requestMetadataInternal(final DataReference track, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this request.
MetadataCache cache = getMetadataCache(SlotReference.getSlotReference(track));
if (cache != null && trackType == CdjStatus.TrackType.REKORDBOX) {
return cache.getTrackMetadata(null, track);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = getMediaDetailsFor(track.getSlotReference());
if (sourceDetails != null) {
final TrackMetadata provided = allMetadataProviders.getTrackMetadata(sourceDetails, track);
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 (passive.get() && failIfPassive && track.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// Use the dbserver protocol implementation to request the metadata.
ConnectionManager.ClientTask<TrackMetadata> task = new ConnectionManager.ClientTask<TrackMetadata>() {
@Override
public TrackMetadata useClient(Client client) throws Exception {
return queryMetadata(track, trackType, client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(track.player, task, "requesting metadata");
} catch (Exception e) {
logger.error("Problem requesting metadata, returning null", e);
}
return null;
} | [
"private",
"TrackMetadata",
"requestMetadataInternal",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"final",
"boolean",
"failIfPassive",
")",
"{",
"// First check if we are using cached data for this request.",
"Metada... | Ask the specified player for metadata about the track 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 track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@param failIfPassive will prevent the request from taking place if we are in passive mode, so that automatic
metadata updates will use available caches only
@return the metadata found, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"metadata",
"about",
"the",
"track",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"using",
"cached",
"media",
"instead",
"if",
"it",
"is",
"available",
"and",
"possibly",
"giving",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L90-L127 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.queryMetadata | TrackMetadata queryMetadata(final DataReference track, final CdjStatus.TrackType trackType, final Client client)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(20, TimeUnit.SECONDS)) {
try {
final Message.KnownType requestType = (trackType == CdjStatus.TrackType.REKORDBOX) ?
Message.KnownType.REKORDBOX_METADATA_REQ : Message.KnownType.UNANALYZED_METADATA_REQ;
final Message response = client.menuRequestTyped(requestType, Message.MenuIdentifier.MAIN_MENU,
track.slot, trackType, new NumberField(track.rekordboxId));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE) {
return null;
}
// Gather the cue list and all the metadata menu items
final List<Message> items = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, track.slot, trackType, response);
final CueList cueList = getCueList(track.rekordboxId, track.slot, client);
return new TrackMetadata(track, trackType, items, cueList);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | java | TrackMetadata queryMetadata(final DataReference track, final CdjStatus.TrackType trackType, final Client client)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(20, TimeUnit.SECONDS)) {
try {
final Message.KnownType requestType = (trackType == CdjStatus.TrackType.REKORDBOX) ?
Message.KnownType.REKORDBOX_METADATA_REQ : Message.KnownType.UNANALYZED_METADATA_REQ;
final Message response = client.menuRequestTyped(requestType, Message.MenuIdentifier.MAIN_MENU,
track.slot, trackType, new NumberField(track.rekordboxId));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE) {
return null;
}
// Gather the cue list and all the metadata menu items
final List<Message> items = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, track.slot, trackType, response);
final CueList cueList = getCueList(track.rekordboxId, track.slot, client);
return new TrackMetadata(track, trackType, items, cueList);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | [
"TrackMetadata",
"queryMetadata",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"final",
"Client",
"client",
")",
"throws",
"IOException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"// Send the ... | Request metadata for a specific track ID, given a dbserver connection to a player that has already been set up.
Separated into its own method so it could be used multiple times with the same connection when gathering
all track metadata.
@param track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved metadata, or {@code null} if there is no such track
@throws IOException if there is a communication problem
@throws InterruptedException if the thread is interrupted while trying to lock the client for menu operations
@throws TimeoutException if we are unable to lock the client for menu operations | [
"Request",
"metadata",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"dbserver",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
".",
"Separated",
"into",
"its",
"own",
"method",
"so",
"it",
"could",
"be",
"used",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L150-L175 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getCueList | CueList getCueList(int rekordboxId, CdjStatus.TrackSourceSlot slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.CUE_LIST_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.CUE_LIST) {
return new CueList(response);
}
logger.error("Unexpected response type when requesting cue list: {}", response);
return null;
} | java | CueList getCueList(int rekordboxId, CdjStatus.TrackSourceSlot slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.CUE_LIST_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.CUE_LIST) {
return new CueList(response);
}
logger.error("Unexpected response type when requesting cue list: {}", response);
return null;
} | [
"CueList",
"getCueList",
"(",
"int",
"rekordboxId",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
... | Requests the cue list for a specific track ID, given a dbserver 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 cue list, or {@code null} if none was available
@throws IOException if there is a communication problem | [
"Requests",
"the",
"cue",
"list",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"dbserver",
"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/MetadataFinder.java#L188-L197 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getFullTrackList | List<Message> getFullTrackList(final CdjStatus.TrackSourceSlot slot, final Client client, final int sortOrder)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
Message response = client.menuRequest(Message.KnownType.TRACK_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slot,
new NumberField(sortOrder));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE || count == 0) {
return Collections.emptyList();
}
// Gather all the metadata menu items
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot, CdjStatus.TrackType.REKORDBOX, response);
}
finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | java | List<Message> getFullTrackList(final CdjStatus.TrackSourceSlot slot, final Client client, final int sortOrder)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
Message response = client.menuRequest(Message.KnownType.TRACK_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slot,
new NumberField(sortOrder));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE || count == 0) {
return Collections.emptyList();
}
// Gather all the metadata menu items
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot, CdjStatus.TrackType.REKORDBOX, response);
}
finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | [
"List",
"<",
"Message",
">",
"getFullTrackList",
"(",
"final",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"final",
"Client",
"client",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"IOException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",... | Request the list of all tracks in the specified slot, given a dbserver connection to a player that has already
been set up.
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved track list entry items
@throws IOException if there is a communication problem
@throws InterruptedException if the thread is interrupted while trying to lock the client for menu operations
@throws TimeoutException if we are unable to lock the client for menu operations | [
"Request",
"the",
"list",
"of",
"all",
"tracks",
"in",
"the",
"specified",
"slot",
"given",
"a",
"dbserver",
"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/MetadataFinder.java#L212-L233 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.clearDeck | private void clearDeck(CdjStatus update) {
if (hotCache.remove(DeckReference.getDeckReference(update.getDeviceNumber(), 0)) != null) {
deliverTrackMetadataUpdate(update.getDeviceNumber(), null);
}
} | java | private void clearDeck(CdjStatus update) {
if (hotCache.remove(DeckReference.getDeckReference(update.getDeviceNumber(), 0)) != null) {
deliverTrackMetadataUpdate(update.getDeviceNumber(), null);
}
} | [
"private",
"void",
"clearDeck",
"(",
"CdjStatus",
"update",
")",
"{",
"if",
"(",
"hotCache",
".",
"remove",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"0",
")",
")",
"!=",
"null",
")",
"{",
"deliv... | We have received an update that invalidates any previous metadata for that player, so clear it out, 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 can have no metadata for the associated player | [
"We",
"have",
"received",
"an",
"update",
"that",
"invalidates",
"any",
"previous",
"metadata",
"for",
"that",
"player",
"so",
"clear",
"it",
"out",
"and",
"alert",
"any",
"listeners",
"if",
"this",
"represents",
"a",
"change",
".",
"This",
"does",
"not",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L432-L436 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.clearMetadata | private void clearMetadata(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) {
deliverTrackMetadataUpdate(player, null); // Inform listeners the metadata is gone.
}
}
}
} | java | private void clearMetadata(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) {
deliverTrackMetadataUpdate(player, null); // Inform listeners the metadata is gone.
}
}
}
} | [
"private",
"void",
"clearMetadata",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"final",
"int",
"player",
"=",
"announcement",
".",
"getNumber",
"(",
")",
";",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
... | We have received notification that a device is no longer on the network, so clear out its metadata.
@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",
"metadata",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L443-L454 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.updateMetadata | private void updateMetadata(CdjStatus update, TrackMetadata data) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), 0), data); // Main deck
if (data.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : data.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), entry.hotCueNumber), data);
}
}
}
deliverTrackMetadataUpdate(update.getDeviceNumber(), data);
} | java | private void updateMetadata(CdjStatus update, TrackMetadata data) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), 0), data); // Main deck
if (data.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : data.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), entry.hotCueNumber), data);
}
}
}
deliverTrackMetadataUpdate(update.getDeviceNumber(), data);
} | [
"private",
"void",
"updateMetadata",
"(",
"CdjStatus",
"update",
",",
"TrackMetadata",
"data",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"0",
")",
",",
"data",
")",
... | We have obtained metadata for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this metadata
@param data the metadata which we received | [
"We",
"have",
"obtained",
"metadata",
"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/MetadataFinder.java#L462-L472 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getLoadedTracks | public Map<DeckReference, TrackMetadata> getLoadedTracks() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, TrackMetadata>(hotCache));
} | java | public Map<DeckReference, TrackMetadata> getLoadedTracks() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, TrackMetadata>(hotCache));
} | [
"public",
"Map",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"getLoadedTracks",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"H... | Get the metadata of all tracks currently loaded in any player, either on the play deck, or in a hot cue.
@return the track information reported by all current players, including any tracks loaded in their hot cue slots
@throws IllegalStateException if the MetadataFinder is not running | [
"Get",
"the",
"metadata",
"of",
"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/MetadataFinder.java#L481-L485 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.attachMetadataCache | public void attachMetadataCache(SlotReference slot, File file)
throws IOException {
ensureRunning();
if (slot.player < 1 || slot.player > 4 || DeviceFinder.getInstance().getLatestAnnouncementFrom(slot.player) == null) {
throw new IllegalArgumentException("unable to attach metadata cache for player " + slot.player);
}
if ((slot.slot != CdjStatus.TrackSourceSlot.USB_SLOT) && (slot.slot != CdjStatus.TrackSourceSlot.SD_SLOT)) {
throw new IllegalArgumentException("unable to attach metadata cache for slot " + slot.slot);
}
MetadataCache cache = new MetadataCache(file);
final MediaDetails slotDetails = getMediaDetailsFor(slot);
if (cache.sourceMedia != null && slotDetails != null) {
if (!slotDetails.hashKey().equals(cache.sourceMedia.hashKey())) {
throw new IllegalArgumentException("Cache was created for different media (" + cache.sourceMedia.hashKey() +
") than is in the slot (" + slotDetails.hashKey() + ").");
}
if (slotDetails.hasChanged(cache.sourceMedia)) {
logger.warn("Media has changed (" + slotDetails + ") since cache was created (" + cache.sourceMedia +
"). Attaching anyway as instructed.");
}
}
attachMetadataCacheInternal(slot, cache);
} | java | public void attachMetadataCache(SlotReference slot, File file)
throws IOException {
ensureRunning();
if (slot.player < 1 || slot.player > 4 || DeviceFinder.getInstance().getLatestAnnouncementFrom(slot.player) == null) {
throw new IllegalArgumentException("unable to attach metadata cache for player " + slot.player);
}
if ((slot.slot != CdjStatus.TrackSourceSlot.USB_SLOT) && (slot.slot != CdjStatus.TrackSourceSlot.SD_SLOT)) {
throw new IllegalArgumentException("unable to attach metadata cache for slot " + slot.slot);
}
MetadataCache cache = new MetadataCache(file);
final MediaDetails slotDetails = getMediaDetailsFor(slot);
if (cache.sourceMedia != null && slotDetails != null) {
if (!slotDetails.hashKey().equals(cache.sourceMedia.hashKey())) {
throw new IllegalArgumentException("Cache was created for different media (" + cache.sourceMedia.hashKey() +
") than is in the slot (" + slotDetails.hashKey() + ").");
}
if (slotDetails.hasChanged(cache.sourceMedia)) {
logger.warn("Media has changed (" + slotDetails + ") since cache was created (" + cache.sourceMedia +
"). Attaching anyway as instructed.");
}
}
attachMetadataCacheInternal(slot, cache);
} | [
"public",
"void",
"attachMetadataCache",
"(",
"SlotReference",
"slot",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"ensureRunning",
"(",
")",
";",
"if",
"(",
"slot",
".",
"player",
"<",
"1",
"||",
"slot",
".",
"player",
">",
"4",
"||",
"Devic... | Attach a metadata cache file to a particular player media slot, so the cache will be used instead of querying
the player for metadata. This supports operation with metadata during shows where DJs are using all four player
numbers and heavily cross-linking between them.
If the media is ejected from that player slot, the cache will be detached.
@param slot the media slot to which a meta data cache is to be attached
@param file the metadata cache to be attached
@throws IOException if there is a problem reading the cache file
@throws IllegalArgumentException if an invalid player number or slot is supplied
@throws IllegalStateException if the metadata finder is not running | [
"Attach",
"a",
"metadata",
"cache",
"file",
"to",
"a",
"particular",
"player",
"media",
"slot",
"so",
"the",
"cache",
"will",
"be",
"used",
"instead",
"of",
"querying",
"the",
"player",
"for",
"metadata",
".",
"This",
"supports",
"operation",
"with",
"metada... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L540-L563 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.attachMetadataCacheInternal | void attachMetadataCacheInternal(SlotReference slot, MetadataCache cache) {
MetadataCache oldCache = metadataCacheFiles.put(slot, cache);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing previous metadata cache", e);
}
}
deliverCacheUpdate(slot, cache);
} | java | void attachMetadataCacheInternal(SlotReference slot, MetadataCache cache) {
MetadataCache oldCache = metadataCacheFiles.put(slot, cache);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing previous metadata cache", e);
}
}
deliverCacheUpdate(slot, cache);
} | [
"void",
"attachMetadataCacheInternal",
"(",
"SlotReference",
"slot",
",",
"MetadataCache",
"cache",
")",
"{",
"MetadataCache",
"oldCache",
"=",
"metadataCacheFiles",
".",
"put",
"(",
"slot",
",",
"cache",
")",
";",
"if",
"(",
"oldCache",
"!=",
"null",
")",
"{"... | Finishes the process of attaching a metadata cache file once it has been opened and validated.
@param slot the slot to which the cache should be attached
@param cache the opened, validated metadata cache file | [
"Finishes",
"the",
"process",
"of",
"attaching",
"a",
"metadata",
"cache",
"file",
"once",
"it",
"has",
"been",
"opened",
"and",
"validated",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L571-L582 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.detachMetadataCache | public void detachMetadataCache(SlotReference slot) {
MetadataCache oldCache = metadataCacheFiles.remove(slot);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing metadata cache", e);
}
deliverCacheUpdate(slot, null);
}
} | java | public void detachMetadataCache(SlotReference slot) {
MetadataCache oldCache = metadataCacheFiles.remove(slot);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing metadata cache", e);
}
deliverCacheUpdate(slot, null);
}
} | [
"public",
"void",
"detachMetadataCache",
"(",
"SlotReference",
"slot",
")",
"{",
"MetadataCache",
"oldCache",
"=",
"metadataCacheFiles",
".",
"remove",
"(",
"slot",
")",
";",
"if",
"(",
"oldCache",
"!=",
"null",
")",
"{",
"try",
"{",
"oldCache",
".",
"close"... | Removes any metadata cache file that might have been assigned to a particular player media slot, so metadata
will be looked up from the player itself.
@param slot the media slot to which a meta data cache is to be attached | [
"Removes",
"any",
"metadata",
"cache",
"file",
"that",
"might",
"have",
"been",
"assigned",
"to",
"a",
"particular",
"player",
"media",
"slot",
"so",
"metadata",
"will",
"be",
"looked",
"up",
"from",
"the",
"player",
"itself",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L590-L600 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getAutoAttachCacheFiles | public List<File> getAutoAttachCacheFiles() {
ArrayList<File> currentFiles = new ArrayList<File>(autoAttachCacheFiles);
Collections.sort(currentFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
return Collections.unmodifiableList(currentFiles);
} | java | public List<File> getAutoAttachCacheFiles() {
ArrayList<File> currentFiles = new ArrayList<File>(autoAttachCacheFiles);
Collections.sort(currentFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
return Collections.unmodifiableList(currentFiles);
} | [
"public",
"List",
"<",
"File",
">",
"getAutoAttachCacheFiles",
"(",
")",
"{",
"ArrayList",
"<",
"File",
">",
"currentFiles",
"=",
"new",
"ArrayList",
"<",
"File",
">",
"(",
"autoAttachCacheFiles",
")",
";",
"Collections",
".",
"sort",
"(",
"currentFiles",
",... | Get the metadata cache files that are currently configured to be automatically attached when matching media is
mounted in a player on the network.
@return the current auto-attache cache files, sorted by name | [
"Get",
"the",
"metadata",
"cache",
"files",
"that",
"are",
"currently",
"configured",
"to",
"be",
"automatically",
"attached",
"when",
"matching",
"media",
"is",
"mounted",
"in",
"a",
"player",
"on",
"the",
"network",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L665-L674 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.flushHotCacheSlot | private void flushHotCacheSlot(SlotReference slot) {
// Iterate over a copy to avoid concurrent modification issues
for (Map.Entry<DeckReference, TrackMetadata> entry : new HashMap<DeckReference,TrackMetadata>(hotCache).entrySet()) {
if (slot == SlotReference.getSlotReference(entry.getValue().trackReference)) {
logger.debug("Evicting cached metadata in response to unmount report {}", entry.getValue());
hotCache.remove(entry.getKey());
}
}
} | java | private void flushHotCacheSlot(SlotReference slot) {
// Iterate over a copy to avoid concurrent modification issues
for (Map.Entry<DeckReference, TrackMetadata> entry : new HashMap<DeckReference,TrackMetadata>(hotCache).entrySet()) {
if (slot == SlotReference.getSlotReference(entry.getValue().trackReference)) {
logger.debug("Evicting cached metadata in response to unmount report {}", entry.getValue());
hotCache.remove(entry.getKey());
}
}
} | [
"private",
"void",
"flushHotCacheSlot",
"(",
"SlotReference",
"slot",
")",
"{",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"entry",
":",
"new",
"HashMap",
"<",
"De... | Discards any tracks from the hot cache that were loaded from a now-unmounted media slot, because they are no
longer valid. | [
"Discards",
"any",
"tracks",
"from",
"the",
"hot",
"cache",
"that",
"were",
"loaded",
"from",
"a",
"now",
"-",
"unmounted",
"media",
"slot",
"because",
"they",
"are",
"no",
"longer",
"valid",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L715-L723 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.recordMount | private void recordMount(SlotReference slot) {
if (mediaMounts.add(slot)) {
deliverMountUpdate(slot, true);
}
if (!mediaDetails.containsKey(slot)) {
try {
VirtualCdj.getInstance().sendMediaQuery(slot);
} catch (Exception e) {
logger.warn("Problem trying to request media details for " + slot, e);
}
}
} | java | private void recordMount(SlotReference slot) {
if (mediaMounts.add(slot)) {
deliverMountUpdate(slot, true);
}
if (!mediaDetails.containsKey(slot)) {
try {
VirtualCdj.getInstance().sendMediaQuery(slot);
} catch (Exception e) {
logger.warn("Problem trying to request media details for " + slot, e);
}
}
} | [
"private",
"void",
"recordMount",
"(",
"SlotReference",
"slot",
")",
"{",
"if",
"(",
"mediaMounts",
".",
"add",
"(",
"slot",
")",
")",
"{",
"deliverMountUpdate",
"(",
"slot",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"mediaDetails",
".",
"containsKey",... | Records that there is media mounted in a particular media player slot, updating listeners if this is a change.
Also send a query to the player requesting details about the media mounted in that slot, if we don't already
have that information.
@param slot the slot in which media is mounted | [
"Records",
"that",
"there",
"is",
"media",
"mounted",
"in",
"a",
"particular",
"media",
"player",
"slot",
"updating",
"listeners",
"if",
"this",
"is",
"a",
"change",
".",
"Also",
"send",
"a",
"query",
"to",
"the",
"player",
"requesting",
"details",
"about",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L748-L759 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.removeMount | private void removeMount(SlotReference slot) {
mediaDetails.remove(slot);
if (mediaMounts.remove(slot)) {
deliverMountUpdate(slot, false);
}
} | java | private void removeMount(SlotReference slot) {
mediaDetails.remove(slot);
if (mediaMounts.remove(slot)) {
deliverMountUpdate(slot, false);
}
} | [
"private",
"void",
"removeMount",
"(",
"SlotReference",
"slot",
")",
"{",
"mediaDetails",
".",
"remove",
"(",
"slot",
")",
";",
"if",
"(",
"mediaMounts",
".",
"remove",
"(",
"slot",
")",
")",
"{",
"deliverMountUpdate",
"(",
"slot",
",",
"false",
")",
";"... | Records that there is no media mounted in a particular media player slot, updating listeners if this is a change,
and clearing any affected items from our in-memory caches.
@param slot the slot in which no media is mounted | [
"Records",
"that",
"there",
"is",
"no",
"media",
"mounted",
"in",
"a",
"particular",
"media",
"player",
"slot",
"updating",
"listeners",
"if",
"this",
"is",
"a",
"change",
"and",
"clearing",
"any",
"affected",
"items",
"from",
"our",
"in",
"-",
"memory",
"... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L767-L772 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverMountUpdate | private void deliverMountUpdate(SlotReference slot, boolean mounted) {
if (mounted) {
logger.info("Reporting media mounted in " + slot);
} else {
logger.info("Reporting media removed from " + slot);
}
for (final MountListener listener : getMountListeners()) {
try {
if (mounted) {
listener.mediaMounted(slot);
} else {
listener.mediaUnmounted(slot);
}
} catch (Throwable t) {
logger.warn("Problem delivering mount update to listener", t);
}
}
if (mounted) {
MetadataCache.tryAutoAttaching(slot);
}
} | java | private void deliverMountUpdate(SlotReference slot, boolean mounted) {
if (mounted) {
logger.info("Reporting media mounted in " + slot);
} else {
logger.info("Reporting media removed from " + slot);
}
for (final MountListener listener : getMountListeners()) {
try {
if (mounted) {
listener.mediaMounted(slot);
} else {
listener.mediaUnmounted(slot);
}
} catch (Throwable t) {
logger.warn("Problem delivering mount update to listener", t);
}
}
if (mounted) {
MetadataCache.tryAutoAttaching(slot);
}
} | [
"private",
"void",
"deliverMountUpdate",
"(",
"SlotReference",
"slot",
",",
"boolean",
"mounted",
")",
"{",
"if",
"(",
"mounted",
")",
"{",
"logger",
".",
"info",
"(",
"\"Reporting media mounted in \"",
"+",
"slot",
")",
";",
"}",
"else",
"{",
"logger",
".",... | Send a mount update announcement to all registered listeners, and see if we can auto-attach a media cache file.
@param slot the slot in which media has been mounted or unmounted
@param mounted will be {@code true} if there is now media mounted in the specified slot | [
"Send",
"a",
"mount",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"and",
"see",
"if",
"we",
"can",
"auto",
"-",
"attach",
"a",
"media",
"cache",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L870-L892 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverCacheUpdate | private void deliverCacheUpdate(SlotReference slot, MetadataCache cache) {
for (final MetadataCacheListener listener : getCacheListeners()) {
try {
if (cache == null) {
listener.cacheDetached(slot);
} else {
listener.cacheAttached(slot, cache);
}
} catch (Throwable t) {
logger.warn("Problem delivering metadata cache update to listener", t);
}
}
} | java | private void deliverCacheUpdate(SlotReference slot, MetadataCache cache) {
for (final MetadataCacheListener listener : getCacheListeners()) {
try {
if (cache == null) {
listener.cacheDetached(slot);
} else {
listener.cacheAttached(slot, cache);
}
} catch (Throwable t) {
logger.warn("Problem delivering metadata cache update to listener", t);
}
}
} | [
"private",
"void",
"deliverCacheUpdate",
"(",
"SlotReference",
"slot",
",",
"MetadataCache",
"cache",
")",
"{",
"for",
"(",
"final",
"MetadataCacheListener",
"listener",
":",
"getCacheListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"cache",
"==",
"null"... | Send a metadata cache update announcement to all registered listeners.
@param slot the media slot whose cache status has changed
@param cache the cache which has been attached, or, if {@code null}, the previous cache has been detached | [
"Send",
"a",
"metadata",
"cache",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L952-L964 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverTrackMetadataUpdate | private void deliverTrackMetadataUpdate(int player, TrackMetadata metadata) {
if (!getTrackMetadataListeners().isEmpty()) {
final TrackMetadataUpdate update = new TrackMetadataUpdate(player, metadata);
for (final TrackMetadataListener listener : getTrackMetadataListeners()) {
try {
listener.metadataChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering track metadata update to listener", t);
}
}
}
} | java | private void deliverTrackMetadataUpdate(int player, TrackMetadata metadata) {
if (!getTrackMetadataListeners().isEmpty()) {
final TrackMetadataUpdate update = new TrackMetadataUpdate(player, metadata);
for (final TrackMetadataListener listener : getTrackMetadataListeners()) {
try {
listener.metadataChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering track metadata update to listener", t);
}
}
}
} | [
"private",
"void",
"deliverTrackMetadataUpdate",
"(",
"int",
"player",
",",
"TrackMetadata",
"metadata",
")",
"{",
"if",
"(",
"!",
"getTrackMetadataListeners",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"TrackMetadataUpdate",
"update",
"=",
"new",
... | Send a track metadata update announcement to all registered listeners. | [
"Send",
"a",
"track",
"metadata",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1023-L1035 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.addMetadataProviderForMedia | private void addMetadataProviderForMedia(String key, MetadataProvider provider) {
if (!metadataProviders.containsKey(key)) {
metadataProviders.put(key, Collections.newSetFromMap(new ConcurrentHashMap<MetadataProvider, Boolean>()));
}
Set<MetadataProvider> providers = metadataProviders.get(key);
providers.add(provider);
} | java | private void addMetadataProviderForMedia(String key, MetadataProvider provider) {
if (!metadataProviders.containsKey(key)) {
metadataProviders.put(key, Collections.newSetFromMap(new ConcurrentHashMap<MetadataProvider, Boolean>()));
}
Set<MetadataProvider> providers = metadataProviders.get(key);
providers.add(provider);
} | [
"private",
"void",
"addMetadataProviderForMedia",
"(",
"String",
"key",
",",
"MetadataProvider",
"provider",
")",
"{",
"if",
"(",
"!",
"metadataProviders",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"metadataProviders",
".",
"put",
"(",
"key",
",",
"Collec... | Internal method that adds a metadata provider to the set associated with a particular hash key, creating the
set if needed.
@param key the hashKey identifying the media for which this provider can offer metadata (or the empty string if
it can offer metadata for all media)
@param provider the metadata provider to be added to the active set | [
"Internal",
"method",
"that",
"adds",
"a",
"metadata",
"provider",
"to",
"the",
"set",
"associated",
"with",
"a",
"particular",
"hash",
"key",
"creating",
"the",
"set",
"if",
"needed",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1082-L1088 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.removeMetadataProvider | public void removeMetadataProvider(MetadataProvider provider) {
for (Set<MetadataProvider> providers : metadataProviders.values()) {
providers.remove(provider);
}
} | java | public void removeMetadataProvider(MetadataProvider provider) {
for (Set<MetadataProvider> providers : metadataProviders.values()) {
providers.remove(provider);
}
} | [
"public",
"void",
"removeMetadataProvider",
"(",
"MetadataProvider",
"provider",
")",
"{",
"for",
"(",
"Set",
"<",
"MetadataProvider",
">",
"providers",
":",
"metadataProviders",
".",
"values",
"(",
")",
")",
"{",
"providers",
".",
"remove",
"(",
"provider",
"... | Removes a metadata provider so it will no longer be consulted to provide metadata for tracks loaded from any
media.
@param provider the metadata provider to remove. | [
"Removes",
"a",
"metadata",
"provider",
"so",
"it",
"will",
"no",
"longer",
"be",
"consulted",
"to",
"provide",
"metadata",
"for",
"tracks",
"loaded",
"from",
"any",
"media",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1096-L1100 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getMetadataProviders | public Set<MetadataProvider> getMetadataProviders(MediaDetails sourceMedia) {
String key = (sourceMedia == null)? "" : sourceMedia.hashKey();
Set<MetadataProvider> result = metadataProviders.get(key);
if (result == null) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new HashSet<MetadataProvider>(result));
} | java | public Set<MetadataProvider> getMetadataProviders(MediaDetails sourceMedia) {
String key = (sourceMedia == null)? "" : sourceMedia.hashKey();
Set<MetadataProvider> result = metadataProviders.get(key);
if (result == null) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new HashSet<MetadataProvider>(result));
} | [
"public",
"Set",
"<",
"MetadataProvider",
">",
"getMetadataProviders",
"(",
"MediaDetails",
"sourceMedia",
")",
"{",
"String",
"key",
"=",
"(",
"sourceMedia",
"==",
"null",
")",
"?",
"\"\"",
":",
"sourceMedia",
".",
"hashKey",
"(",
")",
";",
"Set",
"<",
"M... | Get the set of metadata providers that can offer metadata for tracks loaded from the specified media.
@param sourceMedia the media whose metadata providers are desired, or {@code null} to get the set of
metadata providers that can offer metadata for all media.
@return any registered metadata providers that reported themselves as supporting tracks from that media | [
"Get",
"the",
"set",
"of",
"metadata",
"providers",
"that",
"can",
"offer",
"metadata",
"for",
"tracks",
"loaded",
"from",
"the",
"specified",
"media",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1110-L1117 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.handleUpdate | private void handleUpdate(final CdjStatus update) {
// First see if any metadata caches need evicting or mount sets need updating.
if (update.isLocalUsbEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalUsbLoaded()) {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT));
}
if (update.isLocalSdEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalSdLoaded()){
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT));
}
if (update.isDiscSlotEmpty()) {
removeMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
} else {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
}
// Now see if a track has changed that needs new metadata.
if (update.getTrackType() == CdjStatus.TrackType.UNKNOWN ||
update.getTrackType() == CdjStatus.TrackType.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.UNKNOWN ||
update.getRekordboxId() == 0) { // We no longer have metadata for this device.
clearDeck(update);
} else { // We can offer metadata for this device; check if we already looked up this track.
final TrackMetadata lastMetadata = hotCache.get(DeckReference.getDeckReference(update.getDeviceNumber(), 0));
final DataReference trackReference = new DataReference(update.getTrackSourcePlayer(),
update.getTrackSourceSlot(), update.getRekordboxId());
if (lastMetadata == null || !lastMetadata.trackReference.equals(trackReference)) { // We have something new!
// First see if we can find the new track in the hot cache as a hot cue
for (TrackMetadata cached : hotCache.values()) {
if (cached.trackReference.equals(trackReference)) { // Found a hot cue hit, use it.
updateMetadata(update, cached);
return;
}
}
// Not in the hot cache so try actually retrieving it.
if (activeRequests.add(update.getTrackSourcePlayer())) {
// We had to make sure we were not already asking for this track.
clearDeck(update); // We won't know what it is until our request completes.
new Thread(new Runnable() {
@Override
public void run() {
try {
TrackMetadata data = requestMetadataInternal(trackReference, update.getTrackType(), true);
if (data != null) {
updateMetadata(update, data);
}
} catch (Exception e) {
logger.warn("Problem requesting track metadata from update" + update, e);
} finally {
activeRequests.remove(update.getTrackSourcePlayer());
}
}
}, "MetadataFinder metadata request").start();
}
}
}
} | java | private void handleUpdate(final CdjStatus update) {
// First see if any metadata caches need evicting or mount sets need updating.
if (update.isLocalUsbEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalUsbLoaded()) {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT));
}
if (update.isLocalSdEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalSdLoaded()){
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT));
}
if (update.isDiscSlotEmpty()) {
removeMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
} else {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
}
// Now see if a track has changed that needs new metadata.
if (update.getTrackType() == CdjStatus.TrackType.UNKNOWN ||
update.getTrackType() == CdjStatus.TrackType.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.UNKNOWN ||
update.getRekordboxId() == 0) { // We no longer have metadata for this device.
clearDeck(update);
} else { // We can offer metadata for this device; check if we already looked up this track.
final TrackMetadata lastMetadata = hotCache.get(DeckReference.getDeckReference(update.getDeviceNumber(), 0));
final DataReference trackReference = new DataReference(update.getTrackSourcePlayer(),
update.getTrackSourceSlot(), update.getRekordboxId());
if (lastMetadata == null || !lastMetadata.trackReference.equals(trackReference)) { // We have something new!
// First see if we can find the new track in the hot cache as a hot cue
for (TrackMetadata cached : hotCache.values()) {
if (cached.trackReference.equals(trackReference)) { // Found a hot cue hit, use it.
updateMetadata(update, cached);
return;
}
}
// Not in the hot cache so try actually retrieving it.
if (activeRequests.add(update.getTrackSourcePlayer())) {
// We had to make sure we were not already asking for this track.
clearDeck(update); // We won't know what it is until our request completes.
new Thread(new Runnable() {
@Override
public void run() {
try {
TrackMetadata data = requestMetadataInternal(trackReference, update.getTrackType(), true);
if (data != null) {
updateMetadata(update, data);
}
} catch (Exception e) {
logger.warn("Problem requesting track metadata from update" + update, e);
} finally {
activeRequests.remove(update.getTrackSourcePlayer());
}
}
}, "MetadataFinder metadata request").start();
}
}
}
} | [
"private",
"void",
"handleUpdate",
"(",
"final",
"CdjStatus",
"update",
")",
"{",
"// First see if any metadata caches need evicting or mount sets need updating.",
"if",
"(",
"update",
".",
"isLocalUsbEmpty",
"(",
")",
")",
"{",
"final",
"SlotReference",
"slot",
"=",
"S... | Process an update packet from one of the CDJs. See if it has a valid track loaded; if not, clear any
metadata we had stored for that player. If so, see if it is the same track we already know about; if not,
request the metadata associated with that track.
Also clears out any metadata caches that were attached for slots that no longer have media mounted in them,
and updates the sets of which players have media mounted in which slots.
If any of these reflect a change in state, any registered listeners will be informed.
@param update an update packet we received from a CDJ | [
"Process",
"an",
"update",
"packet",
"from",
"one",
"of",
"the",
"CDJs",
".",
"See",
"if",
"it",
"has",
"a",
"valid",
"track",
"loaded",
";",
"if",
"not",
"clear",
"any",
"metadata",
"we",
"had",
"stored",
"for",
"that",
"player",
".",
"If",
"so",
"s... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1246-L1314 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetail.java | WaveformDetail.getColorWaveformBits | private int getColorWaveformBits(final ByteBuffer waveBytes, final int segment) {
final int base = (segment * 2);
final int big = Util.unsign(waveBytes.get(base));
final int small = Util.unsign(waveBytes.get(base + 1));
return big * 256 + small;
} | java | private int getColorWaveformBits(final ByteBuffer waveBytes, final int segment) {
final int base = (segment * 2);
final int big = Util.unsign(waveBytes.get(base));
final int small = Util.unsign(waveBytes.get(base + 1));
return big * 256 + small;
} | [
"private",
"int",
"getColorWaveformBits",
"(",
"final",
"ByteBuffer",
"waveBytes",
",",
"final",
"int",
"segment",
")",
"{",
"final",
"int",
"base",
"=",
"(",
"segment",
"*",
"2",
")",
";",
"final",
"int",
"big",
"=",
"Util",
".",
"unsign",
"(",
"waveByt... | Color waveforms are represented by a series of sixteen bit integers into which color and height information are
packed. This function returns the integer corresponding to a particular half-frame in the waveform.
@param waveBytes the raw data making up the waveform
@param segment the index of hte half-frame of interest
@return the sixteen-bit number encoding the height and RGB values of that segment | [
"Color",
"waveforms",
"are",
"represented",
"by",
"a",
"series",
"of",
"sixteen",
"bit",
"integers",
"into",
"which",
"color",
"and",
"height",
"information",
"are",
"packed",
".",
"This",
"function",
"returns",
"the",
"integer",
"corresponding",
"to",
"a",
"p... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetail.java#L208-L213 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.addCacheFormatEntry | private static void addCacheFormatEntry(List<Message> trackListEntries, int playlistId, ZipOutputStream zos) throws IOException {
// Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
// that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
// Since we are doing this anyway, we can also provide information about the nature of the cache, and
// how many metadata entries it contains, which is useful for auto-attachment.
zos.putNextEntry(new ZipEntry(CACHE_FORMAT_ENTRY));
String formatEntry = CACHE_FORMAT_IDENTIFIER + ":" + playlistId + ":" + trackListEntries.size();
zos.write(formatEntry.getBytes("UTF-8"));
} | java | private static void addCacheFormatEntry(List<Message> trackListEntries, int playlistId, ZipOutputStream zos) throws IOException {
// Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
// that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
// Since we are doing this anyway, we can also provide information about the nature of the cache, and
// how many metadata entries it contains, which is useful for auto-attachment.
zos.putNextEntry(new ZipEntry(CACHE_FORMAT_ENTRY));
String formatEntry = CACHE_FORMAT_IDENTIFIER + ":" + playlistId + ":" + trackListEntries.size();
zos.write(formatEntry.getBytes("UTF-8"));
} | [
"private",
"static",
"void",
"addCacheFormatEntry",
"(",
"List",
"<",
"Message",
">",
"trackListEntries",
",",
"int",
"playlistId",
",",
"ZipOutputStream",
"zos",
")",
"throws",
"IOException",
"{",
"// Add a marker so we can recognize this as a metadata archive. I would use t... | Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
Since we are doing this anyway, we can also provide information about the nature of the cache, and
how many metadata entries it contains, which is useful for auto-attachment.
@param trackListEntries the tracks contained in the cache, so we can record the number
@param playlistId the playlist contained in the cache, or 0 if it is all tracks from the media
@param zos the stream to which the ZipFile is being written
@throws IOException if there is a problem creating the format entry | [
"Add",
"a",
"marker",
"so",
"we",
"can",
"recognize",
"this",
"as",
"a",
"metadata",
"archive",
".",
"I",
"would",
"use",
"the",
"ZipFile",
"comment",
"but",
"that",
"is",
"not",
"available",
"until",
"Java",
"7",
"and",
"Beat",
"Link",
"is",
"supposed",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L344-L352 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.addCacheDetailsEntry | private static void addCacheDetailsEntry(SlotReference slot, ZipOutputStream zos, WritableByteChannel channel) throws IOException {
// Record the details of the media being cached, to make it easier to recognize now that we can.
MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null) {
zos.putNextEntry(new ZipEntry(CACHE_DETAILS_ENTRY));
Util.writeFully(details.getRawBytes(), channel);
}
} | java | private static void addCacheDetailsEntry(SlotReference slot, ZipOutputStream zos, WritableByteChannel channel) throws IOException {
// Record the details of the media being cached, to make it easier to recognize now that we can.
MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null) {
zos.putNextEntry(new ZipEntry(CACHE_DETAILS_ENTRY));
Util.writeFully(details.getRawBytes(), channel);
}
} | [
"private",
"static",
"void",
"addCacheDetailsEntry",
"(",
"SlotReference",
"slot",
",",
"ZipOutputStream",
"zos",
",",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"// Record the details of the media being cached, to make it easier to recognize now that we c... | Record the details of the media being cached, to make it easier to recognize, now that we have access to that
information.
@param slot the slot from which a metadata cache is being created
@param zos the stream to which the ZipFile is being written
@param channel the low-level channel to which the cache is being written
@throws IOException if there is a problem writing the media details entry | [
"Record",
"the",
"details",
"of",
"the",
"media",
"being",
"cached",
"to",
"make",
"it",
"easier",
"to",
"recognize",
"now",
"that",
"we",
"have",
"access",
"to",
"that",
"information",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L364-L371 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.getCacheFormatEntry | private String getCacheFormatEntry() throws IOException {
ZipEntry zipEntry = zipFile.getEntry(CACHE_FORMAT_ENTRY);
InputStream is = zipFile.getInputStream(zipEntry);
try {
Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
String tag = null;
if (s.hasNext()) tag = s.next();
return tag;
} finally {
is.close();
}
} | java | private String getCacheFormatEntry() throws IOException {
ZipEntry zipEntry = zipFile.getEntry(CACHE_FORMAT_ENTRY);
InputStream is = zipFile.getInputStream(zipEntry);
try {
Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
String tag = null;
if (s.hasNext()) tag = s.next();
return tag;
} finally {
is.close();
}
} | [
"private",
"String",
"getCacheFormatEntry",
"(",
")",
"throws",
"IOException",
"{",
"ZipEntry",
"zipEntry",
"=",
"zipFile",
".",
"getEntry",
"(",
"CACHE_FORMAT_ENTRY",
")",
";",
"InputStream",
"is",
"=",
"zipFile",
".",
"getInputStream",
"(",
"zipEntry",
")",
";... | Find and read the cache format entry in a metadata cache file.
@return the content of the format entry, or {@code null} if none was found
@throws IOException if there is a problem reading the file | [
"Find",
"and",
"read",
"the",
"cache",
"format",
"entry",
"in",
"a",
"metadata",
"cache",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L454-L465 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.getTrackIds | public List<Integer> getTrackIds() {
ArrayList<Integer> results = new ArrayList<Integer>(trackCount);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().startsWith(CACHE_METADATA_ENTRY_PREFIX)) {
String idPart = entry.getName().substring(CACHE_METADATA_ENTRY_PREFIX.length());
if (idPart.length() > 0) {
results.add(Integer.valueOf(idPart));
}
}
}
return Collections.unmodifiableList(results);
} | java | public List<Integer> getTrackIds() {
ArrayList<Integer> results = new ArrayList<Integer>(trackCount);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().startsWith(CACHE_METADATA_ENTRY_PREFIX)) {
String idPart = entry.getName().substring(CACHE_METADATA_ENTRY_PREFIX.length());
if (idPart.length() > 0) {
results.add(Integer.valueOf(idPart));
}
}
}
return Collections.unmodifiableList(results);
} | [
"public",
"List",
"<",
"Integer",
">",
"getTrackIds",
"(",
")",
"{",
"ArrayList",
"<",
"Integer",
">",
"results",
"=",
"new",
"ArrayList",
"<",
"Integer",
">",
"(",
"trackCount",
")",
";",
"Enumeration",
"<",
"?",
"extends",
"ZipEntry",
">",
"entries",
"... | Returns a list of the rekordbox IDs of the tracks contained in the cache.
@return a list containing the rekordbox ID for each track present in the cache, in the order they appear | [
"Returns",
"a",
"list",
"of",
"the",
"rekordbox",
"IDs",
"of",
"the",
"tracks",
"contained",
"in",
"the",
"cache",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L502-L516 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.createMetadataCache | public static void createMetadataCache(SlotReference slot, int playlistId, File cache) throws Exception {
createMetadataCache(slot, playlistId, cache, null);
} | java | public static void createMetadataCache(SlotReference slot, int playlistId, File cache) throws Exception {
createMetadataCache(slot, playlistId, cache, null);
} | [
"public",
"static",
"void",
"createMetadataCache",
"(",
"SlotReference",
"slot",
",",
"int",
"playlistId",
",",
"File",
"cache",
")",
"throws",
"Exception",
"{",
"createMetadataCache",
"(",
"slot",
",",
"playlistId",
",",
"cache",
",",
"null",
")",
";",
"}"
] | Creates a metadata cache archive file of all tracks in the specified slot on the specified player. Any
previous contents of the specified file will be replaced.
@param slot the slot in which the media to be cached can be found
@param playlistId the id of playlist to be cached, or 0 of all tracks should be cached
@param cache the file into which the metadata cache should be written
@throws Exception if there is a problem communicating with the player or writing the cache file. | [
"Creates",
"a",
"metadata",
"cache",
"archive",
"file",
"of",
"all",
"tracks",
"in",
"the",
"specified",
"slot",
"on",
"the",
"specified",
"player",
".",
"Any",
"previous",
"contents",
"of",
"the",
"specified",
"file",
"will",
"be",
"replaced",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L692-L694 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.tryAutoAttaching | static void tryAutoAttaching(final SlotReference slot) {
if (!MetadataFinder.getInstance().getMountedMediaSlots().contains(slot)) {
logger.error("Unable to auto-attach cache to empty slot {}", slot);
return;
}
if (MetadataFinder.getInstance().getMetadataCache(slot) != null) {
logger.info("Not auto-attaching to slot {}; already has a cache attached.", slot);
return;
}
if (MetadataFinder.getInstance().getAutoAttachCacheFiles().isEmpty()) {
logger.debug("No auto-attach files configured.");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5); // Give us a chance to find out what type of media is in the new mount.
final MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null && details.mediaType == CdjStatus.TrackType.REKORDBOX) {
// First stage attempt: See if we can match based on stored media details, which is both more reliable and
// less disruptive than trying to sample the player database to compare entries.
boolean attached = false;
for (File file : MetadataFinder.getInstance().getAutoAttachCacheFiles()) {
final MetadataCache cache = new MetadataCache(file);
try {
if (cache.sourceMedia != null && cache.sourceMedia.hashKey().equals(details.hashKey())) {
// We found a solid match, no need to probe tracks.
final boolean changed = cache.sourceMedia.hasChanged(details);
logger.info("Auto-attaching metadata cache " + cache.getName() + " to slot " + slot +
" based on media details " + (changed? "(changed since created)!" : "(unchanged)."));
MetadataFinder.getInstance().attachMetadataCacheInternal(slot, cache);
attached = true;
return;
}
} finally {
if (!attached) {
cache.close();
}
}
}
// Could not match based on media details; fall back to older method based on probing track metadata.
ConnectionManager.ClientTask<Object> task = new ConnectionManager.ClientTask<Object>() {
@Override
public Object useClient(Client client) throws Exception {
tryAutoAttachingWithConnection(slot, client);
return null;
}
};
ConnectionManager.getInstance().invokeWithClientSession(slot.player, task, "trying to auto-attach metadata cache");
}
} catch (Exception e) {
logger.error("Problem trying to auto-attach metadata cache for slot " + slot, e);
}
}
}, "Metadata cache file auto-attachment attempt").start();
} | java | static void tryAutoAttaching(final SlotReference slot) {
if (!MetadataFinder.getInstance().getMountedMediaSlots().contains(slot)) {
logger.error("Unable to auto-attach cache to empty slot {}", slot);
return;
}
if (MetadataFinder.getInstance().getMetadataCache(slot) != null) {
logger.info("Not auto-attaching to slot {}; already has a cache attached.", slot);
return;
}
if (MetadataFinder.getInstance().getAutoAttachCacheFiles().isEmpty()) {
logger.debug("No auto-attach files configured.");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5); // Give us a chance to find out what type of media is in the new mount.
final MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null && details.mediaType == CdjStatus.TrackType.REKORDBOX) {
// First stage attempt: See if we can match based on stored media details, which is both more reliable and
// less disruptive than trying to sample the player database to compare entries.
boolean attached = false;
for (File file : MetadataFinder.getInstance().getAutoAttachCacheFiles()) {
final MetadataCache cache = new MetadataCache(file);
try {
if (cache.sourceMedia != null && cache.sourceMedia.hashKey().equals(details.hashKey())) {
// We found a solid match, no need to probe tracks.
final boolean changed = cache.sourceMedia.hasChanged(details);
logger.info("Auto-attaching metadata cache " + cache.getName() + " to slot " + slot +
" based on media details " + (changed? "(changed since created)!" : "(unchanged)."));
MetadataFinder.getInstance().attachMetadataCacheInternal(slot, cache);
attached = true;
return;
}
} finally {
if (!attached) {
cache.close();
}
}
}
// Could not match based on media details; fall back to older method based on probing track metadata.
ConnectionManager.ClientTask<Object> task = new ConnectionManager.ClientTask<Object>() {
@Override
public Object useClient(Client client) throws Exception {
tryAutoAttachingWithConnection(slot, client);
return null;
}
};
ConnectionManager.getInstance().invokeWithClientSession(slot.player, task, "trying to auto-attach metadata cache");
}
} catch (Exception e) {
logger.error("Problem trying to auto-attach metadata cache for slot " + slot, e);
}
}
}, "Metadata cache file auto-attachment attempt").start();
} | [
"static",
"void",
"tryAutoAttaching",
"(",
"final",
"SlotReference",
"slot",
")",
"{",
"if",
"(",
"!",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMountedMediaSlots",
"(",
")",
".",
"contains",
"(",
"slot",
")",
")",
"{",
"logger",
".",
"error... | See if there is an auto-attach cache file that seems to match the media in the specified slot, and if so,
attach it.
@param slot the player slot that is under consideration for automatic cache attachment | [
"See",
"if",
"there",
"is",
"an",
"auto",
"-",
"attach",
"cache",
"file",
"that",
"seems",
"to",
"match",
"the",
"media",
"in",
"the",
"specified",
"slot",
"and",
"if",
"so",
"attach",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L776-L835 | train |
Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.gatherCandidateAttachmentGroups | private static Map<Integer, LinkedList<MetadataCache>> gatherCandidateAttachmentGroups() {
Map<Integer,LinkedList<MetadataCache>> candidateGroups = new TreeMap<Integer, LinkedList<MetadataCache>>();
final Iterator<File> iterator = MetadataFinder.getInstance().getAutoAttachCacheFiles().iterator();
while (iterator.hasNext()) {
final File file = iterator.next();
try {
final MetadataCache candidate = new MetadataCache(file);
if (candidateGroups.get(candidate.sourcePlaylist) == null) {
candidateGroups.put(candidate.sourcePlaylist, new LinkedList<MetadataCache>());
}
candidateGroups.get(candidate.sourcePlaylist).add(candidate);
} catch (Exception e) {
logger.error("Unable to open metadata cache file " + file + ", discarding", e);
iterator.remove();
}
}
return candidateGroups;
} | java | private static Map<Integer, LinkedList<MetadataCache>> gatherCandidateAttachmentGroups() {
Map<Integer,LinkedList<MetadataCache>> candidateGroups = new TreeMap<Integer, LinkedList<MetadataCache>>();
final Iterator<File> iterator = MetadataFinder.getInstance().getAutoAttachCacheFiles().iterator();
while (iterator.hasNext()) {
final File file = iterator.next();
try {
final MetadataCache candidate = new MetadataCache(file);
if (candidateGroups.get(candidate.sourcePlaylist) == null) {
candidateGroups.put(candidate.sourcePlaylist, new LinkedList<MetadataCache>());
}
candidateGroups.get(candidate.sourcePlaylist).add(candidate);
} catch (Exception e) {
logger.error("Unable to open metadata cache file " + file + ", discarding", e);
iterator.remove();
}
}
return candidateGroups;
} | [
"private",
"static",
"Map",
"<",
"Integer",
",",
"LinkedList",
"<",
"MetadataCache",
">",
">",
"gatherCandidateAttachmentGroups",
"(",
")",
"{",
"Map",
"<",
"Integer",
",",
"LinkedList",
"<",
"MetadataCache",
">",
">",
"candidateGroups",
"=",
"new",
"TreeMap",
... | Groups all of the metadata cache files that are candidates for auto-attachment to player slots into lists
that are keyed by the playlist ID used to create the cache file. Files that cache all tracks have a playlist
ID of 0.
@return a map from playlist ID to the caches holding tracks from that playlist | [
"Groups",
"all",
"of",
"the",
"metadata",
"cache",
"files",
"that",
"are",
"candidates",
"for",
"auto",
"-",
"attachment",
"to",
"player",
"slots",
"into",
"lists",
"that",
"are",
"keyed",
"by",
"the",
"playlist",
"ID",
"used",
"to",
"create",
"the",
"cach... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L948-L965 | train |
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",
"... | 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",
"play... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L1036-L1042 | train |
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",
... | 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 | train |
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",
"(",
"logge... | 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 | train |
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",
".",
... | 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 | train |
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",
")",
... | 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 | train |
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",
".",
"yieldRespo... | 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 | train |
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",
"(",
"audibleCh... | 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 | train |
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",
"(",
")",
")",
"{"... | 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 | train |
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",
"(",
... | 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 | train |
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 ... | 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 | train |
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",
"(",
")",... | 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",
".",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L100-L109 | train |
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",
")",
"{",
"deli... | 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",
"... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L219-L223 | train |
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",
")",
"{",
"delive... | 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",
"t... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L232-L236 | train |
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",... | 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 | train |
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",
")",... | 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 | train |
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",
")",
";... | 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 | train |
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.",
"retur... | 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 | train |
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... | 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 | train |
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",
".",
"getIns... | 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",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformFinder.java#L410-L447 | train |
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",
"(",
"c... | 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 | train |
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... | 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 | train |
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",
"(",
"cache... | 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 | train |
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 g... | 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 | train |
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",
"(",
"!",
"listen... | 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 | train |
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",
"("... | 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 | train |
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",
",",
"TrackMetada... | 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 | train |
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... | 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 | train |
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",
":"... | 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 | train |
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",
... | 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 | train |
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",... | 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 | train |
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.",
"Metadata... | 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",... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/ArtFinder.java#L280-L326 | train |
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",
"... | 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 | train |
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",
".",
... | 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 | train |
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",
"(",
"c... | 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 | train |
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",
"(",
... | 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 | train |
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",
"(",
")",
"... | 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 | train |
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",
"... | 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 | train |
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",
";",
"}",
... | 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 | train |
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",
";",
... | 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 | train |
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",
";",
... | 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 | train |
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",
")",
">",
"... | 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 | train |
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",
"(",
"... | 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 | train |
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",
")",
"{",
"deliverBeatGridUpd... | 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",
... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGridFinder.java#L131-L135 | train |
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",... | 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 | train |
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",
")",
";",
"... | 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 | train |
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",
... | 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 | train |
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",
")"... | 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 | train |
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",
",... | 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 | train |
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",
... | 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 | train |
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... | 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 | train |
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",
"=",... | 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",
"w... | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TimeFinder.java#L151-L161 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.