11function PianoCtrl ( $xhr ) {
22 $xhr . defaults . headers . post [ 'Content-Type' ] = 'application/json' ;
3- var self = this ;
3+ var scope = this ;
44
5- this . genKeyboard = function ( startOctave , endOctave ) {
5+ scope . genKeyboard = function ( startOctave , endOctave ) {
66 if ( startOctave < 0 || endOctave > 8 || startOctave >= endOctave ) throw "Bad arguments" ;
77 var notes = [
88 [ 'C' , 0 , 'white' ] , [ 'Db' , 0.5 , 'black' ] , [ 'D' , 1 , 'white' ] , [ 'Eb' , 1.5 , 'black' ] ,
@@ -33,31 +33,31 @@ function PianoCtrl($xhr) {
3333 return keys . concat ( genOctave ( endOctave , 0 , 1 ) ) ; // C
3434 }
3535
36- this . NOTE_ON = 144 ;
37- this . NOTE_OFF = 128 ;
38- this . sendMidiCommand = function ( command , midiNote ) {
36+ scope . NOTE_ON = 144 ;
37+ scope . NOTE_OFF = 128 ;
38+ scope . sendMidiCommand = function ( command , midiNote ) {
3939 var midiMessage = {
4040 command : command ,
41- channel : this . channel ,
41+ channel : scope . channel ,
4242 note : midiNote ,
43- velocity : this . velocity
43+ velocity : scope . velocity
4444 }
4545 var timeStart = new Date ( ) . getTime ( ) ;
4646 $xhr ( 'POST' , '/data/midi/send' , midiMessage , function ( code , response ) {
47- self . latency = new Date ( ) . getTime ( ) - timeStart ;
47+ scope . latency = new Date ( ) . getTime ( ) - timeStart ;
4848 } ) ;
4949 }
5050
51- this . startOctave = 2 ;
52- this . endOctave = 6 ;
53- this . resetKeyboard = function ( ) {
54- this . keyboard = this . genKeyboard ( this . startOctave , this . endOctave ) ;
51+ scope . startOctave = 2 ;
52+ scope . endOctave = 6 ;
53+ scope . resetKeyboard = function ( ) {
54+ scope . keyboard = scope . genKeyboard ( scope . startOctave , scope . endOctave ) ;
5555 }
56- this . resetKeyboard ( ) ;
56+ scope . resetKeyboard ( ) ;
5757
58- this . latency = 0 ;
59- this . showNames = true ;
60- this . channel = 0 ;
61- this . velocity = 60 ;
58+ scope . latency = 0 ;
59+ scope . showNames = true ;
60+ scope . channel = 0 ;
61+ scope . velocity = 60 ;
6262}
6363PianoCtrl . $inject = [ '$xhr' ] ;
0 commit comments