Skip to content

Commit

Permalink
Merge pull request sugarlabs#2408 from meganindya/music-state-rework
Browse files Browse the repository at this point in the history
Port music state variables
  • Loading branch information
meganindya authored Jul 14, 2020
2 parents 78e09fc + 222a277 commit 43f73b9
Show file tree
Hide file tree
Showing 25 changed files with 1,171 additions and 1,592 deletions.
8 changes: 1 addition & 7 deletions js/blocks/BoxesBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ function setupBoxesBlocks() {

updateParameter(logo, turtle, blk) {
let cblk = logo.blocks.blockList[blk].connections[1];
let boxname = logo.parseArg(
that,
turtle,
cblk,
blk,
logo.receivedArg
);
let boxname = logo.parseArg(that, turtle, cblk, blk, logo.receivedArg);
if (boxname in logo.boxes) {
return logo.boxes[boxname];
} else {
Expand Down
40 changes: 15 additions & 25 deletions js/blocks/DrumBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ function setupDrumBlocks() {
}
}

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

if (logo.inNoteBlock[turtle].length > 0) {
// Add the noise sound as if it were a drum
logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push(
noisename
);
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(noisename);
if (logo.synthVolume[turtle][noisename] === undefined) {
logo.synthVolume[turtle][noisename] = [DEFAULTVOLUME];
logo.crescendoInitialVolume[turtle][noisename] = [
Expand All @@ -111,9 +111,9 @@ function setupDrumBlocks() {
}

if (logo.inNoteBlock[turtle].length > 0) {
logo.noteBeatValues[turtle][
last(logo.inNoteBlock[turtle])
].push(logo.beatFactor[turtle]);
tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push(
tur.singer.beatFactor
);
}

logo.pushedNote[turtle] = true;
Expand Down Expand Up @@ -365,6 +365,8 @@ function setupDrumBlocks() {
}
}

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

// If we are in a setdrum clamp, override the drum name.
if (logo.drumStyle[turtle].length > 0) {
drumname = last(logo.drumStyle[turtle]);
Expand All @@ -385,9 +387,7 @@ function setupDrumBlocks() {
logo.drumBlocks.push(blk);
}
} else if (logo.inNoteBlock[turtle].length > 0) {
logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push(
drumname
);
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname);
if (logo.synthVolume[turtle][drumname] === undefined) {
logo.synthVolume[turtle][drumname] = [DEFAULTVOLUME];
logo.crescendoInitialVolume[turtle][drumname] = [
Expand All @@ -399,19 +399,9 @@ function setupDrumBlocks() {
last(logo.blocks.blockList[blk].connections) == null
) {
// Play a stand-alone drum block as a quarter note.
logo.clearNoteParams(turtle, blk, []);
logo.clearNoteParams(tur, blk, []);
logo.inNoteBlock[turtle].push(blk);
logo.noteDrums[turtle][last(logo.inNoteBlock[turtle])].push(
drumname
);

// let bpmFactor;
// if (logo.bpm[turtle].length > 0) {
// bpmFactor = TONEBPM / last(logo.bpm[turtle]);
// } else {
// bpmFactor = TONEBPM / logo._masterBPM;
// }
// let beatValue = bpmFactor / noteBeatValue;
tur.singer.noteDrums[last(logo.inNoteBlock[turtle])].push(drumname);

let noteBeatValue = 4;

Expand All @@ -426,14 +416,14 @@ function setupDrumBlocks() {
// _("Drum Block: Did you mean to use a Note block?"),
// blk
// );
console.debug('PLAY DRUM ERROR: missing context');
console.debug('PLAY DRUM ERROR: missing context');
return;
}

if (logo.inNoteBlock[turtle].length > 0) {
logo.noteBeatValues[turtle][
last(logo.inNoteBlock[turtle])
].push(logo.beatFactor[turtle]);
tur.singer.noteBeatValues[last(logo.inNoteBlock[turtle])].push(
tur.singer.beatFactor
);
}

logo.pushedNote[turtle] = true;
Expand Down
94 changes: 40 additions & 54 deletions js/blocks/EnsembleBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,19 @@ function setupEnsembleBlocks() {
});
}

/**
* @todo FIXME
*/
arg(logo, turtle, blk, receivedArg) {
let thisTurtle = _blockFindTurtle(logo, turtle, blk, receivedArg);

if (thisTurtle)
return logo.notesPlayed[i][0] / logo.notesPlayed[i][1];
if (thisTurtle) {
let tur = logo.turtles.ithTurtle(thisTurtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1];
}

return logo.notesPlayed[turtle][0] / logo.notesPlayed[turtle][1];
let tur = logo.turtles.ithTurtle(turtle);
return tur.singer.notesPlayed[0] / tur.singer.notesPlayed[1];
}
}

Expand All @@ -485,32 +491,27 @@ function setupEnsembleBlocks() {
arg(logo, turtle, blk, receivedArg) {
let value = null;
let cblk = logo.blocks.blockList[blk].connections[1];
let targetTurtle = logo.parseArg(
logo,
turtle,
cblk,
blk,
receivedArg
);
let targetTurtle = logo.parseArg(logo, turtle, cblk, blk, receivedArg);

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

for (let i = 0; i < logo.turtles.turtleList.length; i++) {
let thisTurtle = logo.turtles.turtleList[i];
if (targetTurtle === thisTurtle.name) {
let obj;
if (logo.lastNotePlayed[i] !== null) {
let len = logo.lastNotePlayed[i][0].length;
let pitch = logo.lastNotePlayed[i][0].slice(0, len - 1);
let octave = parseInt(
logo.lastNotePlayed[i][0].slice(len - 1)
);
if (thisTurtle.singer.lastNotePlayed !== null) {
let len = thisTurtle.singer.lastNotePlayed[0].length;
let pitch = thisTurtle.singer.lastNotePlayed[0].slice(0, len - 1);
let octave = parseInt(thisTurtle.singer.lastNotePlayed[0].slice(len - 1));

obj = [pitch, octave];
} else if (logo.notePitches[i].length > 0) {
} else if (thisTurtle.singer.notePitches.length > 0) {
obj = getNote(
logo.notePitches[i][0],
logo.noteOctaves[i][0],
thisTurtle.singer.notePitches[0],
thisTurtle.singer.noteOctaves[0],
0,
logo.keySignature[i],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand All @@ -523,7 +524,7 @@ function setupEnsembleBlocks() {

value =
pitchToNumber(obj[0], obj[1], logo.keySignature[i]) -
logo.pitchNumberOffset[turtle];
tur.singer.pitchNumberOffset;
logo.blocks.blockList[blk].value = value;
break;
}
Expand All @@ -543,27 +544,18 @@ function setupEnsembleBlocks() {
}

let obj;
if (logo.lastNotePlayed[turtle] !== null) {
let len = logo.lastNotePlayed[turtle][0].length;
let pitch = logo.lastNotePlayed[turtle][0].slice(
0,
len - 1
);
let octave = parseInt(
logo.lastNotePlayed[turtle][0].slice(len - 1)
);
if (tur.singer.lastNotePlayed !== null) {
let len = tur.singer.lastNotePlayed[0].length;
let pitch = tur.singer.lastNotePlayed[0].slice(0, len - 1);
let octave = parseInt(tur.singer.lastNotePlayed[0].slice(len - 1));
obj = [pitch, octave];
} else if (logo.notePitches[turtle].length > 0) {
} else if (tur.singer.notePitches.length > 0) {
obj = getNote(
logo.notePitches[turtle][
last(logo.inNoteBlock[turtle])
][0],
logo.noteOctaves[turtle][
last(logo.inNoteBlock[turtle])
][0],
tur.singer.notePitches[last(logo.inNoteBlock[turtle])][0],
tur.singer.noteOctaves[last(logo.inNoteBlock[turtle])][0],
0,
logo.keySignature[turtle],
logo.moveable[turtle],
tur.singer.moveable,
null,
logo.errorMsg,
logo.synth.inTemperament
Expand All @@ -576,7 +568,7 @@ function setupEnsembleBlocks() {

value =
pitchToNumber(obj[0], obj[1], logo.keySignature[turtle]) -
logo.pitchNumberOffset[turtle];
tur.singer.pitchNumberOffset;
logo.blocks.blockList[blk].value = value;
}
}
Expand All @@ -599,26 +591,20 @@ function setupEnsembleBlocks() {
arg(logo, turtle, blk, receivedArg) {
let value = null;
let cblk = logo.blocks.blockList[blk].connections[1];
let targetTurtle = logo.parseArg(
logo,
turtle,
cblk,
blk,
receivedArg
);
let targetTurtle = logo.parseArg(logo, turtle, cblk, blk, receivedArg);

for (let i = 0; i < logo.turtles.turtleList.length; i++) {
let thisTurtle = logo.turtles.turtleList[i];
let thisTurtle = logo.turtles.ithTurtle(i);
if (targetTurtle === thisTurtle.name) {
if (
logo.inNoteBlock[i].length > 0 &&
last(logo.inNoteBlock[i]) in logo.noteValue[i]
last(logo.inNoteBlock[i]) in thisTurtle.singer.noteValue
) {
value =
1 / logo.noteValue[i][last(logo.inNoteBlock[i])];
} else if (logo.lastNotePlayed[i] !== null) {
value = logo.lastNotePlayed[i][1];
} else if (logo.notePitches[i].length > 0) {
value = logo.noteBeat[i][last(logo.inNoteBlock[i])];
value = 1 / thisTurtle.singer.noteValue[last(logo.inNoteBlock[i])];
} else if (thisTurtle.singer.lastNotePlayed !== null) {
value = thisTurtle.singer.lastNotePlayed[1];
} else if (thisTurtle.singer.notePitches.length > 0) {
value = thisTurtle.singer.noteBeat[last(logo.inNoteBlock[i])];
} else {
value = -1;
}
Expand Down
9 changes: 3 additions & 6 deletions js/blocks/ExtrasBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,9 @@ function setupExtrasBlocks() {

flow(args, logo, turtle) {
if (args.length === 1) {
let bpmFactor;
if (logo.bpm[turtle].length > 0) {
bpmFactor = TONEBPM / last(logo.bpm[turtle]);
} else {
bpmFactor = TONEBPM / logo._masterBPM;
}
let bpmFactor =
TONEBPM /
logo.bpm[turtle].length > 0 ? last(logo.bpm[turtle]) : Singer.masterBPM;

let noteBeatValue = bpmFactor / (1 / args[0]);
logo.previousTurtleTime[turtle] = logo.turtleTime[turtle];
Expand Down
Loading

0 comments on commit 43f73b9

Please sign in to comment.