annotate Syncopation models/syncopation.py @ 9:c2843ef4de2c

changing filenames to Python conventions
author csong
date Fri, 03 Apr 2015 11:41:01 +0100
parents
children a3ed7d2b57d8 bc3b9022ebc4
rev   line source
csong@9 1 '''
csong@9 2 Author: Chunyang Song
csong@9 3 Institution: Centre for Digital Music, Queen Mary University of London
csong@9 4
csong@9 5 '''
csong@9 6
csong@9 7
csong@9 8 def sync_perbar_permodel(seq, model, timesig = None, subdivision_seq = None, weight_seq = None, L_max = 5, prebar_seq = None, postbar_seq = None, strong_beat_level = None):
csong@9 9 syncopation = None
csong@9 10
csong@9 11 if seq == None or model == None:
csong@9 12 print 'Error: please indicate rhythm sequence and syncopation model.'
csong@9 13
csong@9 14 elif timesig == None and subdivision_seq == None:
csong@9 15 print 'Error: please indicate either time signature or subdivision sequence.'
csong@9 16
csong@9 17 else:
csong@9 18 while subdivision_seq == None:
csong@9 19 from BasicFuncs import get_subdivision_seq
csong@9 20 subdivision_seq = get_subdivision_seq(timesig, L_max)
csong@9 21
csong@9 22 # The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm.
csong@9 23 # For monorhythms, all prime factors of the length of minimum time-span representation of this sequence are
csong@9 24 # elements of its subdivision_seq, otherwise it is polyrhythm;
csong@9 25 # e.g. prime_factors of polyrhythm 100100101010 in 4/4 is [2,3] but subdivision_seq = [1,2,2] for 4/4
csong@9 26 def get_rhythm_category():
csong@9 27 rhythm_category = 'mono'
csong@9 28 from BasicFuncs import get_min_timeSpan, find_prime_factors
csong@9 29 for f in find_prime_factors(len(get_min_timeSpan(seq))):
csong@9 30 if not (f in subdivision_seq):
csong@9 31 rhythm_category = 'poly'
csong@9 32 break
csong@9 33 return rhythm_category
csong@9 34
csong@9 35 rhythm_category = get_rhythm_category()
csong@9 36
csong@9 37 if model == 'LHL':
csong@9 38 import LHL
csong@9 39 if weight_seq == None:
csong@9 40 weight_seq = range(0,-L_max,-1)
csong@9 41 syncopation = LHL.get_syncopation(seq, subdivision_seq, weight_seq, prebar_seq, rhythm_category)
csong@9 42 elif model == 'PRS':
csong@9 43 import PRS
csong@9 44 syncopation = PRS.get_syncopation(seq, subdivision_seq, postbar_seq, rhythm_category)
csong@9 45 elif model == 'TMC':
csong@9 46 import TMC
csong@9 47 if weight_seq == None:
csong@9 48 weight_seq = range(L_max+1,0,-1)
csong@9 49 syncopation = TMC.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category)
csong@9 50 elif model == 'SG':
csong@9 51 import SG
csong@9 52 if weight_seq == None:
csong@9 53 weight_seq = range(L_max+1)
csong@9 54 syncopation = SG.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category)
csong@9 55 elif model == 'KTH':
csong@9 56 import KTH
csong@9 57 syncopation = KTH.get_syncopation(seq, timesig, postbar_seq)
csong@9 58 elif model == 'TOB':
csong@9 59 import TOB
csong@9 60 syncopation = TOB.get_syncopation(seq)
csong@9 61 elif model == 'WNBD':
csong@9 62 import WNBD
csong@9 63 if strong_beat_level == None:
csong@9 64 if timesig == '4/4':
csong@9 65 strong_beat_level = 2
csong@9 66 else:
csong@9 67 strong_beat_level = 1
csong@9 68 syncopation = WNBD.get_syncopation(seq, subdivision_seq, strong_beat_level, postbar_seq)
csong@9 69
csong@9 70 else:
csong@9 71 print 'Error: undefined syncopation model.'
csong@9 72
csong@9 73 return syncopation
csong@9 74
csong@9 75 # def syncopation_all(rhythm, model, timesig, subdivision_seq = None, weight_seq = None, L_max = 5, strong_beat_level = None):
csong@9 76 # syncopation = 0
csong@9 77 # # Chope rhythm into seq
csong@9 78 # # ...
csong@9 79
csong@9 80 # for (seq_perbar in seq):
csong@9 81 # sync_perbar = syncopation_perbar(seq_perbar,model, timesig, subdivision_seq, weight_seq, L_max, strong_beat_level)
csong@9 82 # if sync_perbar != None:
csong@9 83 # syncopation = syncopation + sync_perbar
csong@9 84
csong@9 85 # return syncopation
csong@9 86
csong@9 87
csong@9 88 ### TESTING
csong@9 89 # clave = [1,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0]
csong@9 90 # bf = [0,0,0,1,0,0,0,0,0,0,1,0]
csong@9 91 # rhythm = [0,1,0,1,0,1,0,1]
csong@9 92 # classic1 = [1,0,1,1]*3 + [1,0,0,0]
csong@9 93 # classic2 = [1,0,0,1]*3 + [1,0,0,0]
csong@9 94 # shiko = [1,0,1,1,0,1,1,0]
csong@9 95 # rumba = [1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0]
csong@9 96 # soukous = [1,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0]
csong@9 97 # gahu = [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0]
csong@9 98 # bossanova = [1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0]
csong@9 99
csong@9 100 # classic12 = [1,0,0,1,1,1,1,0,0,1,1,1]
csong@9 101 # soli = [1,0,1,0,1,0,1,0,1,1,0,1]
csong@9 102
csong@9 103 # print sync_perbar(seq = clave, model = 'WNBD', timesig = '4/4')