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.

156 lines
3.1KB

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