comparison src/app/waveform/waveform.component.ts @ 106:fe6b0c525a7d

Use matrix layer for matrix features
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 09 Mar 2017 15:51:34 +0000
parents f8436dd53e7f
children 7740f7fd7c3c
comparison
equal deleted inserted replaced
105:f8436dd53e7f 106:fe6b0c525a7d
137 mainTrack.height = height; 137 mainTrack.height = height;
138 } else { 138 } else {
139 this.timeline = this.renderTimeline(buffer.duration) 139 this.timeline = this.renderTimeline(buffer.duration)
140 } 140 }
141 this.timeline.timeContext.offset = 0.5 * this.timeline.timeContext.visibleDuration; 141 this.timeline.timeContext.offset = 0.5 * this.timeline.timeContext.visibleDuration;
142
142 // time axis 143 // time axis
143 const timeAxis = new wavesUI.helpers.TimeAxisLayer({ 144 const timeAxis = new wavesUI.helpers.TimeAxisLayer({
144 height: height, 145 height: height,
145 color: 'gray' 146 color: '#b0b0b0'
146 }); 147 });
147 this.addLayer(timeAxis, mainTrack, this.timeline.timeContext, true); 148 this.addLayer(timeAxis, mainTrack, this.timeline.timeContext, true);
148 149
149 const waveformLayer = new wavesUI.helpers.WaveformLayer(buffer, { 150 const waveformLayer = new wavesUI.helpers.WaveformLayer(buffer, {
150 top: 10, 151 top: 10,
151 height: height * 0.9, 152 height: height * 0.9,
152 color: 'darkblue' 153 color: 'darkblue'
153 }); 154 });
154 this.addLayer(waveformLayer, mainTrack, this.timeline.timeContext); 155 this.addLayer(waveformLayer, mainTrack, this.timeline.timeContext);
155 156 /*
157 const spectrogramLayer = new wavesUI.helpers.SpectrogramLayer(buffer, {
158 top: 10,
159 height: height * 0.9,
160 stepSize: 512,
161 fftSize: 1024
162 });
163 this.addLayer(spectrogramLayer, mainTrack, this.timeline.timeContext);
164 */
156 this.cursorLayer = new wavesUI.helpers.CursorLayer({ 165 this.cursorLayer = new wavesUI.helpers.CursorLayer({
157 height: height 166 height: height
158 }); 167 });
159 this.addLayer(this.cursorLayer, mainTrack, this.timeline.timeContext); 168 this.addLayer(this.cursorLayer, mainTrack, this.timeline.timeContext);
160 this.timeline.state = new wavesUI.states.CenteredZoomState(this.timeline); 169 this.timeline.state = new wavesUI.states.CenteredZoomState(this.timeline);
329 segmentLayer, 338 segmentLayer,
330 mainTrack, 339 mainTrack,
331 this.timeline.timeContext 340 this.timeline.timeContext
332 ), colour); 341 ), colour);
333 } 342 }
334
335 break; 343 break;
336 } 344 }
345 case 'matrix': {
346 const stepDuration = (features as FixedSpacedFeatures).stepDuration;
347 const matrixData = (features.data as Float32Array[]);
348 if (matrixData.length === 0) return;
349 const matrixEntity = new wavesUI.utils.PrefilledMatrixEntity(matrixData);
350 let matrixLayer = new wavesUI.helpers.MatrixLayer(matrixEntity, {
351 color: colour,
352 height: height
353 });
354 this.colouredLayers.set(this.addLayer(
355 matrixLayer,
356 mainTrack,
357 this.timeline.timeContext
358 ), colour);
359 break;
360 }
337 default: 361 default:
338 console.log('Cannot render an appropriate layer.'); 362 console.log("Cannot render an appropriate layer for feature shape '" +
363 features.shape + "'");
339 } 364 }
340 365
341 this.timeline.tracks.update(); 366 this.timeline.tracks.update();
342 } 367 }
343 368
360 const mustPageBackward = currentTime < -currentOffset; 385 const mustPageBackward = currentTime < -currentOffset;
361 386
362 if (mustPageForward) { 387 if (mustPageForward) {
363 const hasSkippedMultiplePages = offsetTimestamp - visibleDuration > visibleDuration; 388 const hasSkippedMultiplePages = offsetTimestamp - visibleDuration > visibleDuration;
364 389
365 this.timeline.timeContext.offset = hasSkippedMultiplePages 390 this.timeline.timeContext.offset = hasSkippedMultiplePages ?
366 ? -currentTime + 0.5 * visibleDuration 391 -currentTime + 0.5 * visibleDuration :
367 : currentOffset - visibleDuration; 392 currentOffset - visibleDuration;
368 this.timeline.tracks.update(); 393 this.timeline.tracks.update();
369 } 394 }
370 395
371 if (mustPageBackward) { 396 if (mustPageBackward) {
372 const hasSkippedMultiplePages = currentTime + visibleDuration < -currentOffset; 397 const hasSkippedMultiplePages = currentTime + visibleDuration < -currentOffset;
373 this.timeline.timeContext.offset = hasSkippedMultiplePages 398 this.timeline.timeContext.offset = hasSkippedMultiplePages ?
374 ? -currentTime + 0.5 * visibleDuration 399 -currentTime + 0.5 * visibleDuration :
375 : currentOffset + visibleDuration; 400 currentOffset + visibleDuration;
376 this.timeline.tracks.update(); 401 this.timeline.tracks.update();
377 } 402 }
378 403
379 if (this.isPlaying) 404 if (this.isPlaying)
380 requestAnimationFrame(updateSeekingCursor); 405 requestAnimationFrame(updateSeekingCursor);