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 7.8KB

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