ASIO to JACK driver for WINE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # WineASIO Settings GUI
  4. # Copyright (C) 2020 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the COPYING.GUI file
  17. # ---------------------------------------------------------------------------------------------------------------------
  18. import os
  19. import sys
  20. from PyQt5.QtCore import pyqtSlot, QDir
  21. from PyQt5.QtWidgets import QApplication, QDialog
  22. # ---------------------------------------------------------------------------------------------------------------------
  23. from ui_settings import Ui_WineASIOSettings
  24. # ---------------------------------------------------------------------------------------------------------------------
  25. BUFFER_SIZE_LIST = (16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192)
  26. HOME = QDir.homePath()
  27. WINEPREFIX = os.getenv("WINEPREFIX")
  28. if not WINEPREFIX:
  29. WINEPREFIX = os.path.join(HOME, ".wine")
  30. WINEASIO_PREFIX = "HKEY_CURRENT_USER\Software\Wine\WineASIO"
  31. # ---------------------------------------------------------------------------------------------------------------------
  32. def getWineASIOKeyValue(key: str, default: str):
  33. wineFile = os.path.join(WINEPREFIX, "user.reg")
  34. if not os.path.exists(wineFile):
  35. return default
  36. wineDumpF = open(wineFile, "r")
  37. wineDump = wineDumpF.read()
  38. wineDumpF.close()
  39. wineDumpSplit = wineDump.split("[Software\\\\Wine\\\\WineASIO]")
  40. if len(wineDumpSplit) <= 1:
  41. return default
  42. wineDumpSmall = wineDumpSplit[1].split("[")[0]
  43. keyDumpSplit = wineDumpSmall.split('"%s"' % key)
  44. if len(keyDumpSplit) <= 1:
  45. return default
  46. keyDumpSmall = keyDumpSplit[1].split(":")[1].split("\n")[0]
  47. return keyDumpSmall
  48. def smartHex(value: str, length: int):
  49. hexStr = hex(value).replace("0x","")
  50. if len(hexStr) < length:
  51. zeroCount = length - len(hexStr)
  52. hexStr = "%s%s" % ("0"*zeroCount, hexStr)
  53. return hexStr
  54. # ---------------------------------------------------------------------------------------------------------------------
  55. # Set-up GUI (Tweaks, WineASIO)
  56. # Force Restart Dialog
  57. class WineASIOSettingsDialog(QDialog, Ui_WineASIOSettings):
  58. def __init__(self):
  59. QDialog.__init__(self, None)
  60. self.setupUi(self)
  61. self.changed = False
  62. self.loadSettings()
  63. self.accepted.connect(self.slot_saveSettings)
  64. self.sb_ports_in.valueChanged.connect(self.slot_flagChanged)
  65. self.sb_ports_out.valueChanged.connect(self.slot_flagChanged)
  66. self.cb_ports_connect_hw.clicked.connect(self.slot_flagChanged)
  67. self.cb_jack_autostart.clicked.connect(self.slot_flagChanged)
  68. self.cb_jack_fixed_bsize.clicked.connect(self.slot_flagChanged)
  69. self.cb_jack_buffer_size.currentIndexChanged[int].connect(self.slot_flagChanged)
  70. def loadSettings(self):
  71. ins = int(getWineASIOKeyValue("Number of inputs", "00000010"), 16)
  72. outs = int(getWineASIOKeyValue("Number of outputs", "00000010"), 16)
  73. hw = bool(int(getWineASIOKeyValue("Connect to hardware", "00000001"), 10))
  74. autostart = bool(int(getWineASIOKeyValue("Autostart server", "00000000"), 10))
  75. fixed_bsize = bool(int(getWineASIOKeyValue("Fixed buffersize", "00000001"), 10))
  76. prefer_bsize = int(getWineASIOKeyValue("Preferred buffersize", "00000400"), 16)
  77. for bsize in BUFFER_SIZE_LIST:
  78. self.cb_jack_buffer_size.addItem(str(bsize))
  79. if bsize == prefer_bsize:
  80. self.cb_jack_buffer_size.setCurrentIndex(self.cb_jack_buffer_size.count()-1)
  81. self.sb_ports_in.setValue(ins)
  82. self.sb_ports_out.setValue(outs)
  83. self.cb_ports_connect_hw.setChecked(hw)
  84. self.cb_jack_autostart.setChecked(autostart)
  85. self.cb_jack_fixed_bsize.setChecked(fixed_bsize)
  86. @pyqtSlot()
  87. def slot_flagChanged(self):
  88. self.changed = True
  89. @pyqtSlot()
  90. def slot_saveSettings(self):
  91. REGFILE = 'REGEDIT4\n'
  92. REGFILE += '\n'
  93. REGFILE += '[HKEY_CURRENT_USER\Software\Wine\WineASIO]\n'
  94. REGFILE += '"Autostart server"=dword:0000000%i\n' % int(1 if self.cb_jack_autostart.isChecked() else 0)
  95. REGFILE += '"Connect to hardware"=dword:0000000%i\n' % int(1 if self.cb_ports_connect_hw.isChecked() else 0)
  96. REGFILE += '"Fixed buffersize"=dword:0000000%i\n' % int(1 if self.cb_jack_fixed_bsize.isChecked() else 0)
  97. REGFILE += '"Number of inputs"=dword:000000%s\n' % smartHex(self.sb_ports_in.value(), 2)
  98. REGFILE += '"Number of outputs"=dword:000000%s\n' % smartHex(self.sb_ports_out.value(), 2)
  99. REGFILE += '"Preferred buffersize"=dword:0000%s\n' % smartHex(int(self.cb_jack_buffer_size.currentText()), 4)
  100. with open("/tmp/wineasio-settings.reg", "w") as fh:
  101. fh.write(REGFILE)
  102. os.system("regedit /tmp/wineasio-settings.reg")
  103. # ---------------------------------------------------------------------------------------------------------------------
  104. if __name__ == '__main__':
  105. # App initialization
  106. app = QApplication(sys.argv)
  107. app.setApplicationName("WineASIO Settings")
  108. app.setApplicationVersion("1.0.0")
  109. app.setOrganizationName("falkTX")
  110. # Show GUI
  111. gui = WineASIOSettingsDialog()
  112. gui.show()
  113. # Exit properly
  114. sys.exit(app.exec_())
  115. # ---------------------------------------------------------------------------------------------------------------------