SpoutControls.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. SpoutControls.h
  3. Copyright (c) 2015-2016, Lynn Jarvis. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  12. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  13. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  17. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  18. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. */
  21. // ====================================================================================
  22. // Revisions :
  23. //
  24. // 18.08.15 - Cleanup for 1.002 release
  25. //
  26. #pragma once
  27. #ifndef __SpoutControls__
  28. #define __SpoutControls__
  29. #include <Shlobj.h> // to get the program folder path
  30. #include <Knownfolders.h>
  31. #include <comutil.h> // for _bstr_t (used in the string conversion)
  32. #include <direct.h> // for directories
  33. #include <io.h> // for file existence check
  34. #include "spoutSDK.h"
  35. #pragma comment(lib, "comsuppw") // for _bstr_t
  36. // Warnings disabled in this project : C4250
  37. // ISF to freeframe parameters
  38. struct filecontrol {
  39. string name;
  40. string desc; // To link with descriptons "TYPE"
  41. // "event"
  42. // "bool"
  43. // "long"
  44. // "text"
  45. // "float"
  46. // "point2D"
  47. // "color"
  48. // "image"
  49. int fftype; // freeframe parameter type - 0 - 6, 10, 100
  50. float def; // default float value
  51. float value; // user float value
  52. float min; // Minimum
  53. float max; // Maximum
  54. string text; // text value
  55. // TODO deftext
  56. };
  57. struct control {
  58. string name;
  59. int type; // 0-checkbox, 1-button, 10-float, 100-string
  60. float value;
  61. string text;
  62. };
  63. class SPOUT_DLLEXP SpoutControls {
  64. public:
  65. SpoutControls();
  66. ~SpoutControls();
  67. // The controller
  68. bool FindControls (string &mapname);
  69. bool CreateControls(string mapname, vector<control> controls);
  70. bool SetControls (vector<control> controls);
  71. bool Cleanup();
  72. void CloseMap();
  73. bool FindControlFile (string &filepath);
  74. bool CopyControlFile (string &filepath, string &destpath);
  75. // The sender being controlled
  76. bool CreateControl(string name, string type);
  77. bool CreateControl(string name, string type, float value);
  78. bool CreateControl(string name, string type, string text);
  79. bool CreateControl(string name, string type, float minimum, float maximum, float value);
  80. bool OpenControls (string mapname);
  81. bool GetControls (vector<control> &controls);
  82. bool CheckControls(vector<control> &controls);
  83. bool CloseControls();
  84. bool OpenSpoutController(string CommandLine = "");
  85. // Utility for other apps
  86. bool WritePathToRegistry (const char *filepath, const char *subkey, const char *valuename);
  87. bool ReadPathFromRegistry (char *filepath, const char *subkey, const char *valuename);
  88. bool WriteDwordToRegistry (DWORD dwValue, const char *subkey, const char *valuename);
  89. bool ReadDwordFromRegistry (DWORD *pValue, const char *subkey, const char *valuename);
  90. bool RemovePathFromRegistry(char *filepath, const char *subkey);
  91. protected :
  92. string m_sharedMemoryName; // Memory map name
  93. HANDLE m_hSharedMemory; // Memory map handle
  94. LPTSTR m_pBuffer; // Shared memory pointer
  95. HANDLE m_hAccessMutex; // Map access mutex
  96. HANDLE m_hSlot;
  97. DWORD m_dwSize; // Size of the memory map
  98. char m_ControlFilePath[MAX_PATH];
  99. vector<filecontrol> filecontrols; // Vector of control information used to create the sender control file
  100. bool UpdateControls(vector<control> controls);
  101. bool WriteControls(void *pBuffer, vector<control> controls);
  102. bool ReadControls (void *pBuffer, vector<control> &controls);
  103. bool CreateMail(string slotname, HANDLE &hSlot);
  104. bool WriteMail (string SlotName, string SlotMessage);
  105. bool ReadMail (string SlotName, HANDLE hSlot, string &SlotMessage);
  106. bool CheckMail (string SlotName, HANDLE hSlot);
  107. bool CreateFileControl(string name, string type, float minimum, float maximum, float value, string text);
  108. bool CreateControlFile(const char *filepath);
  109. };
  110. #endif