Skip to content

Commit

Permalink
DearPyGui 2.0 support
Browse files Browse the repository at this point in the history
Fixed pin connections
Fixed blinking
Fixed colors
Add colors customization menu
  • Loading branch information
rdoursenaud committed Dec 30, 2024
1 parent 4a059f4 commit 9a6518f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 45 deletions.
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ requires-python = '>=3.10'
# https://peps.python.org/pep-0508
# https://peps.python.org/pep-0440/#version-specifiers
dependencies = [
'dearpygui>=1.8,<1.11',
'dearpygui-ext~=0.9.5',
'dearpygu~=2.0.0',
'dearpygui-ext~=2.0.0',
'midi_const~=0.1.0',
'mido~=1.3.0', # FIXME: currently using custom 1.2.11a1 with EOX, running status and delta time support
'python-rtmidi~=1.5.5', # While it's mido's default backend, we explicitly require it for some features.
'Pillow>=9.5,<10.4',
'pillow~=11.0.0',
]
license = { file = 'LICENSE' }
authors = [
Expand Down Expand Up @@ -60,6 +60,9 @@ classifiers = [
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Topic :: Artistic Software',
'Topic :: Communications',
# 'Topic :: Documentation :: Sphinx', # TODO
Expand Down Expand Up @@ -121,6 +124,8 @@ no-cov = 'cov --no-cov'
python = [
'310',
'311',
'312',
'313',
]

[tool.hatch.envs.docs]
Expand Down
4 changes: 2 additions & 2 deletions src/midiexplorer/gui/windows/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def link_node_callback(sender: int | str,
pin2: dpg.mvNodeAttribute = app_data[1]
_, pin1_label, _, pin2_label = _pins_nodes_labels(pin1, pin2)

logger.log_debug(f"Connection between pins: '{pin1}' & '{pin2}'.")
logger.log_debug(f"Connection between pins: '{pin1}' ({pin1_label}) & '{pin2}' ({pin2_label}).")

# Only allow one link per pin for now
# TODO: Automatically add merger node when linked to multiple nodes.
Expand Down Expand Up @@ -667,7 +667,7 @@ def handle_received_data(timestamp: Timestamp, source: str, dest: str, midi_data
if isinstance(port, MidiOutPort):
logger.log_debug(f"Echoing MIDI data to midi output {port.label}")
port.port.send(midi_data)
if dest == 'probe_in':
if dest == dpg.get_alias_id('probe_in'):
probe_thru_user_data = dpg.get_item_user_data('probe_thru')
if probe_thru_user_data:
# logger.log_debug(f"Probe thru has user data: {probe_thru_user_data}")
Expand Down
86 changes: 53 additions & 33 deletions src/midiexplorer/gui/windows/mon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def _update_notation_mode(sender: int | str, app_data: Any, user_data: Optional[
enable_dpg_cb_debugging(sender, app_data, user_data)

# Update keyboard
for index in range(0, 128): # All MIDI notes
for note_number in range(0, 128): # All MIDI notes
dpg.configure_item(
f'note_{index}',
f'note_{note_number}',
format=_verticalize(
user_data.get(dpg.get_value('notation_mode')).get(index)
user_data.get(dpg.get_value('notation_mode')).get(note_number)
)
)

Expand Down Expand Up @@ -121,9 +121,11 @@ def create() -> None:
# ---------------------------------------
# DEAR PYGUI THEME for activated buttons
# ---------------------------------------
red = (255, 0, 0)
dark_red = (128, 0, 0)
magenta = (170, 0, 170)
dark_magenta = (85, 0, 85)
with dpg.theme(tag='__act'):
red = (255, 0, 0)
light_red = (128, 0, 0)
with dpg.theme_component(dpg.mvButton):
dpg.add_theme_color(
tag='__act_but_col',
Expand All @@ -132,34 +134,32 @@ def create() -> None:
)
with dpg.theme_component(dpg.mvSliderInt):
dpg.add_theme_color(
tag='__act_sli_col', # TODO: allow customizing
tag='__act_sli_col',
target=dpg.mvThemeCol_SliderGrab,
value=red,
)
dpg.add_theme_color(
tag='__act_sli_bg_col', # TODO: allow customizing
tag='__act_sli_bg_col',
target=dpg.mvThemeCol_FrameBg,
value=light_red,
value=dark_red,
)
with dpg.theme(tag='__force_act'):
magenta = (170, 0, 170)
light_magenta = (85, 0, 85)
with dpg.theme_component(dpg.mvButton):
dpg.add_theme_color(
tag='__force_act_col',
tag='__force_act_but_col',
target=dpg.mvThemeCol_Button,
value=magenta, # light magenta
value=magenta,
)
with dpg.theme_component(dpg.mvSliderInt):
dpg.add_theme_color(
tag='__force_act_sli_col', # TODO: allow customizing
tag='__force_act_sli_col',
target=dpg.mvThemeCol_SliderGrab,
value=magenta,
)
dpg.add_theme_color(
tag='__force_act_sli_bg_col', # TODO: allow customizing
tag='__force_act_sli_bg_col',
target=dpg.mvThemeCol_FrameBg,
value=light_magenta,
value=dark_magenta,
)

# -------------------
Expand Down Expand Up @@ -187,13 +187,7 @@ def create() -> None:
# --------
# Settings
# --------
with dpg.menu(label="Settings"):
with dpg.group():
dpg.add_text("Live color:")
dpg.add_color_picker(source='__act_but_col')
with dpg.group():
dpg.add_text("Selected color:")
dpg.add_color_picker(source='__force_act_col')
with dpg.menu(label="Display"):
with dpg.group(horizontal=True):
dpg.add_text("Persistence:")
dpg.add_slider_float(
Expand All @@ -203,6 +197,42 @@ def create() -> None:
callback=lambda:
dpg.set_value('mon_blink_duration', dpg.get_value('mon_blink_duration_slider'))
)
with dpg.group(horizontal=True):
dpg.add_text("Notation:")
dpg.add_radio_button(
items=list(notation_modes.keys()),
default_value=next(iter(notation_modes.values())), # First value
source='notation_mode',
callback=_update_notation_mode,
user_data=notation_modes
)
with dpg.menu(label="Colors"):
dpg.add_text("Buttons")
with dpg.group(horizontal=True):
with dpg.group():
dpg.add_text("Live color:")
dpg.add_color_picker(source='__act_but_col')
with dpg.group():
dpg.add_text("Selected color:")
dpg.add_color_picker(source='__force_act_but_col')
dpg.add_text("Sliders")
with dpg.group(horizontal=True):
with dpg.group():
dpg.add_text("Live color:")
dpg.add_color_picker(source='__act_sli_col')
with dpg.group():
dpg.add_text("Selected color:")
dpg.add_color_picker(source='__force_act_sli_col')
dpg.add_text("Sliders background")
with dpg.group(horizontal=True):
with dpg.group():
dpg.add_text("Live color:")
dpg.add_color_picker(source='__act_sli_bg_col')
with dpg.group():
dpg.add_text("Selected color:")
dpg.add_color_picker(source='__force_act_sli_bg_col')

with dpg.menu(label="Advanced"):
with dpg.group(horizontal=True):
dpg.add_text("Zero (0) velocity Note On is Note Off:")
dpg.add_checkbox(label="(default, MIDI specification compliant)",
Expand All @@ -216,16 +246,6 @@ def create() -> None:
callback=_update_eox_category,
user_data=eox_categories
)
with dpg.group(horizontal=True):
dpg.add_text("Notation:")
dpg.add_radio_button(
items=list(notation_modes.keys()),
default_value=next(iter(notation_modes.values())), # First value
source='notation_mode',
callback=_update_notation_mode,
user_data=notation_modes
)

# TODO: Panic button to reset all monitored states.

# -----
Expand Down Expand Up @@ -549,7 +569,7 @@ def create() -> None:
pos=(xpos, ypos),
vertical=True,
min_value=0, max_value=127,
enabled=True, # Required for theme color to apply properly
enabled=False, # Required for theme color to apply properly
)

tooltip_conv(
Expand Down
14 changes: 7 additions & 7 deletions src/midiexplorer/gui/windows/mon/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def note_on(number: int | str, static: bool = False, velocity: int = None) -> No
:param velocity: Note velocity
"""
theme = get_theme(static)
dpg.bind_item_theme(f'note_{number}', theme)
dpg.enable_item(f'note_{number}')
if velocity is not None:
dpg.set_value(f'note_{number}', velocity)

Expand All @@ -144,8 +143,10 @@ def note_off(number: int | str, static: bool = False) -> None:
:param static: Live or static mode.
"""
theme = get_theme(static, disable=True)
dpg.bind_item_theme(f'note_{number}', theme)
if static:
dpg.enable_item(f'note_{number}')
else:
dpg.disable_item(f'note_{number}')
dpg.set_value(f'note_{number}', 0)


Expand Down Expand Up @@ -184,9 +185,8 @@ def reset_mon(static: bool = False) -> None:
if not static or dpg.get_value(f'{indicator}_active_until') == float('inf'):
_reset_indicator(indicator)

for index in range(0, 128): # All MIDI notes
if not static or dpg.get_item_theme(f'note_{index}') == '__force_act':
note_off(index)
for note_number in range(0, 128): # All MIDI notes
note_off(note_number, not static)

if not static:
for decoder in get_supported_decoders():
Expand Down

0 comments on commit 9a6518f

Please sign in to comment.