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.

236 lines
8.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-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 QDialog
  25. else:
  26. from PyQt4.QtCore import pyqtSlot
  27. from PyQt4.QtGui import QDialog
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Imports (Custom)
  30. from carla_shared import *
  31. import ui_carla_panel_time
  32. # ------------------------------------------------------------------------------------------------------------
  33. # Time Panel
  34. class CarlaPanelTime(QDialog):
  35. def __init__(self, host, parent):
  36. QDialog.__init__(self, parent)
  37. self.host = host
  38. self.ui = ui_carla_panel_time.Ui_Dialog()
  39. self.ui.setupUi(self)
  40. if False:
  41. # kdevelop likes this :)
  42. host = CarlaHostMeta()
  43. self.host = host
  44. # ----------------------------------------------------------------------------------------------------
  45. # Internal stuff
  46. self.fLastTransportFrame = 0
  47. self.fLastTransportState = False
  48. self.fSampleRate = 0.0
  49. #if view == TRANSPORT_VIEW_HMS:
  50. #self.fCurTransportView = TRANSPORT_VIEW_HMS
  51. #self.ui.label_time.setMinimumWidth(QFontMetrics(self.ui.label_time.font()).width("00:00:00") + 3)
  52. #elif view == TRANSPORT_VIEW_BBT:
  53. #self.fCurTransportView = TRANSPORT_VIEW_BBT
  54. #self.ui.label_time.setMinimumWidth(QFontMetrics(self.ui.label_time.font()).width("000|00|0000") + 3)
  55. #elif view == TRANSPORT_VIEW_FRAMES:
  56. #self.fCurTransportView = TRANSPORT_VIEW_FRAMES
  57. #self.ui.label_time.setMinimumWidth(QFontMetrics(self.ui.label_time.font()).width("000'000'000") + 3)
  58. # ----------------------------------------------------------------------------------------------------
  59. # Disable buttons if plugin
  60. if host.isPlugin:
  61. self.ui.b_play.setEnabled(False)
  62. self.ui.b_stop.setEnabled(False)
  63. self.ui.b_backwards.setEnabled(False)
  64. self.ui.b_forwards.setEnabled(False)
  65. # ----------------------------------------------------------------------------------------------------
  66. # Connect actions to functions
  67. self.ui.b_play.clicked.connect(self.slot_transportPlayPause)
  68. self.ui.b_stop.clicked.connect(self.slot_transportStop)
  69. self.ui.b_backwards.clicked.connect(self.slot_transportBackwards)
  70. self.ui.b_forwards.clicked.connect(self.slot_transportForwards)
  71. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  72. host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  73. # --------------------------------------------------------------------------------------------------------
  74. # Button actions
  75. @pyqtSlot(bool)
  76. def slot_transportPlayPause(self, toggled):
  77. if self.host.isPlugin or not self.host.is_engine_running():
  78. return
  79. if toggled:
  80. self.host.transport_play()
  81. else:
  82. self.host.transport_pause()
  83. self.refreshTransport()
  84. @pyqtSlot()
  85. def slot_transportStop(self):
  86. if self.host.isPlugin or not self.host.is_engine_running():
  87. return
  88. self.host.transport_pause()
  89. self.host.transport_relocate(0)
  90. self.refreshTransport()
  91. @pyqtSlot()
  92. def slot_transportBackwards(self):
  93. if self.host.isPlugin or not self.host.is_engine_running():
  94. return
  95. newFrame = self.host.get_current_transport_frame() - 100000
  96. if newFrame < 0:
  97. newFrame = 0
  98. self.host.transport_relocate(newFrame)
  99. @pyqtSlot()
  100. def slot_transportForwards(self):
  101. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  102. return
  103. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  104. self.host.transport_relocate(newFrame)
  105. def refreshTransport(self, forced = False):
  106. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  107. return
  108. timeInfo = self.host.get_transport_info()
  109. playing = timeInfo['playing']
  110. frame = timeInfo['frame']
  111. if playing != self.fLastTransportState or forced:
  112. if playing:
  113. icon = getIcon("media-playback-pause")
  114. self.ui.b_play.setChecked(True)
  115. self.ui.b_play.setIcon(icon)
  116. #self.ui.b_play.setText(self.tr("&Pause"))
  117. else:
  118. icon = getIcon("media-playback-start")
  119. self.ui.b_play.setChecked(False)
  120. self.ui.b_play.setIcon(icon)
  121. #self.ui.b_play.setText(self.tr("&Play"))
  122. self.fLastTransportState = playing
  123. if frame != self.fLastTransportFrame or forced:
  124. time = frame / self.fSampleRate
  125. secs = time % 60
  126. mins = (time / 60) % 60
  127. hrs = (time / 3600) % 60
  128. self.fLastTransportFrame = frame
  129. self.ui.l_time.setText("Transport %s, at %02i:%02i:%02i" % ("playing" if playing else "stopped", hrs, mins, secs))
  130. #if self.fCurTransportView == TRANSPORT_VIEW_HMS:
  131. #time = pos.frame / int(self.fSampleRate)
  132. #secs = time % 60
  133. #mins = (time / 60) % 60
  134. #hrs = (time / 3600) % 60
  135. #self.ui.label_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  136. #elif self.fCurTransportView == TRANSPORT_VIEW_BBT:
  137. #if pos.valid & jacklib.JackPositionBBT:
  138. #bar = pos.bar
  139. #beat = pos.beat if bar != 0 else 0
  140. #tick = pos.tick if bar != 0 else 0
  141. #else:
  142. #bar = 0
  143. #beat = 0
  144. #tick = 0
  145. #self.ui.label_time.setText("%03i|%02i|%04i" % (bar, beat, tick))
  146. #elif self.fCurTransportView == TRANSPORT_VIEW_FRAMES:
  147. #frame1 = pos.frame % 1000
  148. #frame2 = (pos.frame / 1000) % 1000
  149. #frame3 = (pos.frame / 1000000) % 1000
  150. #self.ui.label_time.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  151. #if pos.valid & jacklib.JackPositionBBT:
  152. #if self.fLastBPM != pos.beats_per_minute:
  153. #self.ui.sb_bpm.setValue(pos.beats_per_minute)
  154. #self.ui.sb_bpm.setStyleSheet("")
  155. #else:
  156. #pos.beats_per_minute = -1.0
  157. #if self.fLastBPM != pos.beats_per_minute:
  158. #self.ui.sb_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  159. #self.fLastBPM = pos.beats_per_minute
  160. #if state != self.fLastTransportState:
  161. #self.fLastTransportState = state
  162. #if state == jacklib.JackTransportStopped:
  163. #icon = getIcon("media-playback-start")
  164. #self.ui.act_transport_play.setChecked(False)
  165. #self.ui.act_transport_play.setText(self.tr("&Play"))
  166. #self.ui.b_transport_play.setChecked(False)
  167. #else:
  168. #icon = getIcon("media-playback-pause")
  169. #self.ui.act_transport_play.setChecked(True)
  170. #self.ui.act_transport_play.setText(self.tr("&Pause"))
  171. #self.ui.b_transport_play.setChecked(True)
  172. #self.ui.act_transport_play.setIcon(icon)
  173. #self.ui.b_transport_play.setIcon(icon)
  174. # --------------------------------------------------------------------------------------------------------
  175. # Engine callbacks
  176. @pyqtSlot(str)
  177. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  178. self.fSampleRate = self.host.get_sample_rate()
  179. self.refreshTransport(True)
  180. @pyqtSlot(float)
  181. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  182. self.fSampleRate = newSampleRate
  183. self.refreshTransport(True)
  184. # ------------------------------------------------------------------------------------------------------------