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.

notes-ui 8.1KB

10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla Native Plugins
  4. # Copyright (C) 2012-2014 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 (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import pyqtSlot, Qt
  24. from PyQt5.QtWidgets import QGridLayout, QLabel, QPushButton, QTextEdit, QWidget
  25. else:
  26. from PyQt4.QtCore import pyqtSlot, Qt
  27. from PyQt4.QtGui import QGridLayout, QLabel, QPushButton, QTextEdit, QWidget
  28. # -----------------------------------------------------------------------
  29. # Imports (Custom)
  30. from carla_shared import *
  31. from carla_utils import *
  32. # -----------------------------------------------------------------------
  33. # Imports (ExternalUI)
  34. from carla_app import CarlaApplication
  35. from externalui import ExternalUI
  36. from paramspinbox import ParamSpinBox
  37. # -----------------------------------------------------------------------
  38. # External UI
  39. class DistrhoUINotes(ExternalUI, QWidget):
  40. def __init__(self):
  41. ExternalUI.__init__(self)
  42. QWidget.__init__(self, None)
  43. self.fCurPage = 1
  44. self.fSaveSizeNowChecker = -1
  45. self.fSaveTextNowChecker = -1
  46. self.fNotes = ["" for x in range(100)]
  47. self.fTextEdit = QTextEdit(self)
  48. self.fButton = QPushButton(self)
  49. self.fProgressBar = ParamSpinBox(self)
  50. self.fSpacer = QLabel(self)
  51. self.fGridLayout = QGridLayout(self)
  52. self.fButton.setCheckable(True)
  53. self.fButton.setChecked(True)
  54. self.fButton.setText("Edit")
  55. self.fButton.setFixedSize(self.fButton.minimumSizeHint())
  56. self.fProgressBar.setMinimum(1.0)
  57. self.fProgressBar.setMaximum(100.0)
  58. self.fProgressBar.setValue(1.0)
  59. self.fProgressBar.setStep(1.0)
  60. self.fProgressBar.setStepSmall(1.0)
  61. self.fProgressBar.setStepLarge(10.0)
  62. self.fSpacer.setText("")
  63. self.fSpacer.setFixedSize(5, 5)
  64. self.fTextEdit.setReadOnly(False)
  65. self.setLayout(self.fGridLayout)
  66. self.fGridLayout.addWidget(self.fTextEdit, 0, 0, 1, 3)
  67. self.fGridLayout.addWidget(self.fButton, 1, 0, 1, 1)
  68. self.fGridLayout.addWidget(self.fProgressBar, 1, 1, 1, 1)
  69. self.fGridLayout.addWidget(self.fSpacer, 1, 2, 1, 1)
  70. self.fGridLayout.setContentsMargins(0, 0, 0, 0)
  71. self.fButton.clicked.connect(self.slot_buttonClicked)
  72. self.fProgressBar.valueChanged.connect(self.slot_progressBarValueChanged)
  73. self.fTextEdit.textChanged.connect(self.slot_textChanged)
  74. self.fIdleTimer = self.startTimer(50)
  75. self.resize(300, 200)
  76. self.setWindowTitle(self.fUiName)
  77. self.ready()
  78. def saveCurrentTextState(self):
  79. pageKey = "pageText #%i" % self.fCurPage
  80. pageValue = self.fTextEdit.toPlainText()
  81. if pageValue != self.fNotes[self.fCurPage-1]:
  82. self.fNotes[self.fCurPage-1] = pageValue
  83. self.sendConfigure(pageKey, pageValue)
  84. # -------------------------------------------------------------------
  85. @pyqtSlot(bool)
  86. def slot_buttonClicked(self, click):
  87. readOnly = not click
  88. self.fTextEdit.setReadOnly(readOnly)
  89. self.sendConfigure("readOnly", "yes" if readOnly else "no")
  90. @pyqtSlot(float)
  91. def slot_progressBarValueChanged(self, value):
  92. ivalue = int(value)
  93. value = float(ivalue)
  94. if self.fCurPage == ivalue:
  95. return
  96. # maybe save current text before changing page
  97. if self.fSaveTextNowChecker >= 0 and value >= 1.0 and value <= 100.0:
  98. self.saveCurrentTextState()
  99. self.fSaveTextNowChecker = -1
  100. # change current page
  101. self.dspParameterChanged(0, value)
  102. # tell host about this change
  103. self.sendControl(0, value)
  104. @pyqtSlot()
  105. def slot_textChanged(self):
  106. self.fSaveTextNowChecker = 0
  107. # -------------------------------------------------------------------
  108. # DSP Callbacks
  109. def dspParameterChanged(self, index, value):
  110. if index != 0:
  111. return
  112. nextCurPage = int(value)
  113. if nextCurPage != self.fCurPage and nextCurPage >= 1 and nextCurPage <= 100:
  114. self.saveCurrentTextState()
  115. self.fCurPage = nextCurPage
  116. self.fTextEdit.setPlainText(self.fNotes[self.fCurPage-1])
  117. self.fProgressBar.setValue(self.fCurPage)
  118. self.fProgressBar.update()
  119. def dspStateChanged(self, key, value):
  120. if key == "guiWidth":
  121. try:
  122. width = int(value)
  123. except:
  124. width = 0
  125. if width > 0:
  126. self.resize(width, self.height())
  127. elif key == "guiHeight":
  128. try:
  129. height = int(value)
  130. except:
  131. height = 0
  132. if height > 0:
  133. self.resize(self.width(), height)
  134. elif key.startswith("pageText #"):
  135. try:
  136. pageIndex = int(key.replace("pageText #",""))
  137. except:
  138. pageIndex = 0
  139. if pageIndex >= 1 and pageIndex <= 100:
  140. self.fNotes[pageIndex-1] = value
  141. if pageIndex == self.fCurPage:
  142. self.fTextEdit.setPlainText(self.fNotes[pageIndex-1])
  143. elif key == "readOnly":
  144. readOnly = (value == "yes")
  145. self.fButton.setChecked(not readOnly)
  146. self.fTextEdit.setReadOnly(readOnly)
  147. # -------------------------------------------------------------------
  148. # ExternalUI Callbacks
  149. def uiShow(self):
  150. self.show()
  151. def uiFocus(self):
  152. self.setWindowState((self.windowState() & ~Qt.WindowMinimized) | Qt.WindowActive)
  153. self.show()
  154. self.raise_()
  155. self.activateWindow()
  156. def uiHide(self):
  157. self.hide()
  158. def uiQuit(self):
  159. self.closeExternalUI()
  160. self.close()
  161. app.quit()
  162. def uiTitleChanged(self, uiTitle):
  163. self.setWindowTitle(uiTitle)
  164. # -------------------------------------------------------------------
  165. # Qt events
  166. def resizeEvent(self, event):
  167. self.fSaveSizeNowChecker = 0
  168. QWidget.resizeEvent(self, event)
  169. def timerEvent(self, event):
  170. if event.timerId() == self.fIdleTimer:
  171. self.idleExternalUI()
  172. if self.fSaveSizeNowChecker == 11:
  173. self.sendConfigure("guiWidth", str(self.width()))
  174. self.sendConfigure("guiHeight", str(self.height()))
  175. self.fSaveSizeNowChecker = -1
  176. elif self.fSaveSizeNowChecker >= 0:
  177. self.fSaveSizeNowChecker += 1
  178. if self.fSaveTextNowChecker == 11:
  179. self.saveCurrentTextState()
  180. self.fSaveTextNowChecker = -1
  181. elif self.fSaveTextNowChecker >= 0:
  182. self.fSaveTextNowChecker += 1
  183. QWidget.timerEvent(self, event)
  184. def closeEvent(self, event):
  185. self.closeExternalUI()
  186. QWidget.closeEvent(self, event)
  187. # there might be other qt windows open which will block the UI from quitting
  188. app.quit()
  189. #--------------- main ------------------
  190. if __name__ == '__main__':
  191. import resources_rc
  192. pathBinaries, pathResources = getPaths()
  193. gCarla.utils = CarlaUtils(os.path.join(pathBinaries, "libcarla_utils." + DLL_EXTENSION))
  194. gCarla.utils.set_process_name("Notes")
  195. app = CarlaApplication("Notes")
  196. gui = DistrhoUINotes()
  197. app.exit_exec()