def test_getBeams_offset(self): ''' Test getting Beams from a Measure that has an anacrusis that makes the first note not beamed. ''' m = stream.Measure() m.repeatAppend(note.Note(type='eighth'), 5) ts = TimeSignature('2/2') beams = ts.getBeams(m, measureStartOffset=1.5) self.assertIsNone(beams[0]) for b in beams[1:]: self.assertIsNotNone(b) match = '''[None, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match)) m.append(note.Note(type='eighth')) beams = ts.getBeams(m, measureStartOffset=1.0) match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match), str(beams)) m = stream.Measure() m.repeatAppend(note.Note(type='eighth'), 5) ts = TimeSignature('3/2') beams = ts.getBeams(m, measureStartOffset=3.5) match = '''[None, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match)) m = stream.Measure() m.repeatAppend(note.Note(type='eighth'), 4) ts = TimeSignature('6/8') beams = ts.getBeams(m, measureStartOffset=1.0) match = '''[None, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match)) m.append(note.Note(type='eighth')) beams = ts.getBeams(m, measureStartOffset=0.5) match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match), str(beams))
def testMixedDurationsBeams(self): fourFour = TimeSignature('4/4') n = note.Note dList = [ n(type='eighth'), n(type='quarter'), n(type='eighth'), n(type='eighth'), n(type='quarter'), n(type='eighth') ] beamList = fourFour.getBeams(dList) self.assertEqual(beamList, [None] * 6) dList = [ n(type='eighth'), n(type='quarter'), n(type='eighth'), n(type='eighth'), n(type='eighth'), n(type='quarter') ] beamList = fourFour.getBeams(dList) self.assertEqual([repr(b) for b in beamList], [ 'None', 'None', 'None', '<music21.beam.Beams <music21.beam.Beam 1/start>>', '<music21.beam.Beams <music21.beam.Beam 1/stop>>', 'None' ])
def testGetBeams(self): ts = TimeSignature('6/8') durList = [16, 16, 16, 16, 8, 16, 16, 16, 16, 8] notesList = [note.Note(quarterLength=4 / d) for d in durList] beams = ts.getBeams(notesList) match = '''[<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>, <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]''' self.assertTrue(common.whitespaceEqual(str(beams), match))