Пример #1
0
 def mute(self):
     """Mute track (do nothing if track is already muted)."""
     code = """
     if not track.is_muted:
         track.toggle_mute()
     """
     Program(code).run(track=self)
Пример #2
0
    def add_item(self, start=0, end=None, length=0):
        """
        Create new item on track and return it.

        Parameters
        ----------
        start : float, optional
            New item start in seconds (default=0).
        end : float, optional
            New item end in seconds (default None). If None, `length`
            is used instead.
        length : float, optional
            New item length in seconds (default 0).

        Returns
        -------
        item : Item
            New item on track.
        """
        if end is None:
            end = start + length
        code = """
        item_id = RPR.AddMediaItemToTrack(track_id)
        item = reapy.Item(item_id)
        item.position = start
        item.length = end - start
        """
        item = Program(code, "item").run(
            track_id=self.id, start=start, end=end
        )[0]
        return item
Пример #3
0
    def add_track(self, index=0, name=""):
        """
        Add track at a specified index.

        Parameters
        ----------
        index : int
            Index at which to insert track.
        name : str, optional
            Name of created track.

        Returns
        -------
        track : Track
            New track.
        """
        code = """
        current_project = reapy.Project()
        project.make_current_project()
        n_tracks = project.n_tracks
        index = max(-n_tracks, min(index, n_tracks))
        if index < 0:
            index = index % n_tracks
        RPR.InsertTrackAtIndex(index, True)
        current_project.make_current_project()
        track = reapy.Track(RPR.GetTrack(project.id, index))
        track.name = name
        """
        track, = Program(code, "track").run(project=self,
                                            index=index,
                                            name=name)
        return track
Пример #4
0
    def get_value(self, time, raw=False):
        """
        Return envelope value at a given time.

        Parameters
        ----------
        time : float
            Time in seconds.
        raw : bool, optional
            Whether to return raw value or its human-readable version,
            which is the one that is printed in REAPER GUI
            (default=False).

        Returns
        -------
        value : float or str
            Envelope value.

        Examples
        --------
        >>> envelope = track.envelopes["Pan"]
        >>> envelope.get_value(10, raw=True)
        -0.5145481809245827
        >>> envelope.get_value(10)  # human-readable
        '51%R'
        """
        code = """
        value = RPR.Envelope_Evaluate(env_id, time, 0, 0, 0, 0, 0, 0)[5]
        if not raw:
            value = RPR.Envelope_FormatValue(env_id, value, "", 2048)[2]
        """
        value = Program(code, "value").run(env_id=self.id, time=time,
                                           raw=raw)[0]
        return value
Пример #5
0
 def unmute(self):
     """Unmute track (do nothing if track is not muted)."""
     code = """
     if track.is_muted:
         track.toggle_mute()
     """
     Program(code).run(track=self)
Пример #6
0
    def focused_fx(self):
        """
        FX that has focus if any, else None.

        :type: FX or NoneType
        """
        code = """
        def get_focused_fx():
            if not project.is_current_project:
                return
            res = RPR.GetFocusedFX(0, 0, 0)
            if not res[0]:
                return
            if res[1] == 0:
                track = project.master_track
            else:
                track = project.tracks[res[1] - 1]
            if res[0] == 1:  # Track FX
                return track.fxs[res[3]]
            # Take FX
            item = track.items[res[2]]
            take = item.takes[res[3] // 2**16]
            return take.fxs[res[3] % 2**16]

        fx = get_focused_fx()
        """
        fx, = Program(code, "fx").run(project=self)
        return fx
Пример #7
0
    def infos(self):
        """
        Return infos about CC.

        Keys are {"selected", "muted", "position", "channel",
        "channel_message", "messages"}.

        :type: dict
        """
        code = """
        res = list(RPR.MIDI_GetCC(
            take.id, index, 0, 0, 0, 0, 0, 0, 0
        ))[3:]
        res[0] = bool(res[0])
        res[1] = bool(res[1])
        res[2] = take.ppq_to_time(res[2])
        res[-2] = res[-2], res[-1]
        res.pop()
        keys = (
            "selected", "muted", "position", "channel_message", "channel",
            "messages"
        )
        infos = {k: r for k, r in zip(keys, res)}
        """
        infos, = Program(code, "infos").run(take=self.parent, index=self.index)
        return infos
