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.5KB

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