1
0

PluginStructs.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * PluginStructs.h
  3. * ---------------
  4. * Purpose: Basic plugin structs for CSoundFile.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "../Snd_defs.h"
  12. #ifndef NO_PLUGINS
  13. #include "openmpt/base/Endian.hpp"
  14. #endif // NO_PLUGINS
  15. OPENMPT_NAMESPACE_BEGIN
  16. ////////////////////////////////////////////////////////////////////
  17. // Mix Plugins
  18. using PlugParamIndex = uint32;
  19. using PlugParamValue = float;
  20. struct SNDMIXPLUGINSTATE;
  21. struct SNDMIXPLUGIN;
  22. class IMixPlugin;
  23. class CSoundFile;
  24. #ifndef NO_PLUGINS
  25. struct SNDMIXPLUGININFO
  26. {
  27. // dwInputRouting flags
  28. enum RoutingFlags
  29. {
  30. irApplyToMaster = 0x01, // Apply to master mix
  31. irBypass = 0x02, // Bypass effect
  32. irWetMix = 0x04, // Wet Mix (dry added)
  33. irExpandMix = 0x08, // [0%,100%] -> [-200%,200%]
  34. irAutoSuspend = 0x10, // Plugin will automatically suspend on silence
  35. };
  36. int32le dwPluginId1; // Plugin type (kEffectMagic, kDmoMagic, kBuzzMagic)
  37. int32le dwPluginId2; // Plugin unique ID
  38. uint8le routingFlags; // See RoutingFlags
  39. uint8le mixMode;
  40. uint8le gain; // Divide by 10 to get real gain
  41. uint8le reserved;
  42. uint32le dwOutputRouting; // 0 = send to master 0x80 + x = send to plugin x
  43. uint32le dwReserved[4]; // Reserved for routing info
  44. mpt::modecharbuf<32, mpt::String::nullTerminated> szName; // User-chosen plugin display name - this is locale ANSI!
  45. mpt::modecharbuf<64, mpt::String::nullTerminated> szLibraryName; // original DLL name - this is UTF-8!
  46. // Should only be called from SNDMIXPLUGIN::SetBypass() and IMixPlugin::Bypass()
  47. void SetBypass(bool bypass = true) { if(bypass) routingFlags |= irBypass; else routingFlags &= uint8(~irBypass); }
  48. };
  49. MPT_BINARY_STRUCT(SNDMIXPLUGININFO, 128) // this is directly written to files, so the size must be correct!
  50. struct SNDMIXPLUGIN
  51. {
  52. IMixPlugin *pMixPlugin = nullptr;
  53. std::vector<std::byte> pluginData;
  54. SNDMIXPLUGININFO Info = {};
  55. float fDryRatio = 0;
  56. int32 defaultProgram = 0;
  57. int32 editorX = 0, editorY = 0;
  58. #if defined(MPT_ENABLE_CHARSET_LOCALE)
  59. const char * GetNameLocale() const
  60. {
  61. return Info.szName.buf;
  62. }
  63. mpt::ustring GetName() const
  64. {
  65. return mpt::ToUnicode(mpt::Charset::Locale, Info.szName);
  66. }
  67. #endif // MPT_ENABLE_CHARSET_LOCALE
  68. mpt::ustring GetLibraryName() const
  69. {
  70. return mpt::ToUnicode(mpt::Charset::UTF8, Info.szLibraryName);
  71. }
  72. // Check if a plugin is loaded into this slot (also returns true if the plugin in this slot has not been found)
  73. bool IsValidPlugin() const { return (Info.dwPluginId1 | Info.dwPluginId2) != 0; }
  74. // Input routing getters
  75. uint8 GetGain() const
  76. { return Info.gain; }
  77. uint8 GetMixMode() const
  78. { return Info.mixMode; }
  79. bool IsMasterEffect() const
  80. { return (Info.routingFlags & SNDMIXPLUGININFO::irApplyToMaster) != 0; }
  81. bool IsWetMix() const
  82. { return (Info.routingFlags & SNDMIXPLUGININFO::irWetMix) != 0; }
  83. bool IsExpandedMix() const
  84. { return (Info.routingFlags & SNDMIXPLUGININFO::irExpandMix) != 0; }
  85. bool IsBypassed() const
  86. { return (Info.routingFlags & SNDMIXPLUGININFO::irBypass) != 0; }
  87. bool IsAutoSuspendable() const
  88. { return (Info.routingFlags & SNDMIXPLUGININFO::irAutoSuspend) != 0; }
  89. // Input routing setters
  90. void SetGain(uint8 gain);
  91. void SetMixMode(uint8 mixMode)
  92. { Info.mixMode = mixMode; }
  93. void SetMasterEffect(bool master = true)
  94. { if(master) Info.routingFlags |= SNDMIXPLUGININFO::irApplyToMaster; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irApplyToMaster); }
  95. void SetWetMix(bool wetMix = true)
  96. { if(wetMix) Info.routingFlags |= SNDMIXPLUGININFO::irWetMix; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irWetMix); }
  97. void SetExpandedMix(bool expanded = true)
  98. { if(expanded) Info.routingFlags |= SNDMIXPLUGININFO::irExpandMix; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irExpandMix); }
  99. void SetBypass(bool bypass = true);
  100. void SetAutoSuspend(bool suspend = true)
  101. { if(suspend) Info.routingFlags |= SNDMIXPLUGININFO::irAutoSuspend; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irAutoSuspend); }
  102. // Output routing getters
  103. bool IsOutputToMaster() const
  104. { return Info.dwOutputRouting == 0; }
  105. PLUGINDEX GetOutputPlugin() const
  106. { return Info.dwOutputRouting >= 0x80 ? static_cast<PLUGINDEX>(Info.dwOutputRouting - 0x80) : PLUGINDEX_INVALID; }
  107. // Output routing setters
  108. void SetOutputToMaster()
  109. { Info.dwOutputRouting = 0; }
  110. void SetOutputPlugin(PLUGINDEX plugin)
  111. { if(plugin < MAX_MIXPLUGINS) Info.dwOutputRouting = plugin + 0x80; else Info.dwOutputRouting = 0; }
  112. void Destroy();
  113. };
  114. bool CreateMixPluginProc(SNDMIXPLUGIN &mixPlugin, CSoundFile &sndFile);
  115. #endif // NO_PLUGINS
  116. OPENMPT_NAMESPACE_END