Mercurial > hg > syncopation-dataset
comparison Syncopation models/parameter_setter.py @ 28:5de1cb45c145
Parameters setting implemented.
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Sun, 12 Apr 2015 22:34:35 +0100 |
parents | b959c2acb927 |
children | 273450d5980a |
comparison
equal
deleted
inserted
replaced
27:ed29ed80635c | 28:5de1cb45c145 |
---|---|
1 ''' | 1 ''' |
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 # Set the parameters: subdivision_seq, weight_seq, L_max, strong_beat_level | 6 # Set the parameters: time-signature, subdivision-sequence, strong-beat-level; Lmax; weight-sequence |
7 # Important condition: Lmax needs to be no less than the length of subdivision-sequence and the length of weight-sequence | |
8 | |
7 | 9 |
8 # {'key': time-signature} : | 10 # {'key': time-signature} : |
9 # {'value': [subdivision_seq, theoretical beat-level represented by index in the subdivision_seq list]} | 11 # {'value': [subdivision-sequence, theoretical beat-level represented by index in the subdivision-sequence list]} |
10 timeSignatureBase = { | 12 timeSignatureBase = { |
11 '2/2': [[1,2,2,2,2,2],1], | 13 '2/2': [[1,2,2,2,2,2],1], |
12 '3/2': [[1,3,2,2,2,2],1], | 14 '3/2': [[1,3,2,2,2,2],1], |
13 '4/2': [[1,2,2,2,2,2],1], | 15 '4/2': [[1,2,2,2,2,2],1], |
14 '2/4': [[1,2,2,2,2,2],1], | 16 '2/4': [[1,2,2,2,2,2],1], |
20 '5/8': [[1,5,2,2,2,2],1], | 22 '5/8': [[1,5,2,2,2,2],1], |
21 '6/8': [[1,2,3,2,2,2],1], | 23 '6/8': [[1,2,3,2,2,2],1], |
22 '9/8': [[1,3,3,2,2,2],1], | 24 '9/8': [[1,3,3,2,2,2],1], |
23 '12/8':[[1,2,2,3,2,2],2], | 25 '12/8':[[1,2,2,3,2,2],2], |
24 } | 26 } |
27 | |
25 | 28 |
26 def add_time_signature(timeSignature, subdivisionSequence, beatLevel): | 29 def add_time_signature(timeSignature, subdivisionSequence, beatLevel): |
27 if is_time_signature_valid(timeSignature,subdivisionSequence,beatLevel): | 30 if is_time_signature_valid(timeSignature,subdivisionSequence,beatLevel): |
28 if timeSignature in timesigBase: | 31 if timeSignature in timesigBase: |
29 print 'This time-signature is existed already.' | 32 print 'This time-signature is existed already.' |
67 def print_time_signature_base(): | 70 def print_time_signature_base(): |
68 data = read_time_signature() | 71 data = read_time_signature() |
69 for timeSignature, settings in data.items(): | 72 for timeSignature, settings in data.items(): |
70 print timeSignature, settings | 73 print timeSignature, settings |
71 | 74 |
72 # def get_subdivision_seq(timeSignature): | |
73 # if timeSignature in readTimesig(): | |
74 # return timesigBase[timesig][0] | |
75 # else: | |
76 # print 'Error: the subdivision sequence for this time-signature is not defined.' | |
77 # return None | |
78 | 75 |
79 # def get_beat_level(timesig): | 76 def are_parameters_valid(Lmax, weightSequence, subdivisionSequence): |
80 # if timesig in readTimesig(): | 77 |
81 # return timesigBase[timesig][1] | 78 # is_Lmax_valid() checks: |
82 # else: | 79 # 1. if Lmax is a non-negative integer |
83 # print 'Error: the subdivision sequence for this time-signature is not defined.' | 80 # 2. if Lmax is higher than the length of weightSequence and subdivisionSequence |
84 # return None | 81 def is_Lmax_valid(): |
82 isValid = False | |
83 if isinstance(Lmax,int) and Lmax > 0: | |
84 if Lmax <= len(subdivisionSequence): | |
85 if Lmax <= len(weightSequence): | |
86 isValid = True | |
87 else: | |
88 print """Error: Lmax exceeds the length of subdivision-sequence. | |
89 Either reduce Lmax, or extend subdivision-sequence through updating time-signature (refer to update_time_signature function). """ | |
90 else: | |
91 print """Error: Lmax exceeds the length of weight-sequence. Either reduce Lmax, or provide a new weight-sequence | |
92 whose length is greater or equal to Lmax.""" | |
93 else: | |
94 print 'Error: Lmax needs to be a positive integer.' | |
95 return isValid | |
96 | |
97 # is_weight_sequence_valid() checks: | |
98 # 1. weightSequence is a list of numbers | |
99 # 2. the length of weightSequence is no less than Lmax | |
100 def is_weight_sequence_valid(): | |
101 isValid = False | |
102 if isinstance(weightSequence,list) and weightSequence == [i for i in weightSequence if isinstance(i,int)]: | |
103 if len(weightSequence) >= Lmax: | |
104 isValid = True | |
105 else: | |
106 print 'Error: the length of weight-sequence needs to be greater or equal to Lmax.' | |
107 else: | |
108 print 'Error: the weight-sequence needs to be a list of integers.' | |
109 return isValid | |
110 | |
111 | |
112 if is_Lmax_valid() and is_weight_sequence_valid(): | |
113 return True | |
114 else: | |
115 return False |