@@ -5,6 +5,82 @@ import _ from 'lodash';
5
5
* Music converter
6
6
*/
7
7
const MusicConverter = {
8
+ onSend : function ( receiver , name , args , rubyBlockArgs , rubyBlock ) {
9
+ let block ;
10
+ if ( ( this . _isSelf ( receiver ) || receiver === Opal . nil ) && ! rubyBlock ) {
11
+ switch ( name ) {
12
+ case 'play_drum' :
13
+ if ( args . length === 1 && this . _isHash ( args [ 0 ] ) && args [ 0 ] . size === 2 ) {
14
+ const drum = args [ 0 ] . get ( 'sym:drum' ) ;
15
+ const beats = args [ 0 ] . get ( 'sym:beats' ) ;
16
+ if ( this . _isNumberOrBlock ( drum ) && this . _isNumberOrBlock ( beats ) ) {
17
+ block = this . _createBlock ( 'music_playDrumForBeats' , 'statement' ) ;
18
+ this . _addInput (
19
+ block ,
20
+ 'DRUM' ,
21
+ this . _createFieldBlock ( 'music_menu_DRUM' , 'DRUM' , drum )
22
+ ) ;
23
+ this . _addNumberInput ( block , 'BEATS' , 'math_number' , beats , 0.25 ) ;
24
+ }
25
+ }
26
+ break ;
27
+ case 'rest' :
28
+ if ( args . length === 1 && this . _isNumberOrBlock ( args [ 0 ] ) ) {
29
+ block = this . _createBlock ( 'music_restForBeats' , 'statement' ) ;
30
+ this . _addNumberInput ( block , 'BEATS' , 'math_number' , args [ 0 ] , 0.25 ) ;
31
+ }
32
+ break ;
33
+ case 'play_note' :
34
+ if ( args . length === 1 && this . _isHash ( args [ 0 ] ) && args [ 0 ] . size === 2 ) {
35
+ const note = args [ 0 ] . get ( 'sym:note' ) ;
36
+ const beats = args [ 0 ] . get ( 'sym:beats' ) ;
37
+ if ( this . _isNumberOrBlock ( note ) && this . _isNumberOrBlock ( beats ) ) {
38
+ block = this . _createBlock ( 'music_playNoteForBeats' , 'statement' ) ;
39
+ this . _addNoteInput ( block , 'NOTE' , note , 60 ) ;
40
+ this . _addNumberInput ( block , 'BEATS' , 'math_number' , beats , 0.25 ) ;
41
+ }
42
+ }
43
+ break ;
44
+ case 'instrument=' :
45
+ if ( args . length === 1 && this . _isNumberOrBlock ( args [ 0 ] ) ) {
46
+ block = this . _createBlock ( 'music_setInstrument' , 'statement' ) ;
47
+ this . _addInput (
48
+ block ,
49
+ 'INSTRUMENT' ,
50
+ this . _createFieldBlock ( 'music_menu_INSTRUMENT' , 'INSTRUMENT' , args [ 0 ] )
51
+ ) ;
52
+ }
53
+ break ;
54
+ case 'tempo=' :
55
+ if ( args . length === 1 && this . _isNumberOrBlock ( args [ 0 ] ) ) {
56
+ block = this . _createBlock ( 'music_setTempo' , 'statement' ) ;
57
+ this . _addNumberInput ( block , 'TEMPO' , 'math_number' , args [ 0 ] , 60 ) ;
58
+ }
59
+ break ;
60
+ case 'tempo' :
61
+ if ( args . length === 0 ) {
62
+ block = this . _createBlock ( 'music_getTempo' , 'value' ) ;
63
+ }
64
+ break ;
65
+ }
66
+ }
67
+ return block ;
68
+ } ,
69
+
70
+ // eslint-disable-next-line no-unused-vars
71
+ onOpAsgn : function ( lh , operator , rh ) {
72
+ let block ;
73
+ if ( this . _isBlock ( lh ) && operator === '+' && this . _isNumberOrBlock ( rh ) ) {
74
+ let xy ;
75
+ switch ( lh . opcode ) {
76
+ case 'music_getTempo' :
77
+ block = this . _changeBlock ( lh , 'music_changeTempo' , 'statement' ) ;
78
+ this . _addNumberInput ( block , 'TEMPO' , 'math_number' , rh , 20 ) ;
79
+ break ;
80
+ }
81
+ }
82
+ return block ;
83
+ }
8
84
} ;
9
85
10
86
export default MusicConverter ;
0 commit comments