PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
GUI
  • Drawing
  • Simple knobs
Library
  • Params
Rave Generation
  • Preamp
ScriptsLibraryParams
November 04, 2025   Ilya

Adding params

Letimix library script to make adding input/output params and input/output strings more convenient. This is Angelscript version, there's also native (C++) version available.

See examples of use below. And here's a how-to article

Download this library

  1. ////////////////////////////////////
  2. // This is a helper library for more convenient way of adding
  3. // input/output params and strings in Plug'n Script DSP API (AngelScript version)
  4. // examples of use: https://pns.letimix.com/scripts/library/params
  5. ////////////////////////////////////
  6. // 2020-2025 (c) LetiMix | Ilya Orlov
  7. ////////////////////////////////////
  8.  
  9. // HOW TO USE
  10.  
  11. // #include "_lib/params.as"
  12.  
  13. // // create placeholders for params indexes
  14. // int ENABLE, MODE, THRESHOLD, MIX, GR, OUT_MODE, OUT_LEVEL, PP_LEVEL, PP_STATE, FILENAME, MYDATA1;
  15.  
  16. // void initialize(){
  17. // // format for adding params
  18. // // index, "name", ["units", min, max, default, "format", [steps]]
  19. // // format for adding enumerated values params
  20. // // index, "name", "value1;value2;value3", ["default_value"]
  21.  
  22. // // add input params
  23. // ENABLE = ip("Enable", "Off;On");
  24. // MODE = ip("Mode", "Simple;Classic;1176;Opto", "Classic");
  25. // THRESHOLD = ip("Threshold", "dB", -40, 0, -18, ".1");
  26. // MIX = ip("Wet/Dry");
  27.  
  28. // // add output params
  29. // GR = op("Gain Reduction", "db", 0, 10);
  30. // OUT_MODE = op("Out mode", "Simple;Classic;1176;Opto");
  31. // OUT_LEVEL = op("Out level");
  32.  
  33. // // add private output params
  34. // PP_LEVEL = pp("Out level", "dB", -40, 0, -18, ".1");
  35. // PP_STATE = pp("Out state", "Idle;Ready;Running", "Idle");
  36.  
  37. // // add input strings
  38. // FILENAME = ips("Filename", [true = makes persistent]);
  39.  
  40. // // add output strings (with max length)
  41. // MYDATA1 = ops("MyData1", 256);
  42. // }
  43.  
  44. // You can use shortcuts IP (for inputParameters), OP (for outputParameters), PP (for privateOutputParameters)
  45. // IPS and OPS (for inputStrings and outputStrings)
  46.  
  47. // void updateInputParameters() {
  48. // double threshold = IP[THRESHOLD];
  49. // string mystring = IPS[FILENAME];
  50. // }
  51.  
  52. // void computeOutputData(){
  53. // OP[GR] = rand(0,10);
  54. // PP[PP_LEVEL] = rand(-40,0);
  55. // OPS[MYDATA1] = "Enable: "+IP[ENABLE];
  56. // }
  57.  
  58.  
  59. // create arrays for input/output params and strings
  60. array<double> inputParameters, outputParameters, privateOutputParameters,
  61. inputParametersMin, outputParametersMin, privateOutputParametersMin,
  62. inputParametersMax, outputParametersMax, privateOutputParametersMax,
  63. inputParametersDefault, outputParametersDefault, privateOutputParametersDefault;
  64. array<string> inputParametersNames, outputParametersNames, privateOutputParametersNames,
  65. inputParametersUnits, outputParametersUnits, privateOutputParametersUnits,
  66. inputParametersFormats, outputParametersFormats, privateOutputParametersFormats,
  67. inputParametersEnums, outputParametersEnums, privateOutputParametersEnums,
  68. inputStrings, outputStrings, inputStringsNames, outputStringsNames;
  69. array<int> inputParametersSteps, outputStringsMaxLengths, inputStringsPersistency;
  70.  
  71. // shortcuts for input/output parameters and strings
  72. array<double>@ IP = inputParameters;
  73. array<double>@ OP = outputParameters;
  74. array<double>@ PP = privateOutputParameters;
  75. array<string>@ IPS = inputStrings;
  76. array<string>@ OPS = outputStrings;
  77.  
  78. // INPUT PARAMETERS
  79.  
  80. // add (or update) input parameter
  81. void ip(int index, string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", int steps = 0, string enums = "") {
  82. if (index < 0) index = int(inputParameters.length); // auto-increase index
  83. uint nn = index+1;
  84. // verify arrays size
  85. if (inputParameters.length < nn) {
  86. inputParameters.resize(nn);
  87. inputParametersNames.resize(nn);
  88. inputParametersUnits.resize(nn);
  89. inputParametersMin.resize(nn);
  90. inputParametersMax.resize(nn);
  91. inputParametersDefault.resize(nn);
  92. inputParametersFormats.resize(nn);
  93. inputParametersSteps.resize(nn);
  94. inputParametersEnums.resize(nn);
  95. }
  96. // add param name (name)
  97. inputParametersNames[index] = name;
  98. inputParametersUnits[index] = units;
  99. inputParametersMin[index] = min;
  100. inputParametersMax[index] = max;
  101. inputParametersDefault[index] = def_no;
  102. inputParametersFormats[index] = vf;
  103. // auto calculation of steps if value_format = .0
  104. if ((steps < 1) and ((parseFloat(vf) - floor(parseFloat(vf))) == 0)) {
  105. steps = int(max - min) + 1;
  106. }
  107. inputParametersSteps[index] = steps;
  108. inputParametersEnums[index] = enums;
  109. }
  110.  
  111. // add or update enumerated input parameter
  112. void ip(int index, string name, string enums = "%", string def_value = ""){
  113. // check if we're adding enums
  114. if (enums.findFirst(";") > 0) {
  115. array<string> ar = enums.split(";");
  116. int max = ar.length - 1;
  117. int def_no = 0; // find index of default_value
  118. if (def_value != "") def_no = ar.find(def_value);
  119. if (def_no < 0) def_no = 0;
  120. // add enum
  121. ip(index, name, "", 0, max, def_no, "", ar.length, enums);
  122. } else {
  123. // add regular param
  124. string units = enums;
  125. ip(index, name, units, 0);
  126. }
  127. }
  128.  
  129. // the same but adding item to the end of list and returning index
  130. int ip(string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", int steps = 0, string enums = ""){
  131. int index = int(inputParameters.length);
  132. ip(index, name, units, min, max, def_no, vf, steps, enums);
  133. return index;
  134. }
  135. // adding enum param to end of list and returning index
  136. int ip(string name, string enums = "%", string def_value = ""){
  137. int index = int(inputParameters.length);
  138. ip(index, name, enums, def_value);
  139. return index;
  140. }
  141.  
  142. // OUTPUT PARAMETERS
  143.  
  144. // add (or update) output parameter
  145. void op(int index, string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", string enums = "", bool is_private = false) {
  146. uint nn = index+1;
  147. if (!is_private) {
  148. // for regular output params (not private)
  149. // verify arrays size
  150. if (outputParameters.length < nn) {
  151. outputParameters.resize(nn);
  152. outputParametersNames.resize(nn);
  153. outputParametersUnits.resize(nn);
  154. outputParametersMin.resize(nn);
  155. outputParametersMax.resize(nn);
  156. outputParametersDefault.resize(nn);
  157. outputParametersFormats.resize(nn);
  158. outputParametersEnums.resize(nn);
  159. }
  160. // add param name (name)
  161. outputParametersNames[index] = name;
  162. outputParametersUnits[index] = units;
  163. outputParametersMin[index] = min;
  164. outputParametersMax[index] = max;
  165. outputParametersDefault[index] = def_no;
  166. outputParametersFormats[index] = vf;
  167. outputParametersEnums[index] = enums;
  168. } else {
  169. // for private params
  170. // verify arrays size
  171. if (privateOutputParameters.length < nn) {
  172. privateOutputParameters.resize(nn);
  173. privateOutputParametersNames.resize(nn);
  174. privateOutputParametersUnits.resize(nn);
  175. privateOutputParametersMin.resize(nn);
  176. privateOutputParametersMax.resize(nn);
  177. privateOutputParametersDefault.resize(nn);
  178. privateOutputParametersFormats.resize(nn);
  179. privateOutputParametersEnums.resize(nn);
  180. }
  181. // add param name (name)
  182. privateOutputParametersNames[index] = name;
  183. privateOutputParametersUnits[index] = units;
  184. privateOutputParametersMin[index] = min;
  185. privateOutputParametersMax[index] = max;
  186. privateOutputParametersDefault[index] = def_no;
  187. privateOutputParametersFormats[index] = vf;
  188. privateOutputParametersEnums[index] = enums;
  189. }
  190. }
  191.  
  192. // add or update enumerated output parameter
  193. void op(int index, string name, string enums = "%", string def_value = "", bool is_private = false){
  194. // check if we're adding enums
  195. if (enums.findFirst(";") > 0) {
  196. array<string> ar = enums.split(";");
  197. int max = ar.length - 1;
  198. int def_no = 0; // find index of default_value
  199. if (def_value != "") def_no = ar.find(def_value);
  200. if (def_no < 0) def_no = 0;
  201. // add enum
  202. op(index, name, "", 0, max, def_no, "", enums, is_private);
  203. } else {
  204. // add regular param
  205. string units = enums;
  206. op(index, name, units, 0.0, 0.0, 0.0, ".1", "", is_private);
  207. }
  208. }
  209. // the same but adding item to the end of list and returning index
  210. int op(string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", string enums = ""){
  211. int index = int(outputParameters.length);
  212. op(index, name, units, min, max, def_no, vf, enums);
  213. return index;
  214. }
  215. // adding enum param to end of list and returning index
  216. int op(string name, string enums = "%", string def_value = ""){
  217. int index = int(outputParameters.length);
  218. op(index, name, enums, def_value);
  219. return index;
  220. }
  221.  
  222. // PRIVATE OUTPUT PARAMS
  223.  
  224. // shortcut to add (or update) private output parameter
  225. void pp(int index, string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", string enums = "") {
  226. op(index, name, units, min, max, def_no, vf, enums, true);
  227. }
  228.  
  229. // shortcut to add or update enumerated private output parameter
  230. void pp(int index, string name, string enums = "%", string def_value = ""){
  231. op(index, name, enums, def_value, true);
  232. }
  233. // the same but adding item to the end of list and returning index
  234. int pp(string name, string units, double min, double max = 0, double def_no = 0, string vf = ".1", string enums = ""){
  235. int index = int(privateOutputParameters.length);
  236. pp(index, name, units, min, max, def_no, vf, enums);
  237. return index;
  238. }
  239. // adding enum param to end of list and returning index
  240. int pp(string name, string enums = "%", string def_value = ""){
  241. int index = int(privateOutputParameters.length);
  242. pp(index, name, enums, def_value);
  243. return index;
  244. }
  245.  
  246. // INPUT STRINGS
  247.  
  248. // add/update input string via index
  249. void ips(int index, string name, bool persistent = false) {
  250. uint nn = index+1;
  251. // verify arrays size
  252. if (inputStrings.length < nn) {
  253. inputStrings.resize(nn);
  254. inputStringsNames.resize(nn);
  255. inputStringsPersistency.resize(nn);
  256. }
  257. inputStringsNames[index] = name;
  258. inputStringsPersistency[index] = persistent ? 1 : 0;
  259. }
  260.  
  261. // adding input string to the end of list and returning index
  262. int ips(string name, bool persistent = false){
  263. int index = int(inputStrings.length);
  264. ips(index, name, persistent);
  265. return index;
  266. }
  267.  
  268. // OUTPUT STRINGS
  269.  
  270. // add/update output string via index
  271. void ops(int index, string name, int maxlen = 1024) {
  272. uint nn = index+1;
  273. // verify arrays size
  274. if (outputStrings.length < nn) {
  275. outputStrings.resize(nn);
  276. outputStringsNames.resize(nn);
  277. outputStringsMaxLengths.resize(nn);
  278. }
  279. outputStringsNames[index] = name;
  280. outputStringsMaxLengths[index] = maxlen;
  281. }
  282.  
  283. // adding output string to the end of list and returning index
  284. int ops(string name, int maxlen = 1024){
  285. int index = int(outputStrings.length);
  286. ops(index, name, maxlen);
  287. return index;
  288. }

