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.

83 lines
2.9KB

  1. /*
  2. Vult API documentation.
  3. Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com
  4. The main difference of the Vult API compared to the JavaScript and Lua is that all interactions
  5. happen through functions rather than accessing to the block arrays.
  6. A Vult script requires the following two functions:
  7. fun process() { }
  8. and update() { }
  9. The 'process' function is called every audio sample. As inputs, it will receive the values from
  10. the input jacks but normalized to 1.0. This means that a value of 10.0 V in VCV Rack is received
  11. as 1.0. Similarly, when you return a value of 1.0 it will be output by the prototype as 10.0V.
  12. You can use the input and output jacks by adding or removing arguments to the function. For example,
  13. to pass all the inputs to the outputs you can declare the function as follows:
  14. fun process(i1, i2, i3, i4, i5, i6) {
  15. return i1, i2, i3, i4, i5, i6;
  16. }
  17. The 'update' function is called once every 32 samples. You can use this function to perform actions
  18. that do not require audio rate speed e.g. setting light colors or displying characters in the screen.
  19. The function 'update' do not takes or returns any value.
  20. Important: Notice that the 'update' function is declared with the keyword 'and'. In Vult language,
  21. this means that they share context. At the moment, declaring them differently could have an undefined
  22. behavior.
  23. To interact with knobs, switches, lights the following builtin functions are provided.
  24. NOTE: the knobs, switches and lights are numbered from 1 to 6
  25. getKnob(n:int) : real // value of the nth knob range: 0.0-1.0
  26. getSwitch(n:int) : bool // value of the nth switch: true/false
  27. setLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0
  28. setSwitchLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0
  29. samplerate() : real // current sample rate
  30. sampletime() : real // current time step (1.0 / samplerate())
  31. display(text:string) // display text in the screen
  32. */
  33. // Returns the r,g,b values for a given voltage
  34. fun getRGB(v) {
  35. if (v > 0.0)
  36. return v, 0.0, 0.0;
  37. else
  38. return 0.0, -v, 0.0;
  39. }
  40. // Takes two inputs and returns the result of different operations on them
  41. fun process(in1, in2) {
  42. // theses are declared as 'mem' so we can remember them and use them in 'update'
  43. mem sum = clip(in1 + in2, -1.0, 1.0); // use 'clip' to keep the signals in the specified range
  44. mem sub = clip(in1 - in2, -1.0, 1.0);
  45. mem mul = clip(in1 * in2, -1.0, 1.0);
  46. return sum, sub, mul;
  47. }
  48. and update() {
  49. _ = display("Add two LFO to IN1 and IN2");
  50. val r, g, b;
  51. // Set the light no 1 with the 'sum' value
  52. r, g, b = getRGB(sum);
  53. _ = setLight(1, r, g, b);
  54. _ = setSwitchLight(1, r, g, b);
  55. // Set the light no 2 with the 'sub' value
  56. r, g, b = getRGB(sub);
  57. _ = setLight(2, r, g, b);
  58. _ = setSwitchLight(2, r, g, b);
  59. // Set the light no 2 with the 'mul' value
  60. r, g, b = getRGB(mul);
  61. _ = setLight(3, r, g, b);
  62. _ = setSwitchLight(3, r, g, b);
  63. }