From 0c8e687ce284d7599b9bfb7c578b0fc7fb32c493 Mon Sep 17 00:00:00 2001 From: Rafael Ortiz Date: Fri, 25 Feb 2011 21:40:07 +0000 Subject: fixing simlimking build error --- (limited to 'TamTamEdit.activity/common/Generation/VariationRythm.py') diff --git a/TamTamEdit.activity/common/Generation/VariationRythm.py b/TamTamEdit.activity/common/Generation/VariationRythm.py new file mode 100644 index 0000000..5fb6111 --- /dev/null +++ b/TamTamEdit.activity/common/Generation/VariationRythm.py @@ -0,0 +1,74 @@ +import random + +import common.Config as Config + +# remplacer position dans notesList par l'attribut de CSoundNote +class RythmShuffle: + + def getNewList( self, notesList, nbeats ): + self.barLength = Config.TICKS_PER_BEAT * nbeats + self.onsetDelta = 0 + self.newOnsetList = [] + self.oldDuration = [] + self.newDuration = [] + self.extractOnsetValue(notesList) + + self.newOnsetList = random.sample(range(len(self.originalList)), len(self.originalList)) + self.getOldDuration(notesList) + self.getNewDuration(notesList) + + for i in range(len(notesList)): + notesList[i].onset = self.onsetDelta + notesList[i].duration = self.oldDuration[i] * self.newDuration[i] + self.onsetDelta = self.onsetDelta + self.originalList[self.newOnsetList[i]] + + return notesList + + def extractOnsetValue( self, notesList ): + self.originalList = [] + for note in notesList: + self.originalList.append(note.onset) + + for i in range(len(self.originalList) -1): + self.originalList[i] = self.originalList[i+1] - self.originalList[i] + + self.originalList[-1] = self.barLength - (self.originalList[-1] % self.barLength) + + def getOldDuration( self, notesList ): + for i in range(len(notesList)): + if (i+1) == len(notesList): + self.oldDuration.append(notesList[i].duration / (self.barLength - (notesList[i].onset % self.barLength))) + else: + self.oldDuration.append(notesList[i].duration / (notesList[i+1].onset - notesList[i].onset)) + + def getNewDuration( self, notesList ): + for i in self.newOnsetList: + if (i+1) == len(notesList): + self.newDuration.append(self.barLength - (notesList[i].onset % self.barLength)) + else: + self.newDuration.append(notesList[i+1].onset - notesList[i].onset) + +class RythmReverse( RythmShuffle ): + + def getNewList( self, notesList, nbeats ): + self.barLength = Config.TICKS_PER_BEAT * nbeats + self.onsetDelta = 0 + self.newOnsetList = [] + self.oldDuration = [] + self.newDuration = [] + RythmShuffle.extractOnsetValue( self, notesList ) + + for i in range( len( self.originalList ) ): + self.newOnsetList.append( i ) + + self.newOnsetList.reverse() + + RythmShuffle.getOldDuration( self, notesList ) + RythmShuffle.getNewDuration( self, notesList ) + + for i in range(len(notesList)): + notesList[i].onset = self.onsetDelta + notesList[i].duration = self.oldDuration[i] * self.newDuration[i] + self.onsetDelta = self.onsetDelta + self.originalList[self.newOnsetList[i]] + + return notesList -- cgit v0.9.1