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.

147 lines
2.9KB

  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. string GetGroupName()
  37. {
  38. return "Control";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. NoteSnapPlugin::NoteSnapPlugin() :
  43. m_Out(0)
  44. {
  45. m_PluginInfo.Name="Note Snap";
  46. m_PluginInfo.Width=90;
  47. m_PluginInfo.Height=80;
  48. m_PluginInfo.NumInputs=1;
  49. m_PluginInfo.NumOutputs=1;
  50. m_PluginInfo.PortTips.push_back("Input");
  51. m_PluginInfo.PortTips.push_back("Output");
  52. for (int n=0; n<12; n++)
  53. {
  54. m_Filter[n]=true;
  55. }
  56. m_AudioCH->Register("Note",&m_Note);
  57. }
  58. NoteSnapPlugin::~NoteSnapPlugin()
  59. {
  60. }
  61. PluginInfo &NoteSnapPlugin::Initialise(const HostInfo *Host)
  62. {
  63. return SpiralPlugin::Initialise(Host);
  64. }
  65. SpiralGUIType *NoteSnapPlugin::CreateGUI()
  66. {
  67. return new NoteSnapPluginGUI(m_PluginInfo.Width,
  68. m_PluginInfo.Height,
  69. this,m_AudioCH,m_HostInfo);
  70. }
  71. void NoteSnapPlugin::Execute()
  72. {
  73. float Freq=0, OldFreq=0;
  74. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  75. {
  76. Freq=GetInputPitch(0,n);
  77. if (Freq!=OldFreq) // if it's changed
  78. {
  79. for (int i=0; i<131; i++) // for every note
  80. {
  81. if (m_Filter[(i+1)%12] && Freq>=NoteTable[i] && Freq<NoteTable[i+1])
  82. {
  83. m_Out=NoteTable[i];
  84. }
  85. }
  86. }
  87. OldFreq=Freq;
  88. SetOutputPitch(0,n,m_Out);
  89. }
  90. }
  91. void NoteSnapPlugin::ExecuteCommands()
  92. {
  93. if (m_AudioCH->IsCommandWaiting())
  94. {
  95. switch (m_AudioCH->GetCommand())
  96. {
  97. case NOTE_ON : m_Filter[m_Note]=true; break;
  98. case NOTE_OFF : m_Filter[m_Note]=false; break;
  99. }
  100. }
  101. }
  102. void NoteSnapPlugin::StreamOut(ostream &s)
  103. {
  104. s<<m_Version<<endl;
  105. for (int n=0; n<12; n++)
  106. {
  107. s<<m_Filter[n]<<" ";
  108. }
  109. }
  110. void NoteSnapPlugin::StreamIn(istream &s)
  111. {
  112. // Pre-version 1 - check for blank line
  113. if (s.peek() == 10) {
  114. for (int n=0; n<12; n++)
  115. {
  116. // Use default (no notes filtered)
  117. m_Filter[n] = 1;
  118. }
  119. } else {
  120. int version;
  121. s>>version;
  122. for (int n=0; n<12; n++)
  123. {
  124. s>>m_Filter[n];
  125. }
  126. }
  127. }