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.

101 lines
3.9KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla Backend code (Web stuff)
  4. # Copyright (C) 2018 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. import requests
  20. # ---------------------------------------------------------------------------------------------------------------------
  21. # Imports (Custom)
  22. from carla_backend_qt import *
  23. # ---------------------------------------------------------------------------------------------------------------------
  24. # Carla Host object for connecting to the REST API
  25. class CarlaHostQtWeb(CarlaHostQtNull):
  26. def __init__(self):
  27. CarlaHostQtNull.__init__(self)
  28. self.baseurl = "http://localhost:2228"
  29. def get_engine_driver_count(self):
  30. # FIXME
  31. return int(requests.get("{}/get_engine_driver_count".format(self.baseurl)).text) - 1
  32. def get_engine_driver_name(self, index):
  33. return requests.get("{}/get_engine_driver_name/{}".format(self.baseurl, index)).text
  34. def get_engine_driver_device_names(self, index):
  35. return requests.get("{}/get_engine_driver_device_names/{}".format(self.baseurl, index)).text.split("\n")
  36. def get_engine_driver_device_info(self, index, name):
  37. return requests.get("{}/get_engine_driver_device_info/{}/{}".format(self.baseurl, index, name)).json()
  38. def engine_init(self, driverName, clientName):
  39. resp = requests.get("{}/engine_init/{}/{}".format(self.baseurl, driverName, clientName)).status_code
  40. # TESTING
  41. if self.fEngineCallback is not None:
  42. self.fEngineCallback(None, ENGINE_CALLBACK_ENGINE_STARTED, 0, self.processMode, self.transportMode, 0.0, driverName)
  43. return resp == 200
  44. def engine_close(self):
  45. # TESTING
  46. if self.fEngineCallback is not None:
  47. self.fEngineCallback(None, ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0, "")
  48. return requests.get("{}/engine_close".format(self.baseurl)).status_code == 200
  49. def engine_idle(self):
  50. requests.get("{}/engine_idle".format(self.baseurl))
  51. def is_engine_running(self):
  52. return requests.get("{}/is_engine_running".format(self.baseurl)).status_code == 200
  53. def set_engine_about_to_close(self):
  54. return requests.get("{}/set_engine_about_to_close".format(self.baseurl)).status_code == 200
  55. def get_last_error(self):
  56. return requests.get("{}/get_last_error".format(self.baseurl)).text
  57. # ---------------------------------------------------------------------------------------------------------------------
  58. # TESTING
  59. if __name__ == '__main__':
  60. baseurl = "http://localhost:2228"
  61. driver_count = int(requests.get("{}/get_engine_driver_count".format(baseurl)).text)
  62. # FIXME
  63. driver_count -= 1
  64. print("Driver names:")
  65. for index in range(driver_count):
  66. print("\t -", requests.get("{}/get_engine_driver_name/{}".format(baseurl, index)).text)
  67. print("Driver device names:")
  68. for index in range(driver_count):
  69. for name in requests.get("{}/get_engine_driver_device_names/{}".format(baseurl, index)).text.split("\n"):
  70. print("\t {}:".format(name), requests.get("{}/get_engine_driver_device_info/{}/{}".format(baseurl, index, name)).json())
  71. # ---------------------------------------------------------------------------------------------------------------------