Computing with Music: Creating Musical Patterns - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Computing with Music: Creating Musical Patterns

Description:

Computing with Music: Creating Musical Patterns Campy, 2003 Quinnipiac University ... by writing computer programs that express musical objects and patterns. ... – PowerPoint PPT presentation

Number of Views:139
Avg rating:5.0/5.0
Slides: 52
Provided by: JCP3
Category:

less

Transcript and Presenter's Notes

Title: Computing with Music: Creating Musical Patterns


1
Computing with MusicCreating Musical Patterns
  • John Peterson
  • Yale University
  • http//haskell.org/edsl

2
Welcome!
  • You should be comfortable using a computer to
    edit text. If you havent used a computer much
    you can pair up with a more experienced partner.
  • You dont need to know anything about music.

3
Making Music
  • We will make music by writing computer programs
    that express musical objects and patterns. Our
    goal is for each student (or team) to make some
    compositions. We will place these on a web page
    for everyone to hear when this session is over.
  • Please ask questions at any time!

4
Using Music Software
  • As I talk I will show you sample music programs.
    Id like you to run these yourself as Im talking
    so you wont fall asleep and start snoring. And
    you can also change these programs a little bit
    to see what happens to the music.
  • Lets see how to run and edit a program.

5
Write a Program
  • Use the text editor to enter the following
    program
  • import Music
  • tune c4 e4 g4
  • Save this in a file ending in .hs in your Music
    folder test.hs, for example.
  • After saving, double click test.hs
  • If there are no errors, type play tune

6
Changing a Program
  • Now go back to your test program and change g4
    to a5 and save the program again.
  • Instead of clicking test.hs, just type r to
    reload your program and play the tune again.
  • Use q to shut down the program.

7
Extending a Language
  • How do we add new words to a language?
  • Lets think about how we extend English to see
    how we can make a language for music that lets
    you add your own words to capture patterns.

8
Whats this mean?
  • Fred gave me his tarka

9
Whats this mean?
  • Fred gave me his tarka
  • Im stumped too! So what should we do?

10
Looking up a new word
  • Fred gave me his tarka
  • From a dictionary
  • n. a small wooden flute found in the Andes.

11
Building Language
  • Aha! We can make a language bigger by giving
    definitions to new words. The new word is a name
    for some new concept.
  • Mathematicians use definitions to create new
    words (names) all the time.
  • These definitions express new words in terms of
    ones you already know.

12
Computer Languages
  • A computer language is just like any other
    language except the computer knows what youre
    saying.
  • Our language uses definitions (written by you) to
    extend a simple music language.
  • Computers are very fussy! If you write down
    something thats wrong (bad spelling, misplaced
    punctuation, total nonsense) it will complain.

13
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

14
Types and Logic
  • There are a lot of ways to mess up in a
    language
  • Syntax Fred ga?ve mehis tar.ka
  • Illogical sentences
  • Have a tarka day!
  • Since tarka is a noun this doesnt make sense.
  • Programmers use syntax rules and logic to tell
    whether a sentence is gibberish or OK.
  • Types (like noun) describe a set of objects.
  • Im sure the computer will occasionally complain
    about the syntax or types in your programs.
    Logic will help us understand things better.

15
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

16
Examples
  • When a slide has an example in a rectangle with a
    name in red that means the example is in your
    demo file and you can play it yourself if you
    want.

tune1 c3 d3 e3
Double click demos.hs now so youll be
ready. Go ahead and play this tune.
17
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 57 or 3.4
  • In addition well also add our own functions
    which can use these objects.

18
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
19
Rests
  • There is a special note called a rest. Its
    name is r and Ill play it for you right now!
  • Ready?

20
Rests
  • There is a special note called a rest. Its
    name is r and Ill play it for you right now!
  • Ready?
  • Actually, rests are really useful when you mix
    them in with other notes

21
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.

