Skip to content

Commit

Permalink
Merge branch 'meganindya-music-state-rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbender committed Jul 27, 2020
2 parents fbc7efc + a6d50b6 commit 2c9f9e7
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 448 deletions.
150 changes: 67 additions & 83 deletions js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4795,13 +4795,10 @@ function Block(protoblock, blocks, overrideName) {
* @private
*/
let __pitchPreview = function() {
let label =
that._pitchWheel.navItems[that._pitchWheel.selectedNavItemIndex]
.title;
let label = that._pitchWheel.navItems[that._pitchWheel.selectedNavItemIndex].title;
let i = noteLabels.indexOf(label);

// Are we wrapping across C? We need to compare with the
// previous pitch.
// Are we wrapping across C? We need to compare with the previous pitch
if (prevPitch === null) {
prevPitch = i;
}
Expand Down Expand Up @@ -4886,15 +4883,17 @@ function Block(protoblock, blocks, overrideName) {
obj[0] = obj[0].replace(SHARP, "#").replace(FLAT, "b");
}

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -5240,15 +5239,17 @@ function Block(protoblock, blocks, overrideName) {
label
);

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -5516,15 +5517,17 @@ function Block(protoblock, blocks, overrideName) {
note = nthDegreeToPitch("C major", 7 + noteValues[i]);
}

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -6189,22 +6192,21 @@ function Block(protoblock, blocks, overrideName) {
};

let __pitchPreviewForNum = function() {
let label =
that._numberWheel.navItems[
that._numberWheel.selectedNavItemIndex
].title;
let label = that._numberWheel.navItems[that._numberWheel.selectedNavItemIndex].title;
let i = wheelLabels.indexOf(label);
let actualPitch = numberToPitch(wheelValues[i] + 3);

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -6235,22 +6237,21 @@ function Block(protoblock, blocks, overrideName) {
};

let __hertzPreview = function() {
let label =
that._numberWheel.navItems[
that._numberWheel.selectedNavItemIndex
].title;
let label = that._numberWheel.navItems[that._numberWheel.selectedNavItemIndex].title;
let i = wheelLabels.indexOf(label);
let actualPitch = frequencyToPitch(wheelValues[i]);

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -6839,22 +6840,22 @@ function Block(protoblock, blocks, overrideName) {
* @private
*/
let __voicePreview = function() {
let label =
that._voiceWheel.navItems[that._voiceWheel.selectedNavItemIndex]
.title;
let label = that._voiceWheel.navItems[that._voiceWheel.selectedNavItemIndex].title;
let i = voiceLabels.indexOf(label);
let voice = voiceValues[i];
let timeout = 0;

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(voice) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(voice) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(voice);
tur.singer.instrumentNames.push(voice);
if (voice === DEFAULTVOICE) {
that.blocks.logo.synth.createDefaultSynth(0);
}
Expand Down Expand Up @@ -7127,16 +7128,11 @@ function Block(protoblock, blocks, overrideName) {
let label =
that._intervalNameWheel.navItems[
that._intervalNameWheel.selectedNavItemIndex
].title;
].title;
let number =
that._intervalWheel.navItems[
that._intervalWheel.selectedNavItemIndex
].title;
that._intervalWheel.navItems[that._intervalWheel.selectedNavItemIndex].title;

that.value =
INTERVALS[that._intervalNameWheel.selectedNavItemIndex][1] +
" " +
number;
that.value = INTERVALS[that._intervalNameWheel.selectedNavItemIndex][1] + " " + number;
if (label === "perfect 1") {
that.text.text = _("unison");
} else {
Expand All @@ -7147,26 +7143,20 @@ function Block(protoblock, blocks, overrideName) {
that.container.setChildIndex(that.text, that.container.children.length - 1);
that.updateCache();

let obj = getNote(
"C",
4,
INTERVALVALUES[that.value][0],
"C major",
false,
null,
null
);
let obj = getNote("C", 4, INTERVALVALUES[that.value][0], "C major", false, null, null);
obj[0] = obj[0].replace(SHARP, "#").replace(FLAT, "b");

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down Expand Up @@ -7504,27 +7494,21 @@ function Block(protoblock, blocks, overrideName) {
}

let i = that._modeWheel.selectedNavItemIndex;
// The mode doesn't matter here, since we are using semi-tones.
let obj = getNote(
key,
4,
i + o,
key + " chromatic",
false,
null,
null
);
// The mode doesn't matter here, since we are using semi-tones
let obj = getNote(key, 4, i + o, key + " chromatic", false, null, null);
obj[0] = obj[0].replace(SHARP, "#").replace(FLAT, "b");

let tur = that.blocks.logo.turtles.ithTurtle(0);

if (
that.blocks.logo.instrumentNames[0] === undefined ||
that.blocks.logo.instrumentNames[0].indexOf(DEFAULTVOICE) === -1
tur.singer.instrumentNames === undefined ||
tur.singer.instrumentNames.indexOf(DEFAULTVOICE) === -1
) {
if (that.blocks.logo.instrumentNames[0] === undefined) {
that.blocks.logo.instrumentNames[0] = [];
if (tur.singer.instrumentNames === undefined) {
tur.singer.instrumentNames = [];
}

that.blocks.logo.instrumentNames[0].push(DEFAULTVOICE);
tur.singer.instrumentNames.push(DEFAULTVOICE);
that.blocks.logo.synth.createDefaultSynth(0);
that.blocks.logo.synth.loadSynth(0, DEFAULTVOICE);
}
Expand Down
4 changes: 2 additions & 2 deletions js/blocks/DrumBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function setupDrumBlocks() {
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(noisename);
if (tur.singer.synthVolume[noisename] === undefined) {
tur.singer.synthVolume[noisename] = [DEFAULTVOLUME];
logo.crescendoInitialVolume[turtle][noisename] = [DEFAULTVOLUME];
tur.singer.crescendoInitialVolume[noisename] = [DEFAULTVOLUME];
}
} else {
logo.errorMsg(_("Noise Block: Did you mean to use a Note block?"), blk);
Expand Down Expand Up @@ -387,7 +387,7 @@ function setupDrumBlocks() {
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname);
if (tur.singer.synthVolume[drumname] === undefined) {
tur.singer.synthVolume[drumname] = [DEFAULTVOLUME];
logo.crescendoInitialVolume[turtle][drumname] = [DEFAULTVOLUME];
tur.singer.crescendoInitialVolume[drumname] = [DEFAULTVOLUME];
}
} else if (
logo.blocks.blockList[blk].connections[0] == null &&
Expand Down
13 changes: 7 additions & 6 deletions js/blocks/FlowBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function setupFlowBlocks() {
} else {
let tur = logo.turtles.ithTurtle(turtle);

logo.duplicateFactor[turtle] *= factor;
tur.singer.duplicateFactor *= factor;

// Queue each block in the clamp.
let listenerName = "_duplicate_" + turtle;
Expand All @@ -120,11 +120,11 @@ function setupFlowBlocks() {
return null;
};

logo.inDuplicate[turtle] = true;
tur.singer.inDuplicate = true;

let __listener = function(event) {
logo.inDuplicate[turtle] = false;
logo.duplicateFactor[turtle] /= factor;
let __listener = event => {
tur.singer.inDuplicate = false;
tur.singer.duplicateFactor /= factor;

// Check for a race condition.
// FIXME: Do something about the race condition.
Expand Down Expand Up @@ -824,7 +824,8 @@ function setupFlowBlocks() {
) {
logo.statusFields.push([blk, "duplicate"]);
} else {
logo.blocks.blockList[blk].value = logo.duplicateFactor[turtle];
logo.blocks.blockList[blk].value =
logo.turtles.ithTurtle(turtle).singer.duplicateFactor;
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions js/blocks/IntervalsBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,13 @@ function setupIntervalsBlocks() {

let i = arg > 0 ? Math.floor(arg) : Math.ceil(arg);
if (i !== 0) {
logo.semitoneIntervals[turtle].push([i, tur.singer.noteDirection]);
tur.singer.semitoneIntervals.push([i, tur.singer.noteDirection]);
tur.singer.noteDirection = 0;

let listenerName = "_semitone_interval_" + turtle;
logo.setDispatchBlock(blk, turtle, listenerName);

let __listener = function() {
logo.semitoneIntervals[turtle].pop();
};
let __listener = () => tur.singer.semitoneIntervals.pop();

logo.setTurtleListener(turtle, listenerName, __listener);
}
Expand Down Expand Up @@ -609,10 +607,8 @@ function setupIntervalsBlocks() {
}

flow(args, logo, turtle, blk, receivedArg, actionArgs, isflow) {
if (args[1] === undefined) {
// Nothing to do.
if (args[1] === undefined)
return;
}

let arg;
if (args[0] === null || typeof args[0] !== "number") {
Expand All @@ -622,15 +618,15 @@ function setupIntervalsBlocks() {
arg = args[0];
}

let tur = logo.turtles.ithTurtle(turtle);

let i = arg > 0 ? Math.floor(arg) : Math.ceil(arg);
logo.intervals[turtle].push(i);
tur.singer.intervals.push(i);

let listenerName = "_interval_" + turtle;
logo.setDispatchBlock(blk, turtle, listenerName);

let __listener = function(event) {
logo.intervals[turtle].pop();
};
let __listener = event => tur.singer.intervals.pop();

logo.setTurtleListener(turtle, listenerName, __listener);

Expand Down
Loading

0 comments on commit 2c9f9e7

Please sign in to comment.