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.

170 lines
6.3KB

  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, QDialogButtonBox
  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.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.slot_restoreDefaults)
  65. self.sb_ports_in.valueChanged.connect(self.slot_flagChanged)
  66. self.sb_ports_out.valueChanged.connect(self.slot_flagChanged)
  67. self.cb_ports_connect_hw.clicked.connect(self.slot_flagChanged)
  68. self.cb_jack_autostart.clicked.connect(self.slot_flagChanged)
  69. self.cb_jack_fixed_bsize.clicked.connect(self.slot_flagChanged)
  70. self.cb_jack_buffer_size.currentIndexChanged[int].connect(self.slot_flagChanged)
  71. def loadSettings(self):
  72. ins = int(getWineASIOKeyValue("Number of inputs", "00000010"), 16)
  73. outs = int(getWineASIOKeyValue("Number of outputs", "00000010"), 16)
  74. hw = bool(int(getWineASIOKeyValue("Connect to hardware", "00000001"), 10))
  75. autostart = bool(int(getWineASIOKeyValue("Autostart server", "00000000"), 10))
  76. fixed_bsize = bool(int(getWineASIOKeyValue("Fixed buffersize", "00000001"), 10))
  77. prefer_bsize = int(getWineASIOKeyValue("Preferred buffersize", "00000400"), 16)
  78. for bsize in BUFFER_SIZE_LIST:
  79. self.cb_jack_buffer_size.addItem(str(bsize))
  80. if bsize == prefer_bsize:
  81. self.cb_jack_buffer_size.setCurrentIndex(self.cb_jack_buffer_size.count()-1)
  82. self.sb_ports_in.setValue(ins)
  83. self.sb_ports_out.setValue(outs)
  84. self.cb_ports_connect_hw.setChecked(hw)
  85. self.cb_jack_autostart.setChecked(autostart)
  86. self.cb_jack_fixed_bsize.setChecked(fixed_bsize)
  87. @pyqtSlot()
  88. def slot_flagChanged(self):
  89. self.changed = True
  90. @pyqtSlot()
  91. def slot_restoreDefaults(self):
  92. self.changed = True
  93. self.sb_ports_in.setValue(16)
  94. self.sb_ports_out.setValue(16)
  95. self.cb_ports_connect_hw.setChecked(True)
  96. self.cb_jack_autostart.setChecked(False)
  97. self.cb_jack_fixed_bsize.setChecked(True)
  98. self.cb_jack_buffer_size.setCurrentIndex(BUFFER_SIZE_LIST.index(1024))
  99. @pyqtSlot()
  100. def slot_saveSettings(self):
  101. REGFILE = 'REGEDIT4\n'
  102. REGFILE += '\n'
  103. REGFILE += '[HKEY_CURRENT_USER\Software\Wine\WineASIO]\n'
  104. REGFILE += '"Autostart server"=dword:0000000%i\n' % int(1 if self.cb_jack_autostart.isChecked() else 0)
  105. REGFILE += '"Connect to hardware"=dword:0000000%i\n' % int(1 if self.cb_ports_connect_hw.isChecked() else 0)
  106. REGFILE += '"Fixed buffersize"=dword:0000000%i\n' % int(1 if self.cb_jack_fixed_bsize.isChecked() else 0)
  107. REGFILE += '"Number of inputs"=dword:000000%s\n' % smartHex(self.sb_ports_in.value(), 2)
  108. REGFILE += '"Number of outputs"=dword:000000%s\n' % smartHex(self.sb_ports_out.value(), 2)
  109. REGFILE += '"Preferred buffersize"=dword:0000%s\n' % smartHex(int(self.cb_jack_buffer_size.currentText()), 4)
  110. with open("/tmp/wineasio-settings.reg", "w") as fh:
  111. fh.write(REGFILE)
  112. os.system("regedit /tmp/wineasio-settings.reg")
  113. # ---------------------------------------------------------------------------------------------------------------------
  114. if __name__ == '__main__':
  115. # App initialization
  116. app = QApplication(sys.argv)
  117. app.setApplicationName("WineASIO Settings")
  118. app.setApplicationVersion("1.0.0")
  119. app.setOrganizationName("falkTX")
  120. # Show GUI
  121. gui = WineASIOSettingsDialog()
  122. gui.show()
  123. # Exit properly
  124. sys.exit(app.exec_())
  125. # ---------------------------------------------------------------------------------------------------------------------