1
2
3
4 """
5 RandMelody.
6
7 A test composition module, as a simple example of to use the software architecture "barebones".
8
9 @author: Øyvind Brandtsegg
10 @contact: obrandts@gmail.com
11 @license: GPL
12 """
13
14 import copy
15 import random
16 import baseComp
17 from constants import *
18
20 """
21 A simple test composition module. Generates melodies with limited random selection of pitch, delta, duration.
22 """
23
25 """
26 Class contructor.
27
28 @param self: The object pointer.
29 """
30 self.eventCaller = eventCaller
31 """Pointer to the event caller."""
32 self.isPlaying = False
33 """A flag indicating if the melody should continue playing or not."""
34 self.pitches = [60,62,64,65,67,69,71,72]
35 """The collection of pitches to select from."""
36 self.deltaTimes = [1,2]
37 """The collection of (relative) delta times to select from."""
38 self.durations = [1,0.8,0.3]
39 """The collection of (relative) durations to select from."""
40 self.pan = 0.5
41 """The stereo pan value."""
42 self.reverb = 0.2
43 """The reverb send value."""
44 self.instrument = 1
45 """The csound instrument for playback of events."""
46
47
49 """
50 Generate pitch, duration and delta time for the next note in the melody.
51
52 @param self: The object pointer.
53 @return: Parameters for the note event.
54 - instrument: The csound instrument for playback of the note event.
55 - amp: The amp of the note, in decibel (dbfs)
56 - pitch: The pitch of the note, in note number format.
57 - delta: Delta time, the time until the next event after this one. The value is relative to the current tempo so that a value of 1 equals one beat.
58 - duration: The duration of the note, relative to the delta time (so that a duration of 1 generates a legato note).
59 - pan: The stereo pan position of the note. A value of 0.0 is hard left, 0.5 is center, 1.0 is hard right.
60 - reverb: The reverb send amount for the note, in the range 0.0 to 1.0.
61 """
62 pitch = self.pitches[int(random.random()*len(self.pitches))]
63 delta = self.deltaTimes[int(random.random()*len(self.deltaTimes))]
64 duration = self.durations[int(random.random()*len(self.durations))]
65 amp = -10
66 return self.instrument, amp, pitch, delta, duration, self.pan, self.reverb
67
68
70 """
71 Set a class variable.
72
73 @param self: The object pointer.
74 @param parameter: The variable name.
75 @param value: The value to set the variable to.
76 """
77 if parameter == 'pitches': self.pitches = value
78 elif parameter == 'deltaTimes': self.deltaTimes = value
79 elif parameter == 'durations': self.durations = value
80 elif parameter == 'pan': self.pan = value
81 elif parameter == 'reverb': self.reverb = value
82 elif parameter == 'instrument': self.instrument = value
83 else: print 'randMelody: parameter named'%parameter
84
85
86 if __name__ == '__main__':
87 r = RandMelody()
88 """Instance of the composition class."""
89 print r.getData()
90 print r.getData()
91 print r.getData()
92