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.

133 lines
2.7KB

  1. /* SpiralSound
  2. * Copyleft (C) 2001 David Griffiths <dave@pawfal.org>
  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 "NoteSnapPlugin.h"
  19. #include "NoteSnapPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../NoteTable.h"
  23. extern "C" {
  24. SpiralPlugin* CreateInstance()
  25. {
  26. return new NoteSnapPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x0018;
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. NoteSnapPlugin::NoteSnapPlugin() :
  39. m_Out(0)
  40. {
  41. m_PluginInfo.Name="Note Snap";
  42. m_PluginInfo.Width=90;
  43. m_PluginInfo.Height=80;
  44. m_PluginInfo.NumInputs=1;
  45. m_PluginInfo.NumOutputs=1;
  46. m_PluginInfo.PortTips.push_back("Input");
  47. m_PluginInfo.PortTips.push_back("Output");
  48. for (int n=0; n<12; n++)
  49. {
  50. m_Filter[n]=true;
  51. }
  52. m_AudioCH->Register("Note",&m_Note);
  53. }
  54. NoteSnapPlugin::~NoteSnapPlugin()
  55. {
  56. }
  57. PluginInfo &NoteSnapPlugin::Initialise(const HostInfo *Host)
  58. {
  59. return SpiralPlugin::Initialise(Host);
  60. }
  61. SpiralGUIType *NoteSnapPlugin::CreateGUI()
  62. {
  63. return new NoteSnapPluginGUI(m_PluginInfo.Width,
  64. m_PluginInfo.Height,
  65. this,m_AudioCH,m_HostInfo);
  66. }
  67. void NoteSnapPlugin::Execute()
  68. {
  69. float Freq=0, OldFreq=0;
  70. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  71. {
  72. Freq=GetInputPitch(0,n);
  73. if (Freq!=OldFreq) // if it's changed
  74. {
  75. for (int i=0; i<131; i++) // for every note
  76. {
  77. if (m_Filter[(i+1)%12] && Freq>=NoteTable[i] && Freq<NoteTable[i+1])
  78. {
  79. m_Out=NoteTable[i];
  80. }
  81. }
  82. }
  83. OldFreq=Freq;
  84. SetOutputPitch(0,n,m_Out);
  85. }
  86. }
  87. void NoteSnapPlugin::ExecuteCommands()
  88. {
  89. if (m_AudioCH->IsCommandWaiting())
  90. {
  91. switch (m_AudioCH->GetCommand())
  92. {
  93. case NOTE_ON : m_Filter[m_Note]=true; break;
  94. case NOTE_OFF : m_Filter[m_Note]=false; break;
  95. }
  96. }
  97. }
  98. void NoteSnapPlugin::StreamOut(ostream &s)
  99. {
  100. s<<m_Version<<endl;
  101. for (int n=0; n<12; n++)
  102. {
  103. s<<m_Filter[n]<<" ";
  104. }
  105. }
  106. void NoteSnapPlugin::StreamIn(istream &s)
  107. {
  108. int version;
  109. s>>version;
  110. for (int n=0; n<12; n++)
  111. {
  112. s>>m_Filter[n];
  113. }
  114. }