Exemple #1
0
    def __init__(self,
                 name,
                 val_units,
                 time_units=None,
                 val_allowed=None,
                 time_allowed=None,
                 markers=None,
                 start=None,
                 reltype="Controller",
                 change_types="all",
                 rel_id=None,
                 path=None,
                 parent=None,
                 mode="create",
                 **kwargs):

        super().__init__(rel_id=rel_id,
                         reltype=reltype,
                         name=name,
                         path=path,
                         parent=parent,
                         mode=mode,
                         markers=markers,
                         time_units=time_units,
                         val_units=val_units,
                         val_allowed=val_allowed,
                         start=start,
                         time_allowed=time_allowed,
                         **kwargs)

        # validate change types
        if change_types == "all":
            change_types = self.change_type_options
        elif not all(i in self.change_type_options for i in change_types):
            raise UnexpectedIssue(
                "Unknown change_type in '{0}' in Controller constructor".
                format(change_types))
        self.valid_change_types = change_types

        desc = get_reldata(self.add, "desc")
        try:
            new_desc = desc.format(val_units=self.val_units,
                                   time_units=time_units,
                                   change_types="', '".join(
                                       self.valid_change_types))
        except:
            # if format fails, it means add docstring is overridden somewhere,
            # and will be handled there
            pass
        else:
            add_reldata(self.add, "desc", new_desc)
Exemple #2
0
    def __init__(self,
                 name,
                 val_units,
                 time_units="beats",
                 val_allowed=None,
                 time_allowed=None,
                 start=None,
                 reltype="Controller",
                 rel_id=None,
                 path=None,
                 markers=None,
                 parent=None,
                 mode="create",
                 **kwargs):
        super().__init__(rel_id=rel_id,
                         reltype=reltype,
                         name=name,
                         path=path,
                         parent=parent,
                         mode=mode,
                         **kwargs)

        self.start = start
        self.markers = {} if markers is None else markers  # {sample_ind : ControllerMarker}

        if time_units is None or time_units not in ("beat", "beats", "sec",
                                                    "secs", "second",
                                                    "seconds"):
            p("Select the timing units to be used for this controller, 'b' for beats notation (recommended), 's' for seconds"
              )
            time_mode = inpt("letter", allowed="bs")
            if time_mode == "b":
                time_units = "beats"
            else:
                time_units = "secs"
        self.time_units = time_units
        self.val_units = val_units
        self.val_allowed = val_allowed
        self.time_allowed = (Units.beats("0b"), None)

        desc = get_reldata(self.add, "desc")
        try:
            new_desc = desc.format(val_units=self.val_units,
                                   time_units=time_units)
        except:
            # if format fails, it means add docstring is overridden somewhere,
            # and will be handled there
            pass
        else:
            add_reldata(self.add, "desc", new_desc)
Exemple #3
0
 def random_method(self):
     """
     desc: implement random sound-editing on recording, with random args. Introduce a little anarchy!
     cat: edit
     """
     public_methods = self.get_all_public_methods()
     public_edits = [i for i in public_methods if get_reldata(i, "category") == Category.EDIT]
     method = rd.choice(public_edits)
     args = method.get_random_defaults()
     try:
         method(*args)
     except Exception as e:
         err_mess("Random Process error:")
         show_error(e)
Exemple #4
0
 def _do_aliases(self):
     """
     add all aliases
     """
     if not hasattr(self, "_rel_data"):
         self._rel_data = _ClsRelData()
     alias_map = self._rel_data.alias_map
     # copy to prevent modifying what we iterate over
     dct = {k: getattr(self, k) for k in dir(self)}
     for meth_name, method in dct.items():
         if has_aliases(method):
             for alias in get_reldata(method, "aliases"):
                 if hasattr(self, alias) or alias in alias_map:
                     raise NameError(
                         "Class '{0}' already has method/name '{1}' that cannot be aliases"
                         .format(self.__class__.__name__, alias))
                 alias_map[alias] = meth_name
Exemple #5
0
    def options(self):
        """
        cat: info
        desc: list all process options that can be run on this object (shortcut 'o')
        """
        nl()
        with style("cyan"):
            info_block("{CATEGORY}", indent=2)
        info_line("- {Process}")
        info_line("{arguments in order, optional if in [square brackets]}",
                  indent=8)
        nl()

        meths = {}
        for mth in self.get_all_public_methods():
            cat = get_reldata(mth, "category")
            try:
                meths[cat].append(mth)
            except KeyError:
                meths[cat] = [mth]

        categories = list(meths.keys())
        # sort by category.value, which is the string representation of that category
        categories.sort(key=lambda x: x.value)
        for cat in categories:
            with style("cyan"):
                info_line(cat.value.upper(), indent=2)
            for method in meths[cat]:
                method._rel_data.display()
            if cat == Category.PROPERTY:
                prop_names = self.get_all_prop_names()
                if not prop_names:
                    info_line("(no properties to edit)", indent=10)
                else:
                    for i in prop_names:
                        info_line("* " + i, indent=10)
Exemple #6
0
 def post_process(self, method_obj):
     """
     override with super() to provide post processing
     """
     if get_reldata(method_obj, "category") == Category.META:
         self.save_metadata()