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.

163 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they 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. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. #if JUCE_LASH
  21. //==============================================================================
  22. /* Got an include error here? If so, you've either not got LASH installed, or
  23. you've not got your paths set up correctly to find its header files.
  24. The package you need to install to get LASH support is "liblash-dev".
  25. If you don't have the LASH library and don't want to build juce with LASH support,
  26. just disable the JUCE_LASH flag in juce_Config.h
  27. */
  28. #include <lash/lash.h>
  29. BEGIN_JUCE_NAMESPACE
  30. //==============================================================================
  31. LashManager::LashManager (AudioProcessor* filter_)
  32. : filter (filter_),
  33. client (0)
  34. {
  35. int argc = 0;
  36. char** argv = 0;
  37. if (filter)
  38. {
  39. client = lash_init (lash_extract_args(&argc, &argv),
  40. filter->getName(),
  41. LASH_Config_File,
  42. LASH_PROTOCOL(2, 0));
  43. if (client)
  44. {
  45. lash_event_t* event;
  46. event = lash_event_new_with_type (LASH_Client_Name);
  47. lash_event_set_string (event, filter->getName());
  48. lash_send_event ((lash_client_t*) client, event);
  49. event = lash_event_new_with_type (LASH_Jack_Client_Name);
  50. lash_event_set_string (event, filter->getName());
  51. lash_send_event ((lash_client_t*) client, event);
  52. startTimer (1000 / 2);
  53. }
  54. }
  55. }
  56. LashManager::~LashManager()
  57. {
  58. if (client && isTimerRunning ())
  59. stopTimer ();
  60. }
  61. //==============================================================================
  62. void LashManager::loadState (const File& fileToLoad)
  63. {
  64. MemoryBlock fileData;
  65. if (fileToLoad.existsAsFile()
  66. && fileToLoad.loadFileAsData (fileData))
  67. {
  68. filter->setStateInformation (fileData.getData (), fileData.getSize());
  69. }
  70. }
  71. void LashManager::saveState (const File& fileToSave)
  72. {
  73. MemoryBlock fileData;
  74. filter->getStateInformation (fileData);
  75. if (fileToSave.replaceWithData (fileData.getData (), fileData.getSize()))
  76. {
  77. }
  78. }
  79. //==============================================================================
  80. void LashManager::timerCallback()
  81. {
  82. if (! client || ! filter)
  83. return;
  84. lash_event_t* event;
  85. while ((event = lash_get_event ((lash_client_t*) client)) != 0)
  86. {
  87. String eventString (lash_event_get_string (event));
  88. switch (lash_event_get_type (event))
  89. {
  90. case LASH_Save_File:
  91. printf ("Asked to save data in %s\n", (const char*) eventString);
  92. saveState (File (eventString + "/" + filter->getName () + ".lash"));
  93. lash_send_event ((lash_client_t*) client, lash_event_new_with_type (LASH_Save_File));
  94. break;
  95. case LASH_Restore_File:
  96. printf ("Asked to restore data from %s\n", (const char*) eventString);
  97. loadState (File (eventString + "/" + filter->getName () + ".lash"));
  98. lash_send_event ((lash_client_t*) client, lash_event_new_with_type (LASH_Restore_File));
  99. break;
  100. case LASH_Quit:
  101. printf ("Asked to quit !\n");
  102. stopTimer ();
  103. break;
  104. case LASH_Server_Lost:
  105. printf ("Server lost !\n");
  106. stopTimer ();
  107. lash_event_destroy (event);
  108. return;
  109. default:
  110. printf("Got unhandled LADCCA event\n");
  111. break;
  112. }
  113. lash_event_destroy (event);
  114. }
  115. /*
  116. while ((config = lash_get_config(client)) != 0)
  117. {
  118. printf ("Unexpected LASH config: %s\n", lash_config_get_key(config));
  119. lash_config_free(config);
  120. free(config);
  121. config = 0;
  122. }
  123. */
  124. }
  125. END_JUCE_NAMESPACE
  126. #endif