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.

canvaslinemov.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, QLineF
  20. from PyQt5.QtGui import QPainter, QPen
  21. from PyQt5.QtWidgets import QGraphicsLineItem
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from . import (
  25. canvas,
  26. options,
  27. port_mode2str,
  28. port_type2str,
  29. CanvasLineMovType,
  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 CanvasLineMov(QGraphicsLineItem):
  39. def __init__(self, port_mode, port_type, parent):
  40. QGraphicsLineItem.__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_lineX = self.scenePos().x()
  46. self.p_lineY = 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::CanvasLineMov({}, {}, {}) - invalid port type".format(
  58. port_mode2str(port_mode), port_type2str(port_type), parent))
  59. pen = QPen(Qt.black)
  60. pen.setCapStyle(Qt.RoundCap)
  61. pen.setWidthF(pen.widthF() + 0.00001)
  62. self.setPen(pen)
  63. def updateLinePos(self, scenePos):
  64. item_pos = [0, 0]
  65. if self.m_port_mode == PORT_MODE_INPUT:
  66. item_pos[0] = 0
  67. item_pos[1] = float(canvas.theme.port_height)/2
  68. elif self.m_port_mode == PORT_MODE_OUTPUT:
  69. item_pos[0] = self.p_width + 12
  70. item_pos[1] = float(canvas.theme.port_height)/2
  71. else:
  72. return
  73. line = QLineF(item_pos[0], item_pos[1], scenePos.x() - self.p_lineX, scenePos.y() - self.p_lineY)
  74. self.setLine(line)
  75. def type(self):
  76. return CanvasLineMovType
  77. def paint(self, painter, option, widget):
  78. painter.save()
  79. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
  80. QGraphicsLineItem.paint(self, painter, option, widget)
  81. painter.restore()
  82. # ------------------------------------------------------------------------------------------------------------