Пример #8
0
    def last_touched_fx(self):
        """
        Last touched FX and corresponding parameter index.

        :type: FX, int or NoneType, NoneType

        Notes
        -----
        Only Track FX are detected by this property. If last touched
        FX is a Take FX, this property is ``(None, None)``.

        Examples
        --------
        >>> fx, index = project.last_touched_fx
        >>> fx.name
        'VSTi: ReaSamplOmatic5000 (Cockos)'
        >>> fx.params[index].name
        "Volume"
        """
        code = """
        if not project.is_current_project:
            fx, index = None, None
        else:
            res = RPR.GetLastTouchedFX(0, 0, 0)
            if not res[0]:
                fx, index = None, None
            else:
                if res[1]:
                    track = project.tracks[res[1] - 1]
                else:
                    track = project.master_track
                fx, index = track.fxs[res[2]], res[3]
        """
        return tuple(Program(code, "fx", "index").run(project=self))
Пример #9
0
 def __iter__(self):
     code = """
     elements = [ro_list[i] for i in range(len(ro_list))]
     """
     elements, = Program(code, "elements").run(ro_list=self)
     for element in elements:
         yield element
Пример #10
0
    def infos(self):
        """
        Return infos about note.

        Keys are {"selected", "muted", "start", "end", "channel",
        "pitch", "velocity"}.

        :type: dict
        """
        code = """
        res = list(RPR.MIDI_GetNote(
            take.id, index, 0, 0, 0, 0, 0, 0, 0
        ))[3:]
        res[0] = bool(res[0])
        res[1] = bool(res[1])
        res[2] = take.ppq_to_time(res[2])
        res[3] = take.ppq_to_time(res[3])
        keys = (
            "selected", "muted", "start", "end", "channel", "pitch",
            "velocity"
        )
        infos = {k: r for k, r in zip(keys, res)}
        """
        infos, = Program(code, "infos").run(take=self.parent, index=self.index)
        return infos
Пример #11
0
 def unsolo(self):
     """Unsolo track (do nothing if track is not solo)."""
     code = """
     if track.is_solo:
         track.toggle_solo()
     """
     Program(code).run(track=self)
Пример #12
0
 def solo(self):
     """Solo track (do nothing if track is already solo)."""
     code = """
     if not track.is_solo:
         track.toggle_solo()
     """
     Program(code).run(track=self)
Пример #13
0
 def flip_phase(self):
     """
     Toggle whether phase is flipped.
     """
     code = """
     send.is_phase_flipped = not send.is_phase_flipped
     """
     Program(code).run(send=self)
Пример #14
0
 def selected_tracks(self, tracks):
     tracks = list(tracks)
     code = """
     project.unselect_all_tracks()
     for track in tracks:
         track.select()
     """
     Program(code).run(project=self, tracks=tracks)
Пример #15
0
 def sends(self):
     code = """
     sends = [
         reapy.Send(track, i, type="send") for i in range(track.n_sends)
     ]
     """
     sends = Program(code, "sends").run(track=self)[0]
     return sends
Пример #16
0
 def __iter__(self):
     code = """
     values = [param_list.functions["GetParam"](
         param_list.parent_id, param_list.fx_index, i, 0, 0
     )[0] for i in range(len(param_list))]
     """
     values, = Program(code, "values").run(param_list=self)
     for i, value in enumerate(values):
         yield FXParam(value, self, i, self.functions)
Пример #17
0
 def toggle_solo(self):
     """Toggle solo on track."""
     code = """
     project = track.project
     selected_tracks = project.selected_tracks
     track.make_only_selected_track()
     project.perform_action(7)
     project.selected_tracks = selected_tracks
     """
     Program(code).run(track=self)
Пример #18
0
 def toggle_mute(self):
     """Toggle mute on track."""
     code = """
     project = track.project
     selected_tracks = project.selected_tracks
     track.make_only_selected_track()
     project.perform_action(40280)
     project.selected_tracks = selected_tracks
     """
     Program(code).run(track=self)
