1
2
3
4 """
5 SerialMelody.
6
7 A test composition module, as a(nother) 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 baseComp
16 from constants import *
17
19 """
20 A simple test composition module. Generates melodies based on serial technique for the parameters pitch, delta and duration.
21 """
22
24 """
25 Class contructor.
26
27 @param self: The object pointer.
28 """
29 self.eventCaller = eventCaller
30 """Pointer to the event caller."""
31 self.isPlaying = False
32 """A flag indicating if the melody should continue playing or not."""
33 self.pitches = [60,62,64,65,67,69,71,72]
34 """The original pitch series."""
35 self.deltaTimes = [1,2]
36 """The collection of (relative) delta times to select from."""
37 self.durations = [1,0.8,0.3]
38 """The collection of (relative) durations to select from."""
39 self.pan = 0.5
40 """The stereo pan value."""
41 self.reverb = 0.2
42 """The reverb send value."""
43 self.instrument = 1
44 """The csound instrument for playback of events."""
45 self.currentPitches = []
46 """The temporary pitch series, updated as values are being used for note events."""
47 self.currentDeltaTimes = []
48 """The temporary delta time series, updated as values are being used for note events."""
49 self.currentDurations = []
50 """The temporary duration series, updated as values are being used for note events."""
51
52
54 """
55 Generate pitch, duration and delta time for the next note in the melody.
56
57 @param self: The object pointer.
58 @return: Parameters for the note event.
59 - instrument: The csound instrument for playback of the note event.
60 - amp: The amp of the note, in decibel (dbfs)
61 - pitch: The pitch of the note, in note number format.
62 - 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.
63 - duration: The duration of the note, relative to the delta time (so that a duration of 1 generates a legato note).
64 - 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.
65 - reverb: The reverb send amount for the note, in the range 0.0 to 1.0.
66 """
67 if self.currentPitches == []:
68 self.currentPitches = copy.copy(self.pitches)
69 pitch = self.currentPitches.pop(0)
70 if self.currentDeltaTimes == []:
71 self.currentDeltaTimes = copy.copy(self.deltaTimes)
72 delta = self.currentDeltaTimes.pop(0)
73 if self.currentDurations == []:
74 self.currentDurations = copy.copy(self.durations)
75 duration = self.currentDurations.pop(0)
76 amp = -10
77 return self.instrument, amp, pitch, delta, duration, self.pan, self.reverb
78
79
81 """
82 Set a class variable.
83
84 @param self: The object pointer.
85 @param parameter: The variable name.
86 @param value: The value to set the variable to.
87 """
88 if parameter == 'pitches': self.pitches = value
89 elif parameter == 'deltaTimes': self.deltaTimes = value
90 elif parameter == 'durations': self.durations = value
91 elif parameter == 'pan': self.pan = value
92 elif parameter == 'reverb': self.reverb = value
93 elif parameter == 'instrument': self.instrument = value
94 else: print 'randMelody: parameter named'%parameter
95
96
97 if __name__ == '__main__':
98 s = SerialMelody()
99 """Instance of the composition class."""
100 print s.getData()
101 print s.getData()
102 print s.getData()
103 print s.getData()
104 print s.getData()
105 print s.getData()
106 print s.getData()
107 print s.getData()
108 print s.getData()
109