Examples

1. Adding params and getting index in return

This is the preferred method. We create placeholders and then get param indexes from function calls. The advantage is that now we can easily re-order and mute (comment out) parameters.

  1. #include "library/params.as"
  2.  
  3. // create placeholders for params indexes
  4. int ENABLE, MODE, THRESHOLD, MIX, GR, OUT_MODE, OUT_LEVEL, PP_LEVEL, PP_STATE, FILENAME, MYDATA1;
  5.  
  6. void initialize() {
  7. // format for adding params
  8. // index, "name", ["units", min, max, default, "format", [steps]]
  9. // format for adding enumerated values params
  10. // index, "name", "value1;value2;value3", ["default_value"]
  11.  
  12. // add input params
  13. ENABLE = ip("Enable", "Off;On");
  14. MODE = ip("Mode", "Simple;Classic;1176;Opto", "Classic");
  15. THRESHOLD = ip("Threshold", "dB", -40, 0, -18, ".1");
  16. MIX = ip("Wet/Dry");
  17.  
  18. // add output params
  19. GR = op("Gain Reduction", "db", 0, 10);
  20. OUT_MODE = op("Out mode", "Simple;Classic;1176;Opto");
  21. OUT_LEVEL = op("Out level");
  22.  
  23. // add private output params
  24. PP_LEVEL = pp("Out level", "dB", -40, 0, -18, ".1");
  25. PP_STATE = pp("Out state", "Idle;Ready;Running", "Idle");
  26.  
  27. // add input strings
  28. FILENAME = ips("Filename");
  29.  
  30. // add output strings (with max length)
  31. MYDATA1 = ops("MyData1", 256);
  32. }

