Package comp :: Module baseComp
[hide private]
[frames] | no frames]

Source Code for Module comp.baseComp

 1  #!/usr/bin/python 
 2  # -*- coding: latin-1 -*- 
 3   
 4  """  
 5  BaseComp. 
 6   
 7  A base composition module, custom composition modules should inherit from this class. 
 8   
 9  @author: Øyvind Brandtsegg 
10  @contact: obrandts@gmail.com 
11  @license: GPL 
12  """ 
13   
14  from constants import * 
15   
16 -class BaseComp:
17 """ 18 A simple test composition module. Generates melodies with limited random selection of pitch, delta, duration. 19 """ 20
21 - def __init__(self):
22 """ 23 Class contructor. 24 25 @param self: The object pointer. 26 """ 27 28 self.isPlaying = False 29 """A flag indicating if the composition process should continue playing or not.""" 30 self.eventCaller = eventCaller 31 """Pointer to the event caller."""
32
33 - def perform(self, state=CONTINUE, beat=0):
34 """ 35 Handle the starting stopping or continuing of the composition process. 36 37 @param self: The object pointer. 38 @param state: The playback state, can be START, CONTINUE, STOP 39 @param beat: The current beat count of the timed queue (self.eventCaller.theTime), may be fractional. This parameter is optional; if it is not supplied, the current beat count (integer) will be polled from theTime. 40 """ 41 if beat == 0: beat = self.eventCaller.theTime.getCurrentBeat() 42 if state == START: # does nothing but put a randMelody event in the timed queue 43 if self.isPlaying != True: 44 self.eventCaller.theTime.insertQueue(beat+1, [self.perform]) 45 self.isPlaying = True 46 elif state == CONTINUE: # play a note and put a randMelody event in the timed queue 47 if self.isPlaying: 48 delta = self.playEvent() 49 self.eventCaller.theTime.insertQueue(beat+delta, [self.perform]) 50 elif state == STOP: # stop playing and remove any pending events for this instance of randMelody 51 self.isPlaying = False 52 for event in self.eventCaller.theTime.getQueue(): 53 if [self.perform] == event[1]: 54 self.eventCaller.theTime.removeEvent(event)
55
56 - def playEvent(self):
57 """ 58 Get event data from composition method, play event to Csound, insert "next" event in theTime queue. 59 60 @param self: The object pointer. 61 """ 62 instrument, amp, pitch, delta, duration, pan, reverb = self.getData() 63 duration = duration * (60.0/self.eventCaller.theTime.bpm) 64 self.eventCaller.csMessages.csoundInputMessage('i %i 0 %f %f %i %f %f'%(instrument, duration, amp, pitch, pan, reverb)) 65 return delta
66
67 - def getData(self):
68 """ 69 Get parameter values for the next event in the composition. You should override this method with something useful. 70 71 @param self: The object pointer. 72 """ 73 return 1,2,3,4,5,6,7
74