# HG changeset patch # User csong # Date 1428082690 -3600 # Node ID 43fa04812800b283fea8661d9be55084e88ff340 # Parent a5a26d2cff409810760a3ab0c071c5164d2c5564 Added TimeSignature class diff -r a5a26d2cff40 -r 43fa04812800 Syncopation models/music_objects.py --- a/Syncopation models/music_objects.py Fri Apr 03 17:28:26 2015 +0100 +++ b/Syncopation models/music_objects.py Fri Apr 03 18:38:10 2015 +0100 @@ -63,7 +63,7 @@ self.tpq = ticksPerQuarter self.qpm = qpmTempo - self.timeSignature = timeSignature + self.timeSignature = TimeSignature(timeSignature) self.nextBar = nextBar self.prevBar = prevBar @@ -93,7 +93,7 @@ self.prevBar = bar def get_subdivision_sequence(self): - return ParameterSetter.get_subdivision_seq(self.timeSignature) + return self.timeSignature.get_subdivision_sequence() def get_beat_level(self): return ParameterSetter.get_beat_level(self.timeSignature) @@ -105,3 +105,25 @@ # return the length of a bar in time units return None # NEED TO IMPLEMENT +class TimeSignature(): + def __init__(self, inputString): + if inputString in parameter_setter.readTimesig(): + self.tsString = inputString + else: + print "Error: undefined time-signature ", inputString + raise NullTimeSignatureError + + def get_subdivision_sequence(self): + return parameter_setter.timesigBase[self.tsString][0] + + def get_beat_level(self): + return parameter_setter.timesigBase[self.tsString][1] + + def get_numerator(self): + return int(self.tsString.split('/')[0]) + + def get_denominator(self): + return int(self.tsString.split('/')[1]) + + +