Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import OperatorsBlocks from './operators.js';
import DataBlocks from './data.js';
import ProcedureBlocks from './procedure.js';
import RubyBlocks from './ruby.js';
import MusicBlocks from './music.js';

const SCALAR_TYPE = '';
const LIST_TYPE = 'list';
Expand Down Expand Up @@ -433,5 +434,6 @@ OperatorsBlocks(RubyGenerator);
DataBlocks(RubyGenerator);
ProcedureBlocks(RubyGenerator);
RubyBlocks(RubyGenerator);
MusicBlocks(RubyGenerator);

export default RubyGenerator;
65 changes: 65 additions & 0 deletions src/lib/ruby-generator/music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Define Ruby code generator for Music Blocks
* @param {RubyGenerator} Generator The RubyGenerator
* @return {RubyGenerator} same as param.
*/
export default function (Generator) {
Generator.music_playDrumForBeats = function (block) {
const drum = Generator.valueToCode(block, 'DRUM', Generator.ORDER_NONE) || null;
const beats = Generator.valueToCode(block, 'BEATS', Generator.ORDER_NONE) || 0;
return `play_drum(drum: ${drum}, beats: ${beats})\n`;
};

Generator.music_menu_DRUM = function (block) {
const drum = Generator.quote_(Generator.getFieldValue(block, 'DRUM') || '1');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも数値の方がよろしいでしょうか?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

はい、数値でお願いします。

return [drum, Generator.ORDER_ATOMIC];
};

Generator.music_restForBeats = function (block) {
const beats = Generator.valueToCode(block, 'BEATS', Generator.ORDER_NONE) || 0;
return `rest(${beats})\n`;
};

Generator.music_playNoteForBeats = function (block) {
const note = Generator.valueToCode(block, 'NOTE', Generator.ORDER_NONE) || 0;
const beats = Generator.valueToCode(block, 'BEATS', Generator.ORDER_NONE) || 0;
return `play_note(note: ${note}, beats: ${beats})\n`;
};

Generator.music_playNoteForBeats = function (block) {
const note = Generator.valueToCode(block, 'NOTE', Generator.ORDER_NONE) || 0;
const beats = Generator.valueToCode(block, 'BEATS', Generator.ORDER_NONE) || 0;
return `play_note(note: ${note}, beats: ${beats})\n`;
};

Generator.note = function (block) {
const note = Generator.getFieldValue(block, 'NOTE') || 0;
return [note, Generator.ORDER_ATOMIC];
};

Generator.music_setInstrument = function (block) {
const instrument = Generator.valueToCode(block, 'INSTRUMENT', Generator.ORDER_NONE) || null;
return `set_instrument(${instrument})\n`;
};

Generator.music_menu_INSTRUMENT = function (block) {
const instrument = Generator.quote_(Generator.getFieldValue(block, 'INSTRUMENT') || '1');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instrumentは数値がいいと思います。

Suggested change
const instrument = Generator.quote_(Generator.getFieldValue(block, 'INSTRUMENT') || '1');
const instrument = Generator.getFieldValue(block, 'INSTRUMENT') || 1;

Copy link
Collaborator Author

@t-kazu t-kazu Dec 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screenshot from 2018-12-05 13-23-03
こういうブロックなので数値ではなく文字列にしました。
case文で"(1)ピアノ"と返す方が良かったりしますか? 数値でよければ数値で良いとは思います!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数値でいいです。
Ruby -> Blocksにするときに、数値で決めうちだと楽だからです。ユーザーがタイプするのも数値だと楽だしね。

return [instrument, Generator.ORDER_ATOMIC];
};

Generator.music_setTempo = function (block) {
const tempo = Generator.valueToCode(block, 'TEMPO', Generator.ORDER_NONE) || 0;
return `self.tempo = ${tempo}\n`;
};

Generator.music_changeTempo = function (block) {
const tempo = Generator.valueToCode(block, 'TEMPO', Generator.ORDER_NONE) || 0;
return `self.tempo += ${tempo}\n`;
};

Generator.music_getTempo = function () {
return ['tempo', Generator.ORDER_ATOMIC];
};

return Generator;
}