Mercurial > hg > syncopation-dataset
view Syncopation models/main.py @ 1:b2da092dc2e0
The consolidated syncopation software. Have finished individual model and basic functions. Need to revise the coding in main.py, and add rhythm-input interface.
author | Chunyang Song <csong@eecs.qmul.ac.uk> |
---|---|
date | Sun, 05 Oct 2014 21:52:41 +0100 |
parents | |
children | 031e2ccb1fb6 |
line wrap: on
line source
def syncopation_perbar(seq, model, timesig = None, subdivision_seq = None, weight_seq = None, L_max = 5, prebar_seq = None, postbar_seq = None, strong_beat_level = None): syncopation = None if seq == None or model == None: print 'Error: please indicate rhythm sequence and syncopation model.' elif timesig == None and subdivision_seq == None: print 'Error: please indicate either time signature or subdivision sequence.' else: while subdivision_seq == None: from basic_functions import get_subdivision_seq subdivision_seq = get_subdivision_seq(timesig, L_max) # polyrhythm detection: def get_rhythm_category(): rhythm_category = 'mono' from basic_functions import get_min_timeSpan, find_prime_factors for f in find_prime_factors(len(get_min_timeSpan(seq))): if not (f in subdivision_seq): # if one of the prime factors of this sequence is not in subdivision_seq rhythm_category = 'poly' break return rhythm_category rhythm_category = get_rhythm_category() if model == 'LHL': import LHL if weight_seq == None: weight_seq = range(0,-L_max,-1) syncopation = LHL.get_syncopation(seq, subdivision_seq, weight_seq, prebar_seq, rhythm_category) elif model == 'PRS': import PRS syncopation = PRS.get_syncopation(seq, subdivision_seq, postbar_seq, rhythm_category) elif model == 'TMC': import TMC if weight_seq == None: weight_seq = range(L_max+1,0,-1) syncopation = TMC.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) elif model == 'SG': import SG if weight_seq == None: weight_seq = range(L_max+1) syncopation = SG.get_syncopation(seq, subdivision_seq, weight_seq, L_max, rhythm_category) elif model == 'KTH': import KTH syncopation = KTH.get_syncopation(seq, timesig, postbar_seq) elif model == 'TOB': import TOB syncopation = TOB.get_syncopation(seq) elif model == 'WNBD': import WNBD # based on normalising per bar so far, should be normalising whole rhythm... if strong_beat_level == None: if timesig == '4/4': strong_beat_level = 2 else: strong_beat_level = 1 syncopation = WNBD.get_syncopation(seq, subdivision_seq, strong_beat_level, postbar_seq) else: print 'Error: undefined syncopation model.' return syncopation #def syncopation(rhythm, model, timesig, subdivision_seq = None, weight_seq = None, L_max = 5, strong_beat_level = None): ### TESTING clave = [1,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0] bf = [0,0,0,1,0,0,0,0,0,0,1,0] rhythm = [0,1,0,1,0,1,0,1] classic1 = [1,0,1,1]*3 + [1,0,0,0] classic2 = [1,0,0,1]*3 + [1,0,0,0] shiko = [1,0,1,1,0,1,1,0] rumba = [1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0] soukous = [1,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0] gahu = [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0] bossanova = [1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0] classic12 = [1,0,0,1,1,1,1,0,0,1,1,1] soli = [1,0,1,0,1,0,1,0,1,1,0,1] print syncopation_perbar(seq = clave, model = 'TMC', timesig = '4/4')