Source code for jdxi_editor.midi.playback.state

"""
MIDI playback state management.
"""

from dataclasses import dataclass, field
from typing import Literal, Optional

from mido import MidiFile

from jdxi_editor.midi.channel.channel import MidiChannel
from picomidi.constant import Midi


@dataclass
[docs] class MidiPlaybackState: """State container for MIDI file playback."""
[docs] channel_selected: Literal[ MidiChannel.DIGITAL_SYNTH_1, MidiChannel.DIGITAL_SYNTH_2, MidiChannel.ANALOG_SYNTH, MidiChannel.DRUM_KIT, ] = MidiChannel.DIGITAL_SYNTH_1
[docs] events: list = field(default_factory=list)
[docs] file: Optional[MidiFile] = None
[docs] file_duration_seconds: float = 0.0
# New attributes for playback state
[docs] suppress_control_changes: bool = field(default=True)
[docs] suppress_program_changes: bool = field( default=False ) # False = send PCs so inserted PCs are heard
# program changes that do not choose a JD-Xi sound (General MIDI ones): not sent
[docs] block_foreign_program_changes: bool = field(default=True)
[docs] custom_tempo_force: bool = field(default=False)
[docs] custom_tempo: int = field( default=Midi.tempo.BPM_162_USEC ) # Default custom tempo in microseconds
[docs] tempo_initial: int = field(default=Midi.tempo.BPM_120_USEC)
[docs] tempo_at_position: int = field(default=Midi.tempo.BPM_120_USEC)
# end of new attributes
[docs] muted_tracks: set[int] = field(default_factory=set)
[docs] muted_channels: set[int] = field(default_factory=set)
[docs] def __post_init__(self) -> None: if self.custom_tempo_force: self.tempo_at_position = self.custom_tempo # Use custom tempo if forced else: self.tempo_at_position = Midi.tempo.BPM_120_USEC # Default of 120 bpm