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.

99 lines
3.4KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. from qt_compat import qt_config
  7. if qt_config == 5:
  8. from PyQt5.QtCore import qWarning, Qt, QPointF
  9. from PyQt5.QtGui import QPainter, QPainterPath, QPen
  10. from PyQt5.QtWidgets import QGraphicsPathItem
  11. elif qt_config == 6:
  12. from PyQt6.QtCore import qWarning, Qt, QPointF
  13. from PyQt6.QtGui import QPainter, QPainterPath, QPen
  14. from PyQt6.QtWidgets import QGraphicsPathItem
  15. # ------------------------------------------------------------------------------------------------------------
  16. # Imports (Custom)
  17. from . import (
  18. canvas,
  19. options,
  20. port_mode2str,
  21. port_type2str,
  22. CanvasBezierLineMovType,
  23. PORT_MODE_INPUT,
  24. PORT_MODE_OUTPUT,
  25. PORT_TYPE_AUDIO_JACK,
  26. PORT_TYPE_MIDI_ALSA,
  27. PORT_TYPE_MIDI_JACK,
  28. PORT_TYPE_PARAMETER,
  29. )
  30. # ------------------------------------------------------------------------------------------------------------
  31. class CanvasBezierLineMov(QGraphicsPathItem):
  32. def __init__(self, port_mode, port_type, parent):
  33. QGraphicsPathItem.__init__(self)
  34. self.setParentItem(parent)
  35. self.m_port_mode = port_mode
  36. self.m_port_type = port_type
  37. # Port position doesn't change while moving around line
  38. self.p_itemX = self.scenePos().x()
  39. self.p_itemY = self.scenePos().y()
  40. self.p_width = parent.getPortWidth()
  41. if port_type == PORT_TYPE_AUDIO_JACK:
  42. pen = QPen(canvas.theme.line_audio_jack, 2)
  43. elif port_type == PORT_TYPE_MIDI_JACK:
  44. pen = QPen(canvas.theme.line_midi_jack, 2)
  45. elif port_type == PORT_TYPE_MIDI_ALSA:
  46. pen = QPen(canvas.theme.line_midi_alsa, 2)
  47. elif port_type == PORT_TYPE_PARAMETER:
  48. pen = QPen(canvas.theme.line_parameter, 2)
  49. else:
  50. qWarning("PatchCanvas::CanvasBezierLineMov({}, {}, {}) - invalid port type".format(
  51. port_mode2str(port_mode), port_type2str(port_type), parent))
  52. pen = QPen(Qt.black)
  53. pen.setCapStyle(Qt.FlatCap)
  54. pen.setWidthF(pen.widthF() + 0.00001)
  55. self.setPen(pen)
  56. def updateLinePos(self, scenePos):
  57. if self.m_port_mode == PORT_MODE_INPUT:
  58. old_x = 0
  59. old_y = float(canvas.theme.port_height)/2
  60. mid_x = abs(scenePos.x() - self.p_itemX) / 2
  61. new_x = old_x - mid_x
  62. elif self.m_port_mode == PORT_MODE_OUTPUT:
  63. old_x = self.p_width + 12
  64. old_y = float(canvas.theme.port_height)/2
  65. mid_x = abs(scenePos.x() - (self.p_itemX + old_x)) / 2
  66. new_x = old_x + mid_x
  67. else:
  68. return
  69. final_x = scenePos.x() - self.p_itemX
  70. final_y = scenePos.y() - self.p_itemY
  71. path = QPainterPath(QPointF(old_x, old_y))
  72. path.cubicTo(new_x, old_y, new_x, final_y, final_x, final_y)
  73. self.setPath(path)
  74. def type(self):
  75. return CanvasBezierLineMovType
  76. def paint(self, painter, option, widget):
  77. painter.save()
  78. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
  79. QGraphicsPathItem.paint(self, painter, option, widget)
  80. painter.restore()
  81. # ------------------------------------------------------------------------------------------------------------