'Correct the time signature for incomplete measures.
If the measure is incomplete or a pickup, insert an appropriate
time signature into this Measure.'

def _fix_time_signature(self):

    numerator = self.duration
    denominator = (self.state.divisions * 4)
    fractional_time_signature = Fraction(numerator, denominator)
    if ((self.state.time_signature is None) and (self.time_signature is None)):
        self.time_signature = TimeSignature(self.state)
        self.time_signature.numerator = fractional_time_signature.numerator
        self.time_signature.denominator = fractional_time_signature.denominator
        self.state.time_signature = self.time_signature
    else:
        fractional_state_time_signature = Fraction(self.state.time_signature.numerator, self.state.time_signature.denominator)
        pickup_measure = False
        if (numerator < self.state.time_signature.numerator):
            pickup_measure = True
        global_time_signature_denominator = self.state.time_signature.denominator
        if ((fractional_time_signature == 1) and (not pickup_measure)):
            new_time_signature = TimeSignature(self.state)
            new_time_signature.numerator = global_time_signature_denominator
            new_time_signature.denominator = global_time_signature_denominator
        else:
            new_time_signature = TimeSignature(self.state)
            new_time_signature.numerator = numerator
            new_time_signature.denominator = denominator
            new_time_sig_fraction = Fraction(numerator, denominator)
            if (new_time_sig_fraction == fractional_time_signature):
                new_time_signature.numerator = fractional_time_signature.numerator
                new_time_signature.denominator = fractional_time_signature.denominator
        if (pickup_measure or ((self.time_signature is None) and (fractional_time_signature != fractional_state_time_signature))):
            new_time_signature.time_position = self.start_time_position
            self.time_signature = new_time_signature
            self.state.time_signature = new_time_signature
