Music Project

Unit 3 Optional Project

This page needs KEEP SUCH THAT updated. –MF, 6/22/20

PG: I’d very much want to have a map-onto-scale one. (I have an example somewhere.) Kids who care about music will find the switches interesting, and even kids who claim not to be able to hear the differences will.

BH: This is fine as far as it goes, but it calls out for more, starting with a note-name-to-midi-number reporter, and then making a round.

MF: BH has reviewing to do (see TG)

This page has been renumbered; need to check if this throws off the numbering in the solutions or TG. –MF, 4/26/19

In this project, you will use the Snap! play note block to create music while you review abstract data types and higher-order functions.

  1. “U3-MusicProject”Create a new project called U3L2-PlaySong

  2. Set Up Your Headphones or Speakers

Reviewing Higher-Order Functions with Sound

  1. Build and compare these play scripts. Run each script a few times.

      The inputs values given to the play note block are musical pitches. Higher values create higher notes. You can input any integer from 0 and 127. The number 60 represents middle C.

    1. play note (item (any) of (list (60) (64) (67) (72) (60))) for (1) beats
    2. for each (note) of (list (60) (64) (67) (72) (60)) (play note (note) for (1) beats)
    3. for each (note) of (map (_ + 5) over (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)
    4. for each (note) of (keep items such that (() < 65) from (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)

Need to Review?

These need updating!! –MF, 4/5/19

Creating an Abstract Data Type to Organize Musical Data

  1. Pitch is the amount of highness or lowness of a musical note; the pitch value goes in the first input slot of the play note block.

    The length of a note is the amount of time that the note plays (the number of beats); the length value goes in the second slot of play note.

    Create a note ADT to manage the pitch and length of each note in a song.

    1. Create the constructor:
      note, pitch: () length: ()
    2. Create two selectors:
      pitch from note: () length from note: ()

Save your work

Creating Blocks to Play Music

  1. Use for each together with your selectors to build a play song {} block that takes a list of notes as input and plays each pitch for the specified number length of time.
    Play Song data type definition
  2. Create a reporter to reports the notes for a song of your choosing. Here’s an example:
    row row row your boat reporter block definition Save Your Work
  3. Test your song with your play song block, and debug any problems.
    play song (row row row your boat)
  4. Save your work

    BPM stands for “beats per minute.”

  1. Use the set tempo to () bpm block to change the pace at which the notes are played. A higher number will make your song play faster; a lower number will make it play slower.

Transposing Music

  1. Talk with Your Partner Compare the output of these two scripts that you created above. Discuss what map + 5 does to the sounds you hear:
    for each (note) of (list (60) (64) (67) (72) (60)) (play note (note) for (1) beats)
    for each (note) of (map (_ + 5) over (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)
  2. Use map together with your ADT blocks to create a reporter that transposes (shifts) a list of notes. It should take a list of notes and a number indicating how much to transpose (shift) the song as input, and it should report the adjusted song. For example:
    play song (transpose (row row row your boat) by (19))

  3. Try playing your song using your transpose block with several different shift numbers so that you can hear the impact of map.

Doesn’t work in Snap! but would have been a nice way to tie the page together… :/

Creating a Round

launch(play song(row row row your boat)); wait (3) secs; launch(play song(row row row your boat)); GitHub Issue #1807

Boring? Maybe not for A/V kids…

Using a Frequency Cutoff

  1. Talk with Your Partner Compare the output of these two scripts that you created above. Discuss what keep \< 65 does to the sounds you hear:
    for each (note) of (list (60) (64) (67) (72) (60)) (play note (note) for (1) beats)
    for each (note) of (keep items such that (() < 65) from (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)