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 <context.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 Context::init() {
  10. engine = new engine::Engine;
  11. patch = new PatchManager;
  12. if (!settings::headless) {
  13. event = new event::State;
  14. history = new history::State;
  15. window = new Window;
  16. scene = new app::Scene;
  17. event->rootWidget = scene;
  18. }
  19. }
  20. Context::~Context() {
  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 (event)
  26. delete event;
  27. event = NULL;
  28. if (history)
  29. delete history;
  30. history = NULL;
  31. if (window)
  32. delete window;
  33. window = NULL;
  34. if (patch)
  35. delete patch;
  36. patch = NULL;
  37. if (engine)
  38. delete engine;
  39. engine = NULL;
  40. }
  41. static Context* context = NULL;
  42. void contextInit() {
  43. assert(!context);
  44. context = new Context;
  45. context->init();
  46. }
  47. void contextDestroy() {
  48. assert(context);
  49. delete context;
  50. context = NULL;
  51. }
  52. Context* contextGet() {
  53. return context;
  54. }
  55. } // namespace rack