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.

57 lines
2.0KB

  1. /*
  2. ==============================================================================
  3. Common.h
  4. Created: 10 Jun 2012 7:30:05pm
  5. Author: David Rowland
  6. ==============================================================================
  7. */
  8. #ifndef __PLUGIN_HELPERS_H__
  9. #define __PLUGIN_HELPERS_H__
  10. //==============================================================================
  11. namespace PresetHelpers
  12. {
  13. static void savePreset (AudioProcessor& processor, MemoryBlock& destData) noexcept
  14. {
  15. const String presetTitle (String (processor.getName() + " SETTINGS").replaceCharacter (' ', '_'));
  16. ValueTree preset (presetTitle);
  17. for (int i = 0; i < processor.getNumParameters(); ++i)
  18. {
  19. const String storedParamName (processor.getParameterName (i).replaceCharacter (' ', '_'));
  20. preset.setProperty (storedParamName, processor.getParameter (i), nullptr);
  21. }
  22. MemoryOutputStream stream (destData, false);
  23. preset.writeToStream (stream);
  24. }
  25. static void loadPreset (AudioProcessor& processor, const void* data, int sizeInBytes) noexcept
  26. {
  27. ValueTree preset (ValueTree::readFromData (data, sizeInBytes));
  28. if (preset.isValid())
  29. {
  30. String presetTitle (String (processor.getName() + " SETTINGS").replaceCharacter (' ', '_'));
  31. // make sure that it's actually our type of XML object..
  32. if (preset.hasType (presetTitle))
  33. {
  34. for (int i = 0; i < processor.getNumParameters(); ++i)
  35. {
  36. const String storedParamName (processor.getParameterName (i).replaceCharacter (' ', '_'));
  37. const float storedParamValue = (float) preset.getProperty (storedParamName, processor.getParameter (i));
  38. processor.setParameter (i, storedParamValue);
  39. }
  40. }
  41. }
  42. }
  43. }
  44. #endif // __PLUGIN_HELPERS_H__