Skip to content

Commit

Permalink
Merge branch 'BeatNoStart' of https://github.com/sksum/musicblocks in…
Browse files Browse the repository at this point in the history
…to sksum-BeatNoStart
  • Loading branch information
walterbender committed Jun 29, 2020
2 parents b671125 + abdc6be commit 2e1ddb8
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7027,8 +7027,18 @@ function Blocks(activity) {

if (turtle != null && turtleNotInTrash > 1) {
console.debug("putting turtle " + turtle + " in the trash");
this.turtles.turtleList[turtle].inTrash = true;
this.turtles.turtleList[turtle].container.visible = false;
let comp = this.turtles.turtleList[turtle].companionTurtle;
if (comp){
if (turtleNotInTrash > 2){
this.turtles.turtleList[comp].inTrash = true;
this.turtles.turtleList[comp].container.visible = false;
this.turtles.turtleList[turtle].inTrash = true;
this.turtles.turtleList[turtle].container.visible = false;
}
} else {
this.turtles.turtleList[turtle].inTrash = true;
this.turtles.turtleList[turtle].container.visible = false;
}
} else {
this.errorMsg(
_("You must always have at least one start block.")
Expand Down
105 changes: 105 additions & 0 deletions js/blocks/MeterBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,111 @@ function setupMeterBlocks() {
}
}
}
class EveryBeatDoBlockNew extends FlowBlock {
constructor() {
// .TRANS: on every note played, do some action
super("everybeatdonew", _("on every beat do"));
this.setPalette("meter");
this.beginnerBlock(true);

this.setHelpString([
_(
"The On-every-beat block let you specify actions to take on every beat."
),
"documentation",
null,
"everybeathelp"
]);


this.formBlock({
args: 1,
argTypes: ["textin"],
defaults: [_("action")]
});

this.makeMacro((x, y) => {
return [
[0, ["everybeatdonew",{}], x, y, [null, 1, null]],
[1, ["text", { "value": "action" }], 0, 0, [0]]
]
});
}

flow(args, logo, turtle, blk, receivedArg, actionArgs, isflow) {
// Set up a listener for every beat for this turtle.
let orgTurtle =turtle ;
console.debug("used from :",orgTurtle)
if (!turtles.turtleList[orgTurtle].companionTurtle){
turtle = logo.turtles.turtleList.length;
turtles.turtleList[orgTurtle].companionTurtle = turtle ;
logo.turtles.addTurtle(
logo.blocks.blockList[blk],
[]
);
console.debug("beat Turtle : ",turtle);
}
turtle = turtles.turtleList[orgTurtle].companionTurtle;

if (!(args[0] in logo.actions)) {
logo.errorMsg(NOACTIONERRORMSG, blk, args[1]);
} else {
let __listener = function(event) {
if (logo.turtles.turtleList[turtle].running) {
let queueBlock = new Queue(
logo.actions[args[0]],
1,
blk
);
logo.parentFlowQueue[turtle].push(blk);
logo.turtles.turtleList[turtle].queue.push(queueBlock);
} else {
// Since the turtle has stopped
// running, we need to run the stack
// from here.
if (isflow) {
logo._runFromBlockNow(
logo,
turtle,
logo.actions[args[0]],
isflow,
receivedArg
);
} else {
logo._runFromBlock(
logo,
turtle,
logo.actions[args[0]],
isflow,
receivedArg
);
}
}
};

let eventName = "__everybeat_" + turtle + "__";
logo.turtles.turtleList[turtle].queue = [];
logo.parentFlowQueue[turtle] = [];
logo.unhighlightQueue[turtle] = [];
logo.parameterQueue[turtle] = [];
logo.initTurtle(turtle);
logo._setListener(turtle, eventName, __listener);
let duration ;
if (logo.bpm[orgTurtle].length > 0) {
duration = 60 / last(logo.bpm[orgTurtle]);
} else {
duration = 60 / logo._masterBPM;
}
if (logo.turtles.turtleList[turtle].interval !== undefined)clearInterval(this.interval);
logo.turtles.turtleList[turtle].interval = setInterval(
() => {
logo.stage.dispatchEvent(eventName);
}
,duration*1000);
console.debug("set listener",eventName);
}
}
}
class EveryBeatDoBlock extends FlowBlock {
constructor() {
// .TRANS: on every note played, do some action
Expand Down Expand Up @@ -1080,6 +1184,7 @@ function setupMeterBlocks() {
new DriftBlock().setup();
new OffBeatDoBlock().setup();
new OnBeatDoBlock().setup();
new EveryBeatDoBlockNew().setup();
new EveryBeatDoBlock().setup();
new SetMasterBPM2Block().setup();
new SetMasterBPMBlock().setup();
Expand Down
12 changes: 12 additions & 0 deletions js/logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ class Logo {
for (let instrumentName in instruments[turtle]) {
this.synth.stopSound(turtle, instrumentName);
}
let comp = this.turtles.turtleList[turtle].companionTurtle;
if (comp){
this.turtles.turtleList[comp].running = false ;
let interval = logo.turtles.turtleList[comp].interval;
if (interval) clearInterval(interval);
}
}

this.synth.stop();
Expand Down Expand Up @@ -1875,6 +1881,12 @@ class Logo {
logo.turtles.turtleList[turtle].running = false;
}

let comp = logo.turtles.turtleList[turtle].companionTurtle;
if (comp){
logo.turtles.turtleList[comp].running = false ;
let interval = logo.turtles.turtleList[comp].interval;
if (interval) clearInterval(interval);
}
// Because flow can come from calc blocks, we are not
// ensured that the turtle is really finished running
// yet. Hence the timeout.
Expand Down

0 comments on commit 2e1ddb8

Please sign in to comment.