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.

103 lines
2.8KB

  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. extern "C" {
  23. SpiralPlugin* SpiralPlugin_CreateInstance () {
  24. return new TransposePlugin;
  25. }
  26. char** SpiralPlugin_GetIcon () {
  27. return SpiralIcon_xpm;
  28. }
  29. int SpiralPlugin_GetID () {
  30. return 122;
  31. }
  32. string SpiralPlugin_GetGroupName() {
  33. return "Control";
  34. }
  35. }
  36. ///////////////////////////////////////////////////////
  37. TransposePlugin::TransposePlugin () :
  38. m_Amount(0),
  39. m_Out(0.0)
  40. {
  41. m_PluginInfo.Name = "Transpose";
  42. m_PluginInfo.Width = 80;
  43. m_PluginInfo.Height = 60;
  44. m_PluginInfo.NumInputs = 2;
  45. m_PluginInfo.NumOutputs = 1;
  46. m_PluginInfo.PortTips.push_back ("Input");
  47. m_PluginInfo.PortTips.push_back ("Transpose CV");
  48. m_PluginInfo.PortTips.push_back ("Output");
  49. m_AudioCH->Register ("Amount", &m_Amount);
  50. }
  51. TransposePlugin::~TransposePlugin () {
  52. }
  53. PluginInfo &TransposePlugin::Initialise (const HostInfo *Host) {
  54. return SpiralPlugin::Initialise (Host);
  55. }
  56. SpiralGUIType *TransposePlugin::CreateGUI() {
  57. return new TransposePluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  58. }
  59. void TransposePlugin::Execute () {
  60. int Match [2];
  61. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  62. Match[0]=0;
  63. Match[1]=0;
  64. for (int i=0; i<2 && InputExists(i); i++) {
  65. float Freq, Dif, MinDif = 30000;
  66. Freq = GetInputPitch (i, n);
  67. for (int c=0; c<131; c++) {
  68. Dif = fabs (NoteTable[c] - Freq);
  69. if (Dif > MinDif) break;
  70. MinDif=Dif;
  71. Match[i]=c;
  72. }
  73. }
  74. if (! InputExists (1)) Match[1] = m_Amount;
  75. m_Out = NoteTable [(Match[0] + Match[1]) % 132];
  76. SetOutputPitch (0, n, m_Out);
  77. }
  78. }
  79. void TransposePlugin::StreamOut (ostream &s) {
  80. s << m_Version << endl;
  81. s << m_Amount;
  82. }
  83. void TransposePlugin::StreamIn (istream &s) {
  84. int version;
  85. s >> version;
  86. s >> m_Amount;
  87. }