Collection of tools useful for audio production
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.7KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # JACK Sequencer
  4. # Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # 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 COPYING file
  17. # Imports (Global)
  18. from PyQt4.QtCore import qFatal, QSettings
  19. from PyQt4.QtCore import QLineF, QPointF, QRectF, QSizeF
  20. from PyQt4.QtGui import QGraphicsItem, QGraphicsScene
  21. from PyQt4.QtGui import QPainter
  22. from PyQt4.QtGui import QApplication, QMainWindow
  23. # Imports (Custom Stuff)
  24. import ui_caitlyn
  25. from caitlib_helpers import *
  26. from shared_settings import *
  27. try:
  28. from PyQt4.QtOpenGL import QGLWidget
  29. hasGL = True
  30. except:
  31. hasGL = False
  32. # ------------------------------------------------------------------------------
  33. # Caitlyn Qt Graphics Scene
  34. class CaitlynCanvasScene(QGraphicsScene):
  35. def __init__(self, parent, view):
  36. QGraphicsScene.__init__(self, parent)
  37. self.m_view = view
  38. if not self.m_view:
  39. qFatal("CaitlynCanvasScene() - invalid view")
  40. # ------------------------------------------------------------------------------
  41. # Caitlyn items
  42. class CaitlynCanvasTimelineTopBar(QGraphicsItem):
  43. def __init__(self, scene, parent=None):
  44. QGraphicsItem.__init__(self, parent, scene)
  45. # horizontal length, matches min(full length of song, window)
  46. self.m_length = 100
  47. def boundingRect(self):
  48. return QRectF(0, 0, self.m_length*4, 4)
  49. def paint(self, painter, option, widget):
  50. painter.setRenderHint(QPainter.Antialiasing, False)
  51. painter.drawRect(0, 0, self.m_length*14, 16)
  52. class CaitlynCanvasBox(QGraphicsItem):
  53. def __init__(self, scene, parent=None):
  54. QGraphicsItem.__init__(self, parent, scene)
  55. self.m_length = 1.0
  56. def length(self):
  57. return self.m_length
  58. def boundingRect(self):
  59. return QRectF(0, 0, self.m_length*4, 4)
  60. def paint(self, painter, option, widget):
  61. painter.setRenderHint(QPainter.Antialiasing, False)
  62. painter.drawRect(0, 0, self.m_length*14, 16)
  63. # ------------------------------------------------------------------------------
  64. # Caitlyn Main Window
  65. class CaitlynMainW(QMainWindow, ui_caitlyn.Ui_CaitlynMainW):
  66. def __init__(self, parent=None):
  67. QMainWindow.__init__(self, parent)
  68. self.setupUi(self)
  69. self.settings = QSettings("Cadence", "Caitlyn")
  70. self.loadSettings(True)
  71. self.scene = CaitlynCanvasScene(self, self.graphicsView)
  72. self.graphicsView.setScene(self.scene)
  73. self.graphicsView.setRenderHint(QPainter.Antialiasing, False)
  74. self.graphicsView.setRenderHint(QPainter.TextAntialiasing, False)
  75. self.item1 = CaitlynCanvasBox(self.scene)
  76. # Sequencer test code
  77. self.m_seq = CailibInstance("Caitlyn")
  78. if self.m_seq.isOk():
  79. self.m_port1 = self.m_seq.createPort("out1")
  80. m = 44
  81. self.m_port1.addControl(0*m, 0, 7, 99)
  82. self.m_port1.addControl(0*m, 0, 10, 63)
  83. self.m_port1.addProgram(0*m, 0, 0, 0)
  84. # 0 On ch=1 n=64 v=90
  85. # 325 Off ch=1 n=64 v=90
  86. # 384 On ch=1 n=62 v=90
  87. # 709 Off ch=1 n=62 v=90
  88. # 768 On ch=1 n=60 v=90
  89. # 1093 Off ch=1 n=60 v=90
  90. self.m_port1.addNote( 0*m, 0, 64, 90, 325*m)
  91. self.m_port1.addNote(384*m, 0, 62, 90, 325*m)
  92. self.m_port1.addNote(768*m, 0, 60, 90, 325*m)
  93. # 1152 On ch=1 n=62 v=90
  94. # 1477 Off ch=1 n=62 v=90
  95. # 1536 On ch=1 n=64 v=90
  96. # 1861 Off ch=1 n=64 v=90
  97. # 1920 On ch=1 n=64 v=90
  98. # 2245 Off ch=1 n=64 v=90
  99. self.m_port1.addNote(1152*m, 0, 62, 90, 325*m)
  100. self.m_port1.addNote(1536*m, 0, 64, 90, 325*m)
  101. self.m_port1.addNote(1920*m, 0, 64, 90, 325*m)
  102. # 2304 On ch=1 n=64 v=90
  103. # 2955 Off ch=1 n=64 v=90
  104. # 3072 On ch=1 n=62 v=90
  105. # 3397 Off ch=1 n=62 v=90
  106. # 3456 On ch=1 n=62 v=90
  107. # 3781 Off ch=1 n=62 v=90
  108. self.m_port1.addNote(2304*m, 0, 64, 90, 650*m)
  109. self.m_port1.addNote(3072*m, 0, 62, 90, 325*m)
  110. self.m_port1.addNote(3456*m, 0, 62, 90, 325*m)
  111. # 3840 On ch=1 n=62 v=90
  112. # 4491 Off ch=1 n=62 v=90
  113. # 4608 On ch=1 n=64 v=90
  114. # 4933 Off ch=1 n=64 v=90
  115. # 4992 On ch=1 n=67 v=90
  116. # 5317 Off ch=1 n=67 v=90
  117. self.m_port1.addNote(3840*m, 0, 62, 90, 650*m)
  118. self.m_port1.addNote(4608*m, 0, 64, 90, 325*m)
  119. self.m_port1.addNote(4992*m, 0, 67, 90, 325*m)
  120. # 5376 On ch=1 n=67 v=90
  121. # 6027 Off ch=1 n=67 v=90
  122. # 6144 On ch=1 n=64 v=90
  123. # 6469 Off ch=1 n=64 v=90
  124. # 6528 On ch=1 n=62 v=90
  125. # 6853 Off ch=1 n=62 v=90
  126. self.m_port1.addNote(5376*m, 0, 67, 90, 650*m)
  127. self.m_port1.addNote(6144*m, 0, 64, 90, 325*m)
  128. self.m_port1.addNote(6528*m, 0, 62, 90, 325*m)
  129. # 6912 On ch=1 n=60 v=90
  130. # 7237 Off ch=1 n=60 v=90
  131. # 7296 On ch=1 n=62 v=90
  132. # 7621 Off ch=1 n=62 v=90
  133. # 7680 On ch=1 n=64 v=90
  134. # 8005 Off ch=1 n=64 v=90
  135. self.m_port1.addNote(6912*m, 0, 60, 90, 325*m)
  136. self.m_port1.addNote(7296*m, 0, 62, 90, 325*m)
  137. self.m_port1.addNote(7680*m, 0, 64, 90, 325*m)
  138. # 8064 On ch=1 n=64 v=90
  139. # 8389 Off ch=1 n=64 v=90
  140. # 8448 On ch=1 n=64 v=90
  141. # 9099 Off ch=1 n=64 v=90
  142. # 9216 On ch=1 n=62 v=90
  143. # 9541 Off ch=1 n=62 v=90
  144. self.m_port1.addNote(8064*m, 0, 64, 90, 325*m)
  145. self.m_port1.addNote(8448*m, 0, 64, 90, 650*m)
  146. self.m_port1.addNote(9216*m, 0, 62, 90, 325*m)
  147. # 9600 On ch=1 n=62 v=90
  148. # 9925 Off ch=1 n=62 v=90
  149. # 9984 On ch=1 n=64 v=90
  150. # 10309 Off ch=1 n=64 v=90
  151. # 10368 On ch=1 n=62 v=90
  152. # 10693 Off ch=1 n=62 v=90
  153. self.m_port1.addNote(9600*m, 0, 62, 90, 325*m)
  154. self.m_port1.addNote(9984*m, 0, 64, 90, 325*m)
  155. self.m_port1.addNote(10368*m, 0, 62, 90, 325*m)
  156. # 10752 On ch=1 n=60 v=90
  157. # 12056 Off ch=1 n=60 v=90
  158. self.m_port1.addNote(10752*m, 0, 60, 90, 650*m)
  159. def saveSettings(self):
  160. self.settings.setValue("Geometry", self.saveGeometry())
  161. def loadSettings(self, geometry):
  162. if geometry:
  163. self.restoreGeometry(self.settings.value("Geometry", ""))
  164. self.m_savedSettings = {
  165. "Main/RefreshInterval": self.settings.value("Main/RefreshInterval", 120, type=int)
  166. }
  167. def closeEvent(self, event):
  168. if self.m_seq.isOk():
  169. self.m_seq.close()
  170. self.scene.removeItem(self.item1)
  171. self.saveSettings()
  172. QMainWindow.closeEvent(self, event)
  173. #--------------- main ------------------
  174. if __name__ == '__main__':
  175. # App initialization
  176. app = QApplication(sys.argv)
  177. app.setApplicationName("Caitlyn")
  178. app.setApplicationVersion(VERSION)
  179. app.setOrganizationName("Cadence")
  180. #app.setWindowIcon(QIcon(":/scalable/caitlyn.svg"))
  181. # Show GUI
  182. gui = CaitlynMainW()
  183. # Set-up custom signal handling
  184. setUpSignals(gui)
  185. gui.show()
  186. # App-Loop and exit
  187. sys.exit(app.exec_())