Пример #1
0
    def read(self, event: str, values: ValuesFilledType,
             tokens: ty.List[str]) -> ty.Optional[ty.List[RegionContents]]:
        wildcards: WildcardDict = {}
        if wildcard_in_tokens(tokens, Wildcard.articulation):
            wildcards[Wildcard.articulation] = ty.cast(
                str, values[self.ns + 'art_name'])
        if wildcard_in_tokens(tokens, Wildcard.part):
            wildcards[Wildcard.part] = ty.cast(str,
                                               values[self.ns + 'art_part'])
        if wildcard_in_tokens(tokens, Wildcard.dyn):
            wildcards[Wildcard.dyn] = values[self.ns + 'dyn']
        if wildcard_in_tokens(tokens, Wildcard.sul):  # type:ignore
            wildcards[Wildcard.sul] = values[self.ns + 'sul']  # type:ignore

        try:
            if event == self.ns + 'cut':
                self._cut(values)
                return None
            if event == self.ns + 'erase_mdata':
                self.erase_metadata()
            if event == self.fade_out.key:
                regions_w_mdata = self.regions_for_part(values)
                self.fade_out.fade_all(values, regions_w_mdata)
                return None
            if event == self.ns + 'regions':
                rpr.Project().begin_undo_block()
                return self.make_regions(values, wildcards, tokens)
        except ItemsError as e:
            raise ArtError(e)
        return None
Пример #2
0
    def make_regions(self, values: ValuesFilledType, wildcards: WildcardDict,
                     tokens: ty.List[str]) -> ty.List[RegionContents]:
        regions_w_mdata = self.regions_for_part(values)
        amount = self._get_amount_of_ready_rr(regions_w_mdata)
        handlers = ItemsHandler().split_by_items_gaps()
        export: ty.List[RegionContents] = []
        pprint(amount)
        for ih in handlers:
            wildcards_i = wildcards.copy()
            wildcards_i.update(self.process_wildcards(tokens,
                                                      items_handler=ih))
            root = self.get_root(wildcards_i, ih)
            if root not in amount:
                amount[root] = []

            rr = len(amount[root]) + 1
            if wildcard_in_tokens(tokens, Wildcard.rr):
                wildcards_i[Wildcard.rr] = rr

            metadata = {'root': root, 'part': self.metadata_key, 'rr': rr}
            pprint(metadata)
            amount[root].append(metadata)
            export.append(
                (wildcards_i, *ih.get_bounds(), 'shorts regions', metadata))
        return export
Пример #3
0
 def mark_sus(
     self, values: ValuesFilledType, tokens: ty.List[str],
     wildcards: WildcardDict
 ) -> ty.Tuple[WildcardDict, float, float, str, object]:
     ih = ItemsHandler()
     start, end = ih.get_bounds(check_for_indentity=False)
     try:
         median_rms = get_rms(ih, median=True)
         if values[self.ns + 'sus_marker']:
             want_marker: ty.Optional[str] = '@Trem_sus_hard'
             get_first_rms_value_ms(ih, median_rms, want_marker=want_marker)
         split_ih = ItemsHandler(item_handlers=[
             i_h for i_h in ih.item_handlers if i_h.item.position == start
         ])
         if values[self.ns + 'sus_want_cut']:
             start_split = get_first_rms_value_ms(
                 split_ih,
                 db_to_amplitude(
                     ty.cast(float,
                             values[self.ns + 'sus_silence_treshold'])))
             left, split_ih = split_ih.split(start + start_split)
             left.delete()
             start, _ = split_ih.get_bounds(check_for_indentity=False)
         if wildcard_in_tokens(tokens, Wildcard.part):
             wildcards[Wildcard.part] = 'sus'
         wildcards.update(self.process_wildcards(tokens))
     except ItemsError as e:
         raise ArtError(str(e))
     root = self.get_root(wildcards, split_ih)
     metadata = {'median_rms': median_rms, 'part': 'sus', 'root': root}
     return wildcards, start, end, 'trem sus region', metadata
Пример #4
0
 def make_release_region(self, values: ValuesFilledType,
                         wildcards: WildcardDict, tokens: ty.List[str],
                         want_cut: bool) -> ty.Optional[RegionContents]:
     rpr.Project().begin_undo_block()
     if want_cut:
         retval = self.release_cut(
             db_to_amplitude(
                 ty.cast(float, values[self.ns + 'silence_treshold'])),
             ty.cast(str, values[self.ns + 'rel_fade_out_shape']),
             ty.cast(float, values[self.ns + 'rel_fade_out_time']))
         if not retval:
             return None
         else:
             cut_handler, median = retval
     else:
         cut_handler = ItemsHandler()
         ret_meta = self.get_metadata_safe('left')
         if ret_meta is None:
             return None
         reg, metadata = ret_meta
         median = ty.cast(float, metadata['median_rms'])
     wildcards.update(self.process_wildcards(tokens))
     if wildcard_in_tokens(tokens, Wildcard.part):
         wildcards[Wildcard.part] = 'rls'
     root = self.get_root(wildcards, cut_handler)
     metadata = {
         'part': 'release',
         'root': root,
         'median_rms': float(median)
     }
     return (wildcards, *cut_handler.get_bounds(count_ts=False),
             'trem release region', metadata)
Пример #5
0
    def read(self, event: str, values: ValuesFilledType,
             tokens: ty.List[str]) -> ty.Optional[ty.List[RegionContents]]:
        wildcards: WildcardDict = {}
        if wildcard_in_tokens(tokens, Wildcard.articulation):
            wildcards[Wildcard.articulation] = 'trem'
        if wildcard_in_tokens(tokens, Wildcard.dyn):
            wildcards[Wildcard.dyn] = values[self.ns + 'dyn']
        if wildcard_in_tokens(tokens, Wildcard.sul):  # type:ignore
            wildcards[Wildcard.sul] = values[self.ns + 'sul']  # type:ignore

        # small GUI interactions

        # big funcs
        try:
            if event == self.ns + 'sus':
                rpr.Project().begin_undo_block()
                return [self.mark_sus(values, tokens, wildcards)]
            if event == self.ns + 'release_cut':
                with rpr.undo_block('cut release', flags=-1):
                    self.release_cut(
                        db_to_amplitude(
                            ty.cast(float,
                                    values[self.ns + 'silence_treshold'])),
                        ty.cast(str, values[self.ns + 'rel_fade_out_shape']),
                        ty.cast(float, values[self.ns + 'rel_fade_out_time']))
                return None
            if event == self.ns + 'release_region':
                rel_reg = self.make_release_region(
                    values, wildcards, tokens,
                    ty.cast(bool, values[self.ns + 'release_region_want_cut']))
                return [rel_reg] if rel_reg is not None else None

            if event == self.rel_fade_out.key:
                self.fade_out_all_releases(values)
        except ItemsError as e:
            raise ArtError(e)

        return None