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.

122 lines
3.0KB

  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 <string>
  19. #include <iostream>
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include "TransposePlugin.h"
  23. #include "TransposePluginGUI.h"
  24. #include "SpiralIcon.xpm"
  25. #include "../../NoteTable.h"
  26. using namespace std;
  27. extern "C" {
  28. SpiralPlugin* SpiralPlugin_CreateInstance () {
  29. return new TransposePlugin;
  30. }
  31. char** SpiralPlugin_GetIcon () {
  32. return SpiralIcon_xpm;
  33. }
  34. int SpiralPlugin_GetID () {
  35. return 122;
  36. }
  37. string SpiralPlugin_GetGroupName() {
  38. return "Control";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. TransposePlugin::TransposePlugin () :
  43. m_Amount(0),
  44. m_Out(0.0),
  45. m_BufferInitialized(false)
  46. {
  47. m_PluginInfo.Name = "Transpose";
  48. m_PluginInfo.Width = 80;
  49. m_PluginInfo.Height = 60;
  50. m_PluginInfo.NumInputs = 2;
  51. m_PluginInfo.NumOutputs = 1;
  52. m_PluginInfo.PortTips.push_back ("Input");
  53. m_PluginInfo.PortTips.push_back ("Transpose CV");
  54. m_PluginInfo.PortTips.push_back ("Output");
  55. m_AudioCH->Register ("Amount", &m_Amount);
  56. }
  57. TransposePlugin::~TransposePlugin () {
  58. }
  59. PluginInfo &TransposePlugin::Initialise (const HostInfo *Host) {
  60. return SpiralPlugin::Initialise (Host);
  61. }
  62. SpiralGUIType *TransposePlugin::CreateGUI() {
  63. return new TransposePluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  64. }
  65. void TransposePlugin::Execute () {
  66. float base=110, transpose=m_Amount;
  67. float alpha = 17.312340490667;
  68. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  69. {
  70. float input0 = GetInputPitch(0, n);
  71. float input1 = GetInputPitch(1, n);
  72. if (input0 > 0)
  73. {
  74. // input's half steps from base of 110 = round(alpha*logf(GetInputPitch(0, n)/110));
  75. // cv's half steps from base of 110 = round(alpha*logf(GetInputPitch(1, n)/110));
  76. base = floor((alpha*logf(input0/110.0)) + 0.5);
  77. if (InputExists(1))
  78. {
  79. transpose = (input1 > 0)?floor((alpha*logf(input1/110)) + 0.5):8.176;
  80. }
  81. m_Out = 110 * powf(2, (base+transpose) / 12);
  82. }
  83. else
  84. {
  85. m_Out = 8.176;
  86. }
  87. SetOutputPitch (0, n, m_Out);
  88. }
  89. }
  90. void TransposePlugin::StreamOut (ostream &s) {
  91. s << m_Version << endl;
  92. s << m_Amount;
  93. }
  94. void TransposePlugin::StreamIn (istream &s) {
  95. int version;
  96. s >> version;
  97. s >> m_Amount;
  98. }