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.

121 lines
2.4KB

  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. {
  40. m_PluginInfo.Name="Note Snap";
  41. m_PluginInfo.Width=220;
  42. m_PluginInfo.Height=125;
  43. m_PluginInfo.NumInputs=1;
  44. m_PluginInfo.NumOutputs=1;
  45. m_PluginInfo.PortTips.push_back("Input");
  46. m_PluginInfo.PortTips.push_back("Output");
  47. }
  48. NoteSnapPlugin::~NoteSnapPlugin()
  49. {
  50. }
  51. PluginInfo &NoteSnapPlugin::Initialise(const HostInfo *Host)
  52. {
  53. return SpiralPlugin::Initialise(Host);
  54. }
  55. SpiralGUIType *NoteSnapPlugin::CreateGUI()
  56. {
  57. m_GUI=NULL;
  58. return m_GUI;
  59. }
  60. void NoteSnapPlugin::Execute()
  61. {
  62. float Freq=0, OldFreq=0;
  63. float Out=0;
  64. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  65. {
  66. Freq=GetInputPitch(0,n);
  67. if (Freq!=OldFreq) // if it's changed
  68. {
  69. for (int i=0; i<131; i++) // for every note
  70. {
  71. if (Freq>=NoteTable[i] && Freq<NoteTable[i+1])
  72. {
  73. Out=NoteTable[i];
  74. }
  75. }
  76. }
  77. OldFreq=Freq;
  78. SetOutputPitch(0,n,Out);
  79. }
  80. }
  81. int main()
  82. {
  83. Fl::visual(FL_DOUBLE|FL_RGB);
  84. HostInfo host;
  85. host.BUFSIZE=256;
  86. host.SAMPLERATE=44100;
  87. host.OUTPUTFILE="/dev/dsp";
  88. host.MIDIFILE="/dev/midi";
  89. host.POLY=1;
  90. host.GUI_COLOUR=100;
  91. SpiralPlugin* test = CreateInstance();
  92. test->Initialise(&host);
  93. test->CreateGUI();
  94. for (;;)
  95. {
  96. if (!Fl::check()) break;
  97. test->Execute();
  98. }
  99. delete test;
  100. return 1;
  101. }