2 # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ------------------------------------------------------------------------------------------------------------
8 from qt_compat
import qt_config
11 from PyQt5
.QtCore
import QPointF
, QRectF
12 from PyQt5
.QtWidgets
import QGraphicsItem
14 from PyQt6
.QtCore
import QPointF
, QRectF
15 from PyQt6
.QtWidgets
import QGraphicsItem
17 # ------------------------------------------------------------------------------------------------------------
20 from .theme
import getDefaultThemeName
22 # ------------------------------------------------------------------------------------------------------------
24 # Maximum Id for a plugin, treated as invalid/zero if above this value
25 MAX_PLUGIN_ID_ALLOWED
= 0x7FF
34 PORT_TYPE_AUDIO_JACK
= 1
35 PORT_TYPE_MIDI_JACK
= 2
36 PORT_TYPE_MIDI_ALSA
= 3
37 PORT_TYPE_PARAMETER
= 4
40 ACTION_GROUP_INFO
= 0 # group_id, N, N
41 ACTION_GROUP_RENAME
= 1 # group_id, N, N
42 ACTION_GROUP_SPLIT
= 2 # group_id, N, N
43 ACTION_GROUP_JOIN
= 3 # group_id, N, N
44 ACTION_GROUP_POSITION
= 4 # group_id, N, N, "x1:y1:x2:y2"
45 ACTION_PORT_INFO
= 5 # group_id, port_id, N
46 ACTION_PORT_RENAME
= 6 # group_id, port_id, N
47 ACTION_PORTS_CONNECT
= 7 # N, N, "outG:outP:inG:inP"
48 ACTION_PORTS_DISCONNECT
= 8 # conn_id, N, N
49 ACTION_PLUGIN_CLONE
= 9 # plugin_id, N, N
50 ACTION_PLUGIN_EDIT
= 10 # plugin_id, N, N
51 ACTION_PLUGIN_RENAME
= 11 # plugin_id, N, N
52 ACTION_PLUGIN_REPLACE
= 12 # plugin_id, N, N
53 ACTION_PLUGIN_REMOVE
= 13 # plugin_id, N, N
54 ACTION_PLUGIN_SHOW_UI
= 14 # plugin_id, N, N
55 ACTION_BG_RIGHT_CLICK
= 15 # N, N, N
56 ACTION_INLINE_DISPLAY
= 16 # plugin_id, N, N
73 ANTIALIASING_SMALL
= 1
81 # ------------------------------------------------------------------------------------------------------------
84 CanvasBoxType
= QGraphicsItem
.UserType
+ 1
85 CanvasIconType
= QGraphicsItem
.UserType
+ 2
86 CanvasPortType
= QGraphicsItem
.UserType
+ 3
87 CanvasLineType
= QGraphicsItem
.UserType
+ 4
88 CanvasBezierLineType
= QGraphicsItem
.UserType
+ 5
89 CanvasLineMovType
= QGraphicsItem
.UserType
+ 6
90 CanvasBezierLineMovType
= QGraphicsItem
.UserType
+ 7
91 CanvasRubberbandType
= QGraphicsItem
.UserType
+ 8
93 # ------------------------------------------------------------------------------------------------------------
96 class options_t(object):
108 class features_t(object):
118 class Canvas(object):
123 self
.initiated
= False
127 self
.connection_list
= []
128 self
.animation_list
= []
129 self
.group_plugin_map
= {}
130 self
.old_group_pos
= {}
132 self
.callback
= self
.callback
135 self
.last_z_value
= 0
136 self
.last_connection_id
= 0
137 self
.initial_pos
= QPointF(0, 0)
138 self
.size_rect
= QRectF()
140 def callback(self
, action
, value1
, value2
, value_str
):
141 print("Canvas::callback({}, {}, {}, {})".format(action
, value1
, value2
, value_str
))
143 # ------------------------------------------------------------------------------------------------------------
146 class group_dict_t(object):
158 class port_dict_t(object):
169 class connection_dict_t(object):
179 class animation_dict_t(object):
185 # ------------------------------------------------------------------------------------------------------------
189 return "True" if check
else "False"
191 def port_mode2str(port_mode
):
192 if port_mode
== PORT_MODE_NULL
:
193 return "PORT_MODE_NULL"
194 elif port_mode
== PORT_MODE_INPUT
:
195 return "PORT_MODE_INPUT"
196 elif port_mode
== PORT_MODE_OUTPUT
:
197 return "PORT_MODE_OUTPUT"
199 return "PORT_MODE_???"
201 def port_type2str(port_type
):
202 if port_type
== PORT_TYPE_NULL
:
203 return "PORT_TYPE_NULL"
204 elif port_type
== PORT_TYPE_AUDIO_JACK
:
205 return "PORT_TYPE_AUDIO_JACK"
206 elif port_type
== PORT_TYPE_MIDI_JACK
:
207 return "PORT_TYPE_MIDI_JACK"
208 elif port_type
== PORT_TYPE_MIDI_ALSA
:
209 return "PORT_TYPE_MIDI_ALSA"
210 elif port_type
== PORT_TYPE_PARAMETER
:
211 return "PORT_TYPE_MIDI_PARAMETER"
213 return "PORT_TYPE_???"
216 if icon
== ICON_APPLICATION
:
217 return "ICON_APPLICATION"
218 elif icon
== ICON_HARDWARE
:
219 return "ICON_HARDWARE"
220 elif icon
== ICON_DISTRHO
:
221 return "ICON_DISTRHO"
222 elif icon
== ICON_FILE
:
224 elif icon
== ICON_PLUGIN
:
226 elif icon
== ICON_LADISH_ROOM
:
227 return "ICON_LADISH_ROOM"
231 def split2str(split
):
232 if split
== SPLIT_UNDEF
:
234 elif split
== SPLIT_NO
:
236 elif split
== SPLIT_YES
:
241 # ------------------------------------------------------------------------------------------------------------
246 options
= options_t()
247 options
.theme_name
= getDefaultThemeName()
248 options
.auto_hide_groups
= False
249 options
.auto_select_items
= False
250 options
.use_bezier_lines
= True
251 options
.antialiasing
= ANTIALIASING_SMALL
252 options
.eyecandy
= EYECANDY_SMALL
253 options
.inline_displays
= False
255 features
= features_t()
256 features
.group_info
= False
257 features
.group_rename
= False
258 features
.port_info
= False
259 features
.port_rename
= False
260 features
.handle_group_pos
= False
263 def setOptions(new_options
):
264 if canvas
.initiated
: return
265 options
.theme_name
= new_options
.theme_name
266 options
.auto_hide_groups
= new_options
.auto_hide_groups
267 options
.auto_select_items
= new_options
.auto_select_items
268 options
.use_bezier_lines
= new_options
.use_bezier_lines
269 options
.antialiasing
= new_options
.antialiasing
270 options
.eyecandy
= new_options
.eyecandy
271 options
.inline_displays
= new_options
.inline_displays
273 def setFeatures(new_features
):
274 if canvas
.initiated
: return
275 features
.group_info
= new_features
.group_info
276 features
.group_rename
= new_features
.group_rename
277 features
.port_info
= new_features
.port_info
278 features
.port_rename
= new_features
.port_rename
279 features
.handle_group_pos
= new_features
.handle_group_pos