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.

130 lines
3.4KB

  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 "MousePlugin.h"
  21. #include "MousePluginGUI.h"
  22. #include "SpiralIcon.xpm"
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance() { return new MousePlugin; }
  25. char** SpiralPlugin_GetIcon() { return SpiralIcon_xpm; }
  26. int SpiralPlugin_GetID() { return 300; }
  27. string SpiralPlugin_GetGroupName() { return "InputOutput"; }
  28. }
  29. ///////////////////////////////////////////////////////
  30. MousePluginSingleton* MousePluginSingleton::m_Singleton = NULL;
  31. int MousePlugin::m_RefCount=0;
  32. MousePluginSingleton::MousePluginSingleton() {
  33. scr = new scratch(SCRATCH_DEVICE); // create scratch object
  34. }
  35. MousePluginSingleton::~MousePluginSingleton() {
  36. if (scr!=NULL) delete scr;
  37. }
  38. ///////////////////////////////////////////////////////
  39. MousePlugin::MousePlugin():
  40. m_Port ('0'),
  41. m_Data (0.0)
  42. {
  43. m_RefCount++;
  44. m_PluginInfo.Name = "Mouse";
  45. m_PluginInfo.Width = 200;
  46. m_PluginInfo.Height = 400;
  47. m_PluginInfo.NumInputs = 1;
  48. m_PluginInfo.NumOutputs = 1;
  49. m_PluginInfo.PortTips.push_back ("Trigger");
  50. m_PluginInfo.PortTips.push_back ("Output");
  51. m_AudioCH->Register ("Port", &m_Port);
  52. m_Version = 1;
  53. }
  54. MousePlugin::~MousePlugin() {
  55. m_RefCount--;
  56. if (m_RefCount==0) {
  57. MousePluginSingleton::PackUpAndGoHome();
  58. }
  59. }
  60. PluginInfo &MousePlugin::Initialise (const HostInfo *Host) {
  61. PluginInfo& Info = SpiralPlugin::Initialise (Host);
  62. m_AudioCH->Register ("Data", &m_Data, ChannelHandler::OUTPUT);
  63. return Info;
  64. }
  65. SpiralGUIType *MousePlugin::CreateGUI() {
  66. return new MousePluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  67. }
  68. void MousePlugin::ExecuteCommands () {
  69. if (m_AudioCH->IsCommandWaiting ()) {
  70. switch (m_AudioCH->GetCommand()) {
  71. case (SETPORT) : // do something
  72. break;
  73. }
  74. }
  75. }
  76. void MousePlugin::Execute() {
  77. float trigger = 1.0;
  78. if (GetOutputBuf(0)) {
  79. if (InputExists(0)) {
  80. trigger = GetInput(0,0);
  81. }
  82. char c = MousePluginSingleton::Get()->getScr()->getData();
  83. if (c!=0x0) {
  84. float val;
  85. int ch = (int)c;
  86. val = (float)(ch / 127.00);
  87. if (val>1) val=1;
  88. if (val<-1) val=-1;
  89. if (trigger>0) {
  90. GetOutputBuf(0)->Set (val);
  91. m_Data = val;
  92. } else {
  93. GetOutputBuf(0)->Set (m_Data);
  94. }
  95. } else {
  96. GetOutputBuf(0)->Set (m_Data);
  97. }
  98. }
  99. }
  100. void MousePlugin::StreamOut (ostream &s) {
  101. s << m_Version;
  102. }
  103. void MousePlugin::StreamIn (istream &s) {
  104. int Version;
  105. s >> Version;
  106. }