jdxi_editor.ui.programs.playlist_orm

SQLAlchemy ORM-based access layer for playlists.

This module provides ORM-based methods for accessing playlists and playlist items using SQLAlchemy, replacing the direct SQLite queries in database.py.

Classes

PlaylistORM

ORM-based access layer for playlists.

Module Contents

class jdxi_editor.ui.programs.playlist_orm.PlaylistORM(db_path: pathlib.Path | None = None)[source]

ORM-based access layer for playlists.

db_session[source]
create_playlist(name: str, description: str | None = None) → int | None[source]

Create a new playlist.

Parameters:
  • name – Playlist name (must be unique)

  • description – Optional description

Returns:

Playlist ID if successful, None otherwise

duplicate_playlist(playlist_id: int, new_name: str) → int | None[source]

Copy a playlist under a new name, with its description and every item (program, MIDI file, cheat preset) in the same order.

Parameters:
  • playlist_id – Playlist to copy

  • new_name – Name of the copy (playlist names are unique)

Returns:

The new playlist’s ID, or None if it could not be created

get_all_playlists() → List[Dict][source]

Get all playlists.

Returns:

List of playlist dictionaries

get_playlist_by_id(playlist_id: int) → Dict | None[source]

Get a playlist by ID.

Parameters:

playlist_id – Playlist ID

Returns:

Playlist dictionary if found, None otherwise

update_playlist(playlist_id: int, name: str | None = None, description: str | None = None) → bool[source]

Update a playlist.

Parameters:
  • playlist_id – Playlist ID

  • name – New name (optional)

  • description – New description (optional)

Returns:

True if successful, False otherwise

delete_playlist(playlist_id: int) → bool[source]

Delete a playlist and all its items.

Parameters:

playlist_id – Playlist ID

Returns:

True if successful, False otherwise

add_program_to_playlist(playlist_id: int, program_id: str, position: int | None = None) → bool[source]

Add a program to a playlist.

Parameters:
  • playlist_id – Playlist ID

  • program_id – Program ID (e.g., “E01”)

  • position – Position in playlist (optional, will append if not provided)

Returns:

True if successful, False otherwise

add_song_to_playlist(playlist_id: int, midi_file_path: str, position: int | None = None) → bool[source]

Append a song that is only a MIDI file.

Parameters:
  • playlist_id – Playlist ID

  • midi_file_path – Path of the MIDI file

  • position – Position in the playlist (appended when omitted)

Returns:

True if the song was added

set_item_program(item_id: int, program_id: str | None) → bool[source]

Set or clear the JD-Xi program on one song.

Parameters:
  • item_id – Playlist item ID

  • program_id – Program ID, or None to clear it

Returns:

True if the song was updated

static _next_position(session, playlist_id: int) → int[source]

The position after the last song in the playlist (1 when it is empty).

static _find_item(session, playlist_id: int, program_id: str | None, item_id: int | None)[source]

The playlist item to act on. A program can be in a playlist more than once (one entry per MIDI file), so item_id picks the exact entry; without it, the first entry for the program is used (older callers).

remove_program_from_playlist(playlist_id: int, program_id: str, item_id: int | None = None) → bool[source]

Remove a program from a playlist.

Parameters:
  • playlist_id – Playlist ID

  • program_id – Program ID

  • item_id – Playlist item ID, to remove one specific entry when the program is in the playlist more than once

Returns:

True if successful, False otherwise

reorder_playlist(playlist_id: int, item_ids: List[int]) → bool[source]

Save a new order for a playlist: item_ids lists every item of the playlist, first to last, and positions become 1..N in that order. Playback follows these positions, so the order shown and the order played stay the same.

Positions are rewritten in two passes (first to temporary negative values) so that swapping two entries never clashes with a uniqueness rule on (playlist, program, position) in older databases.

Parameters:
  • playlist_id – Playlist ID

  • item_ids – Playlist item IDs in their new order

Returns:

True if saved; False if the list isn’t exactly the playlist’s items

get_playlist_programs(playlist_id: int, get_program_func: callable | None = None) → List[Dict][source]

Get all programs in a playlist with their MIDI file paths, ordered by position.

Parameters:
  • playlist_id – Playlist ID

  • get_program_func – Optional function to get JDXiProgram by ID (for compatibility)

Returns:

List of dictionaries with ‘program’ (JDXiProgram) and ‘midi_file_path’ (str)

update_playlist_item_midi_file(playlist_id: int, program_id: str | None, midi_file_path: str | None, item_id: int | None = None) → bool[source]

Update the MIDI file path for a playlist item.

Parameters:
  • playlist_id – Playlist ID

  • program_id – Program ID

  • midi_file_path – Path to MIDI file (or None to clear)

  • item_id – Playlist item ID (the exact entry when the program is used more than once)

Returns:

True if successful, False otherwise

update_playlist_item_artwork(playlist_id: int, item_id: int, artwork_path: str | None = None) → bool[source]

Set the cover image of one playlist entry.

Parameters:
  • playlist_id – Playlist ID

  • item_id – Playlist item ID

  • artwork_path – Image file path, or None to clear

Returns:

True if the entry was found and updated

update_playlist_item_cheat_preset(playlist_id: int, program_id: str | None, cheat_preset_id: str | None = None, item_id: int | None = None) → bool[source]

Update the cheat preset ID for a playlist item.

Parameters:
  • playlist_id – Playlist ID

  • program_id – Program ID

  • cheat_preset_id – Cheat preset ID (e.g., “113”) or None to clear

  • item_id – Playlist item ID (the exact entry when the program is used more than once)

Returns:

True if updated, False otherwise