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.

43 lines
896B

  1. // Rainbow RGB LED example
  2. // by Andrew Belt
  3. // adapted for SC by Brian Heim
  4. // Call process() every 256 audio samples
  5. ~vcv_frameDivider = 256;
  6. ~vcv_bufferSize = 1;
  7. // From https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
  8. ~hsvToRgb = { |h, s, v|
  9. var c, x, rgb, m;
  10. h = h * 6;
  11. c = v * s;
  12. x = c * (1 - abs(h % 2 - 1));
  13. rgb = case
  14. { h < 1 } { [c, x, 0] }
  15. { h < 2 } { [x, c, 0] }
  16. { h < 3 } { [0, c, x] }
  17. { h < 4 } { [0, x, c] }
  18. { h < 5 } { [x, 0, c] }
  19. { [c, 0, x] };
  20. rgb + (v - c);
  21. };
  22. ~phase = 0;
  23. ~vcv_process = { |block|
  24. ~phase = ~phase + block.sampleTime * ~vcv_frameDivider * 0.5;
  25. ~phase = ~phase % 1.0;
  26. VcvPrototypeProcessBlock.numRows.do { |i|
  27. var h = (1 - i / 6 + ~phase) % 1;
  28. var rgb = ~hsvToRgb.value(h, 1, 1);
  29. 3.do { |c|
  30. block.lights[i][c] = rgb[c];
  31. block.switchLights[i][c] = rgb[c];
  32. };
  33. block.outputs[i][0] = sin(2pi * h) * 5 + 5;
  34. };
  35. block
  36. }