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.

62 lines
1.0KB

  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) delete scene;
  23. scene = NULL;
  24. if (patch) delete patch;
  25. patch = NULL;
  26. if (event) delete event;
  27. event = NULL;
  28. if (history) delete history;
  29. history = NULL;
  30. if (window) delete window;
  31. window = NULL;
  32. if (engine) delete engine;
  33. engine = NULL;
  34. }
  35. static App *appInstance = NULL;
  36. void appInit() {
  37. assert(!appInstance);
  38. appInstance = new App;
  39. appInstance->init();
  40. }
  41. void appDestroy() {
  42. assert(appInstance);
  43. delete appInstance;
  44. appInstance = NULL;
  45. }
  46. App *appGet() {
  47. return appInstance;
  48. }
  49. } // namespace rack