Mercurial > hg > syncopation-dataset
view Syncopation models/syncopation.py @ 35:3a878de00d19
made some small changes to files
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Mon, 13 Apr 2015 17:43:18 +0100 |
parents | 5de1cb45c145 |
children | cc38b3047ed9 |
line wrap: on
line source
''' Author: Chunyang Song Institution: Centre for Digital Music, Queen Mary University of London ''' def sync_perbar_permodel (model, bar, parameters=None): return model.get_syncopation(bar, parameters) def syncopation_barlist_permodel(model, source, parameters=None): total = 0 numberOfNotes = 0 for bar in barlist: if sync_perbar_permodel(model, bar, parameters) != None: total += sync_perbar_permodel(model, bar, parameters) numberOfNotes += sum(bar.get_binary_sequence()) else: print 'Bar %d cannot be measured, returning None.' % barlist.index(bar) if model is WNBD: total = (float) total/ numberOfNotes # def sync_perbar_permodel(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) # # The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm. # # For monorhythms, all prime factors of the length of minimum time-span representation of this sequence are # # elements of its subdivision_seq, otherwise it is polyrhythm; # # e.g. prime_factors of polyrhythm 100100101010 in 4/4 is [2,3] but subdivision_seq = [1,2,2] for 4/4 # 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): # 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 # 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_all(rhythm, model, timesig, subdivision_seq = None, weight_seq = None, L_max = 5, strong_beat_level = None): # syncopation = 0 # # Chope rhythm into seq # # ... # for (seq_perbar in seq): # sync_perbar = syncopation_perbar(seq_perbar,model, timesig, subdivision_seq, weight_seq, L_max, strong_beat_level) # if sync_perbar != None: # syncopation = syncopation + sync_perbar # return syncopation