music.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * @license Licensed under the Apache License, Version 2.0 (the "License"):
  3. * http://www.apache.org/licenses/LICENSE-2.0
  4. */
  5. /**
  6. * @fileoverview Ardublockly JavaScript for the Blockly resources and bindings.
  7. */
  8. 'use strict';
  9. goog.provide('Blockly.Blocks.music');
  10. goog.require('Blockly.Blocks');
  11. // goog.require('Blockly.Types');
  12. Blockly.Blocks.music.HUE = 340;
  13. Blockly.Blocks['MusicMidiSetup'] = {
  14. init: function() {
  15. this.appendDummyInput()
  16. .appendField(new Blockly.FieldImage("./../blockly/media/main-music.png", 50, 40, "15"));
  17. this.appendDummyInput()
  18. .appendField(Blockly.Msg.MUSIC_INSTRUMENT)
  19. .appendField(new Blockly.FieldDropdown([
  20. [Blockly.Msg.MUSIC_INSTRUMENT_GPIANO, "1"],
  21. [Blockly.Msg.MUSIC_INSTRUMENT_EPIANO, "5"],
  22. [Blockly.Msg.MUSIC_INSTRUMENT_MUSICBOX, "11"],
  23. [Blockly.Msg.MUSIC_INSTRUMENT_XYLOPHONE, "14"],
  24. [Blockly.Msg.MUSIC_INSTRUMENT_DRAWBARORGAN, "17"],
  25. [Blockly.Msg.MUSIC_INSTRUMENT_ACCORION, "22"],
  26. [Blockly.Msg.MUSIC_INSTRUMENT_GUITAR, "25"],
  27. [Blockly.Msg.MUSIC_INSTRUMENT_EGUITAR, "28"],
  28. [Blockly.Msg.MUSIC_INSTRUMENT_BASS, "33"],
  29. [Blockly.Msg.MUSIC_INSTRUMENT_VIOLIN, "41"],
  30. [Blockly.Msg.MUSIC_INSTRUMENT_VIOLA, "42"],
  31. [Blockly.Msg.MUSIC_INSTRUMENT_CELLO, "43"],
  32. [Blockly.Msg.MUSIC_INSTRUMENT_TRUMPET, "57"],
  33. [Blockly.Msg.MUSIC_INSTRUMENT_SAX, "67"],
  34. [Blockly.Msg.MUSIC_INSTRUMENT_PICCOLO, "73"],
  35. [Blockly.Msg.MUSIC_INSTRUMENT_FLUTE, "74"],
  36. [Blockly.Msg.MUSIC_INSTRUMENT_WHISTLE, "79"],
  37. [Blockly.Msg.MUSIC_INSTRUMENT_SITAR, "105"],
  38. [Blockly.Msg.MUSIC_INSTRUMENT_WOODBLOCK, "116"],
  39. [Blockly.Msg.MUSIC_INSTRUMENT_DRUM, "117"]
  40. ]), "INSTRUMENT");
  41. this.appendDummyInput()
  42. .appendField(Blockly.Msg.MUSIC_VOLUME)
  43. .appendField(new Blockly.FieldDropdown([
  44. [Blockly.Msg.MUSIC_VOL_MIN, "120"],
  45. ["1", "100"],
  46. ["2", "80"],
  47. ["3", "60"],
  48. ["4", "40"],
  49. ["5", "20"],
  50. [Blockly.Msg.MUSIC_VOL_MAX, "0"]
  51. ]), "VOLUME");
  52. this.setColour(Blockly.Blocks.music.HUE);
  53. this.setTooltip("");
  54. this.setHelpUrl("");
  55. }
  56. };
  57. Blockly.Blocks['MusicSetVolume'] = {
  58. init: function() {
  59. this.appendDummyInput()
  60. .appendField(Blockly.Msg.MUSIC_VOLUME)
  61. .appendField(new Blockly.FieldDropdown([
  62. [Blockly.Msg.MUSIC_VOL_MIN, "120"],
  63. ["1", "100"],
  64. ["2", "80"],
  65. ["3", "60"],
  66. ["4", "40"],
  67. ["5", "20"],
  68. [Blockly.Msg.MUSIC_VOL_MAX, "0"]
  69. ]), "VOLUME");
  70. this.setPreviousStatement(true, null);
  71. this.setNextStatement(true, null);
  72. this.setColour(Blockly.Blocks.music.HUE);
  73. this.setTooltip(Blockly.Msg.MUSIC_PLAY_NOTE_TOOLTIP);
  74. this.setHelpUrl("");
  75. }
  76. };
  77. Blockly.Blocks['MusicSetInstrument'] = {
  78. init: function() {
  79. this.appendDummyInput()
  80. .appendField(Blockly.Msg.MUSIC_INSTRUMENT)
  81. .appendField(new Blockly.FieldDropdown([
  82. [Blockly.Msg.MUSIC_INSTRUMENT_GPIANO, "1"],
  83. [Blockly.Msg.MUSIC_INSTRUMENT_EPIANO, "5"],
  84. [Blockly.Msg.MUSIC_INSTRUMENT_MUSICBOX, "11"],
  85. [Blockly.Msg.MUSIC_INSTRUMENT_XYLOPHONE, "14"],
  86. [Blockly.Msg.MUSIC_INSTRUMENT_DRAWBARORGAN, "17"],
  87. [Blockly.Msg.MUSIC_INSTRUMENT_ACCORION, "22"],
  88. [Blockly.Msg.MUSIC_INSTRUMENT_GUITAR, "25"],
  89. [Blockly.Msg.MUSIC_INSTRUMENT_EGUITAR, "28"],
  90. [Blockly.Msg.MUSIC_INSTRUMENT_BASS, "33"],
  91. [Blockly.Msg.MUSIC_INSTRUMENT_VIOLIN, "41"],
  92. [Blockly.Msg.MUSIC_INSTRUMENT_VIOLA, "42"],
  93. [Blockly.Msg.MUSIC_INSTRUMENT_CELLO, "43"],
  94. [Blockly.Msg.MUSIC_INSTRUMENT_TRUMPET, "57"],
  95. [Blockly.Msg.MUSIC_INSTRUMENT_SAX, "67"],
  96. [Blockly.Msg.MUSIC_INSTRUMENT_PICCOLO, "73"],
  97. [Blockly.Msg.MUSIC_INSTRUMENT_FLUTE, "74"],
  98. [Blockly.Msg.MUSIC_INSTRUMENT_WHISTLE, "79"],
  99. [Blockly.Msg.MUSIC_INSTRUMENT_SITAR, "105"],
  100. [Blockly.Msg.MUSIC_INSTRUMENT_WOODBLOCK, "116"],
  101. [Blockly.Msg.MUSIC_INSTRUMENT_DRUM, "117"]
  102. ]), "INSTRUMENT");
  103. this.setPreviousStatement(true, null);
  104. this.setNextStatement(true, null);
  105. this.setColour(Blockly.Blocks.music.HUE);
  106. this.setTooltip(Blockly.Msg.MUSIC_PLAY_NOTE_TOOLTIP);
  107. this.setHelpUrl("");
  108. }
  109. };
  110. Blockly.Blocks['MusicNote'] = {
  111. init: function() {
  112. this.appendDummyInput()
  113. .appendField("♪")
  114. .appendField(Blockly.Msg.MUSIC_NOTE)
  115. .appendField(new Blockly.FieldNumber(60, 0, 100), "NOTE");
  116. this.setOutput(true, Blockly.Types.NUMBER.output);
  117. this.setColour(Blockly.Blocks.music.HUE);
  118. this.setTooltip("");
  119. this.setHelpUrl("http://cocorobo.cn/cocoblockly/dev/reference/notes.jpg");
  120. },
  121. getBlockType: function() {
  122. return Blockly.Types.NUMBER;
  123. }
  124. };
  125. Blockly.Blocks['MusicBeat'] = {
  126. init: function() {
  127. this.appendDummyInput()
  128. .appendField("♪")
  129. .appendField(new Blockly.FieldDropdown([
  130. ["1", "1000"],
  131. ["1/2", "500"],
  132. ["1/4", "250"],
  133. ["1/8", "125"],
  134. ["2", "2000"],
  135. ["4", "4000"],
  136. ]), "BEAT")
  137. .appendField(Blockly.Msg.MUSIC_BEAT);
  138. this.setOutput(true, "Number");
  139. this.setColour(Blockly.Blocks.music.HUE);
  140. this.setTooltip("");
  141. this.setHelpUrl("");
  142. }
  143. };
  144. Blockly.Blocks['MusicPlayTone'] = {
  145. init: function() {
  146. this.appendValueInput("NOTE")
  147. .appendField("♩ " + Blockly.Msg.MUSIC_PLAY_NOTE);
  148. this.appendValueInput("DURATION")
  149. .appendField(Blockly.Msg.MUSIC_DURATION);
  150. this.setPreviousStatement(true, null);
  151. this.setNextStatement(true, null);
  152. this.setInputsInline(true);
  153. this.setColour(Blockly.Blocks.music.HUE);
  154. this.setTooltip(Blockly.Msg.MUSIC_PLAY_NOTE_TOOLTIP);
  155. this.setHelpUrl("http://cocorobo.cn/cocoblockly/dev/reference/notes.jpg");
  156. }
  157. };
  158. Blockly.Blocks['MusicRest'] = {
  159. init: function() {
  160. this.appendValueInput("BEAT")
  161. .appendField("♩ " + Blockly.Msg.MUSIC_REST);
  162. this.setPreviousStatement(true, null);
  163. this.setNextStatement(true, null);
  164. this.setInputsInline(true);
  165. this.setColour(Blockly.Blocks.music.HUE);
  166. this.setTooltip("");
  167. this.setHelpUrl("");
  168. }
  169. };
  170. /*
  171. *MP3 player Setup
  172. */
  173. Blockly.Blocks['Music_mp3_setup'] = {
  174. init: function() {
  175. this.appendDummyInput()
  176. .appendField(new Blockly.FieldImage("./../blockly/media/main-music.png", 50, 40, "15"));
  177. this.appendDummyInput()
  178. .appendField(Blockly.Msg.MUSIC_MP3_SETUP);
  179. this.appendDummyInput()
  180. .appendField(Blockly.Msg.MUSIC_MP3_SETUP_SETVOLUME)
  181. .appendField(new Blockly.FieldDropdown([
  182. [Blockly.Msg.MUSIC_MP3_SETUP_SETVOLUME_LOW, "90"],
  183. [Blockly.Msg.MUSIC_MP3_SETUP_SETVOLUME_MID, "50"],
  184. [Blockly.Msg.MUSIC_MP3_SETUP_SETVOLUME_HIGH, "10"]
  185. ]), "SETVOL")
  186. this.setColour(Blockly.Blocks.music.HUE);
  187. this.setTooltip("");
  188. this.setHelpUrl("");
  189. }
  190. };
  191. /*
  192. *MP3 player
  193. * play one music
  194. */
  195. Blockly.Blocks['Music_mp3_playOneWithName'] = {
  196. init: function() {
  197. this.appendDummyInput()
  198. .appendField(Blockly.Msg.MUSIC_MP3_PLAYONE)
  199. .appendField(new Blockly.FieldTextInput("record.mp3"), "MUSIC_NAME")
  200. // .appendField(new Blockly.FieldDropdown([
  201. // [Blockly.Msg.MUSIC_MP3_PLAYONE_NORMAL, "PM_NORMAL_PLAY"],
  202. // [Blockly.Msg.MUSIC_MP3_PLAYONE_REPEAT, "PM_REPEAT_ONE"]
  203. // ]), "TYPE")
  204. this.setPreviousStatement(true, null);
  205. this.setNextStatement(true, null);
  206. this.setColour(Blockly.Blocks.music.HUE);
  207. this.setTooltip("");
  208. this.setHelpUrl("");
  209. }
  210. };
  211. /*
  212. *MP3 player
  213. * play all Music
  214. */
  215. Blockly.Blocks['Music_mp3_playAllMusic'] = {
  216. init: function() {
  217. this.appendDummyInput()
  218. .appendField(Blockly.Msg.MUSIC_MP3_PLAYALL)
  219. // .appendField(new Blockly.FieldDropdown([
  220. // [Blockly.Msg.MUSIC_MP3_PLAY_NORMAL, "PM_NORMAL_PLAY"],
  221. // [Blockly.Msg.MUSIC_MP3_PLAY_REPEAT, "PM_REPEAT_LIST"]
  222. // ]), "TYPE")
  223. this.setPreviousStatement(true, null);
  224. this.setNextStatement(true, null);
  225. this.setColour(Blockly.Blocks.music.HUE);
  226. this.setTooltip("");
  227. this.setHelpUrl("");
  228. },
  229. };
  230. /**
  231. *MP3 player
  232. * Player Setting
  233. * {pause, resume, nextSong, preSong, volUp, volDown, playAll}
  234. */
  235. Blockly.Blocks['Music_mp3_playSetting'] = {
  236. init: function() {
  237. this.appendDummyInput()
  238. .appendField(Blockly.Msg.MUSIC_MP3_PLAYSETTING)
  239. .appendField(new Blockly.FieldDropdown([
  240. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_RESUME, "0"],
  241. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_PAUSE, "1"],
  242. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_PRESONG, "2"],
  243. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_NEXTSONG, "3"],
  244. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_VOLUP, "4"],
  245. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_VOLDOWN, "5"],
  246. [Blockly.Msg.MUSIC_MP3_PLAYSETTING_PLAYALL, "6"],
  247. ]), "SETTING")
  248. this.setPreviousStatement(true, null);
  249. this.setNextStatement(true, null);
  250. this.setColour(Blockly.Blocks.music.HUE);
  251. this.setTooltip("");
  252. this.setHelpUrl("");
  253. },
  254. };
  255. /**
  256. * MP3 player
  257. * get current volume
  258. */
  259. Blockly.Blocks['Music_mp3_getCurrentVolume'] = {
  260. init: function() {
  261. this.appendDummyInput()
  262. .appendField(Blockly.Msg.MUSIC_MP3_CURRENTVOLUME)
  263. this.setOutput(true, Blockly.Types.NUMBER.output);
  264. this.setColour(Blockly.Blocks.music.HUE);
  265. this.setTooltip("");
  266. this.setHelpUrl("");
  267. },
  268. getBlockType: function() {
  269. return Blockly.Types.NUMBER;
  270. }
  271. }
  272. /**
  273. * MP3 player
  274. * set volume to
  275. */
  276. Blockly.Blocks['Music_mp3_setCurrentVolume'] = {
  277. init: function() {
  278. this.appendDummyInput()
  279. .appendField(Blockly.Msg.MUSIC_MP3_SETVOLUME)
  280. .appendField(new Blockly.FieldDropdown([
  281. ["0","0"],
  282. ["1","1"],
  283. ["2","2"],
  284. ["3","3"],
  285. ["4","4"],
  286. ["5","5"],
  287. ["6","6"],
  288. ["7","7"],
  289. ["8","8"],
  290. ["9","9"],
  291. ["10","10"]
  292. ]),"VOLLEVEL")
  293. this.setInputsInline(true);
  294. this.setPreviousStatement(true, null);
  295. this.setNextStatement(true, null);
  296. this.setColour(Blockly.Blocks.music.HUE);
  297. this.setTooltip("");
  298. this.setHelpUrl("");
  299. },
  300. }