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.

137 lines
3.4KB

  1. /* SpiralSound
  2. * Copyleft (C) 2003 Andy Preston <andy@clublinux.co.uk>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "TransposePlugin.h"
  19. #include "TransposePluginGUI.h"
  20. #include "SpiralIcon.xpm"
  21. #include "../../NoteTable.h"
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance () {
  25. return new TransposePlugin;
  26. }
  27. char** SpiralPlugin_GetIcon () {
  28. return SpiralIcon_xpm;
  29. }
  30. int SpiralPlugin_GetID () {
  31. return 122;
  32. }
  33. string SpiralPlugin_GetGroupName() {
  34. return "Control";
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. TransposePlugin::TransposePlugin () :
  39. m_Amount(0),
  40. m_Out(0.0),
  41. m_BufferInitialized(false)
  42. {
  43. m_PluginInfo.Name = "Transpose";
  44. m_PluginInfo.Width = 80;
  45. m_PluginInfo.Height = 60;
  46. m_PluginInfo.NumInputs = 2;
  47. m_PluginInfo.NumOutputs = 1;
  48. m_PluginInfo.PortTips.push_back ("Input");
  49. m_PluginInfo.PortTips.push_back ("Transpose CV");
  50. m_PluginInfo.PortTips.push_back ("Output");
  51. m_AudioCH->Register ("Amount", &m_Amount);
  52. }
  53. TransposePlugin::~TransposePlugin () {
  54. }
  55. PluginInfo &TransposePlugin::Initialise (const HostInfo *Host) {
  56. return SpiralPlugin::Initialise (Host);
  57. }
  58. SpiralGUIType *TransposePlugin::CreateGUI() {
  59. return new TransposePluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  60. }
  61. void TransposePlugin::Execute () {
  62. float base=110, transpose=m_Amount;
  63. float alpha = 17.312340490667;
  64. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  65. {
  66. float input0 = GetInputPitch(0, n);
  67. float input1 = GetInputPitch(1, n);
  68. if (input0 > 0)
  69. {
  70. // input's half steps from base of 110 = round(alpha*logf(GetInputPitch(0, n)/110));
  71. // cv's half steps from base of 110 = round(alpha*logf(GetInputPitch(1, n)/110));
  72. if ((!m_BufferInitialized) || (input0 != m_Buffer[0][0]) || (input1 != m_Buffer[1][0]))
  73. {
  74. if ((m_BufferInitialized) && (input0 == m_Buffer[0][0]))
  75. {
  76. base = m_Buffer[0][1];
  77. }
  78. else if (input0 != base)
  79. {
  80. base = round(alpha*logf(input0/110));
  81. }
  82. m_Buffer[0][0] = input0;
  83. m_Buffer[0][1] = base;
  84. if ((m_BufferInitialized) && (input1 == m_Buffer[1][0]))
  85. {
  86. transpose = m_Buffer[1][1];
  87. }
  88. else if (InputExists(1))
  89. {
  90. transpose = (input1 > 0)?round(alpha*logf(input1/110)):0;
  91. }
  92. m_Buffer[1][0] = input1;
  93. m_Buffer[1][1] = transpose;
  94. m_BufferInitialized = true;
  95. m_Out = 110*exp2f((base + transpose)/12);
  96. }
  97. }
  98. else
  99. {
  100. m_Out = 8.176;
  101. }
  102. SetOutputPitch (0, n, m_Out);
  103. }
  104. }
  105. void TransposePlugin::StreamOut (ostream &s) {
  106. s << m_Version << endl;
  107. s << m_Amount;
  108. }
  109. void TransposePlugin::StreamIn (istream &s) {
  110. int version;
  111. s >> version;
  112. s >> m_Amount;
  113. }