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.

141 lines
5.6KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla Backend utils
  4. # Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or 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 doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. # ------------------------------------------------------------------------------------------------------------
  20. # Imports (ctypes)
  21. from ctypes import (
  22. c_bool, c_char, c_char_p, c_int, c_uint, c_uint64, c_void_p, cast,
  23. cdll, Structure,
  24. POINTER
  25. )
  26. from sip import unwrapinstance
  27. # ------------------------------------------------------------------------------------------------------------
  28. # Imports (Custom)
  29. from carla_backend import (
  30. structToDict
  31. )
  32. # ---------------------------------------------------------------------------------------------------------------------
  33. # Convert a ctypes struct into a python dict, or None if null
  34. def structToDictOrNull(struct):
  35. return structToDict(struct.contents) if struct else None
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Carla Frontend API (C stuff)
  38. class JackApplicationDialogResults(Structure):
  39. _fields_ = [
  40. ("command", c_char_p),
  41. ("name", c_char_p),
  42. ("labelSetup", c_char_p)
  43. ]
  44. class HostSettings(Structure):
  45. _fields_ = [
  46. ("showPluginBridges", c_bool),
  47. ("showWineBridges", c_bool),
  48. ("useSystemIcons", c_bool),
  49. ("wineAutoPrefix", c_bool),
  50. ("wineExecutable", c_char_p),
  51. ("wineFallbackPrefix", c_char_p),
  52. ]
  53. class PluginListDialogResults(Structure):
  54. _fields_ = [
  55. ("build", c_uint),
  56. ("type", c_uint),
  57. ("hints", c_uint),
  58. ("category", c_char_p),
  59. ("filename", c_char_p),
  60. ("name", c_char_p),
  61. ("label", c_char_p),
  62. ("maker", c_char_p),
  63. ("uniqueId", c_uint64),
  64. ("audioIns", c_uint),
  65. ("audioOuts", c_uint),
  66. ("cvIns", c_uint),
  67. ("cvOuts", c_uint),
  68. ("midiIns", c_uint),
  69. ("midiOuts", c_uint),
  70. ("parametersIns", c_uint),
  71. ("parametersOuts", c_uint),
  72. ]
  73. # ------------------------------------------------------------------------------------------------------------
  74. # Carla Frontend object using a DLL
  75. class CarlaFrontendLib():
  76. def __init__(self, filename):
  77. self.lib = cdll.LoadLibrary(filename)
  78. self.lib.carla_frontend_createAndExecAboutJuceDialog.argtypes = (c_void_p,)
  79. self.lib.carla_frontend_createAndExecAboutJuceDialog.restype = None
  80. self.lib.carla_frontend_createAndExecJackAppDialog.argtypes = (c_void_p, c_char_p)
  81. self.lib.carla_frontend_createAndExecJackAppDialog.restype = POINTER(JackApplicationDialogResults)
  82. self.lib.carla_frontend_createPluginListDialog.argtypes = (c_void_p, POINTER(HostSettings))
  83. self.lib.carla_frontend_createPluginListDialog.restype = c_void_p
  84. self.lib.carla_frontend_destroyPluginListDialog.argtypes = (c_void_p,)
  85. self.lib.carla_frontend_destroyPluginListDialog.restype = None
  86. self.lib.carla_frontend_setPluginListDialogPath.argtypes = (c_void_p, c_int, c_char_p)
  87. self.lib.carla_frontend_setPluginListDialogPath.restype = None
  88. self.lib.carla_frontend_execPluginListDialog.argtypes = (c_void_p,)
  89. self.lib.carla_frontend_execPluginListDialog.restype = POINTER(PluginListDialogResults)
  90. # --------------------------------------------------------------------------------------------------------
  91. def createAndExecAboutJuceDialog(self, parent):
  92. self.lib.carla_frontend_createAndExecAboutJuceDialog(unwrapinstance(parent))
  93. def createAndExecJackAppDialog(self, parent, projectFilename):
  94. return structToDictOrNull(self.lib.carla_frontend_createAndExecJackAppDialog(unwrapinstance(parent),
  95. projectFilename.encode("utf-8")))
  96. def createPluginListDialog(self, parent, hostSettings):
  97. hostSettingsC = HostSettings()
  98. hostSettingsC.showPluginBridges = hostSettings['showPluginBridges']
  99. hostSettingsC.showWineBridges = hostSettings['showWineBridges']
  100. hostSettingsC.useSystemIcons = hostSettings['useSystemIcons']
  101. hostSettingsC.wineAutoPrefix = hostSettings['wineAutoPrefix']
  102. hostSettingsC.wineExecutable = hostSettings['wineExecutable'].encode("utf-8")
  103. hostSettingsC.wineFallbackPrefix = hostSettings['wineFallbackPrefix'].encode("utf-8")
  104. return self.lib.carla_frontend_createPluginListDialog(unwrapinstance(parent), hostSettingsC)
  105. def destroyPluginListDialog(self, dialog):
  106. self.lib.carla_frontend_destroyPluginListDialog(dialog)
  107. def setPluginListDialogPath(self, dialog, ptype, path):
  108. self.lib.carla_frontend_setPluginListDialogPath(dialog, ptype, path.encode("utf-8"))
  109. def execPluginListDialog(self, dialog):
  110. return structToDictOrNull(self.lib.carla_frontend_execPluginListDialog(dialog))
  111. # ------------------------------------------------------------------------------------------------------------