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.

108 lines
3.2KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2023 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. #pragma once
  18. // check if PRIVATE is defined already before including any headers
  19. #ifdef PRIVATE
  20. # define PRIVATE_WAS_DEFINED
  21. #endif
  22. // use mingw print format
  23. #if defined(ARCH_WIN) && !defined(SKIP_MINGW_FORMAT)
  24. # include <regex>
  25. # define format(f,a,b) format(__MINGW_PRINTF_FORMAT,a,b)
  26. #endif
  27. #include_next "common.hpp"
  28. // Workaround for wrong file permissions from zstd extraction and system usage
  29. #ifdef __EMSCRIPTEN__
  30. #define fopen fopen_wasm
  31. #define system system_wasm
  32. extern "C" {
  33. FILE* fopen_wasm(const char* filename, const char* mode);
  34. inline int system_wasm(const char*) { return 0; }
  35. }
  36. namespace std {
  37. using ::fopen_wasm;
  38. using ::system_wasm;
  39. }
  40. #endif
  41. // Make binary resources work the same no matter the OS
  42. #undef BINARY
  43. #undef BINARY_START
  44. #undef BINARY_END
  45. #undef BINARY_SIZE
  46. #define BINARY(sym) extern const unsigned char sym[]; extern const unsigned int sym##_len
  47. #define BINARY_START(sym) ((const void*) sym)
  48. #define BINARY_END(sym) ((const void*) sym + sym##_len)
  49. #define BINARY_SIZE(sym) (sym##_len)
  50. // undefine PRIVATE if needed
  51. #if defined(PRIVATE) && !defined(PRIVATE_WAS_DEFINED)
  52. # undef PRIVATE
  53. #endif
  54. // and also our flag
  55. #undef PRIVATE_WAS_DEFINED
  56. // Cardinal specific API
  57. #include <functional>
  58. #define USING_CARDINAL_NOT_RACK
  59. // OS separator macros
  60. #ifdef ARCH_WIN
  61. # define CARDINAL_OS_SEP '\\'
  62. # define CARDINAL_OS_SEP_STR "\\"
  63. # define CARDINAL_OS_SPLIT ';'
  64. # define CARDINAL_OS_SPLIT_STR ";"
  65. #else
  66. # define CARDINAL_OS_SEP '/'
  67. # define CARDINAL_OS_SEP_STR "/"
  68. # define CARDINAL_OS_SPLIT ':'
  69. # define CARDINAL_OS_SPLIT_STR ":"
  70. #endif
  71. // opens a file browser, startDir and title can be null
  72. // action is always triggered on close (path can be null), must be freed if not null
  73. void async_dialog_filebrowser(bool saving, const char* defaultName, const char* startDir, const char* title,
  74. std::function<void(char* path)> action);
  75. // opens a message dialog with only an "ok" button
  76. void async_dialog_message(const char* message);
  77. // opens a message dialog with "ok" and "cancel" buttons
  78. // action is triggered if user presses "ok"
  79. void async_dialog_message(const char* message, std::function<void()> action);
  80. // opens a text input dialog, message and text can be null
  81. // action is always triggered on close (newText can be null), must be freed if not null
  82. void async_dialog_text_input(const char* message, const char* text, std::function<void(char* newText)> action);
  83. // Cardinal specific config dir (might be equal to userDir)
  84. namespace rack {
  85. namespace asset {
  86. extern std::string configDir;
  87. std::string config(std::string filename = "");
  88. }
  89. }