@@ -22,23 +22,52 @@ function validateNumber(n: number) {
22
22
23
23
export function validatePayload ( data : any ) {
24
24
// == Scale ==
25
- const scale = data . scale . scale ;
25
+ const scaleStore = data . scale ;
26
+ const scale = scaleStore . scale ;
26
27
if ( scale . type !== 'ScaleWorkshopScale' ) {
27
28
throw new Error ( 'Invalid scale data' ) ;
28
29
}
29
30
for ( const ratio of scale . intervalRatios ) {
30
31
validateNumber ( ratio ) ;
31
32
}
33
+ for ( const color of scaleStore . colors ) {
34
+ validateString ( color ) ;
35
+ }
36
+ for ( const label of scaleStore . labels ) {
37
+ validateString ( label ) ;
38
+ }
32
39
validateNumber ( scale . baseFrequency ) ;
33
40
validateNumber ( scale . baseMidiNote ) ;
34
41
validateString ( scale . title , 4095 ) ;
35
42
Interval . reviver ( 'relativeIntervals' , data . scale . relativeIntervals ) ;
36
- validateString ( data . scale . name , 4095 ) ;
37
- validateString ( data . scale . sourceText , 65535 ) ;
43
+ validateString ( scaleStore . name , 4095 ) ;
44
+ validateString ( scaleStore . sourceText , 65535 ) ;
45
+ validateString ( scaleStore . error ) ;
46
+ validateString ( scaleStore . warning ) ;
47
+ validateString ( scaleStore . keyboardMode ) ;
38
48
// TODO: Rest
39
49
40
50
// == Audio ==
41
- validateString ( data . audio . waveform ) ;
51
+ const audio = data . audio ;
52
+ validateNumber ( audio . mainVolume ) ;
53
+ if ( audio . mainVolume < 0 || audio . mainVolume > 1 ) {
54
+ throw new Error ( 'Invalid main volume' ) ;
55
+ }
56
+ validateNumber ( audio . sustainLevel ) ;
57
+ if ( audio . sustainLevel < 0 || audio . sustainLevel > 1 ) {
58
+ throw new Error ( 'Invalid sustain level' ) ;
59
+ }
60
+ validateNumber ( audio . pingPongGain ) ;
61
+ if ( audio . pingPongGain < 0 || audio . pingPongGain > 1 ) {
62
+ throw new Error ( 'Invalid ping pong gain' ) ;
63
+ }
64
+ validateNumber ( audio . pingPongFeedback ) ;
65
+ const fb = Math . abs ( audio . pingPongFeedback ) ;
66
+ if ( fb > 1 ) {
67
+ throw new Error ( 'Invalid ping pong feedback' ) ;
68
+ }
69
+ validateString ( audio . waveform ) ;
70
+ validateString ( audio . aperiodicWaveform ) ;
42
71
// TODO: Rest
43
72
return data ;
44
73
}
0 commit comments