Mercurial > hg > ugly-duckling
changeset 303:dc415a620b15
Merge branch 'dev/tracks-shape' of github.com:cannam/ugly-duckling into dev/tracks-shape
=
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 12 May 2017 02:19:03 +0100 |
parents | c6dd5752f7f7 (current diff) 1d39cc796046 (diff) |
children | 5527c0f82059 |
files | src/app/services/feature-extraction/FeatureReducers.ts src/app/waveform/waveform.component.ts |
diffstat | 1 files changed, 78 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/waveform/waveform.component.ts Fri May 12 01:40:21 2017 +0100 +++ b/src/app/waveform/waveform.component.ts Fri May 12 02:19:03 2017 +0100 @@ -21,8 +21,9 @@ import { FeatureCollection, SimpleResponse, - VectorFeatures, - MatrixFeatures + VectorFeature, + MatrixFeature, + TracksFeature } from 'piper/HigherLevelUtilities'; import {toSeconds} from 'piper'; import {FeatureList, Feature} from 'piper/Feature'; @@ -608,6 +609,69 @@ this.timeline.tracks.update(); } + private addLineLayer(stepDuration: number, + featureData: Float32Array, + colour: Colour) { + + if (featureData.length === 0) { + return; + } + const plotData = [...featureData].map((feature, i) => { + return { + cx: i * stepDuration, + cy: feature + }; + }); + let min = featureData.reduce((m, f) => Math.min(m, f), Infinity); + let max = featureData.reduce((m, f) => Math.max(m, f), -Infinity); + if (min === Infinity) { + min = 0; + max = 1; + } + console.log("adding line layer: min = " + min + ", max = " + max); + if (min !== min || max !== max) { + console.log("WARNING: min or max is NaN"); + min = 0; + max = 1; + } + + const height = this.trackDiv.nativeElement.getBoundingClientRect().height; + const waveTrack = this.timeline.getTrackById(`wave-${this.trackIdPrefix}`); + const lineLayer = new wavesUI.helpers.LineLayer(plotData, { + color: colour, + height: height, + yDomain: [ min, max ] + }); + this.addLayer( + lineLayer, + waveTrack, + this.timeline.timeContext + ); + const scaleLayer = new wavesUI.helpers.ScaleLayer({ + tickColor: colour, + textColor: colour, + height: height, + yDomain: [ min, max ] + }); + this.addLayer( + scaleLayer, + waveTrack, + this.timeline.timeContext + ); + this.highlightLayer = new wavesUI.helpers.HighlightLayer(lineLayer, { + opacity: 0.7, + height: height, + color: '#c33c54', + labelOffset: 38, + yDomain: [ min, max ] + }); + this.addLayer( + this.highlightLayer, + waveTrack, + this.timeline.timeContext + ); + } + // TODO refactor - this doesn't belong here private renderFeatures(extracted: SimpleResponse, colour: Colour): void { if (this.isOneShotExtractor && !this.hasShot) { @@ -625,72 +689,21 @@ } const features: FeatureCollection = (extracted.features as FeatureCollection); const outputDescriptor = extracted.outputDescriptor; - // const height = this.trackDiv.nativeElement.getBoundingClientRect().height / 2; const height = this.trackDiv.nativeElement.getBoundingClientRect().height; const waveTrack = this.timeline.getTrackById(`wave-${this.trackIdPrefix}`); // TODO refactor all of this switch (features.shape) { + case 'vector': { - const collected = features.collected as VectorFeatures; + const collected = features.collected as VectorFeature; + const startTime = collected.startTime; //!!! + make use of const stepDuration = collected.stepDuration; const featureData = collected.data; - if (featureData.length === 0) { - return; - } - const plotData = [...featureData].map((feature, i) => { - return { - cx: i * stepDuration, - cy: feature - }; - }); - let min = featureData.reduce((m, f) => Math.min(m, f), Infinity); - let max = featureData.reduce((m, f) => Math.max(m, f), -Infinity); - if (min === Infinity) { - min = 0; - max = 1; - } - console.log('adding line layer: min = ' + min + ', max = ' + max); - if (min !== min || max !== max) { - console.log('WARNING: min or max is NaN'); - min = 0; - max = 1; - } - const lineLayer = new wavesUI.helpers.LineLayer(plotData, { - color: colour, - height: height, - yDomain: [ min, max ] - }); - this.addLayer( - lineLayer, - waveTrack, - this.timeline.timeContext - ); - const scaleLayer = new wavesUI.helpers.ScaleLayer({ - tickColor: colour, - textColor: colour, - height: height, - yDomain: [ min, max ] - }); - this.addLayer( - scaleLayer, - waveTrack, - this.timeline.timeContext - ); - this.highlightLayer = new wavesUI.helpers.HighlightLayer(lineLayer, { - opacity: 0.7, - height: height, - color: '#c33c54', - labelOffset: 38, - yDomain: [ min, max ] - }); - this.addLayer( - this.highlightLayer, - waveTrack, - this.timeline.timeContext - ); + this.addLineLayer(stepDuration, featureData, colour); break; } + case 'list': { const featureData = features.collected as FeatureList; if (featureData.length === 0) { @@ -794,9 +807,9 @@ break; } case 'matrix': { - const collected = features.collected as MatrixFeatures; + const collected = features.collected as MatrixFeature; + const startTime = collected.startTime; //!!! + make use of const stepDuration = collected.stepDuration; - // !!! + start time const matrixData = collected.data; if (matrixData.length === 0) { @@ -808,11 +821,10 @@ const targetValue = this.estimatePercentile(matrixData, 95); const gain = (targetValue > 0.0 ? (1.0 / targetValue) : 1.0); console.log('setting gain to ' + gain); - const matrixEntity = new wavesUI.utils.PrefilledMatrixEntity( - matrixData, + const matrixEntity = + new wavesUI.utils.PrefilledMatrixEntity(matrixData, 0, // startTime - stepDuration - ); + stepDuration); const matrixLayer = new wavesUI.helpers.MatrixLayer(matrixEntity, { gain, top: 0, @@ -866,8 +878,7 @@ const mustPageBackward = currentTime < -currentOffset; if (mustPageForward) { - const hasSkippedMultiplePages = offsetTimestamp - - visibleDuration > visibleDuration; + const hasSkippedMultiplePages = offsetTimestamp - visibleDuration > visibleDuration; this.timeline.timeContext.offset = hasSkippedMultiplePages ? -currentTime + 0.5 * visibleDuration : @@ -876,8 +887,7 @@ } if (mustPageBackward) { - const hasSkippedMultiplePages = currentTime + - visibleDuration < -currentOffset; + const hasSkippedMultiplePages = currentTime + visibleDuration < -currentOffset; this.timeline.timeContext.offset = hasSkippedMultiplePages ? -currentTime + 0.5 * visibleDuration : currentOffset + visibleDuration;