diff src/app/visualisations/FeatureUtilities.ts @ 396:3eab26a629e1

Revert changes relating to bodging unit onto the shaped features. Now return from the extraction service and add to the analysis item, and send into the cross-hair component with a prop.
author Lucas Thompson <dev@lucas.im>
date Thu, 01 Jun 2017 23:04:39 +0100
parents f45a916eb5b1
children 6672496ff32e
line wrap: on
line diff
--- a/src/app/visualisations/FeatureUtilities.ts	Thu Jun 01 18:56:06 2017 +0100
+++ b/src/app/visualisations/FeatureUtilities.ts	Thu Jun 01 23:04:39 2017 +0100
@@ -74,19 +74,18 @@
 type ShapeDeducedFromList = 'instants' | 'notes';
 export type HigherLevelFeatureShape = CollectedShape | ShapeDeducedFromList;
 
-export type ShapedFeatureData = {unit?: string} & (
+export type ShapedFeatureData =
   VectorFeature
   | MatrixFeature
   | TracksFeature
   | Note[]
-  | Instant[]
-  );
+  | Instant[];
 
 // These needn't be classes (could just be interfaces), just experimenting
 export abstract class ShapedFeature<Shape extends HigherLevelFeatureShape,
-  Data extends ShapedFeatureData & {unit?: string}> {
+  Data extends ShapedFeatureData> {
   shape: Shape;
-  collected: Data & {unit?: string};
+  collected: Data;
 }
 
 export class Vector extends ShapedFeature<'vector', VectorFeature> {}
@@ -145,46 +144,32 @@
 
 export function toKnownShape(response: SimpleResponse): KnownShapedFeature {
   const deducedShape = deduceHigherLevelFeatureShape(response);
-  const shaped: KnownShapedFeature | null = (() => {
-    switch (deducedShape) {
-      case 'vector':
-        return response.features as Vector;
-      case 'matrix':
-        return response.features as Matrix;
-      case 'tracks':
-        return response.features as Tracks;
-      case 'notes':
-        // TODO refactor
-        const notes: Note[] & {unit?: string} = mapFeaturesToNotes(
+  switch (deducedShape) {
+    case 'vector':
+      return response.features as Vector;
+    case 'matrix':
+      return response.features as Matrix;
+    case 'tracks':
+      return response.features as Tracks;
+    case 'notes':
+      return {
+        shape: deducedShape,
+        collected: mapFeaturesToNotes(
           response.features.collected as FeatureList,
           response.outputDescriptor
-        );
-        notes.unit = 'MIDI';
-        return {
-          shape: deducedShape,
-          collected: notes,
-        };
-      case 'instants':
-        const featureData = response.features.collected as FeatureList;
-        return {
-          shape: deducedShape,
-          collected: featureData.map(feature => ({
-            time: toSeconds(feature.timestamp),
-            label: feature.label
-          }))
-        };
-    }
-  })();
-  const unit = response.outputDescriptor.configured.unit;
-  if (shaped) {
-    const bodgeUnit = (shaped: KnownShapedFeature) => {
-      (shaped.collected as any).unit = unit;
-      return shaped;
-    };
-    return unit && !shaped.collected.unit ? bodgeUnit(shaped) : shaped;
-  } else {
-    throwShapeError();
+        )
+      };
+    case 'instants':
+      const featureData = response.features.collected as FeatureList;
+      return {
+        shape: deducedShape,
+        collected: featureData.map(feature => ({
+          time: toSeconds(feature.timestamp),
+          label: feature.label
+        }))
+      };
   }
+  throwShapeError();
 }
 
 export interface PlotData {