Example #1
0
 def get_notes_by_bp_interval(self, interval):
     conversion = TimeConversion(self.tempo_sequence,
                                 self.time_signature_sequence,
                                 Position(self.duration.duration))
     wnt_interval = Interval(conversion.bp_to_position(interval.lower),
                             conversion.bp_to_position(interval.upper))
     return self.get_notes_by_wnt_interval(wnt_interval)
Example #2
0
 def get_notes_starting_in_bp_interval(self, interval):
     """
     Get all notes starting in the score by an interval based on beat position:  Return dict structure as follows:
         instrument_voice --> {voice_index --> [notes]}
     """
     conversion = TimeConversion(self.tempo_sequence,
                                 self.time_signature_sequence,
                                 Position(self.duration.duration))
     wnt_interval = Interval(conversion.bp_to_position(interval.lower),
                             conversion.bp_to_position(interval.upper))
     return self.get_notes_starting_in_wnt_interval(wnt_interval)
Example #3
0
    def test_bp_to_position(self):
        tempo_line = EventSequence([TempoEvent(Tempo(60), Position(0))])
        ts_line = EventSequence(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        conversion = TimeConversion(tempo_line, ts_line, Position(2, 1))

        bp = conversion.bp_to_position(BeatPosition(0, 2))
        print(bp)
        self.assertTrue(bp == Position(1, 2), 'bp is {0}, not 1/2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(1, 1))
        print(bp)
        self.assertTrue(bp == Position(1), 'bp is {0}, not 1'.format(bp))

        tempo_line = EventSequence([
            TempoEvent(Tempo(60), Position(0)),
            TempoEvent(Tempo(20), Position(4, 4))
        ])
        ts_line = EventSequence([
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)),
            TimeSignatureEvent(TimeSignature(2, Duration(1, 8)),
                               Position(6, 4))
        ])
        conversion = TimeConversion(tempo_line, ts_line, Position(2, 1))

        bp = conversion.bp_to_position(BeatPosition(1, 2))
        print(bp)
        self.assertTrue(bp == Position(5, 4), 'bp is {0}, not 5/4'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(2, 1))
        print(bp)
        self.assertTrue(bp == Position(13, 8),
                        'bp is {0}, not 13/8'.format(bp))

        tempo_line = EventSequence([
            TempoEvent(Tempo(60), Position(0)),
            TempoEvent(Tempo(20), Position(4, 4))
        ])
        ts_line = EventSequence([
            TimeSignatureEvent(TimeSignature(4, Duration(1, 4)), Position(0)),
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)),
                               Position(5, 2))
        ])
        conversion = TimeConversion(tempo_line, ts_line, Position(4),
                                    Duration(1, 2))

        # pickup
        bp = conversion.bp_to_position(BeatPosition(0, 2))
        print(bp)
        self.assertTrue(bp == Position(0), 'bp is {0}, not 0'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(0, 3))
        print(bp)
        self.assertTrue(bp == Position(1, 4), 'bp is {0}, not 1/4'.format(bp))

        # measure 1
        bp = conversion.bp_to_position(BeatPosition(1, 0))
        print(bp)
        self.assertTrue(bp == Position(1, 2), 'bp is {0}, not 1/2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(1, 1))
        print(bp)
        self.assertTrue(bp == Position(3, 4), 'bp is {0}, not 3/4'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(1, 2))
        print(bp)
        self.assertTrue(bp == Position(1, 1), 'bp is {0}, not 1'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(1, 3))
        print(bp)
        self.assertTrue(bp == Position(5, 4), 'bp is {0}, not 5/4'.format(bp))

        # measure 2
        bp = conversion.bp_to_position(BeatPosition(2, 0))
        print(bp)
        self.assertTrue(bp == Position(3, 2), 'bp is {0}, not 3/2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(2, 1))
        print(bp)
        self.assertTrue(bp == Position(7, 4), 'bp is {0}, not 7/4'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(2, 2))
        print(bp)
        self.assertTrue(bp == Position(2, 1), 'bp is {0}, not 2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(2, 3))
        print(bp)
        self.assertTrue(bp == Position(9, 4), 'bp is {0}, not 9/4'.format(bp))

        # measure 3
        bp = conversion.bp_to_position(BeatPosition(3, 0))
        print(bp)
        self.assertTrue(bp == Position(5, 2), 'bp is {0}, not 5/2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(3, 1))
        print(bp)
        self.assertTrue(bp == Position(11, 4),
                        'bp is {0}, not 11/4'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(3, 2))
        print(bp)
        self.assertTrue(bp == Position(3, 1), 'bp is {0}, not 3'.format(bp))

        # measure 4
        bp = conversion.bp_to_position(BeatPosition(4, 0))
        print(bp)
        self.assertTrue(bp == Position(13, 4),
                        'bp is {0}, not 13/4'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(4, 1))
        print(bp)
        self.assertTrue(bp == Position(7, 2), 'bp is {0}, not 7, 2'.format(bp))

        bp = conversion.bp_to_position(BeatPosition(4, 2))
        print(bp)
        self.assertTrue(bp == Position(15, 4),
                        'bp is {0}, not 15/4'.format(bp))