Audio plugin host https://kx.studio/carla
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.

pretty-format.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2017 Johannes Lorenz
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * @file pretty-format.h
  26. */
  27. #ifndef PRETTYFORMAT_H
  28. #define PRETTYFORMAT_H
  29. #include <rtosc/rtosc.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. typedef struct
  34. {
  35. bool lossless; //!< will add hex notation behind floats
  36. int floating_point_precision;
  37. const char* sep; //!< separator for multiple argument values
  38. int linelength;
  39. } rtosc_print_options;
  40. /**
  41. * Pretty-print rtosct_arg_val_t structure into buffer
  42. *
  43. * @param arg Pointer to the structure that shall be printed
  44. * @param buffer The buffer to write to
  45. * @param buffersize The maximum size to write to, includin a trailing 0 byte
  46. * @param opt Printer options, NULL for default options
  47. * @param cols_used How many columns have been used for writing in this line
  48. * (will be updated by this function)
  49. * @return The number of bytes written, excluding the null byte
  50. */
  51. size_t rtosc_print_arg_val(const rtosc_arg_val_t* arg, char* buffer,
  52. size_t buffersize, const rtosc_print_options* opt,
  53. int* cols_used);
  54. /**
  55. * Pretty-print rtosct_arg_val_t array into buffer
  56. *
  57. * @see rtosc_print_message
  58. * @warning in case of possible line breaks (almost always), buffer[-1] must
  59. * be accessible and be whitespace (since it can be converted to a newline)
  60. */
  61. size_t rtosc_print_arg_vals(const rtosc_arg_val_t *args, size_t n,
  62. char *buffer, size_t bs,
  63. const rtosc_print_options* opt,
  64. int cols_used);
  65. /**
  66. * Pretty-print OSC message into string buffer
  67. *
  68. * A newline will be appended.
  69. *
  70. * @param address OSC pattern to send message to
  71. * @param args The array to print
  72. * @param n Number of args from the array that should be printed
  73. * @param buffer The buffer to write to
  74. * @param bs The maximum size to write to, includin a trailing 0 byte
  75. * @param opt Printer options, NULL for default options
  76. * @param cols_used How many columns have been used for writing in this line
  77. * @return The number of bytes written, excluding the null byte
  78. */
  79. size_t rtosc_print_message(const char* address,
  80. const rtosc_arg_val_t *args, size_t n,
  81. char *buffer, size_t bs,
  82. const rtosc_print_options* opt,
  83. int cols_used);
  84. /**
  85. * Skip characters from a string until one argument value
  86. * would have been scanned
  87. * @param src The string
  88. * @return The first character after that argument value
  89. */
  90. const char* rtosc_skip_next_printed_arg(const char* src);
  91. /**
  92. * Count arguments that would be scanned and do a complete syntax check
  93. *
  94. * This function should be run before rtosc_scan_arg_vals() in order
  95. * to know the number of argument values. Also, rtosc_scan_arg_vals() does
  96. * no complete syntax check.
  97. *
  98. * @param src The string to scan from
  99. * @return The number of arguments that can be scanned (>=0), or if the nth arg
  100. * (range 1...) can not be scanned, -n
  101. */
  102. int rtosc_count_printed_arg_vals(const char* src);
  103. /**
  104. * Count arguments of a message that would be scanned and
  105. * do a complete syntax check
  106. *
  107. * @param msg The message to scan from
  108. * @return -1 if the address could not be scanned,
  109. * INT_MIN if the whole string is whitespace,
  110. * otherwise @see rtosc_count_printed_arg_vals
  111. */
  112. int rtosc_count_printed_arg_vals_of_msg(const char* msg);
  113. /**
  114. * Scan one argument value from a string
  115. *
  116. * This function does no complete syntaxcheck. Call
  117. * rtosc_count_printed_arg_vals() before.
  118. *
  119. * @param src The string
  120. * @param arg Pointer to where to store the argument value; must be allocated
  121. * @param buffer_for_strings A buffer with enough space for scanned
  122. * strings and blobs
  123. * @param bufsize Size of @p buffer_for_strings , will be shrinked to the
  124. * bufferbytes left after the scan
  125. * @return The number of bytes scanned
  126. */
  127. size_t rtosc_scan_arg_val(const char* src,
  128. rtosc_arg_val_t *arg,
  129. char* buffer_for_strings, size_t* bufsize);
  130. /**
  131. * Scan a fixed number of argument values from a string
  132. *
  133. * This function does no complete syntaxcheck. Call
  134. * rtosc_count_printed_arg_vals() before. This will also give you the @p n
  135. * parameter.
  136. *
  137. * @see rtosc_scan_message
  138. */
  139. size_t rtosc_scan_arg_vals(const char* src,
  140. rtosc_arg_val_t *args, size_t n,
  141. char* buffer_for_strings, size_t bufsize);
  142. /**
  143. * Scan an OSC message from a string
  144. *
  145. * This function does no complete syntaxcheck. Call
  146. * rtosc_count_printed_arg_vals() before. This will also give you the @p n
  147. * parameter. Preceding and trailing whitespace will be consumed.
  148. *
  149. * @param src The string
  150. * @param address A buffer where the port address will be written
  151. * @param adrsize Size of buffer @p address
  152. * @param args Pointer to an array of argument values; the output will be
  153. * written here
  154. * @param n The amount of argument values to scan
  155. * @param buffer_for_strings A buffer with enough space for scanned
  156. * strings and blobs
  157. * @param bufsize Size of @p buffer_for_strings
  158. * @return The number of bytes scanned
  159. */
  160. size_t rtosc_scan_message(const char* src,
  161. char* address, size_t adrsize,
  162. rtosc_arg_val_t *args, size_t n,
  163. char* buffer_for_strings, size_t bufsize);
  164. #ifdef __cplusplus
  165. };
  166. #endif
  167. #endif // PRETTYFORMAT_H