def __mk_kendang():
    def mk_re(pitches):
        def mk_pitch2samples(pitch):
            basic_path = "samples/kendang/new/"
            normalized_pitch = pitch.normalize(2)

            if normalized_pitch == ji.r(8, 7):
                basic_path += "0_"
            elif normalized_pitch == ji.r(5, 4):
                basic_path += "1_"
            elif normalized_pitch == ji.r(8, 5):
                basic_path += "2_"
            elif normalized_pitch == ji.r(7, 4):
                basic_path += "3_"
            else:
                basic_path += "4_"

            octave = pitch.octave

            if octave == 0:
                basic_path += "hand"
            elif octave == 1:
                basic_path += "tak"
            elif octave == -1:
                basic_path += "stick"
            else:
                msg = "Unknonw octave {0} of pitch {1}".format(octave, pitch)
                raise ValueError(msg)

            return itertools.cycle(
                ("{0}{1}.wav".format(basic_path, idx), 1) for idx in range(2))

        pitch2sample = {pitch: mk_pitch2samples(pitch) for pitch in pitches}

        return sound.SampleEngine(pitch2sample)

    pitches = (
        sw.translate(".7- .7+ .5- .5+ .1", False),
        sw.translate("7- 7+ 5- 5+ 1", False),
        sw.translate("7-. 7+. 5-. 5+. 1.", False),
    )

    pitch2notation = tuple(
        instruments.mk_p2n(p, idx, False) for idx, p in enumerate(pitches))
    pitch2notation = instruments.combine_p2n(*pitch2notation)

    notation_styles = tuple(
        notation.MelodicLineStyle("Large", "", True, True, True)
        for i in range(1))
    vertical_line = notation.VerticalLine(0.5, "", 1)
    vertical_line_style = notation.VerticalLineStyle(vertical_line,
                                                     vertical_line,
                                                     vertical_line)

    re0 = mk_re(functools.reduce(operator.add, pitches))
    render_engines = (re0, )

    return instruments.Instrument("Kendang", pitch2notation, notation_styles,
                                  render_engines, vertical_line_style)
class Sign(object):
    _scales = tuple(
        tuple(
            sorted(
                sw.translate("{0} {1}".format(pre, "9 19 5 11 3 13 7 1."),
                             False))) for pre in (r"!+", r"!-"))

    def __init__(self, pitch_conversion_function):
        self.__pcf = pitch_conversion_function

    def __repr__(self) -> str:
        return "SIGN"

    @property
    def scales(self) -> tuple:
        return Sign._scales

    def convert2pitch(self, gender: bool, primes: tuple) -> ji.JIPitch:
        return self.__pcf(gender, primes)

    @staticmethod
    def test_pos(pos):
        try:
            assert pos in (0, 1, 2)
        except AssertionError:
            msg = "Invalide value {0} for 'pos'. ".format(pos)
            msg += "Argument 'pos' can only be 0, 1 or 2."
            raise ValueError(msg)
Beispiel #3
0
 def __call__(self, gender: bool, main_prime: int,
              side_prime: int) -> old.JICadence:
     pitches = sw.translate(
         self.__line,
         decodex={
             self.main: str(main_prime),
             self.side: str(side_prime)
         },
         inverse=not gender,
     )
     return old.JICadence(
         [old.Chord(h, r) for h, r in zip(pitches, self.__rhythms)])
    def __call__(self, gender: bool, main_prime: int,
                 side_prime: int) -> old.JICadence:
        if not main_prime:
            main_prime = 3
        if not side_prime:
            side_prime = 5

        not_current_main_primes = tuple(p for p in (3, 5, 7)
                                        if p != main_prime)
        if len(not_current_main_primes) == 3:
            not_current_main_primes = (5, 7)

        if not_current_main_primes[0] == side_prime:
            not_current_main_primes = tuple(reversed(not_current_main_primes))

        not_current_side_primes = tuple(p for p in (3, 5, 7)
                                        if p != side_prime)
        if len(not_current_side_primes) == 3:
            not_current_side_primes = (5, 7)

        if not_current_side_primes[0] == main_prime:
            not_current_side_primes = tuple(reversed(not_current_side_primes))

        if main_prime == 9:
            tranformed_mp = 3
        else:
            tranformed_mp = main_prime

        if side_prime == 9:
            tranformed_sp = 3
        else:
            tranformed_sp = side_prime

        pitches = sw.translate(
            self.line,
            decodex={
                self.main: str(main_prime),
                self.side: str(side_prime),
                self.not_current_main_prime0: str(not_current_main_primes[0]),
                self.not_current_main_prime1: str(not_current_main_primes[1]),
                self.not_current_side_prime0: str(not_current_side_primes[0]),
                self.not_current_side_prime1: str(not_current_side_primes[1]),
                self.transformed_main_prime: str(tranformed_mp),
                self.transformed_side_prime: str(tranformed_sp),
            },
            inverse=not gender,
        )
        return old.JICadence(
            [old.Chord(h, r) for h, r in zip(pitches, self.rhythms)])
Beispiel #5
0
def __mk_tak():
    def mk_re():
        def mk_tak_cycle():
            names = tuple("samples/klapper/{0}.wav".format(idx) for idx in range(5))
            return itertools.cycle(tuple((n, 1, 0.59) for n in names))

        def mk_schlitz_kurz_cycle():
            names = tuple(
                "samples/schlitztrommel/kurz/{0}.wav".format(idx) for idx in range(6)
            )
            return itertools.cycle(tuple((n, 1, 1.1) for n in names))

        def mk_schlitz_lang_cycle():
            names = tuple(
                "samples/schlitztrommel/lang/{0}.wav".format(idx) for idx in range(5)
            )
            return itertools.cycle(tuple((n, 1, 1.1) for n in names))

        short_pitch = ji.r(1, 1)
        long_pitch = ji.r(1, 2)
        tak_pitch = ji.r(3, 2)
        pitch2sample = {
            tak_pitch: mk_tak_cycle(),
            short_pitch: mk_schlitz_kurz_cycle(),
            long_pitch: mk_schlitz_lang_cycle(),
        }

        return sound.SampleEngine(pitch2sample)

    pitches = sw.translate("1 .1 3", False)

    pitch2notation = instruments.mk_p2n(pitches, 0)

    notation_styles = tuple(
        notation.MelodicLineStyle("Large", "", True, True, True) for i in range(1)
    )
    vertical_line = notation.VerticalLine(0.5, "", 1)
    vertical_line_style = notation.VerticalLineStyle(
        vertical_line, vertical_line, vertical_line
    )

    re = mk_re()
    render_engines = (re,)

    return instruments.Instrument(
        "Tak", pitch2notation, notation_styles, render_engines, vertical_line_style
    )
Beispiel #6
0
from nongkrong.harmony import shortwriting as sw
from mu.mel import ji

CONCERT_PITCH = 260

pitches = ".3++ .7++ .5++ .3+++ 9 19 5 11 3 13 7 1."
pitches = sw.translate(pitches, False)

name = "PLUS"

if __name__ == "__main__":
    import pyteqNew as pyteq

    for p_idx, pitch in enumerate(sorted(pitches)):
        local_name = name + str(p_idx)
        melody = [
            pyteq.MidiTone(ji.JIPitch(pitch, multiply=CONCERT_PITCH),
                           4,
                           4,
                           volume=1)
        ]
        harp_range = tuple(n for n in range(20, 125))
        f = pyteq.Pianoteq(melody, available_midi_notes=harp_range)
        f.export2wav(local_name, preset='"Erard Player"')