Mercurial > hg > syncopation-dataset
diff Syncopation models/TMC.py @ 28:5de1cb45c145
Parameters setting implemented.
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Sun, 12 Apr 2015 22:34:35 +0100 |
parents | df1e7c378ee0 |
children | f5abd2e8cafe |
line wrap: on
line diff
--- a/Syncopation models/TMC.py Sun Apr 12 15:55:12 2015 +0100 +++ b/Syncopation models/TMC.py Sun Apr 12 22:34:35 2015 +0100 @@ -5,6 +5,7 @@ ''' from basic_functions import get_H, ceiling, velocity_sequence_to_min_timespan, get_rhythm_category +from parameter_setter import are_parameters_valid # The get_metricity function calculates the metricity for a binary sequence with given sequence of metrical weights in a certain metrical level. def get_metricity(binarySequence, H): @@ -55,30 +56,31 @@ if get_rhythm_category(binarySequence, subdivisionSequence) == 'poly': print 'Warning: TMC model detects polyrhythms so returning None.' else: - binarySequence = velocity_sequence_to_min_timespan(binarySequence) # converting to the minimum time-span format + + # set the defaults + Lmax = 5 + weightSequence = range(Lmax+1,0,-1) # i.e. [6,5,4,3,2,1] + + if parameters!= None: + if 'Lmax' in parameters: + Lmax = parameters['Lmax'] + if 'W' in parameters: + weightSequence = parameters['W'] - # If the parameters are not given, use the default settings - if parameters == None: - Lmax = 5 - weightSequence = range(Lmax+1,0,-1) # i.e. [6,5,4,3,2,1] + if not are_parameters_valid(Lmax, weightSequence, subdivisionSequence): + print 'Error: the given parameters are not valid.' else: - if are_parameters_valid(parameters): - Lmax = parameters['Lmax'] - weightSequence = parameters['W'] - else: - pass - #raise InvalidParameterError + binarySequence = velocity_sequence_to_min_timespan(binarySequence) # converting to the minimum time-span format + L = find_L(binarySequence, Lmax, weightSequence, subdivisionSequence) + if L != None: + #? generate the metrical weights of the lowest level, + #? using the last matching_level number of elements in the weightSequence, to make sure the last element is 1 + H = get_H (weightSequence[-(L+1):], subdivisionSequence, L) + + metricity = get_metricity(binarySequence, H) # converting to binary sequence then calculate metricity + maxMetricity = get_max_metricity(binarySequence, H) - L = find_L(binarySequence, Lmax, weightSequence, subdivisionSequence) - if L != None: - #? generate the metrical weights of the lowest level, - #? using the last matching_level number of elements in the weightSequence, to make sure the last element is 1 - H = get_H (weightSequence[-(L+1):], subdivisionSequence, L) - - metricity = get_metricity(binarySequence, H) # converting to binary sequence then calculate metricity - maxMetricity = get_max_metricity(binarySequence, H) - - syncopation = maxMetricity - metricity + syncopation = maxMetricity - metricity return syncopation