Mercurial > hg > syncopation-dataset
view Syncopation models/parameter_setter.py @ 15:4fb9c00e4ef0
fixing merge problem
author | csong |
---|---|
date | Fri, 03 Apr 2015 17:26:36 +0100 |
parents | c2843ef4de2c |
children | 9030967a05f8 |
line wrap: on
line source
''' Author: Chunyang Song Institution: Centre for Digital Music, Queen Mary University of London ''' # Set the parameters: subdivision_seq, weight_seq, L_max, strong_beat_level L_max = 5 # {'key': time-signature} : # {'value': [subdivision_seq, theoretical beat-level represented by index in the subdivision_seq list]} timesigBase = { '2/2': [[1,2,2,2,2],1], '3/2': [[1,3,2,2,2],1], '4/2': [[1,2,2,2,2],1], '2/4': [[1,2,2,2,2],1], '3/4': [[1,3,2,2,2],1], '4/4': [[1,2,2,2,2],2], '5/4': [[1,5,2,2,2],1], '7/4': [[1,7,2,2,2],1], '3/8': [[1,3,2,2,2],1], '5/8': [[1,5,2,2,2],1], '6/8': [[1,2,3,2,2],1], '9/8': [[1,3,3,2,2],1], '12/8':[[1,2,2,3,2],2], } def addTimesig(timesig, subdivision_seq, beat_level): if isTSValid(timesig,subdivision_seq,beat_level): if timesig in timesigBase: print 'This time-signature is existed already.' else: timesigBase[timesig] = [subdivision_seq, beat_level] writeTimesig() def updateTimesig(timesig, subdivision_seq, beat_level): if isTSValid(timesig,subdivision_seq,beat_level): if timesig in timesigBase: print 'Original settings for', timesig, ':',timesigBase[timesig] timesigBase[timesig] = [subdivision_seq, beat_level] print 'Changed into:',timesigBase[timesig] writeTimesig() def isTSValid(timesig, subdivision_seq, beat_level): isValid = False if ('/' not in timesig) or (not timesig.split('/')[0].isdigit()) or (not timesig.split('/')[1].isdigit()): print 'Error: invalid time-signature. Please indicate in the form of fraction, e.g. 4/4, 6/8 or 3/4.' elif subdivision_seq != [s for s in subdivision_seq if isinstance(s,int)]: print 'Error: invalid subdivision sequence. Please indicate in the form of list of numbers, e.g [1,2,2,2,2].' elif beat_level >= len(subdivision_seq): print 'Error: beat-level exceeds the range of subdivision sequence list.' else: isValid = True return isValid def writeTimesig(): import cPickle as pickle timesigFile = open('TimeSignature.pkl', 'wb') pickle.dump(timesigBase, timesigFile) timesigFile.close() def readTimesig(): import cPickle as pickle timesigFile = open('TimeSignature.pkl','rb') data = pickle.load(timesigFile) return data timesigFile.close() def viewTimesigBase(): data = readTimesig() for timesig, settings in data.items(): print timesig, settings def set_L_max(number): L_max = number def get_subdivision_seq(timesig): if timesig 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