Skip to content

Commit

Permalink
Dont use Object.assignt() to clone cue props
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Jan 7, 2020
1 parent 9b6b862 commit ebfdb8e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 54 deletions.
30 changes: 15 additions & 15 deletions dist/wavefile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions docs/lib_wavefile-meta-editor.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ <h1 class="page-title">lib/wavefile-meta-editor.js</h1>
}

// Remove attrs that should not go in the results
delete points[i].chunkId;
delete points[i].chunkSize;
delete points[i].value;
}
return points;
Expand Down Expand Up @@ -399,11 +397,17 @@ <h1 class="page-title">lib/wavefile-meta-editor.js</h1>
/** @type {!Array&lt;!Object>} */
let points = [];
for (let i = 0; i &lt; this.cue.points.length; i++) {
// Raw cue point data
let cuePointData = this.getDataForCuePoint_(this.cue.points[i].dwName);
cuePointData.label = cuePointData.value ? cuePointData.value : '';
Object.assign(cuePointData, this.cue.points[i]);
points.push(cuePointData);
/** @type {!Object} */
let chunk = this.cue.points[i];
/** @type {!Object} */
let pointData = this.getDataForCuePoint_(chunk.dwName);
pointData.label = pointData.value ? pointData.value : '';
pointData.dwPosition = chunk.dwPosition;
pointData.fccChunk = chunk.fccChunk;
pointData.dwChunkStart = chunk.dwChunkStart;
pointData.dwBlockStart = chunk.dwBlockStart;
pointData.dwSampleOffset = chunk.dwSampleOffset;
points.push(pointData);
}
return points;
}
Expand All @@ -417,31 +421,32 @@ <h1 class="page-title">lib/wavefile-meta-editor.js</h1>
getDataForCuePoint_(pointDwName) {
/** @type {?number} */
let cIndex = this.getAdtlChunk_();
/** @type {!Object} */
let pointData = {};
if (cIndex !== null) {
// got through all chunks in the adtl LIST checking
// for references to this cue point
for (let i = 0, len = this.LIST[cIndex].subChunks.length; i &lt; len; i++) {
if (this.LIST[cIndex].subChunks[i].dwName ==
pointDwName &amp;&amp; this.LIST[cIndex].subChunks[i].chunkId) {
/** @type {!Object} */
let chunk = this.LIST[cIndex].subChunks[i];
// Some chunks may reference the point but
// have a empty text; this is to ensure that if
// one chunk that reference the point has a text,
// this value will be kept as the associated data label
// for the cue point.
// If different values are present, the last value found
// will be considered the label for the cue point.
let realValue = '';
if (pointData.value) {
realValue = pointData.value;
}
// Merge the cue point data with the associated data
Object.assign(pointData, this.LIST[cIndex].subChunks[i]);
// If the associated data had no value field, keep any
// existing value field that may have been found
if (!pointData.value) {
pointData.value = realValue;
}
pointData.value = chunk.value ? chunk.value : pointData.value;
pointData.dwName = chunk.dwName ? chunk.dwName : 0;
pointData.dwSampleLength =
chunk.dwSampleLength ? chunk.dwSampleLength : 0;
pointData.dwPurposeID = chunk.dwPurposeID ? chunk.dwPurposeID : 0;
pointData.dwCountry = chunk.dwCountry ? chunk.dwCountry : 0;
pointData.dwLanguage = chunk.dwLanguage ? chunk.dwLanguage : 0;
pointData.dwDialect = chunk.dwDialect ? chunk.dwDialect : 0;
pointData.dwCodePage = chunk.dwCodePage ? chunk.dwCodePage : 0;
}
}
}
Expand Down
Loading

0 comments on commit ebfdb8e

Please sign in to comment.