Mercurial > hg > ugly-duckling
comparison 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 |
comparison
equal
deleted
inserted
replaced
395:de9864aeacf0 | 396:3eab26a629e1 |
---|---|
72 | 72 |
73 // TODO regions | 73 // TODO regions |
74 type ShapeDeducedFromList = 'instants' | 'notes'; | 74 type ShapeDeducedFromList = 'instants' | 'notes'; |
75 export type HigherLevelFeatureShape = CollectedShape | ShapeDeducedFromList; | 75 export type HigherLevelFeatureShape = CollectedShape | ShapeDeducedFromList; |
76 | 76 |
77 export type ShapedFeatureData = {unit?: string} & ( | 77 export type ShapedFeatureData = |
78 VectorFeature | 78 VectorFeature |
79 | MatrixFeature | 79 | MatrixFeature |
80 | TracksFeature | 80 | TracksFeature |
81 | Note[] | 81 | Note[] |
82 | Instant[] | 82 | Instant[]; |
83 ); | |
84 | 83 |
85 // These needn't be classes (could just be interfaces), just experimenting | 84 // These needn't be classes (could just be interfaces), just experimenting |
86 export abstract class ShapedFeature<Shape extends HigherLevelFeatureShape, | 85 export abstract class ShapedFeature<Shape extends HigherLevelFeatureShape, |
87 Data extends ShapedFeatureData & {unit?: string}> { | 86 Data extends ShapedFeatureData> { |
88 shape: Shape; | 87 shape: Shape; |
89 collected: Data & {unit?: string}; | 88 collected: Data; |
90 } | 89 } |
91 | 90 |
92 export class Vector extends ShapedFeature<'vector', VectorFeature> {} | 91 export class Vector extends ShapedFeature<'vector', VectorFeature> {} |
93 export class Matrix extends ShapedFeature<'matrix', MatrixFeature> {} | 92 export class Matrix extends ShapedFeature<'matrix', MatrixFeature> {} |
94 export class Tracks extends ShapedFeature<'tracks', TracksFeature> {} | 93 export class Tracks extends ShapedFeature<'tracks', TracksFeature> {} |
143 throwShapeError(); | 142 throwShapeError(); |
144 } | 143 } |
145 | 144 |
146 export function toKnownShape(response: SimpleResponse): KnownShapedFeature { | 145 export function toKnownShape(response: SimpleResponse): KnownShapedFeature { |
147 const deducedShape = deduceHigherLevelFeatureShape(response); | 146 const deducedShape = deduceHigherLevelFeatureShape(response); |
148 const shaped: KnownShapedFeature | null = (() => { | 147 switch (deducedShape) { |
149 switch (deducedShape) { | 148 case 'vector': |
150 case 'vector': | 149 return response.features as Vector; |
151 return response.features as Vector; | 150 case 'matrix': |
152 case 'matrix': | 151 return response.features as Matrix; |
153 return response.features as Matrix; | 152 case 'tracks': |
154 case 'tracks': | 153 return response.features as Tracks; |
155 return response.features as Tracks; | 154 case 'notes': |
156 case 'notes': | 155 return { |
157 // TODO refactor | 156 shape: deducedShape, |
158 const notes: Note[] & {unit?: string} = mapFeaturesToNotes( | 157 collected: mapFeaturesToNotes( |
159 response.features.collected as FeatureList, | 158 response.features.collected as FeatureList, |
160 response.outputDescriptor | 159 response.outputDescriptor |
161 ); | 160 ) |
162 notes.unit = 'MIDI'; | 161 }; |
163 return { | 162 case 'instants': |
164 shape: deducedShape, | 163 const featureData = response.features.collected as FeatureList; |
165 collected: notes, | 164 return { |
166 }; | 165 shape: deducedShape, |
167 case 'instants': | 166 collected: featureData.map(feature => ({ |
168 const featureData = response.features.collected as FeatureList; | 167 time: toSeconds(feature.timestamp), |
169 return { | 168 label: feature.label |
170 shape: deducedShape, | 169 })) |
171 collected: featureData.map(feature => ({ | 170 }; |
172 time: toSeconds(feature.timestamp), | 171 } |
173 label: feature.label | 172 throwShapeError(); |
174 })) | |
175 }; | |
176 } | |
177 })(); | |
178 const unit = response.outputDescriptor.configured.unit; | |
179 if (shaped) { | |
180 const bodgeUnit = (shaped: KnownShapedFeature) => { | |
181 (shaped.collected as any).unit = unit; | |
182 return shaped; | |
183 }; | |
184 return unit && !shaped.collected.unit ? bodgeUnit(shaped) : shaped; | |
185 } else { | |
186 throwShapeError(); | |
187 } | |
188 } | 173 } |
189 | 174 |
190 export interface PlotData { | 175 export interface PlotData { |
191 cx: number; | 176 cx: number; |
192 cy: number; | 177 cy: number; |