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.

138 lines
4.9KB

  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 qCritical, QPointF, QTimer
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Custom)
  22. from . import bool2str, canvas, CanvasBoxType
  23. from .canvasfadeanimation import CanvasFadeAnimation
  24. # ------------------------------------------------------------------------------------------------------------
  25. def CanvasGetNewGroupPos(horizontal):
  26. if canvas.debug:
  27. print("PatchCanvas::CanvasGetNewGroupPos(%s)" % bool2str(horizontal))
  28. new_pos = QPointF(canvas.initial_pos)
  29. items = canvas.scene.items()
  30. #break_loop = False
  31. while True:
  32. break_for = False
  33. for i, item in enumerate(items):
  34. if item and item.type() == CanvasBoxType:
  35. if item.sceneBoundingRect().adjusted(-5, -5, 5, 5).contains(new_pos):
  36. itemRect = item.boundingRect()
  37. if horizontal:
  38. new_pos += QPointF(itemRect.width() + 50, 0)
  39. else:
  40. itemHeight = itemRect.height()
  41. if itemHeight < 30:
  42. new_pos += QPointF(0, itemHeight + 50)
  43. else:
  44. new_pos.setY(item.scenePos().y() + itemHeight + 20)
  45. break_for = True
  46. break
  47. else:
  48. if not break_for:
  49. break
  50. #break_loop = True
  51. return new_pos
  52. def CanvasGetFullPortName(group_id, port_id):
  53. if canvas.debug:
  54. print("PatchCanvas::CanvasGetFullPortName(%i, %i)" % (group_id, port_id))
  55. for port in canvas.port_list:
  56. if port.group_id == group_id and port.port_id == port_id:
  57. group_id = port.group_id
  58. for group in canvas.group_list:
  59. if group.group_id == group_id:
  60. return group.group_name + ":" + port.port_name
  61. break
  62. qCritical("PatchCanvas::CanvasGetFullPortName(%i, %i) - unable to find port" % (group_id, port_id))
  63. return ""
  64. def CanvasGetPortConnectionList(group_id, port_id):
  65. if canvas.debug:
  66. print("PatchCanvas::CanvasGetPortConnectionList(%i, %i)" % (group_id, port_id))
  67. conn_list = []
  68. for connection in canvas.connection_list:
  69. if connection.group_out_id == group_id and connection.port_out_id == port_id:
  70. conn_list.append((connection.connection_id, connection.group_in_id, connection.port_in_id))
  71. elif connection.group_in_id == group_id and connection.port_in_id == port_id:
  72. conn_list.append((connection.connection_id, connection.group_out_id, connection.port_out_id))
  73. return conn_list
  74. def CanvasCallback(action, value1, value2, value_str):
  75. if canvas.debug:
  76. print("PatchCanvas::CanvasCallback(%i, %i, %i, %s)" % (action, value1, value2, value_str.encode()))
  77. canvas.callback(action, value1, value2, value_str)
  78. def CanvasItemFX(item, show, destroy):
  79. if canvas.debug:
  80. print("PatchCanvas::CanvasItemFX(%s, %s, %s)" % (item, bool2str(show), bool2str(destroy)))
  81. # Check if the item already has an animation
  82. for animation in canvas.animation_list:
  83. if animation.item() == item:
  84. animation.forceStop()
  85. canvas.animation_list.remove(animation)
  86. del animation
  87. break
  88. animation = CanvasFadeAnimation(item, show)
  89. animation.setDuration(750 if show else 500)
  90. if show:
  91. animation.finished.connect(canvas.qobject.AnimationFinishedShow)
  92. else:
  93. if destroy:
  94. animation.finished.connect(canvas.qobject.AnimationFinishedDestroy)
  95. else:
  96. animation.finished.connect(canvas.qobject.AnimationFinishedHide)
  97. canvas.animation_list.append(animation)
  98. animation.start()
  99. def CanvasRemoveItemFX(item):
  100. if canvas.debug:
  101. print("PatchCanvas::CanvasRemoveItemFX(%s)" % item)
  102. if item.type() == CanvasBoxType:
  103. item.removeIconFromScene()
  104. canvas.scene.removeItem(item)
  105. del item
  106. QTimer.singleShot(0, canvas.scene.update)
  107. # ------------------------------------------------------------------------------------------------------------