123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /**
- * @license Licensed under the Apache License, Version 2.0 (the "License"):
- * http://www.apache.org/licenses/LICENSE-2.0
- */
- /**
- * @fileoverview Code generator for the test 2 blocks.
- */
- /*'use strict';
- goog.provide('Blockly.Python.music');
- goog.require('Blockly.Python');
- Blockly.Python['music_setup'] = function(block) {
- var decl = '#include <SPI.h>\n' +
- '#include <SD.h>\n' +
- '#include <MusicPlayer.h>\n' +
- '#include <Wire.h>\n' +
- 'MusicPlayer player;\n';
- Blockly.Python.addDeclaration('music_setup_decl', decl);
- var setup = 'Serial.begin(9600);\n'+
- 'player.beginMidi();\n';
- Blockly.Python.addSetup('music_setup', setup);
- var func = 'void midiSendByte(char data)\n' +
- '{\n' +
- ' SPI.transfer(0x00);\n' +
- ' SPI.transfer(data);\n' +
- '}\n' +
- 'void midiWriteData(char cmd, char high, char low)\n' +
- '{\n' +
- ' while(!digitalRead(VS_DREQ));\n' +
- ' digitalWrite(VS_XDCS, LOW);\n' +
- ' midiSendByte(cmd);\n' +
- ' if((cmd & 0xF0) <= 0xB0 || (cmd & 0xF0) >= 0xE0)\n' +
- ' {\n' +
- ' midiSendByte(high);\n' +
- ' midiSendByte(low);\n' +
- ' }\n' +
- ' else\n' +
- ' {\n' +
- ' midiSendByte(high);\n' +
- ' }\n' +
- ' digitalWrite(VS_XDCS, HIGH);\n' +
- '}\n' +
- 'void midiNoteOff(char channel, char note, char rate)\n' +
- '{\n' +
- ' midiWriteData((0x80 | channel), note, rate);\n' +
- '}\n' +
- 'void midiNoteOn(char channel, char note, char rate)\n' +
- '{\n' +
- ' midiWriteData((0x90 | channel), note, rate);\n' +
- '}\n';
- // Blockly.Python.addFunction('func', func);
- return "";
- };
- var original_beat;
- Blockly.Python['music_set_beat'] = function(block) {
- var dropdown_beat_option = block.getFieldValue('beat_option');
- Blockly.Python.addDeclaration('beat', 'float beat;');
- original_beat = dropdown_beat_option;
- var code = 'beat = '+dropdown_beat_option;
- return [code, Blockly.Python.ORDER_NONE];
- };
- Blockly.Python['music_set_bpm'] = function(block) {
- var dropdown_bpm = block.getFieldValue('bpm');
- Blockly.Python.addDeclaration('bpm', 'int bpm;');
- var code = 'bpm = '+dropdown_beat_option;
- return [code, Blockly.Python.ORDER_NONE];
- };
- Blockly.Python['music_instrument'] = function(block) {
- var dropdown_instru = block.getFieldValue('instru');
- var code = 'midiWriteData(0xC0, '+dropdown_instru+', 0)';
- return [code, Blockly.Python.ORDER_NONE];
- };
- Blockly.Python['music_rest'] = function(block) {
- var text_rest_beat = block.getFieldValue('rest_beat');
- // TODO: Assemble JavaScript into code variable.
- var code = '...;\n';
- return code;
- };
- Blockly.Python['music_volume'] = function(block) {
- var number_music_volume = block.getFieldValue('music_volume');
- // TODO: Assemble JavaScript into code variable.
- var code = 'midiWriteData(0xB0, 0x07, '+number_music_volume+');\n';
- return code;
- };
- Blockly.Python['music_customize_melody'] = function(block) {
- var value_instru = Blockly.Python.valueToCode(block, 'instru', Blockly.Python.ORDER_ATOMIC);
- var text_melody_name = block.getFieldValue('melody_name');
- var statements_composition = Blockly.Python.statementToCode(block, 'composition');
- var code = '...;\n';
- return code;
- };
- Blockly.Python['music_change_tempo'] = function(block) {
- var dropdown_beat = block.getFieldValue('beat');
- var statements_name = Blockly.Python.statementToCode(block, 'melody');
- // TODO: Assemble JavaScript into code variable.
- var code = 'beat = '+dropdown_beat+';\n'
- + statements_name
- + 'beat = '+original_beat+';\n';
- return code;
- };
- Blockly.Python['music_rest'] = function(block) {
- var text_name = block.getFieldValue('beat');
- var code = ' midiNoteOff(0, 75, 127);\n' +
- 'delay(1000*60 / bpm * '+text_name+');\n';
- return code;
- };
- Blockly.Python['music_combination'] = function(block) {
- var value_instrument = Blockly.Python.valueToCode(block, 'instrument', Blockly.Python.ORDER_ATOMIC);
- var value_note = Blockly.Python.valueToCode(block, 'note', Blockly.Python.ORDER_ATOMIC);
- var value_beat = Blockly.Python.valueToCode(block, 'beat', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble JavaScript into code variable.
- var code = '...;\n';
- return code;
- };
- */
|