Skip to content

Commit

Permalink
📜 Adds music adventure level 1 to 14 in English (#4991)
Browse files Browse the repository at this point in the history
Start of #4962 

Can be merged once the music notes bugs are resolved.

Depends-On: #5035
  • Loading branch information
MarleenGilsing committed Feb 1, 2024
1 parent a0ab901 commit 338af73
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 20 deletions.
284 changes: 284 additions & 0 deletions content/adventures/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,290 @@ adventures:
```
{print} 2.5 + 2.5
music:
name: music
default_save_name: music
description: Play a tune!
levels:
1:
story_text: |-
In this level you'll learn how to use the `{play}` command to play a tune!
Type `{play}` followed by the note you want to play. The scale goes C-D-E-F-G-A-B.
As you can see there are 7 different letters, but we can play more than just 7 notes.
Type a number between 1 and 10 behind the letter to choose the scale, for example after B4 comes C5.
C1 is the lowest note you can play, C10 is the highest.
### Exercise
Try out the example code and thenplay around with it! Can you create your own melody?
In the next level you'll learn how to play some existing songs.
example_code: |-
```
play C4
play D4
play E4
play F4
play G4
play A4
play B4
play C5
```
2:
story_text: Finish the songs! We have started the codes for some melodies.
example_code: |
```
{print} Old Mac Donald had a farm
{play} C5
{play} C5
{play} C5
{play} G4
{play} A4
{play} A4
{play} G4
```
story_text_2: As you can see, you can also use the `{sleep}` command to add a little pause in the song.
example_code_2: |
```
{print} Twinkle Twinkle Little Star
{play} C
{play} C
{play} G
{play} G
{play} A
{play} A
{play} G
{sleep} 1
{play} F
{play} F
```
3:
story_text: |
Create a random melody!
### Exercise
The example code creates a random melody, but it's very short and not many notes are used.
Add more notes to the list and create a longer melody by copying the last line a couple more times.
example_code: |
```
notes {is} A4, B4, C4
{play} notes {at} {random}
{play} notes {at} {random}
{play} notes {at} {random}
```
4:
story_text: |
Use the `{clear}` command to create a karaokemachine!
### Exercise
Finish the karaoke version of 'Mary had a little lamb'.
Then, create a karaoke version of any song you'd like!
example_code: |
```
{print} 'Mary had a little lamb'
{play} E
{play} D
{play} C
{play} D
{play} E
{play} E
{play} E
{clear}
{print} 'Little lamb, little lamb'
{play} D
{play} D
{play} D
{play} E
{play} E
{play} E
{clear}
{print} 'Mary had a little lamb'
{play} E
```
5:
story_text: |
You don't always have to use the `{play}` command to play a whole song, sometimes you just want to play one note.
For example, if you want to make a quiz, you can play a happy high note if the answer is right and a sad low note if the answer is wrong.
### Exercise
Finish the first question by adding a line of code that plays a C3 note if the wrong answer is given.
Then think of 3 more questions to add to this quiz.
example_code: |
```
answer {is} {ask} 'What is the capital of Zimbabwe?'
{if} answer {is} Harare {play} C6
_
```
6:
story_text: "Instead of playing notes, you can also play numbers now. Simply type `{play} 1` for the lowest note, `{play} 70` for the highest note, or anything in between.\n\n### Exercise\n This calls for musical maths! Try out the example code a couple of times with different starting\
\ numbers. \nThen, see if you can compose a song using the numbers.\n"
example_code: |
```
number = {ask} 'Say a starting number between 1 and 67'
{print} number
{play} number
number = number + 1
{print} number
{play} number
number = number + 1
{print} number
{play} number
```
7:
story_text: |
Using the `{repeat}` command can make your codes for melodies a lot shorter!
### Exercise
Finish the code for Twinkle Twinkle Little Star by using the `{repeat}`command.
Then go back to the songs you've made in the previous levels. Can you shorten those codes too?
example_code: |
```
{print} 'Twinkle Twinkle Little Star'
{repeat} 2 {times} {play} C4
{repeat} 2 {times} {play} G4
_
```
8:
story_text: |
Now that we can use the `{repeat}` command for multiple lines, we can make songs even more easily!
### Exercise
Finish the song of Brother John (Frère Jacques). Don't forget to use `{repeat}`!
example_code: |
```
{print} 'Brother John'
{repeat} 2 {times}
{play} C
{play} D
{play} E
{play} C
{repeat} 2 {times}
{play} E
{play} F
{play} G
{sleep} 1
```
9:
story_text: |
From this level on you can - among other things - use a {repeat} command inside a {repeat} command.
That makes songs like 'Happy birthday' even shorter!
### Exercise
Finish the song!
example_code: |
```
first_time = yes
{repeat} 2 {times}
{repeat} 2 {times}
{play} C
{play} D
{play} C
{if} first_time {is} yes
{play} F
{play} E
first_time {is} no
{else}
_
```
12:
story_text: |
Use functions in you songs! As you can see in the example code, you can make a function for each line of Twinkle Twinkle little star. Once you've programmed the first three lines, all you have to do is call the functions in the order you want them played in.
### Exercise
Finish the song of Twinkle Twinkle little star.
Then look back at all the songs you've programmed in the levels before, can you make those codes better and shorter using functions too?
example_code: |
```
{define} first_line
{play} C
{play} C
{play} G
{play} G
{play} A
{play} A
{play} G
{sleep}
{define} second_line
{play} F
{play} F
{play} E
{play} E
{play} D
{play} D
{play} C
{sleep}
{define} third_line
{play} G
{play} G
{play} F
{play} F
{play} E
{play} E
{play} D
{sleep}
{call} _
{call} _
{call} _
{call} _
{call} _
{call} _
```
13:
story_text: |
You can use a function with an argument for songs that have line taht are almost the same, but slightly different each time.
One example is the song 'Yankee Doodle'. The first 4 notes of the first lines are the same, buyt each time they are followed by a different couple of notes.
### Exercise
Can you finish the song of Yankee Doodle?
Can you think of another song to programm this way?
example_code: |
```
{print} 'Yankee Doodle'
{define} _ {with} note_1, note_2, note_3
{play} C4
{play} C4
{play} D4
{play} E4
{play} _
{play} _
{play} _
{call} line_1 {with} 29, 31, 30
{call} line_1 {with} 29, 28, 0
{call} line_1 {with} 32, 31, 30
{play} C4
{play} B3
{play} G3
{play} A3
{play} B3
{play} C4
{play} C4
```
14:
story_text: |
You can programm music for fun, but you can also use the musical notes to make something useful like a fire alarm!
### Exercise
Make sure the fire alarm rings when there is a fire!
example_code: |
```
{define} fire_alarm
{print} 'FIRE!'
note = 40
{for} i {in} {range} 1 {to} 100
{if} note _ 50
note = note + 5
{play} _
{else}
note = 40
fire = {ask} 'Is there a fire?'
{if} fire _ 'yes'
{call} fire_alarm
```
parrot:
name: Parrot
default_save_name: Parrot
Expand Down
4 changes: 2 additions & 2 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,10 +1617,10 @@ def make_play_var(self, note, meta):
self.check_var_usage([note], meta.line)

return textwrap.dedent(f"""\
chosen_note = {note}.upper()
chosen_note = str({note}).upper()
if chosen_note not in notes_mapping.keys() and chosen_note not in notes_mapping.values():
raise Exception({exception_text})
play(notes_mapping.get(str(chosen_note), str(chosen_note)))
play(notes_mapping.get(chosen_note, chosen_note))
time.sleep(0.5)""")

def make_color(self, parameter, language):
Expand Down
12 changes: 12 additions & 0 deletions hedy_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'rock',
'haunted',
'story',
'music',
'turtle',
'turtle_draw_it',
'restaurant',
Expand All @@ -57,6 +58,7 @@
'sleep_command',
'parrot',
'story',
'music',
'restaurant',
'turtle',
'turtle_draw_it',
Expand All @@ -67,6 +69,7 @@
'random_command',
'dice',
'rock',
'music',
'fortune',
'restaurant',
'add_remove_command',
Expand All @@ -88,6 +91,7 @@
'turtle',
'turtle_draw_it',
'clear_command',
'music',
'story',
'haunted',
'fortune',
Expand All @@ -97,6 +101,7 @@
5: [
'default',
'if_command',
'music',
'language',
'dice',
'dishes',
Expand All @@ -115,6 +120,7 @@
6: [
'default',
'maths',
'music',
'is_command',
'songs',
'dice',
Expand All @@ -131,6 +137,7 @@
'repeat_command',
'story',
'songs',
'music',
'dishes',
'dice',
'repeat_command_2',
Expand All @@ -146,6 +153,7 @@
'fortune',
'repeat_command_2',
'songs',
'music',
'if_command',
'story',
'haunted',
Expand All @@ -161,6 +169,7 @@
'rock',
'story',
'calculator',
'music',
'restaurant',
'haunted',
'pressit',
Expand Down Expand Up @@ -202,6 +211,7 @@
'quotation_marks',
'story',
'fortune',
'music',
'songs',
'songs_2',
'restaurant',
Expand All @@ -217,6 +227,7 @@
'and_or_command',
'secret',
'functions',
'music',
'story',
'rock',
'turtle_draw_it',
Expand All @@ -229,6 +240,7 @@
'default',
'is_command',
'guess_my_number',
'music',
'haunted',
'functions',
'turtle_draw_it',
Expand Down
Loading

0 comments on commit 338af73

Please sign in to comment.