alphatheta-connect 0.25.0 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { type DatabaseAdapter, type DatabasePreference, type DatabaseType } from 'onelibrary-connect';
1
+ import { type DatabaseAdapter, type DatabasePreference, type DatabaseType, type Track } from 'onelibrary-connect';
2
2
  import StrictEventEmitter from 'strict-event-emitter-types';
3
3
  import { EventEmitter } from 'events';
4
4
  import DeviceManager from "../devices";
@@ -56,6 +56,35 @@ interface DatabaseEvents {
56
56
  hydrationDone: (opts: HydrationDoneOpts) => void;
57
57
  }
58
58
  type Emitter = StrictEventEmitter<EventEmitter, DatabaseEvents>;
59
+ /**
60
+ * What the player knows about the track it is asking us to look up, used to
61
+ * check that the row a database hands back is really that track.
62
+ */
63
+ export interface TrackLookupHint {
64
+ /**
65
+ * The track's BPM as reported in the player's status packet (unpitched,
66
+ * two decimals). `null` when the player did not report one.
67
+ */
68
+ trackBPM?: number | null;
69
+ }
70
+ /**
71
+ * The outcome of {@link LocalDatabase.findTrack}.
72
+ */
73
+ export type TrackLookup = {
74
+ /** The database that answered */
75
+ adapter: DatabaseAdapter;
76
+ track: Track;
77
+ /**
78
+ * Set when answering meant switching the slot to its other database
79
+ * format: the type the slot is now served from.
80
+ */
81
+ switchedTo: DatabaseType | null;
82
+ } | {
83
+ /** The slot's database, or null when the slot has none loaded */
84
+ adapter: DatabaseAdapter | null;
85
+ track: null;
86
+ switchedTo: null;
87
+ };
59
88
  /**
60
89
  * The local database is responsible for syncing the remote rekordbox databases
61
90
  * of media slots on a device into in-memory sqlite databases.
@@ -82,6 +111,23 @@ declare class LocalDatabase {
82
111
  * Disconnects the local database connection for the specified device
83
112
  */
84
113
  disconnectForDevice(device: Device): void;
114
+ /**
115
+ * Looks a track up in the databases of a device slot, checking the answer
116
+ * against what the player reports.
117
+ *
118
+ * A Device Library Plus export carries both `exportLibrary.db` and the
119
+ * legacy `export.pdb`, and their track IDs are different number spaces. A
120
+ * player that reads one while we loaded the other resolves most IDs to a
121
+ * different track and some to nothing at all (NP3-399). So when the active
122
+ * database has no such row, or its row's BPM is not the BPM the player is
123
+ * showing, the other format is loaded and asked. If it agrees with the
124
+ * player, the slot switches to it for every later lookup — artwork,
125
+ * analysis and the next track all follow the database the player is using.
126
+ *
127
+ * When neither database can be confirmed, the active database's row (if any)
128
+ * is returned as before.
129
+ */
130
+ findTrack(deviceId: DeviceID, slot: DatabaseSlot, trackId: number, hint?: TrackLookupHint): Promise<TrackLookup>;
85
131
  /**
86
132
  * Gets the database adapter for the media metadata in the provided device slot.
87
133
  *
@@ -65,7 +65,7 @@ export declare const UInt8: {
65
65
  data: Buffer;
66
66
  };
67
67
  type: NumberFieldType;
68
- bytesToRead: 1 | 4 | 2;
68
+ bytesToRead: 1 | 2 | 4;
69
69
  };
70
70
  /**
71
71
  * Field representing a UInt16
@@ -81,7 +81,7 @@ export declare const UInt16: {
81
81
  data: Buffer;
82
82
  };
83
83
  type: NumberFieldType;
84
- bytesToRead: 1 | 4 | 2;
84
+ bytesToRead: 1 | 2 | 4;
85
85
  };
86
86
  /**
87
87
  * Field representing a UInt32
@@ -97,7 +97,7 @@ export declare const UInt32: {
97
97
  data: Buffer;
98
98
  };
99
99
  type: NumberFieldType;
100
- bytesToRead: 1 | 4 | 2;
100
+ bytesToRead: 1 | 2 | 4;
101
101
  };
102
102
  /**
103
103
  * Field representing a null-terminated big endian UTF-16 string
@@ -131,7 +131,7 @@ declare const fieldMap: {
131
131
  data: Buffer;
132
132
  };
133
133
  type: NumberFieldType;
134
- bytesToRead: 1 | 4 | 2;
134
+ bytesToRead: 1 | 2 | 4;
135
135
  };
136
136
  readonly 16: {
137
137
  new (value: number | Buffer): {
@@ -144,7 +144,7 @@ declare const fieldMap: {
144
144
  data: Buffer;
145
145
  };
146
146
  type: NumberFieldType;
147
- bytesToRead: 1 | 4 | 2;
147
+ bytesToRead: 1 | 2 | 4;
148
148
  };
149
149
  readonly 17: {
150
150
  new (value: number | Buffer): {
@@ -157,7 +157,7 @@ declare const fieldMap: {
157
157
  data: Buffer;
158
158
  };
159
159
  type: NumberFieldType;
160
- bytesToRead: 1 | 4 | 2;
160
+ bytesToRead: 1 | 2 | 4;
161
161
  };
162
162
  readonly 20: typeof Binary;
163
163
  readonly 38: typeof String;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alphatheta-connect",
3
- "version": "0.25.0",
3
+ "version": "0.25.2",
4
4
  "main": "lib/index.js",
5
5
  "author": "Evan Purkhiser <evanpurkhiser@gmail.com>",
6
6
  "contributors": [