Exemplo n.º 1
0
    def visit_Slur(self, slur):
        """
        Attempt to pitch-bend to victory.

        Also apply shortening to the tail of the slur.
        """

        def fail():
            # Cut the tail off the end and return the whole shebang.
            last, rest = self.shorten(slur.exprs[-1])
            return Music(slur.exprs[:-1] + [last, rest]), False

        # If we can't do legato on this instrument, bail.
        if not can_legato(self.inst):
            return fail()

        first = slur.exprs[0]
        exprs = slur.exprs[1:]

        for expr in exprs:
            if abs(expr.pitch - first.pitch) > 12:
                # Bail.
                return fail()

        first = first._replace(
                duration=sum(expr.duration for expr in slur.exprs))
        first, rest = self.shorten(first)
        offset = 0
        out = [first]

        for expr in exprs:
            offset += expr.duration
            out.append(PitchBend(offset,
                (8191 // 12) * (expr.pitch - first.pitch)))

        out.append(rest)

        return Music(out), False
Exemplo n.º 2
0
 def test_guitar_can_legato(self):
     self.assertTrue(can_legato("overdriven guitar"))
Exemplo n.º 3
0
 def test_piano_cannot_legato(self):
     self.assertFalse(can_legato("acoustic grand"))