1 / 34

Computing with Music: Creating Musical Patterns

Computing with Music: Creating Musical Patterns. John Peterson No Longer At Yale University http://haskell.org/edsl. Play Some Music. Copy “ haskore ” from my shared to C: Click on “output.mid” and make sure you hear something then close the player. Use TextPad to open “test1.hs”

badu
Télécharger la présentation

Computing with Music: Creating Musical Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computing with Music:Creating Musical Patterns John Peterson No Longer At Yale University http://haskell.org/edsl

  2. Play Some Music Copy “haskore” from my shared to C: Click on “output.mid” and make sure you hear something then close the player. Use TextPad to open “test1.hs” Change the e3 to ef3 Save this file and then double click it. If everything is OK, type “play music1” Open output.mid again to see if it worked. Change something, save it, and type “:r” to reload Play it again!

  3. Notation The computer wants you to write down definitions in a very particular way: name = thing melody = c4 & d4 & e4 chord n = n ! up 4 n ! up 7 n These have to start in the first column!

  4. About Haskore A program is like a dictionary: it is a set of definitions, each starting in the leftmost column, in any order you want. There is a built-in vocabulary that you use to build new definitions You “load in” a program and can then perform any piece of music defined in the program using “play”

  5. A Vocabulary of Music • Instead of nouns, verbs, or adjectives our language will have the following “types” of things: • Music - something you can listen to • Music glue - something that combines music together • Music changer - something that modifies music • Numbers - things like 2 or 5+7 or 3.4 • Lists – a sequence of things like [c4, d4, e4] • In addition we’ll also add our own functions which can use these objects.

  6. Notation We write “f x” instead of “f(x)” and “f x y” instead of “f(x,y)”. We still use parens for grouping: “f (g 1) (h 2)”. Function application happens before operators like “+”: “f x + g y” means “(f x) + (g y)” You have to say “0.2” instead of “.2”

  7. Note Names The basic vocabulary gives names to the notes of the scale. Notes are the letters a - g. We add a number to them to give an “octave number”. Notes can also be flat (f) or sharp (s). These notes are all “whole notes”. c3 e4 af4 gs7 There are lots of C notes so we need the number too

  8. Rests There is a special note called a rest” – it doesn’t have a sound but it’s still useful. Use “r” for a rest note.

  9. Naming Music Names allow you to use the same bit of music over and over. Like “naming a song” and asking the DJ to play it for you. As you do exercises, you will give names to pieces of music. Use any name you want but you can’t use the same name twice. As you go on to other exercises you can use these named pieces of music again.

  10. Music Glue We can “glue” pieces of music together in two ways: play one first and then the other, or play both at the same time. We use “&” for playing sequentially and “!” for playing at the same time. You can glue any two pieces of music, not just single notes. Exercise 1: Write three phrases, each with three notes. One sequential, one all together, and one using both & and !. Put a rest in one of them Add these to your “MyMusic” file and play them. Give each a different name.

  11. Changing Music There are lots of ways to change a piece of music: • Play it faster or slower • Play it higher or lower • Play on different instruments All of these things are in our music vocabulary.

  12. Faster / Slower (Tempo) Musicians use “whole notes”, “half notes”, “quarter notes”, and so on to tell a performer how long to play a note. A half note is 1/2 as long as a whole note (duh), and so on. We use music changers to make any piece of music (not just notes!) go faster or slower.

  13. Simple Tempo Changers Here are the names of our tempo changers: h - turns whole notes into half notes (go twice as fast) q - quarter notes (4x as fast) e - eighth notes (8x as fast) s - sixteenth notes (16x as fast) dh, dq, de, ds – dotted notes (Adds an extra ½ beat)

  14. Any Speed You Want! You can also say “faster” or “slower”. For example, “h” is just “faster 2”. Exercise 2: write a 4 note phrase that uses a half, quarter, and two eighth notes and play it. Then write another definition that plays the phrase twice at different speeds.

  15. Moving music up and down The “up” and “down” functions change the pitch in a piece of music. You tell these functions how many “piano keys” to move the music. m1 = c3 & d3 & e3 m2 = up 2 m1 m3 = m1 ! m2 ! up 4 m1

  16. Different Instruments There are a lot of different instruments you can play music with. piano, harpsichord, vibes, organ, guitar, electric, bass, violin, viola, cello, trumpet, trombone, horn, sax, oboe, bassoon, clarinet, flute, panFlute, kalimba, woodblock m = oboe (c4 & g4) Exercise 3: take a piece of music you have already written and play it three times, each with a different instrument and starting with a different note.

  17. Reversing You can reverse a piece of music with the “rev” function. m1 = q (c4 & e3 & g3) m2 = rev m1

  18. Activity 1: A Simple Pattern Write a piece of music from 2 different musical patterns, each containing just 4 notes. Use naming, reversal, tempo changes, and transposition to create a short bit of music. A small example to get you started is in MyMusic.hs Guidelines: * not too long! * think of a nice pattern for your piece

  19. Functions Definitions often are parameterized. That is, they contain names that are “filled in” when the definition is used. Example: a major chord built on a note n is n played with the notes 4 and 7 steps higher than n. majchord n = n ! up 4 n ! up 7 n parameter

  20. Play it Again Here’s a really simple pattern: play something twice. We express this by giving “twice” a parameter: the music to be played. twice music = music & music Here’s how it’s used: m2 = twice m1

  21. Exercise 4 Many songs are in “ABA” form. Write a function that has two parameters, the A and B parts of the song, and puts them all together. Test this with two phrases you’ve already written.

  22. What Just Happened? Our computer language allows us to give names to musical patterns and use them to make it easier to write music. You can’t do that using regular sheet music (well, you can do simple patterns like twice or ABA …)

  23. General Repetition We can use a counter to repeat “n” times instead of just twice: rpt 0 m = empty rpt n m = m & rpt (n-1) m Use it like this: m1 = rpt 3 m2

  24. Exercise 5 Use rpt to add a repeating bass to a piece of music. Define two fragments: a slow one with 4 whole notes another one with 4 quarter notes. Play them at the same time, repeating the one with quarter notes so they last the same amount of time. p1 = … p2 = … ex5 = p1 ! (rpt 4 p2)

  25. One More Music Function The “invert” function turns music upside down. You need to give it the note that won’t change; notes above go below and notes below go above. invertPhrase = q (c4 & d4 & e4 & g4) invertDemo = invert c4 invertPhrase This is in MyMusic – try it out

  26. Functions in Functions Function arguments need not be just notes – they can be functions that change notes. Here’s a function that repeats and changes music: rptChange 1 f m = m rptChange n f m = m & rptChange (n-1) f (f m)

  27. Using rptChange What do these do? m1 = rptChange 10 (up 1) (q c4) m2 = rptChange 10 (faster (5/4)) (q c4) addNote m = q c4 & up 2 m m3 = rptChange 5 addNote (q c4)

  28. Exercise 6 Write a short phrase (1 - 4 notes) and then use repeatChange to do something new with it. Some possibilities: add a new note each time add an echo reverse the music each time invert the music each time

  29. Pattern Music We’ll conclude with two ways of creating simple musical patterns rseq n seed [m1, m2, m3, …mn] This creates a random seqence of n selections drawn from m1 .. mn. The “seed” determines which specific sequence you get – use any integer you want here. If you don’t like the music you get maybe changing this helps.

  30. Example p1 = e (d4 & e4 & g4) p2 = s (c5 & a4 & g4 & e4 & d4) p3 = q (c4 ! e4 ! g4 ! a4) p4 = q (e4 & a4) rm = rseq 10 113 [p1, p2, p3, p4]

  31. Random Mutation A more involved way of generating random patterns is to start with a piece of music and then randomly apply some sort of music transformation repeatedly You need: * number of mutations * random seed * a list of music changers * a piece of music to start with

  32. Random Mutation Example ch1 = up 4 ch2 = up 3 ch3 m = s c4 & m ch4 = faster (5/4) rm2 = rchange 15 23 [ch1, ch2, ch3, ch4] (s e4)

  33. Activity 2 Using a phrases of no more that three notes write a musical pattern. You can use any of the functions we’ve already seen like rpt or rptChange or rseq or or rchange you can define your own pattern function. Use both & and ! Use different instruments Write a new function if you want

  34. Homework #1 • Create an interesting piece of music – make it abstract, not something you need to key a lot of notes for. • Make a wiki page with your music on it – upload the audio file too. • Read about “Extreme Programming” for Wednesday.

More Related