module Ex where import Music ---------------------------------------- tune1 = c3 & d3 & e3 ---------------------------------------- notesInSequence = c4 & e4 & g4 notesTogether = c4 ! e4 ! g4 bothST = c4 & (e4 ! g4) ---------------------------------------- someNotes = c4 & d4 & f4 & e4 halves = h c4 & h d4 & h f4 & h e4 eights = e (c4 & d4 & f4 & e4) mixed = h c4 & e d4 & h f4 & e e4 ---------------------------------------- dots = dh c4 & q d4 & dq e4 & e f4 & h g4 ---------------------------------------- speeds = faster (3/2) ( c4 & faster 2 (c4 & c4) & faster 3 (d4 & d4 & d4) & faster 5 (e4 & e4 & e4 & e4 & e4) ) ---------------------------------------- fullScale = halfScale & up per5 halfScale halfScale = e (c4 & d4 & e4 & f4) ---------------------------------------- tuning = clarinet a4 & violin a4 & oboe a4 & viola a4 & flute a4 ---------------------------------------- twA = q (c4 & c4 & g4 & g4 & a4 & a4) & h g4 ---------------------------------------- twinkle = faster (3/2) (violin twAll) twAll = twA & twB & twC & twC & twA & twB twB = q (f4 & f4 & e4 & e4 & d4 & d4) & h c4 twC = q (g4 & g4 & f4 & f4 & e4 & e4) & h d4 ---------------------------------------- twOriginal = q (down per5 (g4 & g4) & (g4 & g4) & up maj2 (g4 & g4)) & h (g4 & g4) twInverted = q (up per5 (g4 & g4) & (g4 & g4) & down maj2 (g4 & g4)) & h (g4 & g4) ---------------------------------------- twMany = faster (3/2) ( oboe (mp (q r & invert g4 (twAll & twB))) ! violin (f (twAll & twB)) ! viola (mp (down per5 (slower (5/4) twAll))) ) ---------------------------------------- ---------------------------------------- -- basic functions twice music = music & music twice1 = twice (e (c4 & d4 & e4 & f4) & q g4) twice2 = twice (e (e4 & f4 & e4 & d4 & e4 & d4)) & dh c4 ---------------------------------------- -- another function inOctaves music = music ! (down per8 music) melodyInOctaves = inOctaves (h (c4 & e4 & g4)) ---------------------------------------- -- functions over non-music values duet instr1 instr2 = instr1 (h (c5 & b4 & a4 & g4)) ! instr2 (h (c4 & d4 & f4 & e4)) duet1 = duet violin viola duet2 = duet oboe clarinet ---------------------------------------- -- bigger example 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) fJ_canon = faster (3/2) (canon fJ (w (r & r)) violin flute) ---------------------------------------- ---------------------------------------- -- tremolo effect -- this is pretty tedious -- we have to c&p notes to extend it -- not flexible in size trem8 = s ( c3 & c4 & c3 & c4 & c3 & c4 & c3 & c4 & c3 & c4 & c3 & c4 & c3 & c4 & c3 & c4 ) ---------------------------------------- -- try to get size flexibility -- still pretty tedious trem1 = s (c3 & c4) trem2 = trem1 & s (c3 & c4) trem3 = trem2 & s (c3 & c4) trem4 = trem3 & s (c3 & c4) -- ... ---------------------------------------- -- why don't we make number of times a parameter? wrongTrem n = s (c3 & c4) & wrongTrem (n-1) ---------------------------------------- -- this will not work. trem1 is different from all of the others -- we need to take a different action when n = 1: trem n = if n == 1 then s (c3 & c4) else s (c3 & c4) & trem (n-1) -- can also be written -- trem 1 = c3 & c4 -- trem n = c3 & c4 & trem (n-1) ---------------------------------------- -- in fact, why not generalize to repeating arbitrary bits of music? rep 1 music = music rep n music = music & rep (n-1) music ---------------------------------------- -- repeating something but altering each time repTf 1 f music = music repTf n f music = music & repTf (n-1) f (f music) augChords = repTf 19 (down maj3) (s c7) ---------------------------------------- -- catamorphisms minorize n = if n `eqPitchClass` e4 || n `eqPitchClass` a4 || n `eqPitchClass` b4 then down 1 n else n minorTwinkle = changePitches minorize twinkle ---------------------------------------- -- crazy recursive structure crazy 1 seed = seed crazy n seed = seed ! (q r & crazy (n-1) (up min3 (faster (3/2) seed))) ! (h r & crazy (n-1) (down maj3 (faster (5/3) seed))) ---------------------------------------- ---------------------------------------- -- lists applyRhythm ns = line (map (\n -> e n & s (n & n)) ns) rhythms = applyRhythm [c4, d4, e4, f4, e4, d4, c4] & h c4 ---------------------------------------- arpeggiate ns = line (map e (ns ++ drop 1 (reverse ns))) & q r & chord ns arpeggio = arpeggiate [c3, e3, g3, c4, e4, g4, c5] ----------------------------------------