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.

utils.py 4.7KB

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