sequence c4 e4 g4 together c4 ! e4 !
g4 bothst c4 (e4 ! g4)
22
Changing Music
  • There are lots of ways to change a piece of
    music
  • Play it faster or slower
  • Play it higher or lower
  • Play it louder or softer
  • Play on different instruments
  • All of these things are part of basic vocabulary
    of our language

23
A note about notation
  • We write f x instead of f(x) like a math textbook
    would use.
  • Parenthesis are for grouping (as usual)
  • Operators like ! and happen last
  • f x g y is the same as (f x) (g y)

24
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.

25
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)
  • someNotes c4 d4 f4 e4
  • halves h c4 h d4 h f4 h e4
  • eights e (c4 d4 f4 e4) -- or e
    somenotes
  • mixed h c4 e d4 h f4 e e4

26
Dotted notes
  • In music, adding a dot to a note makes it half
    again as long. So a dotted quarter note is the
    same as three eighth notes.
  • dh -- dotted half
  • dq -- dotted quarter
  • de -- dotted eighth
  • ds -- dotted sixteenth
  • dots dh c4 q d4
  • dq e4 e f4 h g4

27
Any Speed You Want!
  • You can specify the speed directly using the
    faster or slower functions.
  • speeds
  • faster (3/2) ( c4
  • faster 2 (c4 c4)
  • faster 3 (d4 d4 d4)
  • faster 5 (e4 e4 e4 e4
    e4)
  • )

28
Moving music up and down
  • We can move notes up or down in pitch. The up
    and down functions take a number that indicates
    how many piano keys to move a piece of music.
  • For example, this plays a phrase and then plays
    it again 7 notes higher
  • halfScale e (c4 d4 e4 f4)
  • fullScale halfScale up 7 halfScale
  • twiceScale halfScale down 2 halfScale
  • (The note 7 up from c4 is g4)

29
Interval Names
  • Musicians have names for intervals (distances
    between notes). Well use these instead of
    numbers sometimes. Here are their names
  • min2 1 maj2 2
  • min3 3 maj3 4
  • per4 5
  • aug4 6 dim5 6
  • per5 7
  • min6 8 maj6 9
  • min7 10 maj7 11
  • per8 12 (also called an octave)

30
Louder and Softer
  • Music can be played soft or loud. Musicians have
    names for these levels of loudness. Each of
    these is a function (music changer) which changes
    the loudness of a piece of music.
  • pp really soft
  • p soft
  • mp sort of soft
  • mf sort of loud
  • f loud
  • ff really loud
  • loudSoft q (f (c4 e4) p (c4 a3))

31
Accents
  • An accent plays a note a little louder than the
    other notes around it.
  • accented q (accent c4 c4 c4 c4
  • accent c4 c4 c4 c4)

32
Different Instruments
  • These functions select different instruments
  • piano harpsichord organ
  • guitar bass violin
  • viola cello harp
  • trumpet horn sax
  • oboe bassoon clarinet
  • flute panFlute

33
Tuning Up
  • This sounds like an orchestra tuning up!
  • tuning clarinet a4
  • violin a4
  • oboe a4
  • viola a4
  • flute a4

34
Reading the manual
  • Youll never remember all of this so weve
    written it down for you. You can find all of
    these names in the cheat sheet weve handed
    out.

35
Naming Music
  • Weve been reusing bits of music by adding
    definitions and using them over and over. Its
    like naming a song and asking the DJ to play it
    for you whenever you want. Just using naming we
    can do a lot .

36
A Bigger Example
  • Lets take a familiar tune and break it into
    pieces. Here are three definitions for some
    music you should recognize
  • twA q (c4 c4 g4 g4 a4 a4) h g4
  • twB q (f4 f4 e4 e4 d4 d4) h c4
  • twC q (g4 g4 f4 f4 e4 e4) h d4
  • Well put this together and see if you know it
  • twAll twA twB twC twC twA twB
  • twinkle faster (3/2) (violin twAll)

37
At the rehearsal
  • A bunch of musicians are getting ready to play
    twinkle. Each one of them is playing at a
    different speed, a different pitch, and starting
    at different times (that what the rests are for).
    Here it is

