Skip to content

Commit

Permalink
Add comparison function for timecodesArrays
Browse files Browse the repository at this point in the history
This makes the function reuseable by other methods besides updates.
  • Loading branch information
Agrarvolution committed Feb 22, 2024
1 parent 5781010 commit 694955e
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/jsx/KBRG/ThumbnailMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,10 @@ ThumbnailMetadata.prototype.updateFromTimecodes = function (updates, enableMedia
return false;
}

for (var i = 0; i < updates.length; i++) {
if (!updates[i].fileTC || !(updates[i].fileTC instanceof Timecode)) {
continue;
}
var update = this.compareTimecode(updates, enableMediaStartComparison);

if (updates[i].name.toUpperCase() === this.filename.toUpperCase() &&
(enableMediaStartComparison ?
updates[i].fileTC === this.timecodeMetadata.startTime :
true) &&
updates[i].audioTC instanceof Timecode) {
return this.updateFromTimecode(updates[i].audioTC, overrideFramerate);
}
if (update) {
return this.updateFromTimecode(update.audioTC, overrideFramerate);
}

return false;
Expand Down Expand Up @@ -319,7 +311,7 @@ ThumbnailMetadata.prototype.updateTimecodeMetadata = function (newStartTime) {

if (this.audioMetadata) {
this.audioMetadata.samples = this.timecodeMetadata.startTime.toSamples(this.audioMetadata.sampleFrequency);

this.xmp.setProperty(XMPConst.NS_BWF, "timeReference",
this.audioMetadata.samples.toString(), XMPConst.STRING);
}
Expand All @@ -329,6 +321,28 @@ ThumbnailMetadata.prototype.updateTimecodeMetadata = function (newStartTime) {
return false;
}

/**
* Loops through every update entitiy until a matching filename and or mediastart is found and returns matching timecode structure (not object)
* @param {array} timecodes
* @param {boolean} enableMediaStartComparison
* @returns {object|undefined} on successfull match returns the matching object in the timecodes array
*/
ThumbnailMetadata.prototype.compareTimecode = function (timecodes, enableMediaStartComparison) {
for (var i = 0; i < timecodes.length; i++) {
if (timecodes[i].fileTC
&& timecodes[i].fileTC instanceof Timecode
&& timecodes[i].name
&& timecodes[i].name.toUpperCase() === this.filename.toUpperCase()
&& (enableMediaStartComparison ?
timecodes[i].fileTC === this.timecodeMetadata.startTime :
true) &&
timecodes[i].audioTC instanceof Timecode) {
return timecodes[i];
}
}
return undefined;
}

/**
* If an XMPMeta object is attached to a ThumbnailMetadata object it attempts to write the new metadata to the thumbnail.
* Basically a wrapper.
Expand Down

0 comments on commit 694955e

Please sign in to comment.