Mercurial > hg > syncopation-dataset
comparison Syncopation models/LHL.py @ 38:cc38b3047ed9
updated syncopation.y to allow output of sync for a bar list
also fixed some problems in models and other modules
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Mon, 13 Apr 2015 23:06:49 +0100 |
parents | f5abd2e8cafe |
children |
comparison
equal
deleted
inserted
replaced
37:fefbe0d853c6 | 38:cc38b3047ed9 |
---|---|
5 | 5 |
6 from basic_functions import concatenate, repeat, subdivide, ceiling, get_rhythm_category | 6 from basic_functions import concatenate, repeat, subdivide, ceiling, get_rhythm_category |
7 from parameter_setter import are_parameters_valid | 7 from parameter_setter import are_parameters_valid |
8 | 8 |
9 terminalNodes = [] # Global variable, storing all the terminal nodes from recursive tree structure in time order | 9 terminalNodes = [] # Global variable, storing all the terminal nodes from recursive tree structure in time order |
10 | |
11 | |
10 | 12 |
11 # Each terminnal node contains two properties: its node type (note or rest) and its metrical weight. | 13 # Each terminnal node contains two properties: its node type (note or rest) and its metrical weight. |
12 class Node: | 14 class Node: |
13 def __init__(self,nodeType,metricalWeight): | 15 def __init__(self,nodeType,metricalWeight): |
14 self.nodeType = nodeType | 16 self.nodeType = nodeType |
55 | 57 |
56 if not are_parameters_valid(Lmax, weightSequence, subdivisionSequence): | 58 if not are_parameters_valid(Lmax, weightSequence, subdivisionSequence): |
57 print 'Error: the given parameters are not valid.' | 59 print 'Error: the given parameters are not valid.' |
58 else: | 60 else: |
59 # If there is rhythm in previous bar, process its tree structure | 61 # If there is rhythm in previous bar, process its tree structure |
60 if bar.get_previous_bar() != None: | 62 prevbar = bar.get_previous_bar() |
61 prebarBinarySequence = bar.get_previous_bar().get_binary_sequence() | 63 if prevbar != None and not prevbar.is_empty(): |
64 prebarBinarySequence = prevbar.get_binary_sequence() | |
62 recursive_tree(ceiling(prebarBinarySequence), subdivisionSequence, weightSequence, weightSequence[0],0) | 65 recursive_tree(ceiling(prebarBinarySequence), subdivisionSequence, weightSequence, weightSequence[0],0) |
63 | 66 |
64 # Only keep the last note-type node | 67 if len(terminalNodes)>0: |
65 while terminalNodes[-1].nodeType != 'N': | 68 # Only keep the last note-type node |
66 del terminalNodes[-1] | 69 while terminalNodes[-1].nodeType != 'N': |
67 del terminalNodes[0:-1] | 70 del terminalNodes[-1] |
71 del terminalNodes[0:-1] | |
68 | 72 |
69 # For the rhythm in the current bar, process its tree structure and store the terminal nodes | 73 # For the rhythm in the current bar, process its tree structure and store the terminal nodes |
70 recursive_tree(ceiling(binarySequence), subdivisionSequence, weightSequence, weightSequence[0],0) | 74 recursive_tree(ceiling(binarySequence), subdivisionSequence, weightSequence, weightSequence[0],0) |
71 | 75 |
72 # for t in terminalNodes: | 76 # for t in terminalNodes: |