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.

__init__.py 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # PatchBay Canvas engine using QGraphicsView/Scene
  4. # Copyright (C) 2010-2019 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. from PyQt5.QtCore import QPointF, QRectF
  20. from PyQt5.QtWidgets import QGraphicsItem
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (Theme)
  23. from .theme import getDefaultThemeName
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Maximum Id for a plugin, treated as invalid/zero if above this value
  26. MAX_PLUGIN_ID_ALLOWED = 0x7FF
  27. # Port Mode
  28. PORT_MODE_NULL = 0
  29. PORT_MODE_INPUT = 1
  30. PORT_MODE_OUTPUT = 2
  31. # Port Type
  32. PORT_TYPE_NULL = 0
  33. PORT_TYPE_AUDIO_JACK = 1
  34. PORT_TYPE_MIDI_JACK = 2
  35. PORT_TYPE_MIDI_ALSA = 3
  36. PORT_TYPE_PARAMETER = 4
  37. # Callback Action
  38. ACTION_GROUP_INFO = 0 # group_id, N, N
  39. ACTION_GROUP_RENAME = 1 # group_id, N, N
  40. ACTION_GROUP_SPLIT = 2 # group_id, N, N
  41. ACTION_GROUP_JOIN = 3 # group_id, N, N
  42. ACTION_PORT_INFO = 4 # group_id, port_id, N
  43. ACTION_PORT_RENAME = 5 # group_id, port_id, N
  44. ACTION_PORTS_CONNECT = 6 # N, N, "outG:outP:inG:inP"
  45. ACTION_PORTS_DISCONNECT = 7 # conn_id, N, N
  46. ACTION_PLUGIN_CLONE = 8 # plugin_id, N, N
  47. ACTION_PLUGIN_EDIT = 9 # plugin_id, N, N
  48. ACTION_PLUGIN_RENAME = 10 # plugin_id, N, N
  49. ACTION_PLUGIN_REPLACE = 11 # plugin_id, N, N
  50. ACTION_PLUGIN_REMOVE = 12 # plugin_id, N, N
  51. ACTION_PLUGIN_SHOW_UI = 13 # plugin_id, N, N
  52. ACTION_BG_RIGHT_CLICK = 14 # N, N, N
  53. # Icon
  54. ICON_APPLICATION = 0
  55. ICON_HARDWARE = 1
  56. ICON_DISTRHO = 2
  57. ICON_FILE = 3
  58. ICON_PLUGIN = 4
  59. ICON_LADISH_ROOM = 5
  60. # Split Option
  61. SPLIT_UNDEF = 0
  62. SPLIT_NO = 1
  63. SPLIT_YES = 2
  64. # Antialiasing Option
  65. ANTIALIASING_NONE = 0
  66. ANTIALIASING_SMALL = 1
  67. ANTIALIASING_FULL = 2
  68. # Eye-Candy Option
  69. EYECANDY_NONE = 0
  70. EYECANDY_SMALL = 1
  71. EYECANDY_FULL = 2
  72. # ------------------------------------------------------------------------------------------------------------
  73. # object types
  74. CanvasBoxType = QGraphicsItem.UserType + 1
  75. CanvasIconType = QGraphicsItem.UserType + 2
  76. CanvasPortType = QGraphicsItem.UserType + 3
  77. CanvasLineType = QGraphicsItem.UserType + 4
  78. CanvasBezierLineType = QGraphicsItem.UserType + 5
  79. CanvasLineMovType = QGraphicsItem.UserType + 6
  80. CanvasBezierLineMovType = QGraphicsItem.UserType + 7
  81. CanvasRubberbandType = QGraphicsItem.UserType + 8
  82. # ------------------------------------------------------------------------------------------------------------
  83. # Canvas options
  84. class options_t(object):
  85. __slots__ = [
  86. 'theme_name',
  87. 'auto_hide_groups',
  88. 'auto_select_items',
  89. 'use_bezier_lines',
  90. 'antialiasing',
  91. 'eyecandy'
  92. ]
  93. # Canvas features
  94. class features_t(object):
  95. __slots__ = [
  96. 'group_info',
  97. 'group_rename',
  98. 'port_info',
  99. 'port_rename',
  100. 'handle_group_pos'
  101. ]
  102. # Main Canvas object
  103. class Canvas(object):
  104. def __init__(self):
  105. self.qobject = None
  106. self.settings = None
  107. self.theme = None
  108. self.initiated = False
  109. self.group_list = []
  110. self.port_list = []
  111. self.connection_list = []
  112. self.animation_list = []
  113. self.callback = self.callback
  114. self.debug = False
  115. self.scene = None
  116. self.last_z_value = 0
  117. self.last_connection_id = 0
  118. self.initial_pos = QPointF(0, 0)
  119. self.size_rect = QRectF()
  120. def callback(self, action, value1, value2, value_str):
  121. print("Canvas::callback({}, {}, {}, {})".fmt(action, value1, value2, value_str))
  122. # ------------------------------------------------------------------------------------------------------------
  123. # object lists
  124. class group_dict_t(object):
  125. __slots__ = [
  126. 'group_id',
  127. 'group_name',
  128. 'split',
  129. 'icon',
  130. 'plugin_id',
  131. 'plugin_ui',
  132. 'widgets'
  133. ]
  134. class port_dict_t(object):
  135. __slots__ = [
  136. 'group_id',
  137. 'port_id',
  138. 'port_name',
  139. 'port_mode',
  140. 'port_type',
  141. 'is_alternate',
  142. 'widget'
  143. ]
  144. class connection_dict_t(object):
  145. __slots__ = [
  146. 'connection_id',
  147. 'group_in_id',
  148. 'port_in_id',
  149. 'group_out_id',
  150. 'port_out_id',
  151. 'widget'
  152. ]
  153. class animation_dict_t(object):
  154. __slots__ = [
  155. 'animation',
  156. 'item'
  157. ]
  158. # ------------------------------------------------------------------------------------------------------------
  159. # Internal functions
  160. def bool2str(check):
  161. return "True" if check else "False"
  162. def port_mode2str(port_mode):
  163. if port_mode == PORT_MODE_NULL:
  164. return "PORT_MODE_NULL"
  165. elif port_mode == PORT_MODE_INPUT:
  166. return "PORT_MODE_INPUT"
  167. elif port_mode == PORT_MODE_OUTPUT:
  168. return "PORT_MODE_OUTPUT"
  169. else:
  170. return "PORT_MODE_???"
  171. def port_type2str(port_type):
  172. if port_type == PORT_TYPE_NULL:
  173. return "PORT_TYPE_NULL"
  174. elif port_type == PORT_TYPE_AUDIO_JACK:
  175. return "PORT_TYPE_AUDIO_JACK"
  176. elif port_type == PORT_TYPE_MIDI_JACK:
  177. return "PORT_TYPE_MIDI_JACK"
  178. elif port_type == PORT_TYPE_MIDI_ALSA:
  179. return "PORT_TYPE_MIDI_ALSA"
  180. elif port_type == PORT_TYPE_PARAMETER:
  181. return "PORT_TYPE_MIDI_PARAMETER"
  182. else:
  183. return "PORT_TYPE_???"
  184. def icon2str(icon):
  185. if icon == ICON_APPLICATION:
  186. return "ICON_APPLICATION"
  187. elif icon == ICON_HARDWARE:
  188. return "ICON_HARDWARE"
  189. elif icon == ICON_DISTRHO:
  190. return "ICON_DISTRHO"
  191. elif icon == ICON_FILE:
  192. return "ICON_FILE"
  193. elif icon == ICON_PLUGIN:
  194. return "ICON_PLUGIN"
  195. elif icon == ICON_LADISH_ROOM:
  196. return "ICON_LADISH_ROOM"
  197. else:
  198. return "ICON_???"
  199. def split2str(split):
  200. if split == SPLIT_UNDEF:
  201. return "SPLIT_UNDEF"
  202. elif split == SPLIT_NO:
  203. return "SPLIT_NO"
  204. elif split == SPLIT_YES:
  205. return "SPLIT_YES"
  206. else:
  207. return "SPLIT_???"
  208. # ------------------------------------------------------------------------------------------------------------
  209. # Global objects
  210. canvas = Canvas()
  211. options = options_t()
  212. options.theme_name = getDefaultThemeName()
  213. options.auto_hide_groups = False
  214. options.auto_select_items = False
  215. options.use_bezier_lines = True
  216. options.antialiasing = ANTIALIASING_SMALL
  217. options.eyecandy = EYECANDY_SMALL
  218. features = features_t()
  219. features.group_info = False
  220. features.group_rename = False
  221. features.port_info = False
  222. features.port_rename = False
  223. features.handle_group_pos = False
  224. # PatchCanvas API
  225. def setOptions(new_options):
  226. if canvas.initiated: return
  227. options.theme_name = new_options.theme_name
  228. options.auto_hide_groups = new_options.auto_hide_groups
  229. options.auto_select_items = new_options.auto_select_items
  230. options.use_bezier_lines = new_options.use_bezier_lines
  231. options.antialiasing = new_options.antialiasing
  232. options.eyecandy = new_options.eyecandy
  233. def setFeatures(new_features):
  234. if canvas.initiated: return
  235. features.group_info = new_features.group_info
  236. features.group_rename = new_features.group_rename
  237. features.port_info = new_features.port_info
  238. features.port_rename = new_features.port_rename
  239. features.handle_group_pos = new_features.handle_group_pos