Skip to content

Commit

Permalink
Improved GUI
Browse files Browse the repository at this point in the history
Fix volume computation
  • Loading branch information
rdoursenaud committed Feb 27, 2021
1 parent 063a971 commit 9cd1d2e
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ venv
# PyInstaller
build
dist
__pycache__
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ License: [GPLv3+](LICENSE)

Language: [Python](https://python.org) 3

Dependencies:

- [Unicode Power Symbol](https://unicodepowersymbol.com/) Copyright (c) 2013 Joe Loughry licensed under MIT

### Features

#### Target hardware
Expand Down Expand Up @@ -74,12 +78,11 @@ Language: [Python](https://python.org) 3

##### Windows executable

- [ ] Find a way to make it resident in the task bar with a nice icon, like soundcard control panel
- [x] Find a way to make it resident in the task bar with a nice icon, like soundcard control panel
- [x] [RBTray](https://sourceforge.net/projects/rbtray/files/latest/download)
- [x] [MinimizeToTray](https://github.com/sandwichdoge/MinimizeToTray/releases/latest)
- [ ] The Pythonic Way
- [ ] Handle shutdown to power off the device
- [ ] PyInstaller
- [y] PyInstaller
- [ ] VST plugin? (Not required if MIDI input is implemented but would be neat to have in the monitoring section of a
DAW)
- [ ] See [PyVST](https://pypi.org/project/pyvst/)
Expand Down
Binary file added Unicode_IEC_symbol.ttf
Binary file not shown.
Binary file added assets/DN-500AV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from telnetlib import TELNET_PORT

DEBUG = False

GUI = True

# TODO: override at build time
BUILD_DATE = '<source>'

RECEIVER_IP = '192.168.1.24'
RECEIVER_PORT = TELNET_PORT
GUI = True
DEBUG = True

VOL_PRESET_1 = '-30.0dB'
VOL_PRESET_2 = '-24.0dB'
Expand Down
9 changes: 4 additions & 5 deletions denon/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ def lineReceived(self, line):
state = False
if receiver.parameter_code == 'ON':
state = True
self.factory.app.set_mute_button(state)
self.factory.app.update_volume_mute(state)

# VOLUME
if receiver.command_code == 'MV':
if receiver.subcommand_code is None:
self.factory.app.set_volume(receiver.parameter_label)
self.factory.app.update_volume(receiver.parameter_label)

# POWER
if receiver.command_code == 'PW':
state = True
if receiver.parameter_code == 'STANDBY':
state = False
self.factory.app.set_power_button(state)
self.factory.app.update_power(state)

# SOURCE
if receiver.command_code == 'SI':
source = receiver.parameter_code
self.factory.app.set_source(source)
self.factory.app.update_source(source)

def connectionMade(self):
if self.factory.gui:
Expand Down Expand Up @@ -100,7 +100,6 @@ def get_mute(self):
self.sendLine('MU?'.encode('ASCII'))

def set_mute(self, state):
self.logger.debug("Entering mute callback")
if state:
self.sendLine('MUON'.encode('ASCII'))
else:
Expand Down
51 changes: 37 additions & 14 deletions denon/dn500av.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,48 @@ def srange(start, stop, step, length):
MASTER_VOLUME_ZERODB_REF = 80


def compute_master_volume_label(value):
def compute_master_volume_label(value, zerodb_ref=MASTER_VOLUME_ZERODB_REF):
"""Convert Master Volume ASCII value to dB"""
# TODO: Handle absolute values
label = ''
label = '---.-dB'
if int(value[:2]) < MASTER_VOLUME_MIN or int(value[:2]) > MASTER_VOLUME_MAX:
logger.error("Master volume value %s out of bounds (%s-%s)", value, MASTER_VOLUME_MIN, MASTER_VOLUME_MAX)
# Quirks
if value == '99':
label = "-∞dB"
result = "-∞dB"
elif value == '995':
label = "-80.5dB"
else:
result = "-80.5dB"
elif len(value) == 2:
# General case
result = str(float(value) - zerodb_ref)
elif len(value) == 3:
# Handle undocumented special case for half dB

# Hardcode values around 0 because of computing sign uncertainty
# FIXME: test '985' which seems invalid
if len(value) == 2:
label = str(float(value) - MASTER_VOLUME_ZERODB_REF) + "dB"
if len(value) == 3:
# Handle undocumented special case for half dB
label = str(int(value[:2]) - MASTER_VOLUME_ZERODB_REF) + ".5" + "dB"
if value == str((zerodb_ref - 1)) + '5':
result = "-0.5"
elif value == str(zerodb_ref) + '5':
result = "0.5"
else:
value = int(value[:2]) # Drop the third digit
offset = 0
if value < zerodb_ref:
offset = 1
logger.debug("Add offset %i to dB calculation with value %i5", offset, value)
result = str(int(value + offset - zerodb_ref)) + ".5"
else:
raise ValueError

# Format label with fixed width like the actual display:
# [ NEG SIGN or EMPTY ] [ DIGIT er EMPTY ] [ DIGIT ] [ DOT ] [ DIGIT ] [ d ] [ B ]
label = "%s%s%s.%sdB" % (
result[0] if result[0] == '-' else " ",
" " if len(result) <= 3 or result[-4] == '-' else result[-4],
result[-3],
result[-1])

logger.debug(label)
return label


Expand Down Expand Up @@ -734,7 +757,7 @@ def parse_response(self, status_command):
self.logger.error("Command unknown: %s", status_command)
return
else:
self.logger.info("Found command %s: %s", self.command_code, self.command_label)
self.logger.info("Parsed command %s: %s", self.command_code, self.command_label)

# Trim command from status command stream
status_command = status_command[len(self.command_code):]
Expand All @@ -757,7 +780,7 @@ def parse_response(self, status_command):
self.logger.debug("Subcommand unknown. Probably a parameter: %s", status_command)
self.subcommand_code = None
else:
self.logger.info("Found subcommand %s: %s", self.subcommand_code, self.subcommand_label)
self.logger.info("Parsed subcommand %s: %s", self.subcommand_code, self.subcommand_label)
# Trim subcommand from status command stream
status_command = status_command[
len(self.subcommand_code) + 1:] # Subcommands have a space before the parameter
Expand All @@ -778,7 +801,7 @@ def parse_response(self, status_command):

# Handle unexpected leftovers
if status_command:
self.logger.error("unexpected unparsed data found: %s", status_command)
self.logger.error("Unexpected unparsed data found: %s", status_command)

if self.subcommand_label:
self.response = "%s, %s: %s" % (self.command_label, self.subcommand_label, self.parameter_label)
Expand All @@ -793,7 +816,7 @@ class DN500AVFormat():

def __init__(self, logger=None):
self.logger = logger
self.mv_reverse_params = new_dict = dict([(value, key) for key, value in mv_params.items()])
self.mv_reverse_params = dict([(value, key) for key, value in mv_params.items()])

def get_raw_volume_value_from_db_value(self, value):
self.logger.debug('value: %s', value)
Expand Down
6 changes: 5 additions & 1 deletion denonremote.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ from kivy_deps import sdl2, glew

block_cipher = None

added_files = [
( 'Unicode_IEC_symbol.ttf', '.' ),
('assets', 'assets')
]

a = Analysis(['main.py'],
pathex=['G:\\raph\\Documents\\GitHub\\denonremote'],
binaries=[],
datas=[],
datas=added_files,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
Loading

0 comments on commit 9cd1d2e

Please sign in to comment.