Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Generation/VariationPitch.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@activitycentral.org>2011-02-28 16:13:13 (GMT)
committer Aleksey Lim <alsroot@activitycentral.org>2011-02-28 16:13:13 (GMT)
commita0705d8ff9b25c1172e38925ec27bb28f9e5a1e9 (patch)
treed3a20dff1d1e8d196fab33530fb21dd470addef5 /common/Generation/VariationPitch.py
parent0c8e687ce284d7599b9bfb7c578b0fc7fb32c493 (diff)
Revert "fixing simlimking build error"
This reverts commit 0c8e687ce284d7599b9bfb7c578b0fc7fb32c493. Since common/ directory will be copied to .xo in setup.py anyway.
Diffstat (limited to 'common/Generation/VariationPitch.py')
-rw-r--r--common/Generation/VariationPitch.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/common/Generation/VariationPitch.py b/common/Generation/VariationPitch.py
new file mode 100644
index 0000000..5a2b151
--- /dev/null
+++ b/common/Generation/VariationPitch.py
@@ -0,0 +1,82 @@
+import random
+
+class PitchReverse:
+ def __init__( self ):
+ self.pitchList = []
+
+ def reorderPitch( self, notesList ):
+ self.extractOneValue(notesList)
+ self.pitchList.reverse()
+ for i in range(len(notesList)):
+ notesList[i].pitch = self.pitchList[i]
+
+ return notesList
+
+ def extractOneValue( self, notesList ):
+ self.pitchList = []
+ for note in notesList:
+ self.pitchList.append(note.pitch)
+
+class PitchSort( PitchReverse ):
+ def __init__( self ):
+ PitchReverse.__init__( self )
+
+ def reorderPitch( self, notesList ):
+ PitchReverse.extractOneValue(self, notesList)
+ self.pitchList.sort()
+ for i in range(len(notesList)):
+ notesList[i].pitch = self.pitchList[i]
+
+ return notesList
+
+class PitchShuffle( PitchReverse ):
+ def __init__( self ):
+ PitchReverse.__init__ ( self )
+
+ def reorderPitch( self, notesList ):
+ PitchReverse.extractOneValue(self, notesList)
+ self.pitchList = random.sample(self.pitchList, len(self.pitchList))
+ for i in range(len(notesList)):
+ notesList[i].pitch = self.pitchList[i]
+
+ return notesList
+
+class PitchMarkov:
+ def __init__( self ):
+ self.originalList = []
+
+ def getNewList( self, notesList, order=1 ):
+ self.playedNotes = []
+ self.extractOneValue( notesList, order )
+ self.playedNotes = self.originalList[:order]
+
+ for i in range(len(self.originalList) - order):
+ self.playedNotes.append(self.pickupNewValue(order))
+
+ for i in range(len(notesList)):
+ notesList[i].pitch = self.playedNotes[i]
+
+ return notesList
+
+ def extractOneValue( self, notesList, order ):
+ self.originalList = []
+ for note in notesList:
+ self.originalList.append(note.pitch)
+ for i in range(order):
+ self.originalList.append(self.originalList[i])
+
+ def pickupNewValue( self, order ):
+ condition = False
+ self.probTable = []
+ for ilist in range(len(self.originalList) - order):
+ for iord in range(order):
+ if self.playedNotes[len(self.playedNotes) - (iord + 1)] != self.originalList[(order - 1) + ilist - iord]:
+ condition = False
+ break
+ else:
+ condition = True
+
+ if condition == True:
+ self.probTable.append(self.originalList[ilist + order])
+
+ return self.probTable[random.randint(0, (len(self.probTable) - 1))]