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