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.

patch.hpp 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <jansson.h>
  3. #include <common.hpp>
  4. namespace rack {
  5. /** Handles the Rack patch file state */
  6. namespace patch {
  7. /** Handles the Rack patch file state. */
  8. struct Manager {
  9. struct Internal;
  10. Internal* internal;
  11. /** The currently loaded patch file path */
  12. std::string path;
  13. /** Path to autosave dir */
  14. std::string autosavePath;
  15. /** Path to user template patch */
  16. std::string templatePath;
  17. /** Path to factory template patch */
  18. std::string factoryTemplatePath;
  19. PRIVATE Manager();
  20. PRIVATE ~Manager();
  21. PRIVATE void launch(std::string pathArg);
  22. /** Clears the patch. */
  23. void clear();
  24. /** Saves the patch and nothing else. */
  25. void save(std::string path);
  26. void saveDialog();
  27. void saveAsDialog(bool setPath = true);
  28. void saveTemplateDialog();
  29. void saveAutosave();
  30. /** Delete and re-create autosave dir. */
  31. void clearAutosave();
  32. /** Clean up nonexistent module patch storage dirs in autosave dir. */
  33. void cleanAutosave();
  34. /** Loads a patch and nothing else.
  35. Returns whether the patch was loaded successfully.
  36. */
  37. void load(std::string path);
  38. /** Loads the template patch file. */
  39. void loadTemplate();
  40. void loadTemplateDialog();
  41. bool hasAutosave();
  42. /** Loads the patch from the autosave folder.
  43. Throws if loading failed.
  44. */
  45. void loadAutosave();
  46. /** Loads a patch, sets the current path, and updates the recent patches. */
  47. void loadAction(std::string path);
  48. void loadDialog();
  49. void loadPathDialog(std::string path);
  50. /** Asks the user to reload the current patch. */
  51. void revertDialog();
  52. void pushRecentPath(std::string path);
  53. /** Disconnects all cables. */
  54. void disconnectDialog();
  55. json_t* toJson();
  56. void fromJson(json_t* rootJ);
  57. /** Checks if the JSON patch object contains modules not found in the loaded plugins, and launches a dialog box asking the user to cancel loading.
  58. Returns whether the user requests to cancel loading the patch.
  59. */
  60. bool checkUnavailableModulesJson(json_t* rootJ);
  61. };
  62. } // namespace patch
  63. } // namespace rack