def make_note_duration_ext(self, _input, _start, _end, elements): duration_time = gp.Duration( value=duration_values[elements[0].text]).time if elements[1].text == ".": duration_time *= 1.5 if elements[2].text == "t": duration_time *= (2 / 3) self.state.measure_time += duration_time self.state.note_duration = duration_time return elements
class ParserState(object): tuning_string_values = attr.ib(factory=list) measure_time = attr.ib(default=0) time_signature_denominator = attr.ib(default=gp.Duration()) marker = attr.ib(default=None) tempo = attr.ib(default=120) note_duration = attr.ib(default=960) string_number = attr.ib(default=4) measure_content = attr.ib(factory=list) triplet_feel = attr.ib(default=gp.TripletFeel.none) repeat_open = attr.ib(default=False) repeat_close = attr.ib(default=None) previous_note = attr.ib(default=None)
def add_time_signature(self, measure_header): measure_time = max(self.state.measure_time, gp.Duration.minTime) denominator = self.state.time_signature_denominator.time numerator = measure_time / denominator from fractions import Fraction numerator_fraction = Fraction(numerator).limit_denominator(100) denominator_time = max( int(self.state.time_signature_denominator.time / numerator_fraction.denominator), gp.Duration.minTime) denominator_value = (gp.Duration.quarterTime * gp.Duration.quarter) / denominator_time time_signature = gp.TimeSignature( numerator=numerator_fraction.numerator, denominator=gp.Duration(denominator_value)) measure_header.timeSignature = time_signature
def testDuration(value, isDotted, tuplet): dur = gp.Duration(value, isDotted=isDotted, tuplet=gp.Tuplet(*tuplet)) time = dur.time newDur = gp.Duration.fromTime(time) assert isinstance(newDur.value, int) assert time == newDur.time
def test_double_dot_warning(recwarn): warnings.simplefilter('always') d = gp.Duration() assert len(recwarn) == 0 with pytest.deprecated_call(): d.isDoubleDotted = True
class Chord(object): notes = attr.ib(factory=list) duration = attr.ib(default=gp.Duration(gp.Duration.hundredTwentyEighth))
def make_tempo(self, _input, _start, _end, elements): self.state.tempo = int(elements[4].text) self.state.time_signature_denominator = gp.Duration( value=duration_values[elements[1].text]) return elements