forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRhythmBlockPaletteBlocks.js
724 lines (647 loc) · 27.4 KB
/
RhythmBlockPaletteBlocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
// Copyright (c) 2019 Bottersnike
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
/*
global
_, last, FlowBlock, NOINPUTERRORMSG, TONEBPM, Singer,
FlowClampBlock, DEFAULTDRUM, _THIS_IS_MUSIC_BLOCKS_,
_THIS_IS_TURTLE_BLOCKS_
*/
/* exported setupRhythmBlockPaletteBlocks */
const language = localStorage.languagePreference || navigator.language;
let rhythmBlockPalette = language === "ja" ? "rhythm" : "widgets";
if (_THIS_IS_TURTLE_BLOCKS_) {
rhythmBlockPalette = "rhythm";
}
function setupRhythmBlockPaletteBlocks(activity) {
class RhythmBlock extends FlowBlock {
constructor(name) {
super(name || "rhythm");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.formBlock({
name:
this.lang === "ja"
? //.TRANS: rhythm block
_("rhythm1")
: //.TRANS: an arrangement of notes based on duration
_("rhythm"),
args: 2,
defaults: [3, 4],
argLabels: [_("number of notes"), _("note value")],
argTypes: ["anyin", "anyin"]
});
this.hidden = this.deprecated = true;
}
flow(args, logo, turtle, blk) {
let noteBeatValue, arg0, arg1;
if (args[0] === null || typeof args[0] !== "number" || args[0] < 1) {
activity.errorMsg(NOINPUTERRORMSG, blk);
arg0 = 3;
} else {
arg0 = args[0];
}
if (args[1] === null || typeof args[1] !== "number" || args[1] <= 0) {
activity.errorMsg(NOINPUTERRORMSG, blk);
arg1 = 1 / 4;
} else {
arg1 = args[1];
}
if (activity.blocks.blockList[blk].name === "rhythm2") {
noteBeatValue = 1 / arg1;
} else {
noteBeatValue = arg1;
}
if (logo.inMatrix || logo.tuplet) {
if (logo.inMatrix) {
logo.phraseMaker.addColBlock(blk, arg0);
}
for (let i = 0; i < args[0]; i++) {
Singer.processNote(activity, noteBeatValue, false, blk, turtle);
}
} else if (logo.inRhythmRuler) {
// We don't check for balance since we want to support
// polyphonic rhythms.
if (logo.rhythmRulerMeasure === null) {
logo.rhythmRulerMeasure = arg0 * arg1;
} else if (logo.rhythmRulerMeasure != arg0 * arg1) {
activity.textMsg(_("polyphonic rhythm"));
}
// Since there maybe more than one instance of the
// same drum, e.g., if a repeat is used, we look from
// end of the list instead of the beginning of the
// list.
let drumIndex = -1;
for (let i = 0; i < logo.rhythmRuler.Drums.length; i++) {
const j = logo.rhythmRuler.Drums.length - i - 1;
if (logo.rhythmRuler.Drums[j] === logo._currentDrumBlock) {
drumIndex = j;
break;
}
}
if (drumIndex !== -1) {
for (let i = 0; i < arg0; i++) {
logo.rhythmRuler.Rulers[drumIndex][0].push(noteBeatValue);
}
}
} else {
const tur = activity.turtles.ithTurtle(turtle);
if (tur.singer.drumStyle.length > 0) {
// Play rhythm block as if it were a drum
logo.clearNoteParams(tur, blk, tur.singer.drumStyle);
tur.singer.inNoteBlock.push(blk);
} else {
// Or use the current synth.
logo.clearNoteParams(tur, blk, []);
tur.singer.inNoteBlock.push(blk);
tur.singer.notePitches[last(tur.singer.inNoteBlock)] = ["G"];
tur.singer.noteOctaves[last(tur.singer.inNoteBlock)] = [4];
tur.singer.noteCents[last(tur.singer.inNoteBlock)] = [0];
}
const bpmFactor =
TONEBPM / tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM;
const beatValue = bpmFactor / noteBeatValue;
const __rhythmPlayNote = function (thisBeat, blk, turtle, callback, timeout) {
setTimeout(
() => Singer.processNote(activity, thisBeat, false, blk, turtle, callback),
timeout
);
};
let __callback;
for (let i = 0; i < arg0; i++) {
if (i === arg0 - 1) {
__callback = function () {
delete tur.singer.noteDrums[blk];
tur.singer.inNoteBlock.splice(tur.singer.inNoteBlock.indexOf(blk), 1);
};
} else {
__callback = null;
}
__rhythmPlayNote(noteBeatValue, blk, turtle, __callback, i * beatValue * 1000);
}
tur.doWait((arg0 - 1) * beatValue);
}
}
}
class Rhythm2Block extends RhythmBlock {
constructor() {
super("rhythm2");
this.setPalette(rhythmBlockPalette, activity);
this.beginnerBlock(true);
this.piemenuValuesC1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
this.setHelpString([
_("The Rhythm block is used to generate rhythm patterns."),
"documentation",
null,
"rhythm2"
]);
this.extraWidth = 10;
this.formBlock({
name:
this.lang === "ja"
? //.TRANS: translate "rhythm1" as rhythm
_("rhythm1")
: _("rhythm"),
args: 2,
defaults: [3, 4],
argLabels: [_("number of notes"), _("note value")],
argTypes: ["anyin", "anyin"]
});
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 3 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 4 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class SixtyFourthNoteBlock extends FlowBlock {
constructor() {
super("sixtyfourthNote", _("1/64 note") + " 𝅘𝅥𝅱");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 64 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class ThirtySecondNoteBlock extends FlowBlock {
constructor() {
super("thirtysecondNote", _("1/32 note") + " 𝅘𝅥𝅰");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 32 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class SixteenthNoteBlock extends FlowBlock {
constructor() {
super("sixteenthNote", _("1/16 note") + " 𝅘𝅥𝅯");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 16 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class EighthNoteBlock extends FlowBlock {
constructor() {
super("eighthNote", _("eighth note") + " ♪");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 8 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class QuarterNoteBlock extends FlowBlock {
constructor() {
super("quarterNote", _("quarter note") + " ♩");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 4 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class HalfNoteBlock extends FlowBlock {
constructor() {
super("halfNote", _("half note") + " 𝅗𝅥");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 2 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class WholeNoteBlock extends FlowBlock {
constructor() {
super("wholeNote", _("whole note") + " 𝅝");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "rhythm2", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 1 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class Tuplet2Block extends FlowClampBlock {
constructor(name) {
super(name || "tuplet2");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.formBlock({
//.TRANS: A tuplet is a note value divided into irregular time values.
name: _("tuplet"),
args: 2,
defaults: [1, 4],
argLabels: [_("number of notes"), _("note value")]
});
this.hidden = true;
}
flow(args, logo, turtle, blk) {
if (logo.inMatrix) {
if (activity.blocks.blockList[blk].name === "tuplet3") {
logo.tupletParams.push([
args[0],
(1 / args[1]) * activity.turtles.ithTurtle(turtle).singer.beatFactor
]);
} else {
logo.tupletParams.push([
args[0],
args[1] * activity.turtles.ithTurtle(turtle).singer.beatFactor
]);
}
logo.tuplet = true;
logo.addingNotesToTuplet = false;
}
const listenerName = "_tuplet_" + turtle;
logo.setDispatchBlock(blk, turtle, listenerName);
// eslint-disable-next-line no-unused-vars
const __listener = function (event) {
if (logo.inMatrix) {
logo.tuplet = false;
logo.addingNotesToTuplet = false;
}
};
logo.setTurtleListener(turtle, listenerName, __listener);
return [args[2], 1];
}
}
class Tuplet3Block extends Tuplet2Block {
constructor() {
super("tuplet3");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.formBlock({
name: _("tuplet"),
args: 2,
defaults: [1, 4],
argLabels: [_("number of notes"), _("note value")]
});
this.makeMacro((x, y) => [
[0, "tuplet3", x, y, [null, 1, 10, 9, 7]],
[1, ["number", { value: 1 }], 0, 0, [0]],
[2, "rhythm2", 0, 0, [9, 3, 4, 8]],
[3, ["number", { value: 3 }], 0, 0, [2]],
[4, "divide", 0, 0, [2, 5, 6]],
[5, ["number", { value: 1 }], 0, 0, [4]],
[6, ["number", { value: 4 }], 0, 0, [4]],
[7, "hidden", 0, 0, [0, null]],
[8, "vspace", 0, 0, [2, null]],
[9, "vspace", 0, 0, [0, 2]],
[10, "divide", 0, 0, [0, 11, 12]],
[11, ["number", { value: 1 }], 0, 0, [10]],
[12, ["number", { value: 4 }], 0, 0, [10]]
]);
this.hidden = true;
}
}
class Tuplet4Block extends FlowClampBlock {
constructor() {
super("tuplet4");
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString([
_("The Tuplet block is used to generate a group of notes played in a condensed amount of time."),
"documentation",
null,
"tuplet4"
]);
this.extraWidth = 30;
this.formBlock({
name: _("tuplet"),
args: 1,
defaults: [1 / 4],
argLabels: [_("note value")]
});
this.makeMacro((x, y) => [
[0, "tuplet4", x, y, [null, 1, 4, 17]],
[1, "divide", 0, 0, [0, 2, 3]],
[2, ["number", { value: 1 }], 0, 0, [1]],
[3, ["number", { value: 2 }], 0, 0, [1]],
[4, "vspace", 0, 0, [0, 5]],
[5, "rhythm2", 0, 0, [4, 6, 7, 10]],
[6, ["number", { value: 6 }], 0, 0, [5]],
[7, "divide", 0, 0, [5, 8, 9]],
[8, ["number", { value: 1 }], 0, 0, [7]],
[9, ["number", { value: 16 }], 0, 0, [7]],
[10, "vspace", 0, 0, [5, 11]],
[11, "rhythm2", 0, 0, [10, 12, 13, 16]],
[12, ["number", { value: 1 }], 0, 0, [11]],
[13, "divide", 0, 0, [11, 14, 15]],
[14, ["number", { value: 1 }], 0, 0, [13]],
[15, ["number", { value: 4 }], 0, 0, [13]],
[16, "vspace", 0, 0, [11, null]],
[17, "hidden", 0, 0, [0, 18]],
[18, "hidden", 0, 0, [17, null]]
]);
}
flow(args, logo, turtle, blk) {
if (args[1] === undefined) {
// nothing to do
return;
}
let arg;
if (args[0] === null || typeof args[0] !== "number" || args[0] <= 0) {
activity.errorMsg(NOINPUTERRORMSG, blk);
arg = 1 / 2;
} else {
arg = args[0];
}
if (!logo.inMatrix) {
logo.tupletRhythms = [];
logo.tupletParams = [];
}
logo.tuplet = true;
logo.addingNotesToTuplet = false;
logo.tupletParams.push([
1,
(1 / arg) * activity.turtles.ithTurtle(turtle).singer.beatFactor
]);
const listenerName = "_tuplet_" + turtle;
logo.setDispatchBlock(blk, turtle, listenerName);
// eslint-disable-next-line no-unused-vars
const __listener = (event) => {
const tur = activity.turtles.ithTurtle(turtle);
logo.tuplet = false;
logo.addingNotesToTuplet = false;
if (!logo.inMatrix) {
const beatValues = [];
for (let i = 0; i < logo.tupletRhythms.length; i++) {
const tupletParam = [logo.tupletParams[logo.tupletRhythms[i][1]]];
tupletParam.push([]);
let tupletBeats = 0;
for (let j = 2; j < logo.tupletRhythms[i].length; j++) {
tupletBeats += 1 / logo.tupletRhythms[i][j];
tupletParam[1].push(logo.tupletRhythms[i][j]);
}
const factor = tupletParam[0][0] / (tupletParam[0][1] * tupletBeats);
for (let j = 2; j < logo.tupletRhythms[i].length; j++) {
beatValues.push(logo.tupletRhythms[i][j] / factor);
}
}
// Play rhythm block as if it were a drum.
if (tur.singer.drumStyle.length > 0) {
logo.clearNoteParams(tur, blk, tur.singer.drumStyle);
} else {
logo.clearNoteParams(tur, blk, [DEFAULTDRUM]);
}
tur.singer.inNoteBlock.push(blk);
const bpmFactor =
TONEBPM / tur.singer.bpm.length > 0
? last(tur.singer.bpm)
: Singer.masterBPM;
let totalBeats = 0;
const __tupletPlayNote = function (thisBeat, blk, turtle, callback, timeout) {
setTimeout(
() =>
Singer.processNote(
activity,
thisBeat,
false,
blk,
turtle,
callback
),
timeout
);
};
let timeout = 0;
let beatValue;
let __callback = null;
for (let i = 0; i < beatValues.length; i++) {
const thisBeat = beatValues[i];
beatValue = bpmFactor / thisBeat;
if (i === beatValues.length - 1) {
__callback = () => {
delete tur.singer.noteDrums[blk];
tur.singer.inNoteBlock.splice(
tur.singer.inNoteBlock.indexOf(blk),
1
);
};
} else {
__callback = null;
}
__tupletPlayNote(thisBeat, blk, turtle, __callback, timeout);
timeout += beatValue * 1000;
totalBeats += beatValue;
}
tur.doWait(totalBeats - beatValue);
}
};
logo.setTurtleListener(turtle, listenerName, __listener);
return [args[1], 1];
}
}
class SeptupletBlock extends FlowBlock {
constructor() {
//.TRANS: A tuplet divided into 7 time values.
super("stuplet7", _("septuplet"));
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "stuplet", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 7 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 2 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class QuintupletBlock extends FlowBlock {
constructor() {
//.TRANS: A tuplet divided into 5 time values.
super("stuplet5", _("quintuplet"));
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "stuplet", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 5 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 2 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class TripletBlock extends FlowBlock {
constructor() {
//.TRANS: A tuplet divided into 3 time values.
super("stuplet3", _("triplet"));
this.setPalette(rhythmBlockPalette, activity);
this.setHelpString();
this.makeMacro((x, y) => [
[0, "stuplet", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 3 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 2 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
}
class STupletBlock extends FlowBlock {
constructor() {
super("stuplet", _("simple tuplet"));
this.setPalette(rhythmBlockPalette, activity);
this.piemenuValuesC1 = [3, 5, 7, 11];
this.beginnerBlock(_THIS_IS_MUSIC_BLOCKS_);
this.setHelpString([
_("Tuplets are a collection of notes that get scaled to a specific duration.") +
" " +
_("Using tuplets makes it easy to create groups of notes that are not based on a power of 2."),
"documentation",
null,
"matrix"
]);
this.formBlock({
args: 2,
defaults: [3, 1 / 2],
argLabels: [_("number of notes"), _("note value")]
});
this.makeMacro((x, y) => [
[0, "stuplet", x, y, [null, 1, 2, 5]],
[1, ["number", { value: 3 }], 0, 0, [0]],
[2, "divide", 0, 0, [0, 3, 4]],
[3, ["number", { value: 1 }], 0, 0, [2]],
[4, ["number", { value: 2 }], 0, 0, [2]],
[5, "vspace", 0, 0, [0, null]]
]);
}
flow(args, logo, turtle, blk) {
let arg0, arg1;
if (args[0] === null || typeof args[0] !== "number" || args[0] <= 0) {
activity.errorMsg(NOINPUTERRORMSG, blk);
arg0 = 3;
} else {
arg0 = args[0];
}
if (args[1] === null || typeof args[1] !== "number" || args[1] <= 0) {
activity.errorMsg(NOINPUTERRORMSG, blk);
arg1 = 1 / 2;
} else {
arg1 = args[1];
}
const noteBeatValue = (1 / arg1) * activity.turtles.ithTurtle(turtle).singer.beatFactor;
if (logo.inMatrix || logo.tuplet) {
logo.phraseMaker.addColBlock(blk, arg0);
if (logo.tuplet) {
// The simple-tuplet block is inside.
for (let i = 0; i < arg0; i++) {
if (!logo.addingNotesToTuplet) {
logo.tupletRhythms.push(["notes", 0]);
logo.addingNotesToTuplet = true;
}
Singer.processNote(activity, noteBeatValue, false, blk, turtle);
}
} else {
logo.tupletParams.push([1, noteBeatValue]);
const obj = ["simple", 0];
for (let i = 0; i < arg0; i++) {
obj.push((1 / arg1) * activity.turtles.ithTurtle(turtle).singer.beatFactor);
}
logo.tupletRhythms.push(obj);
}
} else {
const tur = activity.turtles.ithTurtle(turtle);
// Play rhythm block as if it were a drum
if (tur.singer.drumStyle.length > 0) {
logo.clearNoteParams(tur, blk, tur.singer.drumStyle);
} else {
logo.clearNoteParams(tur, blk, [DEFAULTDRUM]);
}
tur.singer.inNoteBlock.push(blk);
const bpmFactor =
TONEBPM / tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM;
const beatValue = bpmFactor / noteBeatValue / arg0;
const __rhythmPlayNote = function (thisBeat, blk, turtle, callback, timeout) {
setTimeout(
() => Singer.processNote(activity, thisBeat, false, blk, turtle, callback),
timeout
);
};
let __callback = null;
for (let i = 0; i < arg0; i++) {
if (i === arg0 - 1) {
__callback = function () {
delete tur.singer.noteDrums[blk];
tur.singer.inNoteBlock.splice(tur.singer.inNoteBlock.indexOf(blk), 1);
};
} else {
__callback = null;
}
__rhythmPlayNote(
noteBeatValue * arg0,
blk,
turtle,
__callback,
i * beatValue * 1000
);
}
tur.doWait((arg0 - 1) * beatValue);
}
}
}
new RhythmBlock().setup(activity);
new Rhythm2Block().setup(activity);
new SixtyFourthNoteBlock().setup(activity);
new ThirtySecondNoteBlock().setup(activity);
new SixteenthNoteBlock().setup(activity);
new EighthNoteBlock().setup(activity);
new QuarterNoteBlock().setup(activity);
new HalfNoteBlock().setup(activity);
new WholeNoteBlock().setup(activity);
new Tuplet2Block().setup(activity);
new Tuplet3Block().setup(activity);
new Tuplet4Block().setup(activity);
new SeptupletBlock().setup(activity);
new QuintupletBlock().setup(activity);
new TripletBlock().setup(activity);
new STupletBlock().setup(activity);
}