Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Set Key - Multiple custom modes #2829

Merged
merged 5 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
],
"no-undef": "error",
"no-redeclare": [2, {"builtinGlobals": false}],
"indent": ["warn", 4, { "SwitchCase": 1 }],
"quotes": ["warn", "double", { "avoidEscape": true }],
"semi": "error",
Expand Down
108 changes: 107 additions & 1 deletion documentation/definemode_block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 71 additions & 37 deletions js/blocks/IntervalsBlocks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
global last, _, ValueBlock, FlowClampBlock, FlowBlock, NOINPUTERRORMSG, LeftBlock, Singer,
beginnerMode, blocks
*/

/*
Global locations
- js/utils/utils.js
_, last
- js/protoblocks.js
ValueBlock, FlowClampBlock, LeftBlock, FlowBlock
- js/logo.js
NOINPUTERRORMSG
- js/turtle-singer.js
Singer
- js/activity.js
beginnerMode, blocks
*/

/*exported setupIntervalsBlocks*/

function setupIntervalsBlocks() {
class SetTemperamentBlock extends FlowBlock {
constructor() {
Expand Down Expand Up @@ -25,7 +46,7 @@ function setupIntervalsBlocks() {
]);
}

flow(args, logo) {
flow(args) {
Singer.IntervalsActions.setTemperament(args[0], args[1], args[2]);
}
}
Expand All @@ -35,9 +56,7 @@ function setupIntervalsBlocks() {
super("temperamentname");
this.setPalette("tone");
this.setHelpString([
_(
"The Temperament name block is used to select a tuning method."
),
_("The Temperament name block is used to select a tuning method."),
"documentation",
""
]);
Expand Down Expand Up @@ -84,14 +103,15 @@ function setupIntervalsBlocks() {
return 0;
} else {
let currentblock = cblk;
while (true) {
let condition = true;
while (condition) {
const blockToCheck = logo.blocks.blockList[currentblock];
if (blockToCheck.name === "intervalname") {
// Augmented or diminished only
if (blockToCheck.value[0] === "a") {
return (logo.parseArg(logo, turtle, cblk, blk, receivedArg) + 1);
return logo.parseArg(logo, turtle, cblk, blk, receivedArg) + 1;
} else if (blockToCheck.value[0] === "d") {
return (logo.parseArg(logo, turtle, cblk, blk, receivedArg) - 1);
return logo.parseArg(logo, turtle, cblk, blk, receivedArg) - 1;
} else {
return logo.parseArg(logo, turtle, cblk, blk, receivedArg);
}
Expand All @@ -107,8 +127,10 @@ function setupIntervalsBlocks() {
}

currentblock = logo.blocks.blockList[currentblock].connections[1];
if (currentblock === null)
if (currentblock === null) {
condition = false;
return 0;
}
}
}
}
Expand Down Expand Up @@ -182,6 +204,7 @@ function setupIntervalsBlocks() {

const actionArgs = [];
const saveNoteCount = tur.singer.notesPlayed;
const saveTurtleDicts = JSON.stringify(logo.turtleDicts[turtle]);
let distance = 0;
tur.running = true;
logo.runFromBlockNow(logo, turtle, cblk, true, actionArgs, tur.queue.length);
Expand Down Expand Up @@ -286,7 +309,10 @@ function setupIntervalsBlocks() {

if (tur.singer.firstPitch.length > 0 && tur.singer.lastPitch.length > 0) {
distance = Singer.scalarDistance(
logo, turtle, last(tur.singer.firstPitch), last(tur.singer.lastPitch)
logo,
turtle,
last(tur.singer.firstPitch),
last(tur.singer.lastPitch)
);
tur.singer.firstPitch.pop();
tur.singer.lastPitch.pop();
Expand Down Expand Up @@ -333,18 +359,8 @@ function setupIntervalsBlocks() {
this.setHelpString();
this.makeMacro((x, y) => [
[0, "semitoneinterval", x, y, [null, 1, 6, 7]],
...[
isDown
? [1, "minus", 0, 0, [0, 8, 3]]
: [1, "plus", 0, 0, [0, 2, 3]]
],
[
2,
["intervalname", { value: type + " " + value }],
0,
0,
[1]
],
...[isDown ? [1, "minus", 0, 0, [0, 8, 3]] : [1, "plus", 0, 0, [0, 2, 3]]],
[2, ["intervalname", { value: type + " " + value }], 0, 0, [1]],
[3, "multiply", 0, 0, [1, 4, 5]],
[4, ["number", { value: 0 }], 0, 0, [3]],
[5, ["number", { value: 12 }], 0, 0, [3]],
Expand Down Expand Up @@ -392,8 +408,33 @@ function setupIntervalsBlocks() {
constructor() {
super("semitoneinterval");
this.setPalette("intervals");
this.piemenuValuesC1 = [-12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
this.piemenuValuesC1 = [
-12,
-11,
-10,
-9,
-8,
-7,
-6,
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
];
this.setHelpString([
_(
"The Semi-tone interval block calculates a relative interval based on half steps."
Expand Down Expand Up @@ -422,8 +463,7 @@ function setupIntervalsBlocks() {
}

flow(args, logo, turtle, blk) {
if (args[1] === undefined)
return;
if (args[1] === undefined) return;

Singer.IntervalsActions.setSemitoneInterval(args[0], turtle, blk);

Expand Down Expand Up @@ -549,9 +589,8 @@ function setupIntervalsBlocks() {
]);
}

flow(args, logo, turtle, blk, receivedArg, actionArgs, isflow) {
if (args[1] === undefined)
return;
flow(args, logo, turtle, blk) {
if (args[1] === undefined) return;

Singer.IntervalsActions.setScalarInterval(args[0], turtle, blk);

Expand Down Expand Up @@ -580,7 +619,7 @@ function setupIntervalsBlocks() {
});
this.makeMacro((x, y) => [
[0, "definemode", x, y, [null, 1, 2, 16]],
[1, ["modename", { value: "custom" }], 0, 0, [0]],
[1, ["text", { value: "custom" }], 0, 0, [0]],
[2, "pitchnumber", 0, 0, [0, 3, 4]],
[3, ["number", { value: 0 }], 0, 0, [2]],
[4, "pitchnumber", 0, 0, [2, 5, 6]],
Expand All @@ -600,8 +639,7 @@ function setupIntervalsBlocks() {
}

flow(args, logo, turtle, blk) {
if (args[1] === undefined)
return;
if (args[1] === undefined) return;

Singer.IntervalsActions.defineMode(args[0], turtle, blk);

Expand Down Expand Up @@ -652,9 +690,7 @@ function setupIntervalsBlocks() {
this.beginnerBlock(true);
this.parameter = true;
this.setHelpString([
_(
"The Mode length block is the number of notes in the current scale."
) +
_("The Mode length block is the number of notes in the current scale.") +
" " +
_("Most Western scales have 7 notes."),
"documentation",
Expand Down Expand Up @@ -766,9 +802,7 @@ function setupIntervalsBlocks() {
]);
} else {
this.setHelpString([
_("The Set key block is used to set the key and mode,") +
" " +
_("eg C Major"),
_("The Set key block is used to set the key and mode,") + " " + _("eg C Major"),
"documentation",
null,
"movablehelp"
Expand Down
Loading