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.

60 lines
2.2KB

  1. /*
  2. ==============================================================================
  3. Utils.h
  4. Created: 16 Mar 2021 9:09:05pm
  5. Author: Jack Devlin
  6. ==============================================================================
  7. */
  8. #pragma once
  9. #include <JuceHeader.h>
  10. namespace Utils {
  11. const juce::String pluginSelectorComponentID("PluginSelectorComponent");
  12. inline juce::String busesLayoutToString(juce::AudioProcessor::BusesLayout layout) {
  13. juce::String retVal;
  14. retVal += "Inputs: ";
  15. for (const juce::AudioChannelSet& bus : layout.inputBuses) {
  16. for (const juce::AudioChannelSet::ChannelType channelType : bus.getChannelTypes()) {
  17. retVal += juce::AudioChannelSet::getAbbreviatedChannelTypeName(channelType) + " ";
  18. }
  19. retVal += "| ";
  20. }
  21. retVal += "\n";
  22. retVal += "Outputs: ";
  23. for (const juce::AudioChannelSet& bus : layout.outputBuses) {
  24. for (const juce::AudioChannelSet::ChannelType channelType : bus.getChannelTypes()) {
  25. retVal += juce::AudioChannelSet::getAbbreviatedChannelTypeName(channelType) + " ";
  26. }
  27. retVal += "| ";
  28. }
  29. return retVal;
  30. }
  31. inline void processBalance(float panValue, juce::AudioBuffer<float>& buffer) {
  32. // Check we have enough channels
  33. if (buffer.getNumChannels() >= 2) {
  34. if (panValue > 0) {
  35. // Balance is to the right - so linearly attenuate the left
  36. const float leftGain {1 - panValue};
  37. juce::FloatVectorOperations::multiply(buffer.getWritePointer(0),
  38. leftGain,
  39. buffer.getNumSamples());
  40. } else if (panValue < 0) {
  41. // Balance is to the left - so linearly attenuate the right
  42. const float rightGain {1 + panValue};
  43. juce::FloatVectorOperations::multiply(buffer.getWritePointer(1),
  44. rightGain,
  45. buffer.getNumSamples());
  46. }
  47. }
  48. }
  49. }