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
3.5KB

  1. /* MousePlugin
  2. * Copyleft (C) 2002 Dan Bethell <dan@pawfal.org>
  3. * Dave Griffiths <dave@pawfal.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #define SCRATCH_DEVICE "/dev/ttyS0"
  20. #include <string>
  21. #include "MousePlugin.h"
  22. #include "MousePluginGUI.h"
  23. #include "SpiralIcon.xpm"
  24. extern "C" {
  25. SpiralPlugin* SpiralPlugin_CreateInstance() { return new MousePlugin; }
  26. char** SpiralPlugin_GetIcon() { return SpiralIcon_xpm; }
  27. int SpiralPlugin_GetID() { return 300; }
  28. // string SpiralPlugin_GetGroupName() { return "InputOutput"; }
  29. }
  30. ///////////////////////////////////////////////////////
  31. MousePluginSingleton* MousePluginSingleton::m_Singleton = NULL;
  32. int MousePlugin::m_RefCount=0;
  33. MousePluginSingleton::MousePluginSingleton() {
  34. scr = new scratch(SCRATCH_DEVICE); // create scratch object
  35. }
  36. MousePluginSingleton::~MousePluginSingleton() {
  37. if (scr!=NULL) delete scr;
  38. }
  39. ///////////////////////////////////////////////////////
  40. MousePlugin::MousePlugin():
  41. m_Port ('0'),
  42. m_Data (0.0)
  43. {
  44. m_RefCount++;
  45. m_PluginInfo.Name = "Mouse";
  46. m_PluginInfo.Width = 100;
  47. m_PluginInfo.Height = 140;
  48. m_PluginInfo.NumInputs = 1;
  49. m_PluginInfo.NumOutputs = 1;
  50. m_PluginInfo.PortTips.push_back ("Trigger");
  51. m_PluginInfo.PortTips.push_back ("Output");
  52. m_AudioCH->Register ("Port", &m_Port);
  53. m_Version = 2;
  54. }
  55. MousePlugin::~MousePlugin() {
  56. m_RefCount--;
  57. if (m_RefCount==0) {
  58. MousePluginSingleton::PackUpAndGoHome();
  59. }
  60. }
  61. PluginInfo &MousePlugin::Initialise (const HostInfo *Host) {
  62. PluginInfo& Info = SpiralPlugin::Initialise (Host);
  63. m_AudioCH->Register ("Data", &m_Data, ChannelHandler::OUTPUT);
  64. return Info;
  65. }
  66. SpiralGUIType *MousePlugin::CreateGUI() {
  67. return new MousePluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  68. }
  69. void MousePlugin::ExecuteCommands () {
  70. if (m_AudioCH->IsCommandWaiting ()) {
  71. switch (m_AudioCH->GetCommand()) {
  72. case (SETPORT) : // do something
  73. break;
  74. }
  75. }
  76. }
  77. void MousePlugin::Execute() {
  78. float trigger = 1.0;
  79. if (GetOutputBuf(0)) {
  80. if (InputExists(0)) {
  81. trigger = GetInput(0,0);
  82. }
  83. char c = MousePluginSingleton::Get()->getScr()->getData();
  84. if (c!=0x0) {
  85. float val;
  86. int ch = (int)c;
  87. val = (float)(ch / 127.00);
  88. if (val>1) val=1;
  89. if (val<-1) val=-1;
  90. if (trigger>0) {
  91. GetOutputBuf(0)->Set (val);
  92. m_Data = val;
  93. } else {
  94. GetOutputBuf(0)->Set (m_Data);
  95. }
  96. } else {
  97. GetOutputBuf(0)->Set (m_Data);
  98. }
  99. }
  100. }
  101. void MousePlugin::StreamOut (ostream &s) {
  102. s << m_Version << " " << m_Port;
  103. }
  104. void MousePlugin::StreamIn (istream &s) {
  105. int Version;
  106. s >> Version;
  107. if (Version > 1) s >> m_Port;
  108. }