annotate Syncopation models/syncopation.py @ 21:b6daddeefda9

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