From 51a8b7749148ff5e263e99b77fcc05d4b89efda8 Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Mon, 20 Apr 2015 13:24:20 -0700 Subject: [PATCH 1/7] Testing block drop-down menu repopulating --- blocks.js | 13 +++++++++++++ objects.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/blocks.js b/blocks.js index 72aa5d0d..e5cd1db7 100644 --- a/blocks.js +++ b/blocks.js @@ -811,6 +811,19 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { ); part.setContents(90); break; + case '%note': + part = new InputSlotMorph( + null, + true, + { + 'C (60)' : 60, + 'C# (61)' : 61, + 'D (62)' : 62, + 'D# (63)' : 63, + 'A (69)' : 69 + } + ); + break; case '%inst': part = new InputSlotMorph( null, diff --git a/objects.js b/objects.js index 552bf8eb..a3f960d9 100644 --- a/objects.js +++ b/objects.js @@ -468,7 +468,7 @@ SpriteMorph.prototype.initBlocks = function () { doPlayNote: { type: 'command', category: 'sound', - spec: 'play note %n for %n beats', + spec: 'play note %note for %n beats', defaults: [60, 0.5] }, doChangeTempo: { From 30f069eb1c481b559035001156644ae06911f48c Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Mon, 27 Apr 2015 12:36:59 -0700 Subject: [PATCH 2/7] General subclasses for piano Set up the subclasses needed to display a piano. No differences in actual program yet. --- blocks.js | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 140 insertions(+), 11 deletions(-) diff --git a/blocks.js b/blocks.js index 5d923db8..2ff0d984 100644 --- a/blocks.js +++ b/blocks.js @@ -846,17 +846,7 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { part.setContents(90); break; case '%note': - part = new InputSlotMorph( - null, - true, - { - 'C (60)' : 60, - 'C# (61)' : 61, - 'D (62)' : 62, - 'D# (63)' : 63, - 'A (69)' : 69 - } - ); + part = new NoteInputMorph(); break; case '%inst': part = new InputSlotMorph( @@ -7385,6 +7375,10 @@ InputSlotMorph.prototype.drawRoundBorder = function (context) { context.stroke(); }; + + + + // TemplateSlotMorph /////////////////////////////////////////////////// /* @@ -7720,6 +7714,141 @@ ArrowMorph.prototype.drawNew = function () { context.fill(); }; +// PianoMenuMorph ////////////////////////////////////////////////////// +/* + I am a menu that looks like a piano keyboard. +*/ + +// PianoMenuMorph inherits from MenuMorph + +PianoMenuMorph.prototype = new MenuMorph(); +PianoMenuMorph.prototype.constructor = PianoMenuMorph; +PianoMenuMorph.uber = MenuMorph.prototype; + +// PianoMenuMorph instance creation: + +function PianoMenuMorph(target, title, environment, fontSize) { + this.init(target); +} + +PianoMenuMorph.prototype.init = function(target, title, environment, fontSize) { + this.target = target; + this.title = title || null; + this.environment = environment || null; + this.fontSize = fontSize || null; + this.items = []; + this.label = null; + this.world = null; + this.isListContents = false; + + // initialize inherited properties: + MenuMorph.uber.init.call(this); + + // override inherited properties: + this.isDraggable = false; + + // immutable properties: + this.border = null; + this.edge = null; +}; + +// NoteInputMorph ////////////////////////////////////////////////////// +/* + I am an inputslotmorph designed for selecting midi notes. + My block spec is + + %note - midi notes + + evaluate returns the integer value of the displayed midi note. +*/ + +// NoteInputMorph inherits from InputSlotMorph + +NoteInputMorph.prototype = new InputSlotMorph(); +NoteInputMorph.prototype.constructor = NoteInputMorph; +NoteInputMorph.uber = InputSlotMorph.prototype; + +// NoteInputMorph instance creation: + +function NoteInputMorph() { + this.init(); +} + +NoteInputMorph.prototype.init = function() { + var contents = new StringMorph(''), + arrow = new ArrowMorph( + 'down', + 0, + Math.max(Math.floor(this.fontSize / 6), 1) + ); + + contents.fontSize = this.fontSize; + contents.isShowingBlanks = true; + contents.drawNew(); + + this.isUnevaluated = false; + this.choices = { + 'C (60)' : 60, + 'C# (61)' : 61, + 'D (62)' : 62, + 'D# (63)' : 63, + 'A (69)' : 69 + }; // object, function or selector + this.oldContentsExtent = contents.extent(); + this.isNumeric = true; + this.isReadOnly = false; + this.minWidth = 0; // can be chaged for text-type inputs ("landscape") + this.constant = null; + + InputSlotMorph.uber.init.call(this); + this.color = new Color(255, 255, 255); + this.add(contents); + this.add(arrow); + contents.isEditable = true; + contents.isDraggable = false; + contents.enableSelecting(); + this.setContents(null); +}; + +NoteInputMorph.prototype.dropDownMenu = function () { + var choices = this.choices, + key, + menu = new PianoMenuMorph( + this.setContents, + null, + this, + this.fontSize + ); + + if (choices instanceof Function) { + choices = choices.call(this); + } else if (isString(choices)) { + choices = this[choices](); + } + if (!choices) { + return null; + } + menu.addItem(' ', null); + for (key in choices) { + if (Object.prototype.hasOwnProperty.call(choices, key)) { + if (key[0] === '~') { + menu.addLine(); + // } else if (key.indexOf('§_def') === 0) { + // menu.addItem(choices[key].blockInstance(), choices[key]); + } else { + menu.addItem(key, choices[key]); + } + } + } + if (menu.items.length > 0) { + menu.popUpAtHand(this.world()); + } else { + return null; + } +}; + + + // TextSlotMorph ////////////////////////////////////////////////////// /* From 9d26d58a9e8d959508532af36625b5d8de4fa93f Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Mon, 27 Apr 2015 16:17:42 -0700 Subject: [PATCH 3/7] I'm an idiot Forgot to have correct init arguments --- blocks.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/blocks.js b/blocks.js index 2ff0d984..945e0b3d 100644 --- a/blocks.js +++ b/blocks.js @@ -7728,7 +7728,7 @@ PianoMenuMorph.uber = MenuMorph.prototype; // PianoMenuMorph instance creation: function PianoMenuMorph(target, title, environment, fontSize) { - this.init(target); + this.init(target, title, environment, fontSize); } PianoMenuMorph.prototype.init = function(target, title, environment, fontSize) { @@ -7752,6 +7752,82 @@ PianoMenuMorph.prototype.init = function(target, title, environment, fontSize) { this.edge = null; }; +PianoMenuMorph.prototype.drawNew = function () { + var myself = this, + item, + fb, + x, + y, + isLine = false; + + this.children.forEach(function (m) { + m.destroy(); + }); + this.children = []; + if (!this.isListContents) { + this.edge = MorphicPreferences.isFlat ? 0 : 5; + this.border = MorphicPreferences.isFlat ? 1 : 2; + } + this.color = new Color(255, 255, 255); + this.borderColor = new Color(60, 60, 60); + this.silentSetExtent(new Point(0, 0)); + + y = 2; + x = this.left() + 4; + if (!this.isListContents) { + if (this.title) { + this.createLabel(); + this.label.setPosition(this.bounds.origin.add(4)); + this.add(this.label); + y = this.label.bottom(); + } else { + y = this.top() + 4; + } + } + y += 1; + this.items.forEach(function (tuple) { + isLine = false; + if (tuple instanceof StringFieldMorph || + tuple instanceof ColorPickerMorph || + tuple instanceof SliderMorph) { + item = tuple; + } else if (tuple[0] === 0) { + isLine = true; + item = new Morph(); + item.color = myself.borderColor; + item.setHeight(tuple[1]); + } else { + item = new MenuItemMorph( + myself.target, + tuple[1], + tuple[0], + myself.fontSize || MorphicPreferences.menuFontSize, + MorphicPreferences.menuFontName, + myself.environment, + tuple[2], // bubble help hint + tuple[3], // color + tuple[4], // bold + tuple[5], // italic + tuple[6] // doubleclick action + ); + } + if (isLine) { + y += 1; + } + item.setPosition(new Point(x, y)); + myself.add(item); + y = y + item.height(); + if (isLine) { + y += 1; + } + }); + + fb = this.fullBounds(); + this.silentSetExtent(fb.extent().add(4)); + this.adjustWidths(); + MenuMorph.uber.drawNew.call(this); +}; + // NoteInputMorph ////////////////////////////////////////////////////// /* I am an inputslotmorph designed for selecting midi notes. From fbe4d4f9bacb6eb9d9e851b873269b5fc308db4d Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Mon, 27 Apr 2015 18:29:37 -0700 Subject: [PATCH 4/7] Initial key prototype done A key now appears next to items in the piano menu morph --- blocks.js | 66 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/blocks.js b/blocks.js index 945e0b3d..4d50233f 100644 --- a/blocks.js +++ b/blocks.js @@ -7731,27 +7731,6 @@ function PianoMenuMorph(target, title, environment, fontSize) { this.init(target, title, environment, fontSize); } -PianoMenuMorph.prototype.init = function(target, title, environment, fontSize) { - this.target = target; - this.title = title || null; - this.environment = environment || null; - this.fontSize = fontSize || null; - this.items = []; - this.label = null; - this.world = null; - this.isListContents = false; - - // initialize inherited properties: - MenuMorph.uber.init.call(this); - - // override inherited properties: - this.isDraggable = false; - - // immutable properties: - this.border = null; - this.edge = null; -}; - PianoMenuMorph.prototype.drawNew = function () { var myself = this, item, @@ -7797,7 +7776,7 @@ PianoMenuMorph.prototype.drawNew = function () { item.color = myself.borderColor; item.setHeight(tuple[1]); } else { - item = new MenuItemMorph( + item = new KeyItemMorph( myself.target, tuple[1], tuple[0], @@ -7865,10 +7844,6 @@ NoteInputMorph.prototype.init = function() { this.isUnevaluated = false; this.choices = { 'C (60)' : 60, - 'C# (61)' : 61, - 'D (62)' : 62, - 'D# (63)' : 63, - 'A (69)' : 69 }; // object, function or selector this.oldContentsExtent = contents.extent(); this.isNumeric = true; @@ -7904,7 +7879,6 @@ NoteInputMorph.prototype.dropDownMenu = function () { if (!choices) { return null; } - menu.addItem(' ', null); for (key in choices) { if (Object.prototype.hasOwnProperty.call(choices, key)) { if (key[0] === '~') { @@ -7923,6 +7897,44 @@ NoteInputMorph.prototype.dropDownMenu = function () { } }; +// KeyItemMorph /////////////////////////////////////////////////////// + +KeyItemMorph.prototype = new MenuItemMorph(); +KeyItemMorph.prototype.constructor = KeyItemMorph; +KeyItemMorph.uber = MenuItemMorph.prototype; + +function KeyItemMorph( + target, + action, + labelString, // can also be a Morph or a Canvas or a tuple: [icon, string] + fontSize, + fontStyle, + environment, + hint, + color, + bold, + italic, + doubleClickAction // optional when used as list morph item +) { + key = new BoxMorph(1, 2); + key.setColor(new Color(255, 255, 255)); + this.init( + target, + action, + [key, labelString], + fontSize, + fontStyle, + environment, + hint, + color, + bold, + italic, + doubleClickAction + ); +} + + + // TextSlotMorph ////////////////////////////////////////////////////// From 092999ab06db51b4e8c64b0bd8dcc076f8b786d9 Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Fri, 15 May 2015 16:51:39 -0700 Subject: [PATCH 5/7] Implementation done Finished implementing the piano morph, now to clean up the code and make it pretty. --- blocks.js | 124 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 97 insertions(+), 27 deletions(-) diff --git a/blocks.js b/blocks.js index 4d50233f..23c0bed7 100644 --- a/blocks.js +++ b/blocks.js @@ -7764,22 +7764,31 @@ PianoMenuMorph.prototype.drawNew = function () { } } y += 1; + label = new StringMorph(' '); this.items.forEach(function (tuple) { + blackkey = tuple[0][1] != " "; isLine = false; - if (tuple instanceof StringFieldMorph || - tuple instanceof ColorPickerMorph || - tuple instanceof SliderMorph) { - item = tuple; - } else if (tuple[0] === 0) { - isLine = true; - item = new Morph(); - item.color = myself.borderColor; - item.setHeight(tuple[1]); + key = new BoxMorph(1, 2); + if (blackkey) { + keycolor = new Color(0, 0, 0); + keywidth = 9; + keyheight = 25; + keyposition = new Point(x - 18, y); + newx = x; } else { - item = new KeyItemMorph( + keycolor = new Color(255, 255, 255); + keywidth = 15; + keyheight = 40; + keyposition = new Point(x, y); + newx = x + keywidth - 1; + } + key.setColor(keycolor); + key.setWidth(keywidth); + key.setHeight(keyheight); + item = new KeyItemMorph( myself.target, tuple[1], - tuple[0], + [key, tuple[0]], myself.fontSize || MorphicPreferences.menuFontSize, MorphicPreferences.menuFontName, myself.environment, @@ -7787,26 +7796,34 @@ PianoMenuMorph.prototype.drawNew = function () { tuple[3], // color tuple[4], // bold tuple[5], // italic - tuple[6] // doubleclick action + tuple[6], // doubleclick action + label // String to change ); - } if (isLine) { y += 1; } - item.setPosition(new Point(x, y)); + item.setPosition(keyposition); myself.add(item); - y = y + item.height(); + x = newx; if (isLine) { y += 1; } }); - + label.setPosition(new Point(35, 45)); + this.add(label); fb = this.fullBounds(); this.silentSetExtent(fb.extent().add(4)); this.adjustWidths(); MenuMorph.uber.drawNew.call(this); }; +PianoMenuMorph.prototype.popUpAtHand = function (world) { + var wrrld = world || this.world; + this.drawNew(); + this.popup(wrrld, wrrld.hand.position().subtract(new Point(this.extent().x/2, 0))); +}; + + // NoteInputMorph ////////////////////////////////////////////////////// /* I am an inputslotmorph designed for selecting midi notes. @@ -7844,6 +7861,17 @@ NoteInputMorph.prototype.init = function() { this.isUnevaluated = false; this.choices = { 'C (60)' : 60, + 'D (62)' : 62, + 'C# (61)' : 61, + 'E (64)' : 64, + 'Eb (63)' : 63, + 'F (65)' : 65, + 'G (67)' : 67, + 'F# (66)' : 66, + 'A (69)' : 69, + 'G# (68)' : 68, + 'B (71)' : 71, + 'Bb (70)' : 70 }; // object, function or selector this.oldContentsExtent = contents.extent(); this.isNumeric = true; @@ -7871,14 +7899,14 @@ NoteInputMorph.prototype.dropDownMenu = function () { this.fontSize ); - if (choices instanceof Function) { - choices = choices.call(this); - } else if (isString(choices)) { - choices = this[choices](); - } - if (!choices) { - return null; - } + // if (choices instanceof Function) { + // choices = choices.call(this); + // } else if (isString(choices)) { + // choices = this[choices](); + // } + // if (!choices) { + // return null; + // } for (key in choices) { if (Object.prototype.hasOwnProperty.call(choices, key)) { if (key[0] === '~') { @@ -7914,10 +7942,9 @@ function KeyItemMorph( color, bold, italic, - doubleClickAction // optional when used as list morph item + doubleClickAction, // optional when used as list morph item + label ) { - key = new BoxMorph(1, 2); - key.setColor(new Color(255, 255, 255)); this.init( target, action, @@ -7931,9 +7958,52 @@ function KeyItemMorph( italic, doubleClickAction ); + this.feedback = label; } +KeyItemMorph.prototype.createLabel = function () { + var icon, lbl, np; + if (this.label !== null) { + this.label.destroy(); + } + if (isString(this.labelString)) { + this.label = this.createLabelString(this.labelString); + } else if (this.labelString instanceof Array) { + // assume its pattern is: [icon, string] + this.label = new Morph(); + this.label.alpha = 0; // transparent + icon = this.createIcon(this.labelString[0]); + this.label.add(icon); + // lbl = this.createLabelString(this.labelString[1]); + // this.label.add(lbl); + // lbl.setCenter(icon.center()); + // lbl.setLeft(icon.right() + 4); + // this.label.bounds = (icon.bounds.merge(lbl.bounds)); + this.label.drawNew(); + } else { // assume it's either a Morph or a Canvas + this.label = this.createIcon(this.labelString); + } + this.silentSetExtent(icon.extent()); + //this.silentSetExtent(this.label.extent().add(new Point(4, 0))); + np = this.position().add(new Point(0, 0)); + this.label.bounds = np.extent(this.label.extent()); + this.label.silentSetExtent(new Point(0, 0)); + this.add(this.label); +}; +KeyItemMorph.prototype.mouseEnter = function () { + this.feedback.text = this.labelString[1][1]; + this.feedback.changed(); + this.feedback.drawNew(); + this.feedback.changed(); + if (!this.isListItem()) { + this.image = this.highlightImage; + this.changed(); + } + if (this.hint) { + this.bubbleHelp(this.hint); + } +}; From fc0b88ceb3cdfbf5a4d07bea37863526afa17a70 Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Mon, 18 May 2015 14:55:03 -0700 Subject: [PATCH 6/7] Cleaned up Code has been cleaned up/trimmed down and passes JSLInt --- blocks.js | 201 ++++++++++++++++++------------------------------------ 1 file changed, 68 insertions(+), 133 deletions(-) diff --git a/blocks.js b/blocks.js index 2d369a8f..956b877a 100644 --- a/blocks.js +++ b/blocks.js @@ -183,6 +183,9 @@ var SymbolMorph; var CommentMorph; var ArgLabelMorph; var TextSlotMorph; +var NoteInputMorph; +var PianoMenuMorph; +var KeyItemMorph; WorldMorph.prototype.customMorphs = function () { // add examples to the world's demo menu @@ -7746,7 +7749,13 @@ PianoMenuMorph.prototype.drawNew = function () { fb, x, y, - isLine = false; + label, + blackkey, + key, + keycolor, + keywidth, + keyheight, + keyposition; this.children.forEach(function (m) { m.destroy(); @@ -7760,63 +7769,43 @@ PianoMenuMorph.prototype.drawNew = function () { this.borderColor = new Color(60, 60, 60); this.silentSetExtent(new Point(0, 0)); - y = 2; x = this.left() + 4; - if (!this.isListContents) { - if (this.title) { - this.createLabel(); - this.label.setPosition(this.bounds.origin.add(4)); - this.add(this.label); - y = this.label.bottom(); - } else { - y = this.top() + 4; - } - } - y += 1; - label = new StringMorph(' '); + y = this.top() + 5; + label = new StringMorph(''); this.items.forEach(function (tuple) { - blackkey = tuple[0][1] != " "; - isLine = false; + blackkey = tuple[0][1] !== " "; key = new BoxMorph(1, 2); if (blackkey) { keycolor = new Color(0, 0, 0); keywidth = 9; keyheight = 25; - keyposition = new Point(x - 18, y); - newx = x; + keyposition = new Point(x - 17, y); } else { keycolor = new Color(255, 255, 255); keywidth = 15; keyheight = 40; - keyposition = new Point(x, y); - newx = x + keywidth - 1; - } + keyposition = new Point(x + 1, y); + x = x + keywidth - 1; + } key.setColor(keycolor); key.setWidth(keywidth); key.setHeight(keyheight); item = new KeyItemMorph( - myself.target, - tuple[1], - [key, tuple[0]], - myself.fontSize || MorphicPreferences.menuFontSize, - MorphicPreferences.menuFontName, - myself.environment, - tuple[2], // bubble help hint - tuple[3], // color - tuple[4], // bold - tuple[5], // italic - tuple[6], // doubleclick action - label // String to change - ); - if (isLine) { - y += 1; - } + myself.target, + tuple[1], + [key, tuple[0]], + myself.fontSize || MorphicPreferences.menuFontSize, + MorphicPreferences.menuFontName, + myself.environment, + tuple[2], // bubble help hint + tuple[3], // color + tuple[4], // bold + tuple[5], // italic + tuple[6], // doubleclick action + label // String to change + ); item.setPosition(keyposition); myself.add(item); - x = newx; - if (isLine) { - y += 1; - } }); label.setPosition(new Point(35, 45)); this.add(label); @@ -7829,7 +7818,8 @@ PianoMenuMorph.prototype.drawNew = function () { PianoMenuMorph.prototype.popUpAtHand = function (world) { var wrrld = world || this.world; this.drawNew(); - this.popup(wrrld, wrrld.hand.position().subtract(new Point(this.extent().x/2, 0))); + this.popup(wrrld, + wrrld.hand.position().subtract(new Point(this.extent().x / 2, 0))); }; @@ -7855,47 +7845,23 @@ function NoteInputMorph() { this.init(); } -NoteInputMorph.prototype.init = function() { - var contents = new StringMorph(''), - arrow = new ArrowMorph( - 'down', - 0, - Math.max(Math.floor(this.fontSize / 6), 1) - ); - - contents.fontSize = this.fontSize; - contents.isShowingBlanks = true; - contents.drawNew(); - - this.isUnevaluated = false; +NoteInputMorph.prototype.init = function () { + NoteInputMorph.uber.init.call(this); this.choices = { - 'C (60)' : 60, - 'D (62)' : 62, - 'C# (61)' : 61, - 'E (64)' : 64, - 'Eb (63)' : 63, - 'F (65)' : 65, - 'G (67)' : 67, - 'F# (66)' : 66, - 'A (69)' : 69, - 'G# (68)' : 68, - 'B (71)' : 71, - 'Bb (70)' : 70 - }; // object, function or selector - this.oldContentsExtent = contents.extent(); + 'C (60)' : 60, + 'D (62)' : 62, + 'C# (61)' : 61, + 'E (64)' : 64, + 'Eb (63)' : 63, + 'F (65)' : 65, + 'G (67)' : 67, + 'F# (66)' : 66, + 'A (69)' : 69, + 'G# (68)' : 68, + 'B (71)' : 71, + 'Bb (70)' : 70 + }; this.isNumeric = true; - this.isReadOnly = false; - this.minWidth = 0; // can be chaged for text-type inputs ("landscape") - this.constant = null; - - InputSlotMorph.uber.init.call(this); - this.color = new Color(255, 255, 255); - this.add(contents); - this.add(arrow); - contents.isEditable = true; - contents.isDraggable = false; - contents.enableSelecting(); - this.setContents(null); }; NoteInputMorph.prototype.dropDownMenu = function () { @@ -7907,31 +7873,12 @@ NoteInputMorph.prototype.dropDownMenu = function () { this, this.fontSize ); - - // if (choices instanceof Function) { - // choices = choices.call(this); - // } else if (isString(choices)) { - // choices = this[choices](); - // } - // if (!choices) { - // return null; - // } for (key in choices) { if (Object.prototype.hasOwnProperty.call(choices, key)) { - if (key[0] === '~') { - menu.addLine(); - // } else if (key.indexOf('§_def') === 0) { - // menu.addItem(choices[key].blockInstance(), choices[key]); - } else { - menu.addItem(key, choices[key]); - } + menu.addItem(key, choices[key]); } } - if (menu.items.length > 0) { - menu.popUpAtHand(this.world()); - } else { - return null; - } + menu.popUpAtHand(this.world()); }; // KeyItemMorph /////////////////////////////////////////////////////// @@ -7957,7 +7904,7 @@ function KeyItemMorph( this.init( target, action, - [key, labelString], + labelString, fontSize, fontStyle, environment, @@ -7965,53 +7912,41 @@ function KeyItemMorph( color, bold, italic, - doubleClickAction + doubleClickAction, + label ); this.feedback = label; } KeyItemMorph.prototype.createLabel = function () { - var icon, lbl, np; + var icon; if (this.label !== null) { this.label.destroy(); } - if (isString(this.labelString)) { - this.label = this.createLabelString(this.labelString); - } else if (this.labelString instanceof Array) { - // assume its pattern is: [icon, string] - this.label = new Morph(); - this.label.alpha = 0; // transparent - icon = this.createIcon(this.labelString[0]); - this.label.add(icon); - // lbl = this.createLabelString(this.labelString[1]); - // this.label.add(lbl); - // lbl.setCenter(icon.center()); - // lbl.setLeft(icon.right() + 4); - // this.label.bounds = (icon.bounds.merge(lbl.bounds)); - this.label.drawNew(); - } else { // assume it's either a Morph or a Canvas - this.label = this.createIcon(this.labelString); - } + // assume its pattern is: [icon, string] + this.label = new Morph(); + this.label.alpha = 0; // transparent + icon = this.createIcon(this.labelString[0]); + this.label.add(icon); + this.label.drawNew(); this.silentSetExtent(icon.extent()); - //this.silentSetExtent(this.label.extent().add(new Point(4, 0))); - np = this.position().add(new Point(0, 0)); - this.label.bounds = np.extent(this.label.extent()); + this.label.bounds = this.position().extent(this.label.extent()); this.label.silentSetExtent(new Point(0, 0)); this.add(this.label); }; KeyItemMorph.prototype.mouseEnter = function () { - this.feedback.text = this.labelString[1][1]; + this.feedback.text = this.labelString[1]; this.feedback.changed(); this.feedback.drawNew(); this.feedback.changed(); - if (!this.isListItem()) { - this.image = this.highlightImage; - this.changed(); - } - if (this.hint) { - this.bubbleHelp(this.hint); - } + // if (!this.isListItem()) { + // this.image = this.highlightImage; + // this.changed(); + // } + // if (this.hint) { + // this.bubbleHelp(this.hint); + // } }; From 9a6a3a3801463e5211fea9c31bf4f993340198ac Mon Sep 17 00:00:00 2001 From: Lucas Karahadian Date: Thu, 2 Jul 2015 19:03:43 -0700 Subject: [PATCH 7/7] Second octave Added a second octave for good measure --- blocks.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/blocks.js b/blocks.js index 29f1808d..aee06b8c 100644 --- a/blocks.js +++ b/blocks.js @@ -7816,7 +7816,7 @@ PianoMenuMorph.prototype.drawNew = function () { item.setPosition(keyposition); myself.add(item); }); - label.setPosition(new Point(35, 45)); + label.setPosition(new Point(90, 45)); this.add(label); fb = this.fullBounds(); this.silentSetExtent(fb.extent().add(4)); @@ -7857,6 +7857,18 @@ function NoteInputMorph() { NoteInputMorph.prototype.init = function () { NoteInputMorph.uber.init.call(this); this.choices = { + 'C (48)' : 48, + 'D (50)' : 50, + 'C# (49)' : 49, + 'E (52)' : 52, + 'Eb (51)' : 51, + 'F (53)' : 53, + 'G (55)' : 55, + 'F# (54)' : 54, + 'A (57)' : 57, + 'G# (56)' : 56, + 'B (59)' : 59, + 'Bb (58)' : 58, 'C (60)' : 60, 'D (62)' : 62, 'C# (61)' : 61, @@ -7868,7 +7880,8 @@ NoteInputMorph.prototype.init = function () { 'A (69)' : 69, 'G# (68)' : 68, 'B (71)' : 71, - 'Bb (70)' : 70 + 'Bb (70)' : 70, + 'C (72)' : 72 }; this.isNumeric = true; };