Audio plugin host https://kx.studio/carla
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.

125 lines
4.8KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. # ------------------------------------------------------------------------------------------------------------
  7. # Imports (ctypes)
  8. from ctypes import (
  9. c_bool, c_char, c_char_p, c_int, c_uint, c_uint64, c_void_p, cast,
  10. cdll, Structure,
  11. POINTER
  12. )
  13. try:
  14. from sip import unwrapinstance
  15. except ImportError:
  16. def unwrapinstance(_):
  17. return None
  18. # ------------------------------------------------------------------------------------------------------------
  19. # Imports (Custom)
  20. from carla_backend import (
  21. structToDict
  22. )
  23. # ---------------------------------------------------------------------------------------------------------------------
  24. # Convert a ctypes struct into a python dict, or None if null
  25. def structToDictOrNull(struct):
  26. return structToDict(struct.contents) if struct else None
  27. # ------------------------------------------------------------------------------------------------------------
  28. # Carla Frontend API (C stuff)
  29. class JackApplicationDialogResults(Structure):
  30. _fields_ = [
  31. ("command", c_char_p),
  32. ("name", c_char_p),
  33. ("labelSetup", c_char_p)
  34. ]
  35. class HostSettings(Structure):
  36. _fields_ = [
  37. ("showPluginBridges", c_bool),
  38. ("showWineBridges", c_bool),
  39. ("useSystemIcons", c_bool),
  40. ("wineAutoPrefix", c_bool),
  41. ("wineExecutable", c_char_p),
  42. ("wineFallbackPrefix", c_char_p),
  43. ]
  44. class PluginListDialogResults(Structure):
  45. _fields_ = [
  46. ("build", c_uint),
  47. ("type", c_uint),
  48. ("hints", c_uint),
  49. ("category", c_char_p),
  50. ("filename", c_char_p),
  51. ("name", c_char_p),
  52. ("label", c_char_p),
  53. ("maker", c_char_p),
  54. ("uniqueId", c_uint64),
  55. ("audioIns", c_uint),
  56. ("audioOuts", c_uint),
  57. ("cvIns", c_uint),
  58. ("cvOuts", c_uint),
  59. ("midiIns", c_uint),
  60. ("midiOuts", c_uint),
  61. ("parametersIns", c_uint),
  62. ("parametersOuts", c_uint),
  63. ]
  64. # ------------------------------------------------------------------------------------------------------------
  65. # Carla Frontend object using a DLL
  66. class CarlaFrontendLib():
  67. def __init__(self, filename):
  68. self.lib = cdll.LoadLibrary(filename)
  69. self.lib.carla_frontend_createAndExecJackAppDialog.argtypes = (c_void_p, c_char_p)
  70. self.lib.carla_frontend_createAndExecJackAppDialog.restype = POINTER(JackApplicationDialogResults)
  71. self.lib.carla_frontend_createPluginListDialog.argtypes = (c_void_p, POINTER(HostSettings))
  72. self.lib.carla_frontend_createPluginListDialog.restype = c_void_p
  73. self.lib.carla_frontend_destroyPluginListDialog.argtypes = (c_void_p,)
  74. self.lib.carla_frontend_destroyPluginListDialog.restype = None
  75. self.lib.carla_frontend_setPluginListDialogPath.argtypes = (c_void_p, c_int, c_char_p)
  76. self.lib.carla_frontend_setPluginListDialogPath.restype = None
  77. self.lib.carla_frontend_execPluginListDialog.argtypes = (c_void_p,)
  78. self.lib.carla_frontend_execPluginListDialog.restype = POINTER(PluginListDialogResults)
  79. # --------------------------------------------------------------------------------------------------------
  80. def createAndExecJackAppDialog(self, parent, projectFilename):
  81. return structToDictOrNull(self.lib.carla_frontend_createAndExecJackAppDialog(unwrapinstance(parent),
  82. projectFilename.encode("utf-8")))
  83. def createPluginListDialog(self, parent, hostSettings):
  84. hostSettingsC = HostSettings()
  85. hostSettingsC.showPluginBridges = hostSettings['showPluginBridges']
  86. hostSettingsC.showWineBridges = hostSettings['showWineBridges']
  87. hostSettingsC.useSystemIcons = hostSettings['useSystemIcons']
  88. hostSettingsC.wineAutoPrefix = hostSettings['wineAutoPrefix']
  89. hostSettingsC.wineExecutable = hostSettings['wineExecutable'].encode("utf-8")
  90. hostSettingsC.wineFallbackPrefix = hostSettings['wineFallbackPrefix'].encode("utf-8")
  91. return self.lib.carla_frontend_createPluginListDialog(unwrapinstance(parent), hostSettingsC)
  92. def destroyPluginListDialog(self, dialog):
  93. self.lib.carla_frontend_destroyPluginListDialog(dialog)
  94. def setPluginListDialogPath(self, dialog, ptype, path):
  95. self.lib.carla_frontend_setPluginListDialogPath(dialog, ptype, path.encode("utf-8"))
  96. def execPluginListDialog(self, dialog):
  97. return structToDictOrNull(self.lib.carla_frontend_execPluginListDialog(dialog))
  98. # ------------------------------------------------------------------------------------------------------------