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.

75 lines
2.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. # FIXME strip should not be needed
  36. return requests.get("{}/get_engine_driver_device_names/{}".format(self.baseurl, index)).text.strip().split("\n")
  37. def get_engine_driver_device_info(self, index, name):
  38. return requests.get("{}/get_engine_driver_device_info/{}/{}".format(self.baseurl, index, name)).json()
  39. # ---------------------------------------------------------------------------------------------------------------------
  40. # TESTING
  41. if __name__ == '__main__':
  42. baseurl = "http://localhost:2228"
  43. driver_count = int(requests.get("{}/get_engine_driver_count".format(baseurl)).text)
  44. # FIXME
  45. driver_count -= 1
  46. print("Driver names:")
  47. for index in range(driver_count):
  48. print("\t -", requests.get("{}/get_engine_driver_name/{}".format(baseurl, index)).text)
  49. print("Driver device names:")
  50. # FIXME strip should not be needed
  51. for index in range(driver_count):
  52. for name in requests.get("{}/get_engine_driver_device_names/{}".format(baseurl, index)).text.strip().split("\n"):
  53. print("\t {}:".format(name), requests.get("{}/get_engine_driver_device_info/{}/{}".format(baseurl, index, name)).json())
  54. # ---------------------------------------------------------------------------------------------------------------------