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.

93 lines
3.2KB

  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, QLineF
  9. from PyQt5.QtGui import QPainter, QPen
  10. from PyQt5.QtWidgets import QGraphicsLineItem
  11. elif qt_config == 6:
  12. from PyQt6.QtCore import qWarning, Qt, QLineF
  13. from PyQt6.QtGui import QPainter, QPen
  14. from PyQt6.QtWidgets import QGraphicsLineItem
  15. # ------------------------------------------------------------------------------------------------------------
  16. # Imports (Custom)
  17. from . import (
  18. canvas,
  19. options,
  20. port_mode2str,
  21. port_type2str,
  22. CanvasLineMovType,
  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 CanvasLineMov(QGraphicsLineItem):
  32. def __init__(self, port_mode, port_type, parent):
  33. QGraphicsLineItem.__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_lineX = self.scenePos().x()
  39. self.p_lineY = 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::CanvasLineMov({}, {}, {}) - invalid port type".format(
  51. port_mode2str(port_mode), port_type2str(port_type), parent))
  52. pen = QPen(Qt.black)
  53. pen.setCapStyle(Qt.RoundCap)
  54. pen.setWidthF(pen.widthF() + 0.00001)
  55. self.setPen(pen)
  56. def updateLinePos(self, scenePos):
  57. item_pos = [0, 0]
  58. if self.m_port_mode == PORT_MODE_INPUT:
  59. item_pos[0] = 0
  60. item_pos[1] = float(canvas.theme.port_height)/2
  61. elif self.m_port_mode == PORT_MODE_OUTPUT:
  62. item_pos[0] = self.p_width + 12
  63. item_pos[1] = float(canvas.theme.port_height)/2
  64. else:
  65. return
  66. line = QLineF(item_pos[0], item_pos[1], scenePos.x() - self.p_lineX, scenePos.y() - self.p_lineY)
  67. self.setLine(line)
  68. def type(self):
  69. return CanvasLineMovType
  70. def paint(self, painter, option, widget):
  71. painter.save()
  72. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
  73. QGraphicsLineItem.paint(self, painter, option, widget)
  74. painter.restore()
  75. # ------------------------------------------------------------------------------------------------------------