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.

119 lines
3.1KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Imports (Global)
  4. import dbus, signal, sys
  5. from PyQt5.QtCore import QCoreApplication, QObject
  6. # DBus
  7. class DBus(object):
  8. __slots__ = [
  9. 'bus',
  10. 'jack'
  11. ]
  12. DBus = DBus()
  13. DBus.bus = None
  14. DBus.jack = None
  15. def appQuit(sig, frame):
  16. app.exit(0)
  17. # Main Application
  18. class CadenceUnityApp(QObject):
  19. def __init__(self, parent=None):
  20. QObject.__init__(self, parent)
  21. self.m_lastLoad = None
  22. self.m_lastXruns = None
  23. self.m_timerDBus = self.startTimer(5000)
  24. self.m_timerLauncher = self.startTimer(1000)
  25. self.timerCheckDBus()
  26. self.timerCheckLauncher()
  27. def refreshDBus(self):
  28. DBus.bus = dbus.SessionBus()
  29. try:
  30. DBus.jack = DBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  31. except:
  32. DBus.jack = None
  33. def jackGetLoad(self):
  34. if DBus.jack:
  35. try:
  36. return DBus.jack.GetLoad()
  37. except:
  38. DBus.jack = None
  39. return None
  40. else:
  41. return None
  42. def jackGetXruns(self):
  43. if DBus.jack:
  44. try:
  45. return DBus.jack.GetXruns()
  46. except:
  47. DBus.jack = None
  48. return None
  49. else:
  50. return None
  51. def timerCheckDBus(self):
  52. if not DBus.jack:
  53. self.refreshDBus()
  54. def timerCheckLauncher(self):
  55. load = self.jackGetLoad()
  56. xruns = self.jackGetXruns()
  57. if load != self.m_lastLoad:
  58. if load != None:
  59. launcher.set_property("progress", load/100)
  60. launcher.set_property("progress_visible", True)
  61. else:
  62. launcher.set_property("progress", 0.0)
  63. launcher.set_property("progress_visible", False)
  64. if xruns != self.m_lastXruns:
  65. if xruns != None:
  66. launcher.set_property("count", xruns)
  67. launcher.set_property("count_visible", True)
  68. else:
  69. launcher.set_property("count", 0)
  70. launcher.set_property("count_visible", False)
  71. self.m_lastLoad = load
  72. self.m_lastXruns = xruns
  73. def timerEvent(self, event):
  74. if event.timerId() == self.m_timerDBus:
  75. self.timerCheckDBus()
  76. elif event.timerId() == self.m_timerLauncher:
  77. self.timerCheckLauncher()
  78. QObject.timerEvent(self, event)
  79. #--------------- main ------------------
  80. if __name__ == '__main__':
  81. # Imports (Unity)
  82. from gi import require_version as gi_require_version
  83. gi_require_version('Unity', '7.0')
  84. from gi.repository import Unity
  85. # App initialization
  86. app = QCoreApplication(sys.argv)
  87. app.setApplicationName("Cadence-Unity-Support")
  88. app.setApplicationVersion("0.5.0")
  89. app.setOrganizationName("Cadence")
  90. launcher = Unity.LauncherEntry.get_for_desktop_id("cadence.desktop")
  91. qtLoop = CadenceUnityApp()
  92. signal.signal(signal.SIGTERM, appQuit)
  93. signal.signal(signal.SIGINT, appQuit)
  94. # App-Loop
  95. sys.exit(app.exec_())