Skip to content

Preset

Preset ¤

Bases: ItemBase

Represents a Helix preset for a given setlist. This contains specific metadata (index, name) and all snapshots.

Source code in helixapi\preset.py
  5
  6
  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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
class Preset(ItemBase):
    """
    Represents a Helix preset for a given setlist. This contains specific metadata (index, name) and all snapshots.
    """

    def __init__(self, data: dict, setlist_index: int, index: int, set_active_callback=None, metadata: dict = {}):
        """
        Initialize the Preset class.

        Args:
            data (dict): The data structure representing the preset.
            setlist_index (int): Index of the setlist containing this preset.
            index (int): Index of this preset within its setlist.
            set_active_callback (callable): Callback function to set the active preset.
            metadata (dict, optional): Additional metadata for the preset. Defaults to {}.

        Examples:
        ``` py
        preset = Preset(data, setlist_index=0, index=1)
        ```
        """
        super().__init__(cls=Preset, data=data, metadata=metadata, setlist_index=setlist_index, preset_index=index)
        self.index = index
        self._active = False
        self._set_active_callback = set_active_callback

        # set author if not set or if overwrite is enabled
        # setting here allows us to change it later if needed
        settings = Settings()
        author = self.author
        if not author or settings.author_overwrite:
            self.author = settings.author_name

        # Load the snapshots
        self._snapshots = Snapshots(
            data=data, 
            setlist_index=setlist_index, 
            preset_index=self.index,
            get_active_callback=self._get_active_snapshot_index,
            set_active_callback=self._set_active_snapshot_index
        )

    @property
    def _active_snapshot_index(self):
        """
        Get the current snapshot of the preset.

        Returns:
            int: The index of the current snapshot.

        Examples:
        ``` py
        current_snapshot = preset.current_snapshot
        ```
        """
        return self._get_data("current_snapshot")

    @_active_snapshot_index.setter
    def _active_snapshot_index(self, index):
        self._set_data("current_snapshot", index)

    def _get_active_snapshot_index(self):
        return self._active_snapshot_index

    def _set_active_snapshot_index(self, index):
        self._active_snapshot_index = index

    @property
    def snapshots(self):
        """
        Get the snapshots of the preset.

        Returns:
            Snapshots: The snapshots of the preset.

        Examples:
        ``` py
        preset.snapshots
        ```
        """
        return self._snapshots

    @property
    def name(self) -> str:
        """
        Get the name of the preset.

        Returns:
            str: The name of the preset.

        Examples:
        ``` py
        preset.name
        ```
        """
        return self._get_data("name")

    @name.setter
    def name(self, value: str) -> None:
        """
        Set the name of the preset.

        Args:
            value (str): The name to set for the preset.

        Raises:
            ValueError: If the name length exceeds the maximum allowed length.

        Examples:
        ``` py
        preset.name = "Preset 1"
        ```
        """
        if len(value) > 16:
            raise ValueError("Name must be 16 characters or fewer.")
        self._set_data("name", value)

    @property
    def author(self) -> str:
        """
        Get the author of the preset.

        Returns:
            str: The author of the preset.

        Examples:
        ``` py
        preset.author
        ```
        """
        return str(self._get_data("author"))

    @author.setter
    def author(self, value: str) -> None:
        """
        Set the author of the preset.

        Args:
            value (str): The author to set for the preset.

        Raises:
            ValueError: If the author length exceeds the maximum allowed length.

        Examples:
        ``` py
        preset.author = "Me"
        ```
        """
        if len(value) > 16:
            raise ValueError("Author must be 16 characters or fewer.")
        self._set_data("author", value)

    @property
    def band(self) -> str:
        """
        Get the band of the preset.

        Returns:
            str: The band of the preset.

        Examples:
        ``` py
        preset.band
        ```
        """
        return self._get_data("band")

    @band.setter
    def band(self, value: str) -> None:
        """
        Set the band of the preset.

        Args:
            value (str): The band to set for the preset.

        Raises:
            ValueError: If the band length exceeds the maximum allowed length.

        Examples:
        ``` py
        preset.band = "My Band"
        ```
        """
        if len(value) > 16:
            raise ValueError("Band must be 16 characters or fewer.")
        self._set_data("band", value)
    @property
    def song(self) -> str:
        """
        Get the song name of the preset.

        Returns:
            str: The song name of the preset.

        Examples:
        ``` py
        preset.song
        ```
        """
        return self._get_data("song")

    @song.setter
    def song(self, value: str) -> None:
        """
        Set the song name of the preset.

        Args:
            value (str): The song name to set for the preset.

        Raises:
            ValueError: If the song name length exceeds the maximum allowed length.

        Examples:
        ``` py
        preset.song = "My Song"
        ```
        """
        if len(value) > 16:
            raise ValueError("Song name must be 16 characters or fewer.")
        self._set_data("song", value)


    def import_preset(self, file_path=None) -> None:
        """
        Import a preset from a file.

        Args:
            file_path (str): Path to the preset file to import.

        Examples:
        ``` py
        preset.import_preset("preset.hlx")
        ```

        Raises:
        Exception: If the file path is not specified or the file type is incorrect.

        Returns:
        None
        """
        self._import_file(file_path=file_path)

    def export_preset(self, file_path=None) -> None:
        """
        Export a preset to a file.

        Args:
            file_path (str): Path to export the preset file to.

        Examples:
        ``` py
        preset.export_preset("preset.hlx")
        ```

        Raises:
        Exception: If the file path is not specified or the file type is incorrect.

        Returns:
        None
        """
        self._export_file(file_path=file_path)

    def reset_preset(self) -> None:
        """
        Reset the preset to its default values.

        Examples:
        ``` py
        preset.reset_preset()
        ```

        Returns:
        None
        """
        self.import_preset()

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

        Returns:
            bool: True if the preset is active, False otherwise.

        Examples:
        ``` py
        print(preset.active)
        ```
        """
        return self._active

    @active.setter
    def active(self, value):
        """
        Set the preset as active.

        Args:
            value (bool): True to set the preset as active, False otherwise.

        Examples:
        ``` py
        preset.active = True
        ```
        """
        if value and self._set_active_callback:
            self._set_active_callback(self.index)
        self._active = value

active property writable ¤

Get the preset as active.

Returns:

Name Type Description
bool

True if the preset is active, False otherwise.

Examples:

print(preset.active)

author: str property writable ¤

Get the author of the preset.

Returns:

Name Type Description
str str

The author of the preset.

Examples:

preset.author

band: str property writable ¤

Get the band of the preset.

Returns:

Name Type Description
str str

The band of the preset.

Examples:

preset.band

index = index instance-attribute ¤

name: str property writable ¤

Get the name of the preset.

Returns:

Name Type Description
str str

The name of the preset.

Examples:

preset.name

snapshots property ¤

Get the snapshots of the preset.

Returns:

Name Type Description
Snapshots

The snapshots of the preset.

Examples:

preset.snapshots

song: str property writable ¤

Get the song name of the preset.

Returns:

Name Type Description
str str

The song name of the preset.

Examples:

preset.song

export_preset(file_path=None) ¤

Export a preset to a file.

Parameters:

Name Type Description Default
file_path str

Path to export the preset file to.

None

Examples:

preset.export_preset("preset.hlx")

Raises: Exception: If the file path is not specified or the file type is incorrect.

Returns: None

Source code in helixapi\preset.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
def export_preset(self, file_path=None) -> None:
    """
    Export a preset to a file.

    Args:
        file_path (str): Path to export the preset file to.

    Examples:
    ``` py
    preset.export_preset("preset.hlx")
    ```

    Raises:
    Exception: If the file path is not specified or the file type is incorrect.

    Returns:
    None
    """
    self._export_file(file_path=file_path)

import_preset(file_path=None) ¤

Import a preset from a file.

Parameters:

Name Type Description Default
file_path str

Path to the preset file to import.

None

Examples:

preset.import_preset("preset.hlx")

Raises: Exception: If the file path is not specified or the file type is incorrect.

Returns: None

Source code in helixapi\preset.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def import_preset(self, file_path=None) -> None:
    """
    Import a preset from a file.

    Args:
        file_path (str): Path to the preset file to import.

    Examples:
    ``` py
    preset.import_preset("preset.hlx")
    ```

    Raises:
    Exception: If the file path is not specified or the file type is incorrect.

    Returns:
    None
    """
    self._import_file(file_path=file_path)

reset_preset() ¤

Reset the preset to its default values.

Examples:

preset.reset_preset()

Returns: None

Source code in helixapi\preset.py
267
268
269
270
271
272
273
274
275
276
277
278
279
def reset_preset(self) -> None:
    """
    Reset the preset to its default values.

    Examples:
    ``` py
    preset.reset_preset()
    ```

    Returns:
    None
    """
    self.import_preset()