Mercurial > hg > syncopation-dataset
comparison 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 |
comparison
equal
deleted
inserted
replaced
20:b959c2acb927 | 21:b6daddeefda9 |
---|---|
2 Author: Chunyang Song | 2 Author: Chunyang Song |
3 Institution: Centre for Digital Music, Queen Mary University of London | 3 Institution: Centre for Digital Music, Queen Mary University of London |
4 | 4 |
5 ''' | 5 ''' |
6 | 6 |
7 def sync_perbar_permodel (model, bar, parameters): | |
8 return model.get_syncopation(bar, parameters) | |
7 | 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): | 10 # def syncopation_barlist_permodel(model, barlist, parameters): |
9 syncopation = None | |
10 | 11 |
11 if seq == None or model == None: | 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): |
12 print 'Error: please indicate rhythm sequence and syncopation model.' | 13 # syncopation = None |
13 | 14 |
14 elif timesig == None and subdivision_seq == None: | 15 # if seq == None or model == None: |
15 print 'Error: please indicate either time signature or subdivision sequence.' | 16 # print 'Error: please indicate rhythm sequence and syncopation model.' |
17 | |
18 # elif timesig == None and subdivision_seq == None: | |
19 # print 'Error: please indicate either time signature or subdivision sequence.' | |
16 | 20 |
17 else: | 21 # else: |
18 while subdivision_seq == None: | 22 # while subdivision_seq == None: |
19 from basic_functions import get_subdivision_seq | 23 # from basic_functions import get_subdivision_seq |
20 subdivision_seq = get_subdivision_seq(timesig, L_max) | 24 # subdivision_seq = get_subdivision_seq(timesig, L_max) |
21 | 25 |
22 # The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm. | 26 # # 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 | 27 # # 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; | 28 # # 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 | 29 # # 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(): | 30 # def get_rhythm_category(): |
27 rhythm_category = 'mono' | 31 # rhythm_category = 'mono' |
28 from basic_functions import get_min_timeSpan, find_prime_factors | 32 # from basic_functions import get_min_timeSpan, find_prime_factors |
29 for f in find_prime_factors(len(get_min_timeSpan(seq))): | 33 # for f in find_prime_factors(len(get_min_timeSpan(seq))): |
30 if not (f in subdivision_seq): | 34 # if not (f in subdivision_seq): |
31 rhythm_category = 'poly' | 35 # rhythm_category = 'poly' |
32 break | 36 # break |
33 return rhythm_category | 37 # return rhythm_category |
34 | 38 |
35 rhythm_category = get_rhythm_category() | 39 # rhythm_category = get_rhythm_category() |
36 | 40 |
37 if model == 'LHL': | 41 # if model == 'LHL': |
38 import LHL | 42 # import LHL |
39 if weight_seq == None: | 43 # if weight_seq == None: |
40 weight_seq = range(0,-L_max,-1) | 44 # weight_seq = range(0,-L_max,-1) |
41 syncopation = LHL.get_syncopation(seq, subdivision_seq, weight_seq, prebar_seq, rhythm_category) | 45 # syncopation = LHL.get_syncopation(seq, subdivision_seq, weight_seq, prebar_seq, rhythm_category) |
42 elif model == 'PRS': | 46 # elif model == 'PRS': |
43 import PRS | 47 # import PRS |
44 syncopation = PRS.get_syncopation(seq, subdivision_seq, postbar_seq, rhythm_category) | 48 # syncopation = PRS.get_syncopation(seq, subdivision_seq, postbar_seq, rhythm_category) |
45 elif model == 'TMC': | 49 # elif model == 'TMC': |
46 import TMC | 50 # import TMC |
47 if weight_seq == None: | 51 # if weight_seq == None: |
48 weight_seq = range(L_max+1,0,-1) | 52 # weight_seq = range(L_max+1,0,-1) |
49 syncopation = TMC.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) | 53 # syncopation = TMC.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) |
50 elif model == 'SG': | 54 # elif model == 'SG': |
51 import SG | 55 # import SG |
52 if weight_seq == None: | 56 # if weight_seq == None: |
53 weight_seq = range(L_max+1) | 57 # weight_seq = range(L_max+1) |
54 syncopation = SG.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) | 58 # syncopation = SG.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) |
55 elif model == 'KTH': | 59 # elif model == 'KTH': |
56 import KTH | 60 # import KTH |
57 syncopation = KTH.get_syncopation(seq, timesig, postbar_seq) | 61 # syncopation = KTH.get_syncopation(seq, timesig, postbar_seq) |
58 elif model == 'TOB': | 62 # elif model == 'TOB': |
59 import TOB | 63 # import TOB |
60 syncopation = TOB.get_syncopation(seq) | 64 # syncopation = TOB.get_syncopation(seq) |
61 elif model == 'WNBD': | 65 # elif model == 'WNBD': |
62 import WNBD | 66 # import WNBD |
63 if strong_beat_level == None: | 67 # if strong_beat_level == None: |
64 if timesig == '4/4': | 68 # if timesig == '4/4': |
65 strong_beat_level = 2 | 69 # strong_beat_level = 2 |
66 else: | 70 # else: |
67 strong_beat_level = 1 | 71 # strong_beat_level = 1 |
68 syncopation = WNBD.get_syncopation(seq, subdivision_seq, strong_beat_level, postbar_seq) | 72 # syncopation = WNBD.get_syncopation(seq, subdivision_seq, strong_beat_level, postbar_seq) |
69 | 73 |
70 else: | 74 # else: |
71 print 'Error: undefined syncopation model.' | 75 # print 'Error: undefined syncopation model.' |
72 | 76 |
73 return syncopation | 77 # return syncopation |
74 | 78 |
75 # def syncopation_all(rhythm, model, timesig, subdivision_seq = None, weight_seq = None, L_max = 5, strong_beat_level = None): | 79 # def syncopation_all(rhythm, model, timesig, subdivision_seq = None, weight_seq = None, L_max = 5, strong_beat_level = None): |
76 # syncopation = 0 | 80 # syncopation = 0 |
77 # # Chope rhythm into seq | 81 # # Chope rhythm into seq |
78 # # ... | 82 # # ... |