ysfx_parse.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2021 Jean Pierre Cimalando
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // SPDX-License-Identifier: Apache-2.0
  16. //
  17. #pragma once
  18. #include "ysfx.h"
  19. #include "ysfx_reader.hpp"
  20. #include "ysfx_utils.hpp"
  21. #include <string>
  22. #include <vector>
  23. #include <cstdint>
  24. struct ysfx_section_t;
  25. struct ysfx_toplevel_t;
  26. struct ysfx_slider_t;
  27. struct ysfx_header_t;
  28. using ysfx_section_u = std::unique_ptr<ysfx_section_t>;
  29. using ysfx_toplevel_u = std::unique_ptr<ysfx_toplevel_t>;
  30. using ysfx_slider_u = std::unique_ptr<ysfx_slider_t>;
  31. using ysfx_header_u = std::unique_ptr<ysfx_header_t>;
  32. #ifndef _WIN32
  33. #ifndef strnicmp
  34. #define strnicmp(x,y,z) strncasecmp(x,y,z)
  35. #endif
  36. #ifndef stricmp
  37. #define stricmp(x,y) strcasecmp(x,y)
  38. #endif
  39. #endif
  40. struct ysfx_section_t {
  41. uint32_t line_offset = 0;
  42. std::string text;
  43. };
  44. struct ysfx_toplevel_t {
  45. ysfx_section_u header;
  46. ysfx_section_u init;
  47. ysfx_section_u slider;
  48. ysfx_section_u block;
  49. ysfx_section_u sample;
  50. ysfx_section_u serialize;
  51. ysfx_section_u gfx;
  52. uint32_t gfx_w = 0;
  53. uint32_t gfx_h = 0;
  54. };
  55. struct ysfx_parse_error {
  56. uint32_t line = 0;
  57. std::string message;
  58. explicit operator bool() { return !message.empty(); }
  59. };
  60. struct ysfx_slider_t {
  61. uint32_t id = 0;
  62. bool exists = false;
  63. ysfx_real def = 0;
  64. ysfx_real min = 0;
  65. ysfx_real max = 0;
  66. ysfx_real inc = 0;
  67. std::string var;
  68. std::string path;
  69. bool is_enum = false;
  70. ysfx::string_list enum_names;
  71. std::string desc;
  72. uint8_t shape = 0;
  73. ysfx_real shape_modifier = 0;
  74. bool initially_visible = false;
  75. };
  76. struct ysfx_options_t {
  77. std::string gmem;
  78. uint32_t maxmem = 0;
  79. int32_t prealloc = 0;
  80. bool want_all_kb = false;
  81. bool no_meter = false;
  82. uint32_t gfx_hz = 30;
  83. };
  84. struct ysfx_config_item {
  85. std::string identifier;
  86. std::string name;
  87. ysfx_real default_value{0};
  88. ysfx::string_list var_names{};
  89. std::vector<ysfx_real> var_values{};
  90. };
  91. struct ysfx_header_t {
  92. std::string desc;
  93. std::string author;
  94. ysfx::string_list tags;
  95. ysfx::string_list imports;
  96. ysfx::string_list in_pins;
  97. ysfx::string_list out_pins;
  98. bool explicit_pins = false;
  99. ysfx::string_list filenames;
  100. ysfx_options_t options;
  101. ysfx_slider_t sliders[ysfx_max_sliders];
  102. std::vector<ysfx_config_item> config_items;
  103. };
  104. struct ysfx_parsed_filename_t {
  105. uint32_t index;
  106. std::string filename;
  107. };
  108. bool ysfx_parse_toplevel(ysfx::text_reader &reader, ysfx_toplevel_t &toplevel, ysfx_parse_error *error, bool onlyHeader);
  109. bool ysfx_parse_slider(const char *line, ysfx_slider_t &slider);
  110. bool ysfx_parse_filename(const char *line, ysfx_parsed_filename_t &filename);
  111. bool ysfx_parse_header(ysfx_section_t *section, ysfx_header_t &header, ysfx_parse_error *error);
  112. ysfx_config_item ysfx_parse_config_line(const char *rest);
  113. bool ysfx_config_item_is_valid(const ysfx_config_item& item);