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.

carla-ui 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # DISTRHO Notes Plugin
  4. # Copyright (C) 2012-2013 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from numpy import rint
  20. from sys import argv, exit
  21. try:
  22. from PyQt5.QtCore import pyqtSlot
  23. from PyQt5.QtWidgets import QApplication, QGridLayout, QLabel, QPushButton, QTextEdit, QWidget
  24. except:
  25. from PyQt4.QtCore import pyqtSlot
  26. from PyQt4.QtGui import QApplication, QGridLayout, QLabel, QPushButton, QTextEdit, QWidget
  27. # -----------------------------------------------------------------------
  28. # Imports (ExternalUI)
  29. from externalui import ExternalUI
  30. from paramspinbox import ParamSpinBox
  31. # -----------------------------------------------------------------------
  32. # External UI
  33. class DistrhoUINotes(QWidget, ExternalUI):
  34. def __init__(self):
  35. QWidget.__init__(self, None)
  36. ExternalUI.__init__(self)
  37. self.fCurPage = 1
  38. self.fSaveSizeNowChecker = -1
  39. self.fSaveTextNowChecker = -1
  40. self.fNotes = ["" for x in range(100)]
  41. self.fTextEdit = QTextEdit(self)
  42. self.fButton = QPushButton(self)
  43. self.fProgressBar = ParamSpinBox(self)
  44. self.fSpacer = QLabel(self)
  45. self.fGridLayout = QGridLayout(self)
  46. self.fButton.setCheckable(True)
  47. self.fButton.setChecked(True)
  48. self.fButton.setText("Edit")
  49. self.fButton.setFixedSize(self.fButton.minimumSizeHint())
  50. self.fProgressBar.setMinimum(1.0)
  51. self.fProgressBar.setMaximum(100.0)
  52. self.fProgressBar.setValue(1.0)
  53. self.fProgressBar.setStep(1.0)
  54. self.fProgressBar.setStepSmall(1.0)
  55. self.fProgressBar.setStepLarge(10.0)
  56. self.fSpacer.setText("")
  57. self.fSpacer.setFixedSize(5, 5)
  58. self.fTextEdit.setReadOnly(False)
  59. self.setLayout(self.fGridLayout)
  60. self.fGridLayout.addWidget(self.fTextEdit, 0, 0, 1, 3)
  61. self.fGridLayout.addWidget(self.fButton, 1, 0, 1, 1)
  62. self.fGridLayout.addWidget(self.fProgressBar, 1, 1, 1, 1)
  63. self.fGridLayout.addWidget(self.fSpacer, 1, 2, 1, 1)
  64. self.fGridLayout.setContentsMargins(0, 0, 0, 0)
  65. self.resize(300, 200)
  66. self.setWindowTitle(self.fUiName)
  67. self.fButton.clicked.connect(self.slot_buttonClicked)
  68. self.fProgressBar.valueChanged.connect(self.slot_progressBarValueChanged)
  69. self.fTextEdit.textChanged.connect(self.slot_textChanged)
  70. self.fIdleTimer = self.startTimer(50)
  71. def saveCurrentTextState(self):
  72. pageKey = "pageText %i" % self.fCurPage
  73. pageValue = self.fTextEdit.toPlainText()
  74. if pageValue != self.fNotes[self.fCurPage-1]:
  75. self.fNotes[self.fCurPage-1] = pageValue
  76. self.d_setState(pageKey, pageValue)
  77. # -------------------------------------------------------------------
  78. @pyqtSlot(bool)
  79. def slot_buttonClicked(self, click):
  80. readOnly = not click
  81. self.fTextEdit.setReadOnly(readOnly)
  82. self.d_setState("readOnly", "yes" if readOnly else "no")
  83. @pyqtSlot(float)
  84. def slot_progressBarValueChanged(self, value):
  85. value = rint(value)
  86. if self.fCurPage == int(value):
  87. return
  88. # maybe save current text before changing page
  89. if self.fSaveTextNowChecker >= 0 and value >= 1.0 and value <= 100.0:
  90. self.saveCurrentTextState()
  91. self.fSaveTextNowChecker = -1
  92. # change current page
  93. self.d_parameterChanged(0, value)
  94. # tell host about this change
  95. self.d_setParameterValue(0, value)
  96. @pyqtSlot()
  97. def slot_textChanged(self):
  98. self.fSaveTextNowChecker = 0
  99. # -------------------------------------------------------------------
  100. # DSP Callbacks
  101. def d_parameterChanged(self, index, value):
  102. if index != 0:
  103. return
  104. nextCurPage = int(value)
  105. if nextCurPage != self.fCurPage and nextCurPage >= 1 and nextCurPage <= 100:
  106. self.saveCurrentTextState()
  107. self.fCurPage = nextCurPage
  108. self.fTextEdit.setPlainText(self.fNotes[self.fCurPage-1])
  109. self.fProgressBar.setValue(self.fCurPage)
  110. self.fProgressBar.update()
  111. def d_stateChanged(self, key, value):
  112. if key == "guiWidth":
  113. try:
  114. width = int(value)
  115. except:
  116. width = 0
  117. if width > 0:
  118. self.resize(width, self.height())
  119. elif key == "guiHeight":
  120. try:
  121. height = int(value)
  122. except:
  123. height = 0
  124. if height > 0:
  125. self.resize(self.width(), height)
  126. elif key.startswith("pageText #"):
  127. try:
  128. pageIndex = int(key.replace("pageText #",""))
  129. except:
  130. pageIndex = 0
  131. if pageIndex >= 1 and pageIndex <= 100:
  132. self.fNotes[pageIndex-1] = value
  133. if pageIndex == self.fCurPage:
  134. self.fTextEdit.setPlainText(self.fNotes[pageIndex-1])
  135. elif key == "readOnly":
  136. readOnly = (value == "yes")
  137. self.fButton.setChecked(not readOnly)
  138. self.fTextEdit.setReadOnly(readOnly)
  139. # -------------------------------------------------------------------
  140. # ExternalUI Callbacks
  141. def d_uiShow(self):
  142. self.show()
  143. def d_uiHide(self):
  144. self.hide()
  145. def d_uiQuit(self):
  146. self.close()
  147. app.quit()
  148. def d_uiTitleChanged(self, uiTitle):
  149. self.setWindowTitle(uiTitle)
  150. # -------------------------------------------------------------------
  151. # Qt events
  152. def resizeEvent(self, event):
  153. self.fSaveSizeNowChecker = 0
  154. QWidget.resizeEvent(self, event)
  155. def timerEvent(self, event):
  156. if event.timerId() == self.fIdleTimer:
  157. if self.fSaveSizeNowChecker == 11:
  158. self.d_setState("guiWidth", str(self.width()))
  159. self.d_setState("guiHeight", str(self.height()))
  160. self.fSaveSizeNowChecker = -1
  161. elif self.fSaveSizeNowChecker >= 0:
  162. self.fSaveSizeNowChecker += 1
  163. if self.fSaveTextNowChecker == 11:
  164. self.saveCurrentTextState()
  165. self.fSaveTextNowChecker = -1
  166. elif self.fSaveTextNowChecker >= 0:
  167. self.fSaveTextNowChecker += 1
  168. if not self.idleExternalUI():
  169. self.d_uiQuit()
  170. QWidget.timerEvent(self, event)
  171. def closeEvent(self, event):
  172. self.closeExternalUI()
  173. QWidget.closeEvent(self, event)
  174. #--------------- main ------------------
  175. if __name__ == '__main__':
  176. app = QApplication(argv)
  177. #app...
  178. gui = DistrhoUINotes()
  179. exit(app.exec_())