Skip to content

Presets

Presets ¤

Bases: CollectionBase

Represents a collection of Helix presets for a given setlist.

Source code in helixapi\presets.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
class Presets(CollectionBase):
    """
    Represents a collection of Helix presets for a given setlist.
    """
    def __init__(self, data: dict=None, setlist_index: int=None):
        """
        Initialize the Presets class.

        Args:
            data (dict): The data structure representing the setlist.
            setlist_index (int): Index of the setlist containing this preset.

        Examples:
        ``` py
        setlist = Setlist(data, index=0)
        ```
        """
        self._midi = MIDI()

        super().__init__(cls=Preset, items=[Preset(data=data, setlist_index=setlist_index, index=i, set_active_callback=self._set_active_preset) for i in range(MAX_PRESETS)])

        self._setlist_index = setlist_index
        self._active_index = 0  # Set the first preset as active initially

        # Ensure the initial active preset is correctly marked as active
        if self._items:
            self._items[self._active_index].active = True
            self._set_active_preset(self._active_index)

    def _set_active_preset(self, index):
        self._active_index = index
        self._midi.commands.change_to_preset(index)

    @property
    def active_index(self):
        """
        Get the index of the active preset.

        Returns:
            int: The index of the active preset.
        """
        return self._active_index

    @active_index.setter
    def active_index(self, index):
        """
        Set the index of the active preset.

        Args:
            index (int): The index of the preset to set as active.
        """
        self._set_active_preset(index)

    @property
    def active_item(self):
        """
        Get the active preset.

        Returns:
            Preset: The active preset.
        """
        return self._active_item

    @active_item.setter
    def active_item(self, item):
        """
        Set the active preset.

        Args:
            item (Preset): The preset to set as active.
        """
        self._active_item = item
        self._set_active_preset(item.index)

    def export_presets(self, file_path=None):
        """
        Export presets to a single file.

        Args:
            file_path (str): The path to the file to export presets to. 

        Returns:
            None
        """
        self._export_files(file_path)

    def import_presets(self, file_paths: List[str]):
        """
        Import presets from multiple files.


        !!! note


            Preset order will follow the order of the provided file_paths (i.e. the first file path will be preset 1, etc)

        Args:
            file_paths (List[str]): List of file paths to import presets from.

        Returns:
            None
        """
        self._import_files(file_paths)

active_index property writable ¤

Get the index of the active preset.

Returns:

Name Type Description
int

The index of the active preset.

active_item property writable ¤

Get the active preset.

Returns:

Name Type Description
Preset

The active preset.

export_presets(file_path=None) ¤

Export presets to a single file.

Parameters:

Name Type Description Default
file_path str

The path to the file to export presets to.

None

Returns:

Type Description

None

Source code in helixapi\presets.py
81
82
83
84
85
86
87
88
89
90
91
def export_presets(self, file_path=None):
    """
    Export presets to a single file.

    Args:
        file_path (str): The path to the file to export presets to. 

    Returns:
        None
    """
    self._export_files(file_path)

import_presets(file_paths) ¤

Import presets from multiple files.

Note

Preset order will follow the order of the provided file_paths (i.e. the first file path will be preset 1, etc)

Parameters:

Name Type Description Default
file_paths List[str]

List of file paths to import presets from.

required

Returns:

Type Description

None

Source code in helixapi\presets.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def import_presets(self, file_paths: List[str]):
    """
    Import presets from multiple files.


    !!! note


        Preset order will follow the order of the provided file_paths (i.e. the first file path will be preset 1, etc)

    Args:
        file_paths (List[str]): List of file paths to import presets from.

    Returns:
        None
    """
    self._import_files(file_paths)