2. Adding params with static index number (not recommended)

This is another approach, where we first add constants (0,1,2,3...) that we'll later use as param indexes.

  1. #include "library/params.as"
  2.  
  3. // adding params indexes
  4. enum inputParamsEnum{
  5. ENABLE,
  6. MODE,
  7. THRESHOLD,
  8. MIX,
  9. }
  10. enum outParamsEnum{
  11. GR,
  12. OUT_MODE,
  13. OUT_LEVEL
  14. }
  15. enum privateOutParamsEnum{
  16. PP_LEVEL,
  17. PP_STATE,
  18. }
  19. enum inStringsEnum{
  20. FILENAME
  21. }
  22. enum outStringsEnum{
  23. MYDATA1
  24. }
  25.  
  26. void initialize() {
  27.  
  28. // format for adding params
  29. // index, "name", ["units", min, max, default, "format", [steps]]
  30. // format for adding enumerated values params
  31. // index, "name", "value1;value2;value3", ["default_value"]
  32.  
  33. // add input params
  34. ip(ENABLE, "Enable", "Off;On");
  35. ip(MODE, "Mode", "Simple;Classic;1176;Opto", "Classic");
  36. ip(THRESHOLD, "Threshold", "dB", -40, 0, -18, ".1");
  37. ip(MIX, "Wet/Dry");
  38.  
  39. // add output params
  40. op(GR, "Gain Reduction", "db", 0, 10);
  41. op(OUT_MODE, "Out mode", "Simple;Classic;1176;Opto");
  42. op(OUT_LEVEL, "Out level");
  43.  
  44. // add private output params
  45. pp(PP_LEVEL, "Level", "db", 0, 10);
  46. pp(PP_STATE, "State", "Idle;Ready;Running");
  47.  
  48. // add input strings
  49. ips(FILENAME, "Filename");
  50.  
  51. // add output strings
  52. ops(MYDATA1, "MyData1", 256);
  53. }

Note, that we've used Enums instead of writing "const int ENABLE = 0, MODE = 1 ..." , because it's easier to add and re-order values.

3. Using short aliases for long names

To make our code more compact, we can use shortcuts IP (for inputParameters), OP (for outputParameters), IPS and OPS (for inputStrings and outputStrings)

  1. void updateInputParameters() {
  2. double threshold = IP[THRESHOLD];
  3. string mystring = IPS[FILENAME];
  4. }
  5.  
  6. void computeOutputData() {
  7. OP[GR] = rand(0,10);
  8. OPS[MYDATA1] = someString;
  9. PP[PP_LEVEL] = rand(-40,0);
  10. }

Comments

Please, authorize to view and post comments.

2020 - 2026 © Site by LetiMix · Donate  |  Plug'n Script and KUIML by Blue Cat Audio