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.

124 lines
3.3KB

  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/ttyS1"
  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. //static const HostInfo* host;
  31. MousePluginSingleton* MousePluginSingleton::m_Singleton = NULL;
  32. int MousePlugin::m_RefCount=0;
  33. ///////////////////////////////////////////////////////
  34. MousePluginSingleton::MousePluginSingleton() {
  35. scr = new scratch(SCRATCH_DEVICE); // create scratch object
  36. }
  37. MousePluginSingleton::~MousePluginSingleton() {
  38. if (scr!=NULL) {
  39. delete scr;
  40. }
  41. }
  42. ///////////////////////////////////////////////////////
  43. MousePlugin::MousePlugin():
  44. m_Data (0.0)
  45. {
  46. m_RefCount++;
  47. m_PluginInfo.Name = "Mouse";
  48. m_PluginInfo.Width = 70;
  49. m_PluginInfo.Height = 125;
  50. m_PluginInfo.NumInputs = 1;
  51. m_PluginInfo.NumOutputs = 1;
  52. m_PluginInfo.PortTips.push_back ("Trigger");
  53. m_PluginInfo.PortTips.push_back ("Output");
  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::Execute() {
  70. float trigger = 1.0;
  71. if (GetOutputBuf(0)) {
  72. if (InputExists(0)) {
  73. trigger = GetInput(0,0);
  74. }
  75. char c = MousePluginSingleton::Get()->getScr()->getData();
  76. if (c!=0x0) {
  77. float val;
  78. int ch = (int)c;
  79. val = (float)(ch / 127.00);
  80. if (val>1) val=1;
  81. if (val<-1) val=-1;
  82. if (trigger>0) {
  83. GetOutputBuf(0)->Set (val);
  84. m_Data = val;
  85. } else {
  86. GetOutputBuf(0)->Set (m_Data);
  87. }
  88. } else {
  89. GetOutputBuf(0)->Set (m_Data);
  90. }
  91. }
  92. }
  93. void MousePlugin::StreamOut (ostream &s) {
  94. s << m_Version;
  95. }
  96. void MousePlugin::StreamIn (istream &s) {
  97. int Version;
  98. s >> Version;
  99. }