''' GENERATING SCORES WITH O-L LINDENMAYER SYSTEMS IN MUSIC SPACES Copyright (C) 2005 by Michael Gogins All rights reserved. See: http://ruccas.org/pub/Gogins/parametric_composition_in_music_spaces.pdf ''' import psyco import math import sys from Numeric import * import CsoundVST import vrlindenmayer print __doc__ filename = 'c:/utah/home/mkg/projects/icmc2006-mkg/samplepiece' lindenmayer = vrlindenmayer.Lindenmayer(voiceCount=4, octaveCount=4, cubeOctaveCount=4, debug=False) lindenmayer.axiom = 'C=CM7 A Cv Cv [ B Cv Cv [ Pv0,1,0,2 B Cv Cv Cv Cv ] ] A Cv Cv' lindenmayer.generations = 3 lindenmayer.timeStep = 1. lindenmayer.rules['A'] = 'F F E D D E F E Cv Cv' # Move one voice at a time. lindenmayer.rules['B'] = 'Td1.125 Cv Va0,2 Cv Va1,3 Va2,2 Cv B Vs3,4 Cv B Va0,2 Cv Va1,3 Va2,4 Cv Va3,3 Cv Cv Tm1.125' # Continually modulating chord progression. lindenmayer.rules['D'] = 'Cv Pv1,2,1,2 Cv Pv2,3,2,3 Cv D Cv' # Activity within a chord. lindenmayer.rules['E'] = 'Cv [ Td2. Vs3,12 Ca Vs2,12 Ca Vs1,12, Ca Vs0,12 Vs1,12 Vs2,12 Vs3,12 Ca E Tm2. ] Cv' # Continually modulating chord progression. lindenmayer.rules['F'] = 'Cv Pv1,2,1,2 Cv Pv5,5,5,6 Cv Pv2,2,3,2 Cv F Cv' lindenmayer.generate() model = CsoundVST.MusicModel() model.setCppSound(csound) # Place the ChordLindenmayer node inside a Random node to randomize velocity and pan, # place the Random node inside a Rescale node, # and place the Rescale node inside the MusicModel. random = CsoundVST.Random() random.createDistribution("uniform_01") random.setElement(CsoundVST.Event.PAN, 11, 1) rescale = CsoundVST.Rescale() rescale.setRescale(CsoundVST.Event.INSTRUMENT, 1, 0, 2., 5.) rescale.setRescale(CsoundVST.Event.KEY, 1, 0, 48., 0.) rescale.setRescale(CsoundVST.Event.VELOCITY, 1, 1, 60., 9.) rescale.setRescale(CsoundVST.Event.PAN, 1, 1, -0.25, 1.5) random.addChild(lindenmayer) rescale.addChild(random) model.addChild(rescale) model.generate() model.getScore().save(filename + '.mid') instruments = [25,12,15,10,20] instruments = [25,10,25,12,25] instruments = [25,25,25,25,25] instruments = [5,5,5,5,5] for event in model.getScore(): #event.setInstrument(instruments[int(event.getInstrument())]) #event.setDuration(math.fabs(event.getDuration() * 2.0)) print event.toString() print 'Filename:', filename model.setConformPitches(False) model.setTonesPerOctave(12.0) csound.load('c:/utah/home/mkg/projects/music/library/orchestra.csd') csound.setCommand("csound -m7 -RWdfo " + filename + ".wav " + filename + ".orc " + filename + ".sco") csound.setFilename(filename) duration = model.getScore().getDuration() print 'duration =',duration model.createCsoundScore(''' ; SoundFonts ; to Chorus i 1 0 0 100 200 0.2 ; to Reverb i 1 0 0 100 210 0.1 ; to Output i 1 0 0 100 220 1 ; to Chorus i 1 0 0 4 200 0.2 ; to Reverb i 1 0 0 4 210 0.1 ; to Output i 1 0 0 4 220 1 ; to Chorus i 1 0 0 5 200 0.2 ; to Reverb i 1 0 0 5 210 0.2 ; to Output i 1 0 0 5 220 1 ; to Chorus i 1 0 0 6 200 0.2 ; to Reverb i 1 0 0 6 210 0.2 ; to Output i 1 0 0 6 220 1 ; to Chorus i 1 0 0 7 200 0.2 ; to Reverb i 1 0 0 7 210 0.2 ; to Output i 1 0 0 7 220 1 ; to Chorus i 1 0 0 8 200 0.2 ; to Reverb i 1 0 0 8 210 0.2 ; to Output i 1 0 0 8 220 1 ; to Chorus i 1 0 0 9 200 0.2 ; to Reverb i 1 0 0 9 210 0.5 ; to Output i 1 0 0 9 220 1 ; to Chorus i 1 0 0 10 200 0.2 ; to Reverb i 1 0 0 10 210 0.2 ; to Output i 1 0 0 10 220 3.0 ; to Chorus i 1 0 0 11 200 0.2 ; to Reverb i 1 0 0 11 210 0.2 ; to Output i 1 0 0 11 220 1 ; to Chorus i 1 0 0 12 200 .2 ; to Reverb i 1 0 0 12 210 .2 ; to Output i 1 0 0 12 220 2 ; to Chorus i 1 0 0 13 200 .2 ; to Reverb i 1 0 0 13 210 .1 ; to Output i 1 0 0 13 220 1 ; to Chorus i 1 0 0 14 200 .2 ; to Reverb i 1 0 0 14 210 .1 ; to Output i 1 0 0 14 220 1 ; to Chorus i 1 0 0 15 200 .2 ; to Reverb i 1 0 0 15 210 .1 ; to Output i 1 0 0 15 220 1 ; to Chorus i 1 0 0 16 200 .2 ; to Reverb i 1 0 0 16 210 .1 ; to Output i 1 0 0 16 220 1 ; to Chorus i 1 0 0 17 200 .2 ; to Reverb i 1 0 0 17 210 .1 ; to Output i 1 0 0 17 220 1 ; to Chorus i 1 0 0 17 200 .2 ; to Reverb i 1 0 0 17 210 .1 ; to Output i 1 0 0 17 220 1 ; to Chorus i 1 0 0 18 200 .2 ; to Reverb i 1 0 0 18 210 .1 ; to Output i 1 0 0 18 220 1 ; to Chorus i 1 0 0 19 200 .2 ; to Reverb i 1 0 0 19 210 .1 ; to Output i 1 0 0 19 220 1 ; to Chorus i 1 0 0 20 200 .2 ; to Reverg i 1 0 0 20 210 .1 ; to Output i 1 0 0 20 220 1 ; to Chorus i 1 0 0 21 200 .2 ; to Reverb i 1 0 0 21 210 .1 ; to Output i 1 0 0 21 220 1 ; to Chorus i 1 0 0 25 200 .2 ; to Reverb i 1 0 0 25 210 .1 ; to Output i 1 0 0 25 220 1 ; to Chorus i 1 0 0 26 200 .2 ; to Reverb i 1 0 0 26 210 .1 ; to Output i 1 0 0 26 220 1 ; to Chorus i 1 0 0 27 200 .2 ; to Reverb i 1 0 0 27 210 .1 ; to Output i 1 0 0 27 220 1 ; to Chorus i 1 0 0 28 200 .2 ; to Reverb i 1 0 0 28 210 .1 ; to Output i 1 0 0 28 220 1 ; to Chorus i 1 0 0 29 200 .2 ; to Reverb i 1 0 0 29 210 .1 ; to Output i 1 0 0 29 220 1 ; to Chorus i 1 0 0 34 200 .2 ; to Reverb i 1 0 0 34 210 .1 ; to Output i 1 0 0 34 220 1 ; to Chorus i 1 0 0 41 200 .2 ; to Reverb i 1 0 0 41 210 .1 ; to Output i 1 0 0 41 220 3.5 ; Chorus to Reverb i 1 0 0 200 210 0.05 ; Chorus to Output i 1 0 0 200 220 0.0 ; Reverb to Output i 1 0 0 210 220 0.3 ; SoundFont outout. i 100 0 [''' + str(duration) + '''+5] 80 ; Chorus. i 200 0 [''' + str(duration) + '''+5] 11 33 ; Reverb. i 210 0 [''' + str(duration) + '''+5] 0.90 0.3 15000 ; Master output. i 220 0 [''' + str(duration) + '''+5] 1 1 ''') #csound.perform()