Skip to content

Commit

Permalink
integrated octave switching in piano keyboard widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoenig committed Jul 24, 2024
1 parent 72711df commit 370a359
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
* new "svg poly" export format for vector pen trails, optimized for speed and laser-cutting
* export vector pen trails as embroidery files (DST, EXP)
* added pen trails export options to the project ("file") menu
* added ability to switch octaves in the piano keyboard menu, thanks, ego-lay-atman-bay!
* **Notable Changes:**
1. Blocks all the way
* renamed "primitive" blocks into "extension"
Expand Down Expand Up @@ -123,6 +124,9 @@
* **Translation Updates:**
* German

### 2024-07-24
* widgets: added ability to switch octaves in the piano keyboard widget, thanks, ego-lay-atman-bay!

### 2024-07-22
* edited help screen for doDeleteBlock, converted to PNG, reduced file size
* v10-rc5
Expand Down
2 changes: 1 addition & 1 deletion snap.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<meta name="msapplication-TileColor" content="#FFFFFF">
<script src="src/morphic.js?version=2024-06-04"></script>
<script src="src/symbols.js?version=2024-01-24"></script>
<script src="src/widgets.js?version=2023-05-24"></script>
<script src="src/widgets.js?version=2024-07-24"></script>
<script src="src/blocks.js?version=2024-06-10"></script>
<script src="src/threads.js?version=2024-06-10"></script>
<script src="src/objects.js?version=2024-07-11"></script>
Expand Down
55 changes: 15 additions & 40 deletions src/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2023 by Jens Mönig
Copyright (C) 2024 by Jens Mönig
This file is part of Snap!.
Expand All @@ -33,6 +33,7 @@
credits
-------
Lucas Karahadian contributed a first prototype of the piano keyboard
ego-lay-atman-bay contributed the capability to switch octaves
I. hierarchy
Expand Down Expand Up @@ -87,7 +88,7 @@ ScrollFrameMorph, MenuItemMorph, useBlurredShadows, getDocumentPositionOf*/

/*jshint esversion: 6*/

modules.widgets = '2023-May-24';
modules.widgets = '2024-July-24';

var PushButtonMorph;
var ToggleButtonMorph;
Expand Down Expand Up @@ -3532,7 +3533,7 @@ PianoMenuMorph.prototype.init = function (
}
}
}
this.addItem('C', choices['C'] + (12 * this.visibleOctaves))
this.addItem('C', choices.C + (12 * this.visibleOctaves));
};

PianoMenuMorph.prototype.createItems = function () {
Expand Down Expand Up @@ -3603,19 +3604,19 @@ PianoMenuMorph.prototype.createItems = function () {
var downOctave = new ArrowMorph(
'left',
fontHeight(this.fontSize),
Math.max(Math.floor(this.fontSize / 6), 1),
Math.max(Math.floor(this.fontSize / 6), 1)
);
downOctave.setPosition(new Point(5, 3));
downOctave.mouseClickLeft = () => {this.octaveDown()};
downOctave.mouseClickLeft = () => this.octaveDown();
this.add(downOctave);

var upOctave = new ArrowMorph(
'right',
fontHeight(this.fontSize),
Math.max(Math.floor(this.fontSize / 6), 1),
Math.max(Math.floor(this.fontSize / 6), 1)
);
upOctave.setPosition(new Point(fb.width() - upOctave.width() - 2, 3));
upOctave.mouseClickLeft = () => {this.octaveUp()};
upOctave.mouseClickLeft = () => this.octaveUp();
this.add(upOctave);

fb = this.fullBounds();
Expand Down Expand Up @@ -3690,20 +3691,16 @@ PianoMenuMorph.prototype.processKeyDown = function (event) {
case 37: // 'left arrow'
case 40: // 'down arrow'
case 189: // -
if (event.shiftKey) {
return this.octaveDown();
} else {
return this.selectDown();
}
return event.shiftKey ?
this.octaveUp()
: this.octaveDown();
case 38: // 'up arrow'
case 39: // 'right arrow'
case 187: // +
case 220: // #
if (event.shiftKey) {
return this.octaveUp();
} else {
return this.selectUp();
}
return event.shiftKey ?
this.octaveDown()
: this.octaveUp();
default:
switch(event.key) {
case 'c':
Expand Down Expand Up @@ -3742,28 +3739,6 @@ PianoMenuMorph.prototype.processKeyDown = function (event) {
}
};

PianoMenuMorph.prototype.selectUp = function () {
var next = 1;
if (this.selection) {
next = this.selection.action + 1;
if (next > 143) {
next = 143;
}
}
this.selectKey(next);
};

PianoMenuMorph.prototype.selectDown = function () {
var next = 1;
if (this.selection) {
next = this.selection.action - 1;
if (next < 0) {
next = 0;
}
}
this.selectKey(next);
};

PianoMenuMorph.prototype.octaveUp = function () {
this.octave += this.visibleOctaves;
this.octave = Math.min(this.octave, 10 - (11) % this.visibleOctaves);
Expand All @@ -3780,7 +3755,7 @@ PianoMenuMorph.prototype.octaveDown = function () {
if (this.selection) {
this.selection.mouseEnter();
}
}
};

PianoMenuMorph.prototype.destroy = function () {
this.children.forEach(key => {
Expand Down

0 comments on commit 370a359

Please sign in to comment.