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.

106 lines
3.8KB

  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 qWarning, Qt, QPointF
  20. from PyQt5.QtGui import QPainter, QPainterPath, QPen
  21. from PyQt5.QtWidgets import QGraphicsPathItem
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from . import (
  25. canvas,
  26. options,
  27. port_mode2str,
  28. port_type2str,
  29. CanvasBezierLineMovType,
  30. PORT_MODE_INPUT,
  31. PORT_MODE_OUTPUT,
  32. PORT_TYPE_AUDIO_JACK,
  33. PORT_TYPE_MIDI_ALSA,
  34. PORT_TYPE_MIDI_JACK,
  35. PORT_TYPE_PARAMETER,
  36. )
  37. # ------------------------------------------------------------------------------------------------------------
  38. class CanvasBezierLineMov(QGraphicsPathItem):
  39. def __init__(self, port_mode, port_type, parent):
  40. QGraphicsPathItem.__init__(self)
  41. self.setParentItem(parent)
  42. self.m_port_mode = port_mode
  43. self.m_port_type = port_type
  44. # Port position doesn't change while moving around line
  45. self.p_itemX = self.scenePos().x()
  46. self.p_itemY = self.scenePos().y()
  47. self.p_width = parent.getPortWidth()
  48. if port_type == PORT_TYPE_AUDIO_JACK:
  49. pen = QPen(canvas.theme.line_audio_jack, 2)
  50. elif port_type == PORT_TYPE_MIDI_JACK:
  51. pen = QPen(canvas.theme.line_midi_jack, 2)
  52. elif port_type == PORT_TYPE_MIDI_ALSA:
  53. pen = QPen(canvas.theme.line_midi_alsa, 2)
  54. elif port_type == PORT_TYPE_PARAMETER:
  55. pen = QPen(canvas.theme.line_parameter, 2)
  56. else:
  57. qWarning("PatchCanvas::CanvasBezierLineMov({}, {}, {}) - invalid port type".format(
  58. port_mode2str(port_mode), port_type2str(port_type), parent))
  59. pen = QPen(Qt.black)
  60. pen.setCapStyle(Qt.FlatCap)
  61. pen.setWidthF(pen.widthF() + 0.00001)
  62. self.setPen(pen)
  63. def updateLinePos(self, scenePos):
  64. if self.m_port_mode == PORT_MODE_INPUT:
  65. old_x = 0
  66. old_y = float(canvas.theme.port_height)/2
  67. mid_x = abs(scenePos.x() - self.p_itemX) / 2
  68. new_x = old_x - mid_x
  69. elif self.m_port_mode == PORT_MODE_OUTPUT:
  70. old_x = self.p_width + 12
  71. old_y = float(canvas.theme.port_height)/2
  72. mid_x = abs(scenePos.x() - (self.p_itemX + old_x)) / 2
  73. new_x = old_x + mid_x
  74. else:
  75. return
  76. final_x = scenePos.x() - self.p_itemX
  77. final_y = scenePos.y() - self.p_itemY
  78. path = QPainterPath(QPointF(old_x, old_y))
  79. path.cubicTo(new_x, old_y, new_x, final_y, final_x, final_y)
  80. self.setPath(path)
  81. def type(self):
  82. return CanvasBezierLineMovType
  83. def paint(self, painter, option, widget):
  84. painter.save()
  85. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
  86. QGraphicsPathItem.paint(self, painter, option, widget)
  87. painter.restore()
  88. # ------------------------------------------------------------------------------------------------------------