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.

63 lines
1.1KB

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