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.

68 lines
1.1KB

  1. #include <app.hpp>
  2. #include <window.hpp>
  3. #include <patch.hpp>
  4. #include <engine/Engine.hpp>
  5. #include <app/Scene.hpp>
  6. #include <history.hpp>
  7. #include <settings.hpp>
  8. namespace rack {
  9. void App::init() {
  10. engine = new engine::Engine;
  11. if (!settings::headless) {
  12. event = new event::State;
  13. history = new history::State;
  14. window = new Window;
  15. patch = new PatchManager;
  16. scene = new app::Scene;
  17. event->rootWidget = scene;
  18. }
  19. }
  20. App::~App() {
  21. // Set pointers to NULL so other objects will segfault when attempting to access them
  22. if (scene)
  23. delete scene;
  24. scene = NULL;
  25. if (patch)
  26. delete patch;
  27. patch = NULL;
  28. if (event)
  29. delete event;
  30. event = NULL;
  31. if (history)
  32. delete history;
  33. history = NULL;
  34. if (window)
  35. delete window;
  36. window = NULL;
  37. if (engine)
  38. delete engine;
  39. engine = NULL;
  40. }
  41. static App* appInstance = NULL;
  42. void appInit() {
  43. assert(!appInstance);
  44. appInstance = new App;
  45. appInstance->init();
  46. }
  47. void appDestroy() {
  48. assert(appInstance);
  49. delete appInstance;
  50. appInstance = NULL;
  51. }
  52. App* appGet() {
  53. return appInstance;
  54. }
  55. } // namespace rack