Mercurial > hg > syncopation-dataset
comparison Syncopation models/synpy/syncopation.py @ 50:e71028851131
updating latex and bug fixes to main py files
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Mon, 27 Apr 2015 09:51:15 +0100 |
parents | 6e9154fc58df |
children |
comparison
equal
deleted
inserted
replaced
49:af3f32cebf8c | 50:e71028851131 |
---|---|
19 | 19 |
20 if isinstance(source, BarList): | 20 if isinstance(source, BarList): |
21 barlist = source | 21 barlist = source |
22 sourceType = "bar list" | 22 sourceType = "bar list" |
23 elif isinstance(source, Bar): | 23 elif isinstance(source, Bar): |
24 barlist = BarList().append(source) | 24 barlist = BarList() |
25 barlist.append(source) | |
26 print barlist | |
25 sourceType = "single bar" | 27 sourceType = "single bar" |
26 elif isinstance(source, basestring): | 28 elif isinstance(source, basestring): |
27 #treat source as a filename | 29 #treat source as a filename |
28 sourceType = source | 30 sourceType = source |
29 if source[-4:]==".mid": | 31 if source[-4:]==".mid": |
41 | 43 |
42 barsDiscarded=0 | 44 barsDiscarded=0 |
43 discardedlist = [] | 45 discardedlist = [] |
44 includedlist = [] | 46 includedlist = [] |
45 | 47 |
48 | |
46 if barlist!=None: | 49 if barlist!=None: |
47 for bar in barlist: | 50 for bar in barlist: |
48 if not bar.is_empty(): | 51 print 'processing bar %d' % (barlist.index(bar)+1) |
49 barSyncopation = sync_perbar_permodel(model, bar, parameters) | 52 |
50 else: | 53 barSyncopation = sync_perbar_permodel(model, bar, parameters) |
51 barSyncopation = None | 54 |
52 print 'Bar %d cannot be measured because it is empty, returning None.' % barlist.index(bar) | 55 |
56 # if not bar.is_empty(): | |
57 # barSyncopation = sync_perbar_permodel(model, bar, parameters) | |
58 # else: | |
59 # barSyncopation = None | |
60 # print 'Bar %d cannot be measured because it is empty, returning None.' % barlist.index(bar) | |
53 | 61 |
54 barResults.append(barSyncopation) | 62 barResults.append(barSyncopation) |
55 if barSyncopation != None: | 63 if barSyncopation != None: |
56 total += barSyncopation | 64 total += barSyncopation |
57 numberOfNotes += sum(bar.get_binary_sequence()) | 65 numberOfNotes += sum(bar.get_binary_sequence()) |
58 includedlist.append(barlist.index(bar)) | 66 includedlist.append(barlist.index(bar)) |
59 else: | 67 else: |
60 barsDiscarded += 1 | 68 barsDiscarded += 1 |
61 discardedlist.append(barlist.index(bar)) | 69 discardedlist.append(barlist.index(bar)) |
62 print 'Model could not measure bar %d, returning None.' % barlist.index(bar) | 70 print 'Model could not measure bar %d, returning None.' % (barlist.index(bar)+1) |
63 | 71 |
64 import WNBD | 72 import WNBD |
65 if model is WNBD: | 73 if model is WNBD: |
66 total = total / numberOfNotes | 74 total = total / numberOfNotes |
67 | 75 |
68 average = total / (len(barResults)-barsDiscarded) | 76 if len(barResults)>barsDiscarded: |
77 average = total / (len(barResults)-barsDiscarded) | |
78 else: | |
79 average = total | |
69 | 80 |
70 output = { | 81 output = { |
71 "model_name":model.__name__ , | 82 "model_name":model.__name__ , |
72 "summed_syncopation":total, | 83 "summed_syncopation":total, |
73 "mean_syncopation_per_bar":average, | 84 "mean_syncopation_per_bar":average, |
74 "source":sourceType, | 85 "source":sourceType, |
75 "number_of_bars":len(barResults), | 86 "number_of_bars":len(barResults), |
76 "number_of_bars_not_measured":barsDiscarded, | 87 "number_of_bars_not_measured":barsDiscarded, |
77 "bars_with_valid_output":includedlist, | 88 "bars_with_valid_output":includedlist, |
89 "bars_without_valid_output":discardedlist, | |
78 "syncopation_by_bar":barResults | 90 "syncopation_by_bar":barResults |
79 } | 91 } |
80 | 92 |
81 if outfile!=None: | 93 if outfile!=None: |
82 | 94 |