1
1
"use strict" ;
2
2
var App = /** @class */ ( function ( ) {
3
- function App ( window , patterns_container , handpan_notes_input , handpan_notes_result_element , number_of_bars_input , number_of_bars_result_element , regenerate_button , rhythm_inputs , rhythm_input_to_enable ) {
3
+ function App ( ) {
4
4
this . handpan_tune = new HandpanTune ( ) ;
5
5
this . _running = false ;
6
6
this . window = window ;
7
7
this . document = window . document ;
8
+ var patterns_container = this . document . getElementById ( 'pattern' ) ;
9
+ if ( ! ( patterns_container instanceof HTMLElement ) ) {
10
+ throw App . invalidTypeMessage ( 'patterns_container' , 'HTMLElement' , typeof patterns_container ) ;
11
+ }
12
+ var number_of_bars_input = this . document . getElementById ( 'pattern_bars' ) ;
13
+ if ( ! ( number_of_bars_input instanceof HTMLInputElement ) ) {
14
+ throw App . invalidTypeMessage ( 'number_of_bars_input' , 'HTMLInputElement' , typeof number_of_bars_input ) ;
15
+ }
16
+ var number_of_bars_result_element = this . document . getElementById ( 'pattern_bars_result' ) ;
17
+ if ( ! ( number_of_bars_result_element instanceof HTMLElement ) ) {
18
+ throw App . invalidTypeMessage ( 'number_of_bars_result_element' , 'var_type' , typeof number_of_bars_result_element ) ;
19
+ }
20
+ var regenerate_button = this . document . getElementById ( 'regenerate_button' ) ;
21
+ if ( ! ( regenerate_button instanceof HTMLElement ) ) {
22
+ throw App . invalidTypeMessage ( 'regenerate_button' , 'HTMLElement' , typeof regenerate_button ) ;
23
+ }
24
+ var rhythm_inputs = this . document . querySelectorAll ( 'input[name="rhythm"]' ) ;
25
+ if ( ! ( rhythm_inputs instanceof NodeList ) ) {
26
+ throw App . invalidTypeMessage ( 'rhythm_inputs' , 'NodeList' , typeof rhythm_inputs ) ;
27
+ }
28
+ var rhythm_input_to_enable = rhythm_inputs [ 1 ] || rhythm_inputs [ 0 ] ;
29
+ if ( ! ( rhythm_input_to_enable instanceof HTMLInputElement ) ) {
30
+ throw App . invalidTypeMessage ( 'rhythm_input_to_enable' , 'HTMLInputElement' , typeof rhythm_input_to_enable ) ;
31
+ }
8
32
this . patterns_container = patterns_container ;
9
- this . handpan_notes_input = handpan_notes_input ;
10
- this . handpan_notes_result_element = handpan_notes_result_element ;
11
33
this . number_of_bars_input = number_of_bars_input ;
12
34
this . number_of_bars_result_element = number_of_bars_result_element ;
13
- this . rhythm_inputs = rhythm_inputs ;
14
35
this . regenerate_button = regenerate_button ;
36
+ this . rhythm_inputs = rhythm_inputs ;
15
37
this . rhythm_input_to_enable = rhythm_input_to_enable ;
16
38
this . _currentPattern = new Pattern ( 0 , this . handpan_tune ) ;
17
39
this . _patternRenderer = new PatternRenderer ( this . document , this . patterns_container ) ;
@@ -23,8 +45,6 @@ var App = /** @class */ (function () {
23
45
}
24
46
this . _running = true ;
25
47
this . regenerate_button . addEventListener ( 'click' , function ( ) { return _this . refreshRandomPattern ( ) ; } ) ;
26
- // handpan_notes_result_element.value = 9;
27
- // handpan_notes_input.addEventListener('input', this.refreshRandomPattern);
28
48
this . rhythm_input_to_enable . checked = true ;
29
49
this . number_of_bars_input . value = '2' ;
30
50
this . refreshRandomPattern ( ) ;
@@ -57,6 +77,9 @@ var App = /** @class */ (function () {
57
77
} ) ;
58
78
return value ;
59
79
} ;
80
+ App . invalidTypeMessage = function ( var_name , type , current_type ) {
81
+ return 'Variable ' + var_name + ' was expected to be a ' + type + ', ' + current_type + ' given' ;
82
+ } ;
60
83
return App ;
61
84
} ( ) ) ;
62
85
var Hand ;
@@ -287,7 +310,7 @@ var PatternRenderer = /** @class */ (function () {
287
310
var i = 0 ;
288
311
for ( var _i = 0 , _a = pattern . hits ; _i < _a . length ; _i ++ ) {
289
312
var handpan_hit = _a [ _i ] ;
290
- var pattern_item = this . createPatternItem ( pattern , handpan_hit ) ;
313
+ var pattern_item = PatternRenderer . createPatternItem ( pattern , handpan_hit ) ;
291
314
this . container . appendChild ( pattern_item ) ;
292
315
// Alternate left/right
293
316
pattern_item . classList . add ( handpan_hit . hand === Hand . left ? 'hand-left' : 'hand-right' ) ;
@@ -302,7 +325,7 @@ var PatternRenderer = /** @class */ (function () {
302
325
i ++ ;
303
326
}
304
327
} ;
305
- PatternRenderer . prototype . createPatternItem = function ( pattern , handpan_hit ) {
328
+ PatternRenderer . createPatternItem = function ( pattern , handpan_hit ) {
306
329
var pattern_item = document . createElement ( 'div' ) ;
307
330
pattern_item . className = 'pattern_item' ;
308
331
// Display handpan hit type
0 commit comments