Skip to content

Commit

Permalink
Update v2 tutorials to use new playable music blocks (#5920)
Browse files Browse the repository at this point in the history
* update v2 tutorials to new sound api

* correct the sound name

* spell 'nyab' correctly

* change tone to playable in 'countdown'

* well it's actually 'nyan'
  • Loading branch information
ganicke authored and abchatra committed Sep 6, 2024
1 parent 558616c commit 345c576
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
8 changes: 4 additions & 4 deletions docs/projects/v2-cat-napping.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ input.onButtonPressed(Button.A, function () {

Let's now add an auditory indicator that your @boardname@ is logging data!

► From the ``||music:Music||`` category, grab a ``||music:play sound [giggle] [until done]||`` block and snap it into the **bottom** of the **top container** of your ``||logic:if then / else||`` statement.
► Click on the ``giggle`` dropdown and select ``hello``. Your block should now say ``||music:play sound [hello] [until done]||``.
► From the ``||music:Music||`` category, grab a ``||music:play sound [dadadum] [in background]||`` block and snap it into the **bottom** of the **top container** of your ``||logic:if then / else||`` statement.
► Click on the ``[dadadum]`` dropdown and select ``nyan``, then set the playback mode to ``||music:[until done]||``. Your block should now say ``||music:play melody [nyan] [until done]||``.

```blocks
let logging = false
input.onButtonPressed(Button.A, function () {
logging = !(logging)
if (logging) {
basic.showIcon(IconNames.Target)
music.playSoundEffect(music.builtinSoundEffect(soundExpression.hello), SoundExpressionPlayMode.UntilDone)
music.play(music.builtInPlayableMelody(Melodies.Nyan), music.PlaybackMode.UntilDone)
} else {
}
})
Expand All @@ -98,7 +98,7 @@ input.onButtonPressed(Button.A, function () {
logging = !(logging)
if (logging) {
basic.showIcon(IconNames.Target)
music.playSoundEffect(music.builtinSoundEffect(soundExpression.hello), SoundExpressionPlayMode.UntilDone)
music.play(music.builtInPlayableMelody(Melodies.Nyan), music.PlaybackMode.UntilDone)
} else {
basic.clearScreen()
}
Expand Down
20 changes: 10 additions & 10 deletions docs/projects/v2-countdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ for (let index = 0; index <= 2; index++) {

## {Play music}

► From ``||music:Music||``, grab ``||music:play tone [Middle C] for [1 beat]||`` and snap it into your empty ``for`` loop.
► From ``||music:Music||``, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and snap it into your empty ``for`` loop.
💡 Your simulator might start playing music. You can mute it if distracting.
► 1 beat is a little long. Use the **dropdown** to set the tone to play for ``||music:1/4 beat||``.

```blocks
for (let index = 0; index <= 2; index++) {
// @highlight
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
}
```

Expand All @@ -47,7 +47,7 @@ With every tone, we also want to **display** our countdown.

```blocks
for (let index = 0; index <= 2; index++) {
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
// @highlight
basic.showNumber(index)
}
Expand All @@ -66,7 +66,7 @@ If you take a look at your simulator, you'll notice the @boardname@ flashing 0-1

```blocks
for (let index = 0; index <= 2; index++) {
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
// @highlight
basic.showNumber(3 - index)
}
Expand All @@ -79,7 +79,7 @@ for (let index = 0; index <= 2; index++) {

```blocks
for (let index = 0; index <= 2; index++) {
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
basic.showNumber(3 - index)
}
// @highlight
Expand All @@ -88,18 +88,18 @@ basic.showString("GO!")

## {Adding a "GO!" noise}

► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat]||`` and place it **above** your ``||basic:show string ["GO!"]||`` block and **below** your ``||loops:for||`` loop.
► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and place it **above** your ``||basic:show string ["GO!"]||`` block and **below** your ``||loops:for||`` loop.
💡 This will let your @boardname@ play the sound and show ``GO!`` at the same time.
► Set the ``||music:tone||`` to be ``Middle G``.
💡 ``Middle G`` is also tone ``392``.

```blocks
for (let index = 0; index <= 2; index++) {
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
basic.showNumber(3 - index)
}
// @highlight
music.playTone(392, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
basic.showString("GO!")
```

Expand All @@ -111,10 +111,10 @@ If you have a @boardname@ with sound (the one with the **shiny gold** logo at th

```blocks
for (let index = 0; index <= 2; index++) {
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
basic.showNumber(3 - index)
}
music.playTone(392, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
basic.showString("GO!")
```

Expand Down
30 changes: 18 additions & 12 deletions docs/projects/v2-morse-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ radio.onReceivedNumber(function (receivedNumber) {

## {Playing a sound pt. 1}

► From the ``||music:Music||`` category, grab a ``||music:play tone [Middle C] for [1 beat]||`` block and snap it at the **end** of the **bottom container** in your ``||logic:if then / else||`` statement.
► From the ``||music:Music||`` category, grab a ``||music:play tone [Middle C] for [1 beat] [until done]||`` block and snap it at the **end** of the **bottom container** in your ``||logic:if then / else||`` statement.

```blocks
radio.onReceivedNumber(function (receivedNumber) {
Expand All @@ -121,7 +121,7 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
`)
// @highlight
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
})
```
Expand Down Expand Up @@ -150,14 +150,14 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
})
```

## {Playing a sound pt. 2}

► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat]||`` and snap it in at the **end** of the **top container** in your ``||logic:if then / else||`` statement.
► From the ``||music:Music||`` category, grab ``||music:play tone [Middle C] for [1 beat] [until done]||`` and snap it in at the **end** of the **top container** in your ``||logic:if then / else||`` statement.
► Dots are shorter than dashes! Set the tone to play for ``1/4 beat``.

```blocks
Expand All @@ -171,7 +171,7 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
`)
// @highlight
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
} else {
basic.showLeds(`
. . . . .
Expand All @@ -180,7 +180,7 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
})
```
Expand All @@ -199,7 +199,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
} else {
basic.showLeds(`
. . . . .
Expand All @@ -208,7 +209,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
// @highlight
basic.clearScreen()
Expand All @@ -232,7 +234,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
} else {
basic.showLeds(`
. . . . .
Expand All @@ -241,7 +244,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
basic.clearScreen()
})
Expand Down Expand Up @@ -270,7 +274,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Quarter))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone)
} else {
basic.showLeds(`
. . . . .
Expand All @@ -279,7 +284,8 @@ radio.onReceivedNumber(function (receivedNumber) {
. . . . .
. . . . .
`)
music.playTone(262, music.beat(BeatFraction.Whole))
music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone)
}
basic.clearScreen()
})
Expand Down
22 changes: 11 additions & 11 deletions docs/projects/v2-pet-hamster.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ input.onLogoEvent(TouchButtonEvent.Pressed, function () {

## {Tickle sound}

► From the ``||music:Music||`` category, get a ``||music:play sound [giggle] until done||`` and add it to the **bottom** of your ``||input:on logo [pressed]||`` container.
► From the ``||music:Music||`` category, get a ``||music:play melody [jump up] [in background]||`` and add it to the **bottom** of your ``||input:on logo [pressed]||`` container. Change the playback mode to ``||music:[until done]||``.

```blocks
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
basic.showIcon(IconNames.Happy)
//@highlight
soundExpression.giggle.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.JumpUp), music.PlaybackMode.UntilDone)
})
```

Expand All @@ -60,14 +60,14 @@ input.onGesture(Gesture.Shake, function () {

## {Dizzy sound}

► From the ``||music:Music||`` category, find the ``||music:play sound [giggle] until done||`` block and add it to the **bottom** of your ``||input:on [shake]||`` container.
► Click on the **dropdown** and set it so Cyrus plays a ``||music:sad||`` sound until done.
► From the ``||music:Music||`` category, find the ``||music:play melody [dadadum] [in background]||`` block and add it to the **bottom** of your ``||input:on [shake]||`` container. Change the playback mode to ``||music:[until done]||``.
► Click on the **dropdown** and set it so Cyrus plays a sad sound until done.

```blocks
input.onGesture(Gesture.Shake, function () {
basic.showIcon(IconNames.Sad)
//@highlight
soundExpression.sad.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.Wawawawaa), music.PlaybackMode.UntilDone)
})
```

Expand All @@ -81,13 +81,13 @@ Let's ensure that Cyrus will always go back to sleep after being shaken or tickl
```blocks
input.onGesture(Gesture.Shake, function () {
basic.showIcon(IconNames.Sad)
soundExpression.sad.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.Wawawawaa), music.PlaybackMode.UntilDone)
//@highlight
basic.showIcon(IconNames.Asleep)
})
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
basic.showIcon(IconNames.Happy)
soundExpression.giggle.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.JumpUp), music.PlaybackMode.UntilDone)
})
basic.showIcon(IconNames.Asleep)
```
Expand All @@ -99,12 +99,12 @@ basic.showIcon(IconNames.Asleep)
```blocks
input.onGesture(Gesture.Shake, function () {
basic.showIcon(IconNames.Sad)
soundExpression.sad.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.Wawawawaa), music.PlaybackMode.UntilDone)
basic.showIcon(IconNames.Asleep)
})
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
basic.showIcon(IconNames.Happy)
soundExpression.giggle.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.JumpUp), music.PlaybackMode.UntilDone)
//@highlight
basic.showIcon(IconNames.Asleep)
})
Expand All @@ -124,12 +124,12 @@ If you have a new @boardname@ (the one with the **shiny gold** logo at the top),
```blocks
input.onGesture(Gesture.Shake, function () {
basic.showIcon(IconNames.Sad)
soundExpression.sad.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.Wawawawaa), music.PlaybackMode.UntilDone)
basic.showIcon(IconNames.Asleep)
})
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
basic.showIcon(IconNames.Happy)
soundExpression.giggle.playUntilDone()
music.play(music.builtInPlayableMelody(Melodies.JumpUp), music.PlaybackMode.UntilDone)
basic.showIcon(IconNames.Asleep)
})
basic.showIcon(IconNames.Asleep)
Expand Down

0 comments on commit 345c576

Please sign in to comment.