Mercurial > hg > syncopation-dataset
diff 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 |
line wrap: on
line diff
--- a/Syncopation models/parameter_setter.py Sun Apr 12 15:55:12 2015 +0100 +++ b/Syncopation models/parameter_setter.py Sun Apr 12 22:34:35 2015 +0100 @@ -3,10 +3,12 @@ Institution: Centre for Digital Music, Queen Mary University of London ''' -# Set the parameters: subdivision_seq, weight_seq, L_max, strong_beat_level +# Set the parameters: time-signature, subdivision-sequence, strong-beat-level; Lmax; weight-sequence +# Important condition: Lmax needs to be no less than the length of subdivision-sequence and the length of weight-sequence + # {'key': time-signature} : -# {'value': [subdivision_seq, theoretical beat-level represented by index in the subdivision_seq list]} +# {'value': [subdivision-sequence, theoretical beat-level represented by index in the subdivision-sequence list]} timeSignatureBase = { '2/2': [[1,2,2,2,2,2],1], '3/2': [[1,3,2,2,2,2],1], @@ -23,6 +25,7 @@ '12/8':[[1,2,2,3,2,2],2], } + def add_time_signature(timeSignature, subdivisionSequence, beatLevel): if is_time_signature_valid(timeSignature,subdivisionSequence,beatLevel): if timeSignature in timesigBase: @@ -69,16 +72,44 @@ for timeSignature, settings in data.items(): print timeSignature, settings -# def get_subdivision_seq(timeSignature): -# if timeSignature in readTimesig(): -# return timesigBase[timesig][0] -# else: -# print 'Error: the subdivision sequence for this time-signature is not defined.' -# return None -# def get_beat_level(timesig): -# if timesig in readTimesig(): -# return timesigBase[timesig][1] -# else: -# print 'Error: the subdivision sequence for this time-signature is not defined.' -# return None +def are_parameters_valid(Lmax, weightSequence, subdivisionSequence): + + # is_Lmax_valid() checks: + # 1. if Lmax is a non-negative integer + # 2. if Lmax is higher than the length of weightSequence and subdivisionSequence + def is_Lmax_valid(): + isValid = False + if isinstance(Lmax,int) and Lmax > 0: + if Lmax <= len(subdivisionSequence): + if Lmax <= len(weightSequence): + isValid = True + else: + print """Error: Lmax exceeds the length of subdivision-sequence. + Either reduce Lmax, or extend subdivision-sequence through updating time-signature (refer to update_time_signature function). """ + else: + print """Error: Lmax exceeds the length of weight-sequence. Either reduce Lmax, or provide a new weight-sequence + whose length is greater or equal to Lmax.""" + else: + print 'Error: Lmax needs to be a positive integer.' + return isValid + + # is_weight_sequence_valid() checks: + # 1. weightSequence is a list of numbers + # 2. the length of weightSequence is no less than Lmax + def is_weight_sequence_valid(): + isValid = False + if isinstance(weightSequence,list) and weightSequence == [i for i in weightSequence if isinstance(i,int)]: + if len(weightSequence) >= Lmax: + isValid = True + else: + print 'Error: the length of weight-sequence needs to be greater or equal to Lmax.' + else: + print 'Error: the weight-sequence needs to be a list of integers.' + return isValid + + + if is_Lmax_valid() and is_weight_sequence_valid(): + return True + else: + return False