| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | 'use strict';
|
| |
|
| | goog.provide('Blockly.FieldNote');
|
| |
|
| | goog.require('Blockly.DropDownDiv');
|
| | goog.require('Blockly.FieldTextInput');
|
| | goog.require('goog.math');
|
| | goog.require('goog.userAgent');
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote = function(opt_value, opt_validator) {
|
| | opt_value = (opt_value && !isNaN(opt_value)) ? String(opt_value) : '0';
|
| | Blockly.FieldNote.superClass_.constructor.call(
|
| | this, opt_value, opt_validator);
|
| | this.addArgType('note');
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.fieldEditorWidth_ = 0;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.fieldEditorHeight_ = 0;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.pianoSVG_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.keySVGs_ = [];
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.noteNameText_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.lowCText_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.highCText_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.displayedOctave_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.animationPos_ = 0;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.animationTarget_ = 0;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.mouseIsDown_ = false;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.mouseDownWrappers_ = [];
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.mouseUpWrapper_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.mouseEnterWrappers_ = [];
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.octaveDownMouseDownWrapper_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.octaveUpMouseDownWrapper_ = null;
|
| | };
|
| | goog.inherits(Blockly.FieldNote, Blockly.FieldTextInput);
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.INSET = 5;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.TOP_MENU_HEIGHT = 32 - Blockly.FieldNote.INSET;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.EDGE_PADDING = 1;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.SHADOW_HEIGHT = 4;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.SHADOW_COLOR = '#000';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.SHADOW_OPACITY = .2;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.WHITE_KEY_COLOR = '#FFFFFF';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.BLACK_KEY_COLOR = '#323133';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.BLACK_KEY_STROKE = '#555555';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.KEY_SELECTED_COLOR = '#b0d6ff';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.NUM_WHITE_KEYS = 8;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.WHITE_KEY_HEIGHT = 72;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.WHITE_KEY_WIDTH = 40;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.BLACK_KEY_HEIGHT = 40;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.BLACK_KEY_WIDTH = 32;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.KEY_RADIUS = 6;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.KEY_LABEL_PADDING = 8;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.KEY_INFO = [
|
| | {name: 'C', pitch: 0},
|
| | {name: 'C♯', pitch: 1, isBlack: true},
|
| | {name: 'D', pitch: 2},
|
| | {name: 'E♭', pitch: 3, isBlack: true},
|
| | {name: 'E', pitch: 4},
|
| | {name: 'F', pitch: 5},
|
| | {name: 'F♯', pitch: 6, isBlack: true},
|
| | {name: 'G', pitch: 7},
|
| | {name: 'G♯', pitch: 8, isBlack: true},
|
| | {name: 'A', pitch: 9},
|
| | {name: 'B♭', pitch: 10, isBlack: true},
|
| | {name: 'B', pitch: 11},
|
| | {name: 'C', pitch: 12}
|
| | ];
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.MAX_NOTE = 130;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.ANIMATION_FRACTION = 0.2;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.ARROW_SVG_PATH = 'icons/arrow_button.svg';
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.OCTAVE_BUTTON_SIZE = 32;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.fromJson = function(options) {
|
| | return new Blockly.FieldNote(options['note']);
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.dispose_ = function() {
|
| | var thisField = this;
|
| | return function() {
|
| | Blockly.FieldNote.superClass_.dispose_.call(thisField)();
|
| | thisField.mouseDownWrappers_.forEach(function(wrapper) {
|
| | Blockly.unbindEvent_(wrapper);
|
| | });
|
| | thisField.mouseEnterWrappers_.forEach(function(wrapper) {
|
| | Blockly.unbindEvent_(wrapper);
|
| | });
|
| | if (thisField.mouseUpWrapper_) {
|
| | Blockly.unbindEvent_(thisField.mouseUpWrapper_);
|
| | }
|
| | if (thisField.octaveDownMouseDownWrapper_) {
|
| | Blockly.unbindEvent_(thisField.octaveDownMouseDownWrapper_);
|
| | }
|
| | if (thisField.octaveUpMouseDownWrapper_) {
|
| | Blockly.unbindEvent_(thisField.octaveUpMouseDownWrapper_);
|
| | }
|
| | this.pianoSVG_ = null;
|
| | this.keySVGs_.length = 0;
|
| | this.noteNameText_ = null;
|
| | this.lowCText_ = null;
|
| | this.highCText_ = null;
|
| | };
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.showEditor_ = function() {
|
| |
|
| | Blockly.FieldNote.superClass_.showEditor_.call(this, this.useTouchInteraction_);
|
| |
|
| |
|
| | Blockly.DropDownDiv.hideWithoutAnimation();
|
| | Blockly.DropDownDiv.clearContent();
|
| |
|
| |
|
| | var div = Blockly.DropDownDiv.getContentDiv();
|
| |
|
| | this.fieldEditorWidth_ = Blockly.FieldNote.NUM_WHITE_KEYS * Blockly.FieldNote.WHITE_KEY_WIDTH +
|
| | Blockly.FieldNote.EDGE_PADDING;
|
| | this.fieldEditorHeight_ = Blockly.FieldNote.TOP_MENU_HEIGHT +
|
| | Blockly.FieldNote.WHITE_KEY_HEIGHT +
|
| | Blockly.FieldNote.EDGE_PADDING;
|
| |
|
| | var svg = Blockly.utils.createSvgElement('svg', {
|
| | 'xmlns': 'http://www.w3.org/2000/svg',
|
| | 'xmlns:html': 'http://www.w3.org/1999/xhtml',
|
| | 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
| | 'version': '1.1',
|
| | 'height': this.fieldEditorHeight_ + 'px',
|
| | 'width': this.fieldEditorWidth_ + 'px'
|
| | }, div);
|
| |
|
| |
|
| |
|
| |
|
| | this.pianoSVG_ = Blockly.utils.createSvgElement('g', {}, svg);
|
| | var whiteKeyGroup = Blockly.utils.createSvgElement('g', {}, this.pianoSVG_);
|
| | var blackKeyGroup = Blockly.utils.createSvgElement('g', {}, this.pianoSVG_);
|
| |
|
| |
|
| |
|
| | this.keySVGs_ = [];
|
| | this.addPianoOctave_(-this.fieldEditorWidth_ + Blockly.FieldNote.EDGE_PADDING,
|
| | whiteKeyGroup, blackKeyGroup, null);
|
| | this.addPianoOctave_(0, whiteKeyGroup, blackKeyGroup, this.keySVGs_);
|
| | this.addPianoOctave_(this.fieldEditorWidth_ - Blockly.FieldNote.EDGE_PADDING,
|
| | whiteKeyGroup, blackKeyGroup, null);
|
| |
|
| |
|
| | this.noteNameText_ = Blockly.utils.createSvgElement('text',
|
| | {
|
| | 'x': this.fieldEditorWidth_ / 2,
|
| | 'y': Blockly.FieldNote.TOP_MENU_HEIGHT / 2,
|
| | 'class': 'blocklyText',
|
| | 'text-anchor': 'middle',
|
| | 'dominant-baseline': 'middle',
|
| | }, svg);
|
| |
|
| |
|
| | var lowCX = Blockly.FieldNote.WHITE_KEY_WIDTH / 2;
|
| | this.lowCText_ = this.addCKeyLabel_(lowCX, svg);
|
| | var highCX = lowCX + (Blockly.FieldNote.WHITE_KEY_WIDTH *
|
| | (Blockly.FieldNote.NUM_WHITE_KEYS - 1));
|
| | this.highCText_ = this.addCKeyLabel_(highCX, svg);
|
| |
|
| |
|
| | Blockly.utils.createSvgElement('line',
|
| | {
|
| | 'stroke': this.sourceBlock_.getColourTertiary(),
|
| | 'x1': 0,
|
| | 'y1': Blockly.FieldNote.TOP_MENU_HEIGHT,
|
| | 'x2': this.fieldEditorWidth_,
|
| | 'y2': Blockly.FieldNote.TOP_MENU_HEIGHT
|
| | }, svg);
|
| |
|
| |
|
| | Blockly.utils.createSvgElement('rect',
|
| | {
|
| | 'x': 0,
|
| | 'y': Blockly.FieldNote.TOP_MENU_HEIGHT,
|
| | 'width': this.fieldEditorWidth_,
|
| | 'height': Blockly.FieldNote.SHADOW_HEIGHT,
|
| | 'fill': Blockly.FieldNote.SHADOW_COLOR,
|
| | 'fill-opacity': Blockly.FieldNote.SHADOW_OPACITY
|
| | }, svg);
|
| |
|
| |
|
| | this.octaveDownButton = this.addOctaveButton_(0, true, svg);
|
| | this.octaveUpButton = this.addOctaveButton_(
|
| | (this.fieldEditorWidth_ + Blockly.FieldNote.INSET * 2) -
|
| | Blockly.FieldNote.OCTAVE_BUTTON_SIZE, false, svg);
|
| |
|
| | this.octaveDownMouseDownWrapper_ =
|
| | Blockly.bindEvent_(this.octaveDownButton, 'mousedown', this, function() {
|
| | this.changeOctaveBy_(-1);
|
| | });
|
| | this.octaveUpMouseDownWrapper_ =
|
| | Blockly.bindEvent_(this.octaveUpButton, 'mousedown', this,function() {
|
| | this.changeOctaveBy_(1);
|
| | });
|
| | Blockly.DropDownDiv.setColour(this.sourceBlock_.parentBlock_.getColour(),
|
| | this.sourceBlock_.getColourTertiary());
|
| | Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
|
| | Blockly.DropDownDiv.showPositionedByBlock(this, this.sourceBlock_);
|
| |
|
| | this.updateSelection_();
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.addPianoOctave_ = function(x, whiteKeyGroup, blackKeyGroup, keySVGarray) {
|
| | var xIncrement, width, height, fill, stroke, group;
|
| | x += Blockly.FieldNote.EDGE_PADDING / 2;
|
| | var y = Blockly.FieldNote.TOP_MENU_HEIGHT;
|
| | for (var i = 0; i < Blockly.FieldNote.KEY_INFO.length; i++) {
|
| |
|
| | if (Blockly.FieldNote.KEY_INFO[i].isBlack) {
|
| |
|
| | x -= Blockly.FieldNote.BLACK_KEY_WIDTH / 2;
|
| | xIncrement = Blockly.FieldNote.BLACK_KEY_WIDTH / 2;
|
| | width = Blockly.FieldNote.BLACK_KEY_WIDTH;
|
| | height = Blockly.FieldNote.BLACK_KEY_HEIGHT;
|
| | fill = Blockly.FieldNote.BLACK_KEY_COLOR;
|
| | stroke = Blockly.FieldNote.BLACK_KEY_STROKE;
|
| | group = blackKeyGroup;
|
| | } else {
|
| | xIncrement = Blockly.FieldNote.WHITE_KEY_WIDTH;
|
| | width = Blockly.FieldNote.WHITE_KEY_WIDTH;
|
| | height = Blockly.FieldNote.WHITE_KEY_HEIGHT;
|
| | fill = Blockly.FieldNote.WHITE_KEY_COLOR;
|
| | stroke = this.sourceBlock_.getColourTertiary();
|
| | group = whiteKeyGroup;
|
| | }
|
| | var attr = {
|
| | 'd': this.getPianoKeyPath_(x, y, width, height),
|
| | 'fill': fill,
|
| | 'stroke': stroke
|
| | };
|
| | x += xIncrement;
|
| |
|
| | var keySVG = Blockly.utils.createSvgElement('path', attr, group);
|
| |
|
| | if (keySVGarray) {
|
| | keySVGarray[i] = keySVG;
|
| | keySVG.setAttribute('data-pitch', Blockly.FieldNote.KEY_INFO[i].pitch);
|
| | keySVG.setAttribute('data-name', Blockly.FieldNote.KEY_INFO[i].name);
|
| | keySVG.setAttribute('data-isBlack', Blockly.FieldNote.KEY_INFO[i].isBlack);
|
| |
|
| | this.mouseDownWrappers_[i] =
|
| | Blockly.bindEvent_(keySVG, 'mousedown', this, this.onMouseDownOnKey_);
|
| | this.mouseEnterWrappers_[i] =
|
| | Blockly.bindEvent_(keySVG, 'mouseenter', this, this.onMouseEnter_);
|
| | }
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.getPianoKeyPath_ = function(x, y, width, height) {
|
| | return 'M' + x + ' ' + y + ' ' +
|
| | 'L' + x + ' ' + (y + height - Blockly.FieldNote.KEY_RADIUS) + ' ' +
|
| | 'Q' + x + ' ' + (y + height) + ' ' +
|
| | (x + Blockly.FieldNote.KEY_RADIUS) + ' ' + (y + height) + ' ' +
|
| | 'L' + (x + width - Blockly.FieldNote.KEY_RADIUS) + ' ' + (y + height) + ' ' +
|
| | 'Q' + (x + width) + ' ' + (y + height) + ' ' +
|
| | (x + width) + ' ' + (y + height - Blockly.FieldNote.KEY_RADIUS) + ' ' +
|
| | 'L' + (x + width) + ' ' + y + ' ' +
|
| | 'L' + x + ' ' + y;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.addOctaveButton_ = function(x, flipped, svg) {
|
| | var group = Blockly.utils.createSvgElement('g', {}, svg);
|
| | var imageSize = Blockly.FieldNote.OCTAVE_BUTTON_SIZE;
|
| | var arrow = Blockly.utils.createSvgElement('image',
|
| | {
|
| | 'width': imageSize,
|
| | 'height': imageSize,
|
| | 'x': x - Blockly.FieldNote.INSET,
|
| | 'y': -1 * Blockly.FieldNote.INSET
|
| | }, group);
|
| | arrow.setAttributeNS(
|
| | 'http://www.w3.org/1999/xlink',
|
| | 'xlink:href',
|
| | Blockly.mainWorkspace.options.pathToMedia + Blockly.FieldNote.ARROW_SVG_PATH
|
| | );
|
| | Blockly.utils.createSvgElement('line',
|
| | {
|
| | 'stroke': this.sourceBlock_.getColourTertiary(),
|
| | 'x1': x - Blockly.FieldNote.INSET,
|
| | 'y1': 0,
|
| | 'x2': x - Blockly.FieldNote.INSET,
|
| | 'y2': Blockly.FieldNote.TOP_MENU_HEIGHT - Blockly.FieldNote.INSET
|
| | }, group);
|
| | if (flipped) {
|
| | var translateX = -1 * Blockly.FieldNote.OCTAVE_BUTTON_SIZE + (Blockly.FieldNote.INSET * 2);
|
| | group.setAttribute('transform', 'scale(-1, 1) ' +
|
| | 'translate(' + translateX + ', 0)');
|
| | }
|
| | return group;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.addCKeyLabel_ = function(x, svg) {
|
| | return Blockly.utils.createSvgElement('text',
|
| | {
|
| | 'x': x,
|
| | 'y': Blockly.FieldNote.TOP_MENU_HEIGHT + Blockly.FieldNote.WHITE_KEY_HEIGHT -
|
| | Blockly.FieldNote.KEY_LABEL_PADDING,
|
| | 'class': 'scratchNotePickerKeyLabel',
|
| | 'text-anchor': 'middle'
|
| | }, svg);
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.setCKeyLabelsVisible_ = function(visible) {
|
| | if (visible) {
|
| | this.fadeSvgToOpacity_(this.lowCText_, 1);
|
| | this.fadeSvgToOpacity_(this.highCText_, 1);
|
| | } else {
|
| | this.fadeSvgToOpacity_(this.lowCText_, 0);
|
| | this.fadeSvgToOpacity_(this.highCText_, 0);
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.fadeSvgToOpacity_ = function(svg, opacity) {
|
| | svg.setAttribute('style', 'opacity: ' + opacity + '; transition: opacity 0.1s;');
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.onMouseDownOnKey_ = function(e) {
|
| | this.mouseIsDown_ = true;
|
| | this.mouseUpWrapper_ = Blockly.bindEvent_(document.body, 'mouseup', this, this.onMouseUp_);
|
| | this.selectNoteWithMouseEvent_(e);
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.onMouseUp_ = function() {
|
| | this.mouseIsDown_ = false;
|
| | Blockly.unbindEvent_(this.mouseUpWrapper_);
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.onMouseEnter_ = function(e) {
|
| | if (this.mouseIsDown_) {
|
| | this.selectNoteWithMouseEvent_(e);
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.selectNoteWithMouseEvent_ = function(e) {
|
| | var newNoteNum = Number(e.target.getAttribute('data-pitch')) + this.displayedOctave_ * 12;
|
| | this.setNoteNum_(newNoteNum);
|
| | this.playNoteInternal_();
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.playNoteInternal_ = function() {
|
| | if (Blockly.FieldNote.playNote_) {
|
| | Blockly.FieldNote.playNote_(
|
| | this.getValue(),
|
| | this.sourceBlock_.parentBlock_.getCategory()
|
| | );
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.playNote_ = function() {
|
| | return;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.changeOctaveBy_ = function(octaves) {
|
| | this.displayedOctave_ += octaves;
|
| | if (this.displayedOctave_ < 0) {
|
| | this.displayedOctave_ = 0;
|
| | return;
|
| | }
|
| | var maxOctave = Math.floor(Blockly.FieldNote.MAX_NOTE / 12);
|
| | if (this.displayedOctave_ > maxOctave) {
|
| | this.displayedOctave_ = maxOctave;
|
| | return;
|
| | }
|
| |
|
| | var newNote = Number(this.getText()) + (octaves * 12);
|
| | this.setNoteNum_(newNote);
|
| |
|
| | this.animationTarget_ = this.fieldEditorWidth_ * octaves * -1;
|
| | this.animationPos_ = 0;
|
| | this.stepOctaveAnimation_();
|
| | this.setCKeyLabelsVisible_(false);
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.stepOctaveAnimation_ = function() {
|
| | var absDiff = Math.abs(this.animationPos_ - this.animationTarget_);
|
| | if (absDiff < 1) {
|
| | this.pianoSVG_.setAttribute('transform', 'translate(0, 0)');
|
| | this.setCKeyLabelsVisible_(true);
|
| | this.playNoteInternal_();
|
| | return;
|
| | }
|
| | this.animationPos_ += (this.animationTarget_ - this.animationPos_) *
|
| | Blockly.FieldNote.ANIMATION_FRACTION;
|
| | this.pianoSVG_.setAttribute('transform', 'translate(' + this.animationPos_ + ',0)');
|
| | requestAnimationFrame(this.stepOctaveAnimation_.bind(this));
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.setNoteNum_ = function(noteNum) {
|
| | noteNum = this.callValidator(noteNum);
|
| | this.setValue(noteNum);
|
| | Blockly.FieldTextInput.htmlInput_.value = noteNum;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.setText = function(text) {
|
| | Blockly.FieldNote.superClass_.setText.call(this, text);
|
| | if (!this.textElement_) {
|
| |
|
| | return;
|
| | }
|
| | this.updateSelection_();
|
| |
|
| | this.size_.width = 0;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.noteNumToKeyIndex_ = function(noteNum) {
|
| | return Math.floor(noteNum) - (this.displayedOctave_ * 12);
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.updateSelection_ = function() {
|
| | var noteNum = Number(this.getText());
|
| |
|
| |
|
| | if (this.displayedOctave_ == null ||
|
| | noteNum > ((this.displayedOctave_ * 12) + 12) ||
|
| | noteNum < (this.displayedOctave_ * 12)) {
|
| | this.displayedOctave_ = Math.floor(noteNum / 12);
|
| | }
|
| |
|
| | var index = this.noteNumToKeyIndex_(noteNum);
|
| |
|
| |
|
| | this.keySVGs_.forEach(function(svg) {
|
| | var isBlack = svg.getAttribute('data-isBlack');
|
| | if (isBlack === 'true') {
|
| | svg.setAttribute('fill', Blockly.FieldNote.BLACK_KEY_COLOR);
|
| | } else {
|
| | svg.setAttribute('fill', Blockly.FieldNote.WHITE_KEY_COLOR);
|
| | }
|
| | });
|
| |
|
| | if (this.keySVGs_[index]) {
|
| | this.keySVGs_[index].setAttribute('fill', Blockly.FieldNote.KEY_SELECTED_COLOR);
|
| |
|
| | var noteName = Blockly.FieldNote.KEY_INFO[index].name;
|
| | this.noteNameText_.textContent = noteName + ' (' + Math.floor(noteNum) + ')';
|
| |
|
| | var lowCNum = this.displayedOctave_ * 12;
|
| | this.lowCText_.textContent = 'C(' + lowCNum + ')';
|
| | this.highCText_.textContent = 'C(' + (lowCNum + 12) + ')';
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.FieldNote.prototype.classValidator = function(text) {
|
| | if (text === null) {
|
| | return null;
|
| | }
|
| | var n = parseFloat(text || 0);
|
| | if (isNaN(n)) {
|
| | return null;
|
| | }
|
| | if (n < 0) {
|
| | n = 0;
|
| | }
|
| | if (n > Blockly.FieldNote.MAX_NOTE) {
|
| | n = Blockly.FieldNote.MAX_NOTE;
|
| | }
|
| | return String(n);
|
| | };
|
| |
|
| | Blockly.Field.register('field_note', Blockly.FieldNote);
|
| |
|