Skip to content

Commit c76b117

Browse files
authored
Add music blocks: play_drum, play_note, set_instrument (#272)
Adds implementations and documentation for the missing music extension blocks: - `play_drum drum, beats` — plays a drum for a number of beats - `play_note note, beats` — plays a note for a number of beats - `set_instrument instrument` — sets the instrument
2 parents a54f0e8 + 8e809ee commit c76b117

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

docs/language/blocks/music.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Music Blocks
22

3+
### play drum () for () beats
4+
5+
```goboscript
6+
play_drum drum, beats;
7+
```
8+
9+
```scratchblocks
10+
play drum (1 v) for (beats) beats
11+
```
12+
13+
### play note () for () beats
14+
15+
```goboscript
16+
play_note note, beats;
17+
```
18+
19+
```scratchblocks
20+
play note (note) for (beats) beats
21+
```
22+
23+
### set instrument to ()
24+
25+
```goboscript
26+
set_instrument instrument;
27+
```
28+
29+
```scratchblocks
30+
set instrument to (instrument)
31+
```
32+
333
### rest for () beats
434

535
```goboscript

gdsl.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ change_pen_saturation changePenColorParamBy VALUE |
149149
change_pen_brightness changePenColorParamBy VALUE | | COLOR_PARAM@colorParam:pen_menu_colorParam=brightness
150150
change_pen_transparency changePenColorParamBy VALUE | | COLOR_PARAM@colorParam:pen_menu_colorParam=transparency
151151
[music]==========================================================|==========================|
152+
play_drum playDrumForBeats DRUM,BEATS | | DRUM:music_menu_DRUM=1
153+
play_note playNoteForBeats NOTE,BEATS | |
154+
set_instrument setInstrument INSTRUMENT | | INSTRUMENT:music_menu_INSTRUMENT=1
152155
rest restForBeats BEATS | |
153156
set_tempo setTempo TEMPO | |
154157
change_tempo changeTempo ... | |

src/blocks.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ pub enum Block {
276276
ChangePenSaturation,
277277
ChangePenBrightness,
278278
ChangePenTransparency,
279+
PlayDrum1,
280+
PlayDrum2,
281+
PlayNote,
282+
SetInstrument,
279283
Rest,
280284
SetTempo,
281285
ChangeTempo,
@@ -434,6 +438,24 @@ impl Block {
434438
field: "colorParam",
435439
default: "transparency",
436440
}),
441+
Self::PlayDrum1 => Some(Menu {
442+
opcode: "music_menu_DRUM",
443+
input: "DRUM",
444+
field: "DRUM",
445+
default: "1",
446+
}),
447+
Self::PlayDrum2 => Some(Menu {
448+
opcode: "music_menu_DRUM",
449+
input: "DRUM",
450+
field: "DRUM",
451+
default: "1",
452+
}),
453+
Self::SetInstrument => Some(Menu {
454+
opcode: "music_menu_INSTRUMENT",
455+
input: "INSTRUMENT",
456+
field: "INSTRUMENT",
457+
default: "1",
458+
}),
437459
_ => None,
438460
}
439461
}
@@ -445,6 +467,7 @@ impl Block {
445467
"say" => &[Self::Say2, Self::Say1],
446468
"think" => &[Self::Think2, Self::Think1],
447469
"clone" => &[Self::Clone0, Self::Clone1],
470+
"play_drum" => &[Self::PlayDrum1, Self::PlayDrum2],
448471
_ => &[],
449472
}
450473
}
@@ -550,6 +573,11 @@ impl Block {
550573
("change_pen_saturation", _) => Some(Self::ChangePenSaturation),
551574
("change_pen_brightness", _) => Some(Self::ChangePenBrightness),
552575
("change_pen_transparency", _) => Some(Self::ChangePenTransparency),
576+
("play_drum", 1) => Some(Self::PlayDrum1),
577+
("play_drum", 2) => Some(Self::PlayDrum2),
578+
("play_drum", _) => Some(Self::PlayDrum1),
579+
("play_note", _) => Some(Self::PlayNote),
580+
("set_instrument", _) => Some(Self::SetInstrument),
553581
("rest", _) => Some(Self::Rest),
554582
("set_tempo", _) => Some(Self::SetTempo),
555583
("change_tempo", _) => Some(Self::ChangeTempo),
@@ -653,6 +681,10 @@ impl Block {
653681
Self::ChangePenSaturation => "change_pen_saturation",
654682
Self::ChangePenBrightness => "change_pen_brightness",
655683
Self::ChangePenTransparency => "change_pen_transparency",
684+
Self::PlayDrum1 => "play_drum",
685+
Self::PlayDrum2 => "play_drum",
686+
Self::PlayNote => "play_note",
687+
Self::SetInstrument => "set_instrument",
656688
Self::Rest => "rest",
657689
Self::SetTempo => "set_tempo",
658690
Self::ChangeTempo => "change_tempo",
@@ -750,6 +782,9 @@ impl Block {
750782
"change_pen_saturation",
751783
"change_pen_brightness",
752784
"change_pen_transparency",
785+
"play_drum",
786+
"play_note",
787+
"set_instrument",
753788
"rest",
754789
"set_tempo",
755790
"change_tempo",
@@ -852,6 +887,10 @@ impl Block {
852887
Self::ChangePenSaturation => "pen_changePenColorParamBy",
853888
Self::ChangePenBrightness => "pen_changePenColorParamBy",
854889
Self::ChangePenTransparency => "pen_changePenColorParamBy",
890+
Self::PlayDrum1 => "music_playDrumForBeats",
891+
Self::PlayDrum2 => "music_playDrumForBeats",
892+
Self::PlayNote => "music_playNoteForBeats",
893+
Self::SetInstrument => "music_setInstrument",
855894
Self::Rest => "music_restForBeats",
856895
Self::SetTempo => "music_setTempo",
857896
Self::ChangeTempo => "music_changeTempo",
@@ -954,6 +993,10 @@ impl Block {
954993
Self::ChangePenSaturation => &["VALUE"],
955994
Self::ChangePenBrightness => &["VALUE"],
956995
Self::ChangePenTransparency => &["VALUE"],
996+
Self::PlayDrum1 => &["BEATS"],
997+
Self::PlayDrum2 => &["DRUM", "BEATS"],
998+
Self::PlayNote => &["NOTE", "BEATS"],
999+
Self::SetInstrument => &["INSTRUMENT"],
9571000
Self::Rest => &["BEATS"],
9581001
Self::SetTempo => &["TEMPO"],
9591002
Self::ChangeTempo => &["TEMPO"],
@@ -1058,6 +1101,10 @@ impl Block {
10581101
Self::ChangePenSaturation => None,
10591102
Self::ChangePenBrightness => None,
10601103
Self::ChangePenTransparency => None,
1104+
Self::PlayDrum1 => None,
1105+
Self::PlayDrum2 => None,
1106+
Self::PlayNote => None,
1107+
Self::SetInstrument => None,
10611108
Self::Rest => None,
10621109
Self::SetTempo => None,
10631110
Self::ChangeTempo => None,
@@ -1145,8 +1192,10 @@ impl Repr {
11451192
}
11461193
}
11471194

1148-
pub fn overloads(_name: &str) -> &'static [Self] {
1149-
&[]
1195+
pub fn overloads(name: &str) -> &'static [Self] {
1196+
match name {
1197+
_ => &[],
1198+
}
11501199
}
11511200

11521201
pub fn from_shape(name: &str, args: usize) -> Option<Self> {

0 commit comments

Comments
 (0)