38
At the rehearsal
  • rehersal faster 3 (flute (up 14 twAll)) !
  • faster 2.1 (trumpet (h r twAll)) !
  • faster 1.9 (bassoon (down 6 (r
    twAll))) !
  • faster 1.4 (horn (up 3 (r r twB
    twA))) !
  • faster 4 (guitar (up 6 (r r r
    twAll)))

39
Activity 1 Simple Music
  • Write your own music! Start a file with
  • your name and the import Music. Add some
    definitions of your own. Create as many as you
    want - well use them later. Select the best one
    to play for us.

40
Functions
  • So far weve given names to pieces of music but
    its always exactly the same music.
  • Now we want to capture more general patterns by
    adding parameters to our definitions.

41
Play it Again
  • Heres a really simple pattern play something
    twice. We express this by giving twice a
    parameter the music to be played.
  • twice music music music
  • Heres how its used
  • twice music music music
  • twice1 twice (e (c4 d4 e4 f4) q g4)
  • twice2 twice (e (e4 f4 e4 d4 e4 d4))
  • dh c4

42
A Major Chord
  • Heres how you could define a chord
  • Definition a major chord built on a note n is n
    played with the notes 4 and 7 steps higher than
    n.
  • How do we express this on the computer?
  • majorChord m m ! (up 4 m) ! (up 7 m)
  • This is all major chords, not just one!
  • chords h (majorChord c4 majorChord f4
  • majorChord g4 majorChord c5)

43
Function Composition
Function composition notation (f . g) x f
(g x) Make a pipeline of music changers flute
. mf . faster 2 play a flute mf twice as fast
Such notation makes it easier to work with
functions!
44
Functions of Functions
The arguments to a function can also be
functions. Remember that a music changer is a
function! This pattern lets you plug in two
different music changers. duet instr1 instr2
instr1 (h (c5 b4 a4 g4))
! instr2 (h (c4 d4 f4 e4)) duet1 duet
violin viola duet2 duet oboe clarinet
45
A Round
More familiar music. We use the function canon
music delay instr1 instr2 instr1 music
! instr2 (delay
music) fJ twice (q (g4 a4 b4 g4))
twice (q (b4 c5) h d5) twice (e (d5 e5
d5 c5) q (b4 g4)) twice (q (g4 d4)
h g4) fJcanon faster (3/2) (canon
fJ (w (r r)) violin flute)
46
Simple Iteration
A function can call itself! This lets a function
do something more than once. This uses two
clauses one that stops iteration and one that
keeps it going. rep 1 music music rep n music
music rep (n-1) music
Pretty tricky! But we can do more. Theres
no reason to play the exact same thing each time.
47
Infinite Iteration
What does this do? repeatedly m m repeatedly
m
48
Infinite Iteration
What does this do? repeatedly m m repeatedly
m If the music never stops, what good is it?
Well, there is a special form of ! that cuts off
the second piece of music when the first one
finishes. baseline accent (de c2) s c2 e
(c2 c2) twbase flute twA !(repeatedly baseline)
49
Modified Iteration
This time well do something to change the
music when it is iterated. The function f
changes the music at each repetition. repTf 1 f
music music repTf n f music music repTf
(n-1) f (f music) augChords repTf 19 (down
maj3) (s c7)
Ouch - my brain hurts!!
50
Changing the Notes
Another way to change a piece of music is to do
something to every note. The changeNotes functi
on replaces each note in a piece of music
with some new music. dotme m faster 1.5 m
faster 3 m dotall changeNotes dotme fJ (If
you were clever you could avoid dotting the
half notes!)
51
Activity 2
OK - you know how to do some strange and
wonderful things to music. Go nuts! Make your
own music. Try to use functions that put patterns
in your music. Dont waste too much time trying
to turn music you know into notes. Use few notes
and many functions! Be ready for a concert at
the end of the session.
Erics favorite piece
Write a Comment
User Comments (0)
About PowerShow.com