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.

235 lines
7.2KB

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