# Path: expremigen/patterns/pattern.py
# class Pattern(metaclass=abc.ABCMeta):
#     """
#     abstract base class for a Pattern
#     """
# 
#     def __str__(self):
#         return "{0}".format(self.__class__.__name__)
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/pchord.py
# class Pchord(Pattern):
#     """
#     special pattern that is never flattened; interpreted as a chord by the rest of the system
#     """
# 
#     def __init__(self, notes=0):
#         super().__init__()
#         self.notes = notes
# 
#     def __str__(self):
#         return "{0}({1})".format(self.__class__.__name__, self.notes)
# 
#     def __iter__(self):
#         yield Pchord(self.notes)
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def __eq__(self, other):
#         return self.notes == other.notes


import itertools
import random
from expremigen.patterns.pattern import Pattern
from expremigen.patterns.pchord import Pchord

def myrepeat(what, fn, times=None):
    """

    :param what: something to repeat
    :param fn: extra function to apply
    :param times: number of times to repeat
    :return:
    """
    if times is None:
        while True:
            if fn is not None:
                yield fn(what)
            else:
                yield what
    else:
        for i in range(times):
            if fn is not None:
                yield fn(what)
            else:
                yield what


def flatten(l):
    """

    :param l: list l
    :return: iterator to flatten list l; Pchord are not flattened
    """
    for el in l:

# Path: expremigen/patterns/pattern.py
# class Pattern(metaclass=abc.ABCMeta):
#     """
#     abstract base class for a Pattern
#     """
# 
#     def __str__(self):
#         return "{0}".format(self.__class__.__name__)
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/pchord.py
# class Pchord(Pattern):
#     """
#     special pattern that is never flattened; interpreted as a chord by the rest of the system
#     """
# 
#     def __init__(self, notes=0):
#         super().__init__()
#         self.notes = notes
# 
#     def __str__(self):
#         return "{0}({1})".format(self.__class__.__name__, self.notes)
# 
#     def __iter__(self):
#         yield Pchord(self.notes)
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def __eq__(self, other):
#         return self.notes == other.notes


# Path: expremigen/patterns/utils.py
import itertools
import random
from expremigen.patterns.pattern import Pattern
from expremigen.patterns.pchord import Pchord


def myrepeat(what, fn, times=None):
    """

    :param what: something to repeat
    :param fn: extra function to apply
    :param times: number of times to repeat
    :return:
    """
    if times is None:
        while True:
            if fn is not None:
                yield fn(what)
            else:
                yield what
    else:
        for i in range(times):
            if fn is not None:
                yield fn(what)
            else:
                yield what


def flatten(l):
    """

    :param l: list l
    :return: iterator to flatten list l; Pchord are not flattened
    """
    for el in l:

        if isinstance(el, Pattern) and not isinstance(el, Pchord):