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.

92 lines
2.1KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. /**
  18. * This file is an edited version of VCVRack's context.cpp
  19. * Copyright (C) 2016-2021 VCV.
  20. *
  21. * This program is free software: you can redistribute it and/or
  22. * modify it under the terms of the GNU General Public License as
  23. * published by the Free Software Foundation; either version 3 of
  24. * the License, or (at your option) any later version.
  25. */
  26. #include <context.hpp>
  27. #include <window/Window.hpp>
  28. #include <patch.hpp>
  29. #include <engine/Engine.hpp>
  30. #include <app/Scene.hpp>
  31. #include <history.hpp>
  32. #include <settings.hpp>
  33. #ifdef NDEBUG
  34. # undef DEBUG
  35. #endif
  36. #include "DistrhoUtils.hpp"
  37. namespace rack {
  38. Context::~Context() {
  39. // Deleting NULL is safe in C++.
  40. // Set pointers to NULL so other objects will segfault when attempting to access them
  41. INFO("Deleting window");
  42. delete window;
  43. window = NULL;
  44. INFO("Deleting patch manager");
  45. delete patch;
  46. patch = NULL;
  47. INFO("Deleting scene");
  48. delete scene;
  49. scene = NULL;
  50. INFO("Deleting event state");
  51. delete event;
  52. event = NULL;
  53. INFO("Deleting history state");
  54. delete history;
  55. history = NULL;
  56. INFO("Deleting engine");
  57. delete engine;
  58. engine = NULL;
  59. }
  60. static thread_local Context* threadContext = NULL;
  61. Context* contextGet() {
  62. DISTRHO_SAFE_ASSERT(threadContext != nullptr);
  63. return threadContext;
  64. }
  65. // Apple's clang incorrectly compiles this function when -O2 or higher is enabled.
  66. #ifdef ARCH_MAC
  67. __attribute__((optnone))
  68. #endif
  69. void contextSet(Context* context) {
  70. threadContext = context;
  71. }
  72. } // namespace rack