Making music Consider music as structured sound Components include –Pitch –Duration...

11
Making music Consider music as structured sound Components include – Pitch – Duration – Instrument Stereo direction Each attribute has a set of possible values Can specify by number or name

Transcript of Making music Consider music as structured sound Components include –Pitch –Duration...

Page 1: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Making music

• Consider music as structured sound• Components include

– Pitch– Duration– Instrument– Stereo direction

• Each attribute has a set of possible values– Can specify by number or name

Page 2: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Components

• Pitch – defined by note values/names– Letters A-G, which repeat in the next octave– half steps between most notes (just not B-C and E-F)– 12 notes per octave

A, A♯, B, C, C ♯, D, D♯, E, F, F♯, G, G♯– Pitch values double at the next octave up

• Duration– System of notes and rests– One beat is usually denoted with a “quarter note”– Dotted note has 1.5x the duration

Page 3: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Musical scale

• Ever watch The Sound of Music?• The easiest musical scale is called C Major. It

works like this:

• Actually, the movie used a B-flat Major scale which is 2 half-steps lower than C.

Note C D E F G A B C

Song name do re mi fa so la ti do

Page 4: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Getting started

• We won’t use IDLE. Download new system:– http://www.cs.cofc.edu/~manaris/jythonmusic/– Click on “download”– Open folder, double-click on JEM2.jar

• “Jython” is a version of the Python language– Does not change how your write code– Allows us to run programs to interact with Java on

your computer to access extra multimedia capabilities

• Near top of program: from music import *

Page 5: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Note( ) function

• note = Note(pitch, duration, volume, panning)• Note the 4 parameters

– Pitch = name of note with octave number, e.g. C4, D5; or a number 0-127 where middle C = 60.

– Duration = number of quarter-note beats, or a given name e.g. QN, HN, WH; precede with D to dot a note.

– Volume = number 0-127. Forte = 85 is the default. Others are FFF, FF, F, MF, MP, P, PP, PPP

– Panning = stereo direction. 0.0 = left, 0.5 = center (default), 1.0 = right

– In most cases we just need first 2 parameters.

Page 6: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Examples

note = Note(C4, DHN, FF)

Play.midi(note)

---------------------------

rest = Rest(HN)

Play.midi(note)

---------------------------

note = Note(E4, QN)

Play.midi(note)

---------------------------

note = Note(G4, QN)

Play.midi(note)

Page 7: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Phrase

• Do you want to play more than 1 note? Then put your notes into a phrase.– Create a phrase p = Phrase()– Add notes to phrase p.addNote(Note(C4, QN))

p.addNote(Note(E4, QN))

p.addNote(Note(G4, QN))

p.addNote(REST)– Play the phrase Play.midi(p)

Page 8: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Phrase features

• We can set a tempo and instrumentp.setTempo(120)

p.setInstrument(FLUTE)

• Tempo indicates speed of quarter note.– If we set tempo to 120, each beat is 1/120 of a minute

or ½ a second.

• PIANO instrument is default. Choices include:

CLARINET, VIOLA, GLOCKENSPIEL, ACCORDION, TRUMPET, ELECTRIC_GUITAR, FLUTE

Page 9: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

List of notes

• Music has a lot of notes. Put them in a list! It will save typing.

• Create a list of pitches, which can include rests.

[C4, C4, C4, C4, E4, D4, C4]• Create a list of matching durations

[QN, QN, QN, QN, DQN, EN, HN]• Call this function on the 2 lists:

p.addNoteList(<pitches>, <durations>)

Page 10: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Example

p = Phrase()

p.setInstrument(FLUTE)

p.setTempo(120)

pitch1 = [C4, C4, C4, C4, E4, D4, C4]

duration1 = [QN, QN, QN, QN, DQN, EN, HN]

pitch2 = [E4, E4, E4, E4, G4, F4, E4]

p.addNoteList(pitch1, duration1)

p.addNoteList(pitch2, duration1)

Play.midi(p)

Page 11: Making music Consider music as structured sound Components include –Pitch –Duration –Instrument –Stereo direction Each attribute has a set of possible.

Simultaneous notes

• The function p.addChord( ) allows you to specify that some notes play at the same time.

• Format: p.addChord(<pitch list>, <duration>)

p = Phrase()

p.addChord([C4, E4, G4], HN)

p.addNote(REST, QN)

p.addChord([C4, EF4, G4], HN)

p.addNote(REST, QN)

p.addNote(E4, HN)

Play.midi(p)