Пример #19
0
 def _get_param_index(self, name):
     code = """
     names = [param_list[i].name for i in range(len(param_list))]
     index = names.index(name)
     """
     try:
         index = Program(code, "index").run(name=name, param_list=self)[0]
         return index
     except DistError:
         raise IndexError("{} has no param named {}".format(
             self.parent_fx, name))
Пример #20
0
 def disarm_rec_on_all_tracks(self):
     """
     Disarm record on all tracks.
     """
     code = """
     current_project = reapy.Project()
     project.make_current_project()
     RPR.ClearAllRecArmed()
     current_project.make_current_project()
     """
     Program(code).run(project=self)
Пример #21
0
    def is_active(self):
        """
        Whether take is active.

        :type: bool
        """
        code = """
        from reapy.core.item.take import Take
        take = Take(take_id)
        is_active = take == take.item.active_take
        """
        return Program(code, "is_active").run(take_id=self.id)[0]
Пример #22
0
    def items(self):
        """
        List of items in project.

        :type: list of Item
        """
        code = """
        n_items = project.n_items
        item_ids = [RPR.GetMediaItem(project.id, i) for i in range(n_items)]
        """
        item_ids, = Program(code, "item_ids").run(project=self)
        return list(map(reapy.Item, item_ids))
Пример #23
0
 def _get_enum_index(self):
     """
     Return marker index as needed by RPR.EnumProjectMarkers2.
     """
     code = """
     index = [
         i for i, m in enumerate(project.markers)
         if m.index == marker.index
     ][0]
     """
     index = Program(code,
                     "index").run(marker=self,
                                  project=reapy.Project(self.project_id))[0]
     return index
Пример #24
0
    def project(self):
        """
        Track parent project.

        :type: Project
        """
        if self._project is None:
            code = """
            for project in reapy.get_projects():
                if track.id in [t.id for t in project.tracks]:
                    break
            """
            self._project, = Program(code, "project").run(track=self)
        return self._project
Пример #25
0
    def time_selection(self, selection):
        """
        Set time selection bounds.

        Parameters
        ----------
        selection : (float, float)
            Start and end of new time selection in seconds.
        """
        code = """
        project.time_selection.start = selection[0]
        project.time_selection.end = selection[1]
        """
        Program(code).run(project=self, selection=selection)
Пример #26
0
    def _get_project(self):
        """
        Return parent project of track.

        Should only be used internally; one should directly access
        Track.project instead of calling this method.
        """
        code = """
        for project in reapy.get_projects():
            if track.id in [t.id for t in project.tracks]:
                break
        """
        project, = Program(code, "project").run(track=self)
        return project
Пример #27
0
    def start(self):
        """
        Region start.

        :type: float
        """
        code = """
        index = region._get_enum_index()
        start = RPR.EnumProjectMarkers2(
            region.project_id, index, 0, 0, 0, 0, 0
        )[4]
        """
        start = Program(code, "start").run(region=self)[0]
        return start
Пример #28
0
 def _get_enum_index(self):
     """
     Return region index as needed by RPR.EnumProjectMarkers2.
     """
     code = """
     index = [
         i for i, r in enumerate(project.regions)
         if r.index == region.index
     ][0]
     """
     index = Program(code,
                     "index").run(region=self,
                                  project=reapy.Project(self.project_id))[0]
     return index
Пример #29
0
    def unsolo_all_tracks(self):
        """
        Unsolo all tracks in project.

        See also
        --------
        Project.solo_all_tracks
        """
        code = """
        current_project = reapy.Project()
        project.make_current_project()
        RPR.SoloAllTracks(0)
        current_project.make_current_project()
        """
        Program(code).run(project=self)
Пример #30
0
    def selected_tracks(self):
        """
        List of selected tracks (excluding master).

        :type: list of Track
        """
        code = """
        track_ids = [
            RPR.GetSelectedTrack(project_id, i)
            for i in range(reapy.Project(project_id).n_selected_tracks)
        ]
        """
        track_ids = Program(code, "track_ids").run(project_id=self.id)[0]
        tracks = list(map(reapy.Track, track_ids))
        return tracks