The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

164 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../JuceLibraryCode/JuceHeader.h"
  18. namespace
  19. {
  20. String getIPAddress()
  21. {
  22. Array<IPAddress> addresses;
  23. IPAddress::findAllAddresses (addresses);
  24. return addresses[1].toString();
  25. }
  26. String getBroadcastIPAddress()
  27. {
  28. return getIPAddress().upToLastOccurrenceOf (".", false, false) + ".255";
  29. }
  30. static const int masterPortNumber = 9001; // the UDP port the master sends on / the clients receive.
  31. static const int clientPortNumber = 9002; // the UDP port the clients send on / the master receives.
  32. static const String canvasStateOSCAddress = "/juce/nfd/canvasState";
  33. static const String newClientOSCAddress = "/juce/nfd/newClient";
  34. static const String userInputOSCAddress = "/juce/nfd/userInput";
  35. };
  36. #include "SharedCanvas.h"
  37. #include "SlaveComponent.h"
  38. #include "Demos.h"
  39. #include "MasterComponent.h"
  40. //==============================================================================
  41. class NetworkGraphicsDemoApplication : public JUCEApplication
  42. {
  43. public:
  44. NetworkGraphicsDemoApplication() : properties (getPropertyFileOptions())
  45. {}
  46. const String getApplicationName() override { return ProjectInfo::projectName; }
  47. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  48. bool moreThanOneInstanceAllowed() override { return true; }
  49. void anotherInstanceStarted (const String&) override {}
  50. //==============================================================================
  51. void initialise (const String& commandLine) override
  52. {
  53. #if ! JUCE_IOS && ! JUCE_ANDROID
  54. // Run as the master if we have a command-line flag "master" or if the exe itself
  55. // has been renamed to include the word "master"..
  56. bool isMaster = commandLine.containsIgnoreCase ("master")
  57. || File::getSpecialLocation (File::currentApplicationFile)
  58. .getFileName().containsIgnoreCase ("master");
  59. if (isMaster)
  60. mainWindows.add (new MainWindow (properties));
  61. #endif
  62. mainWindows.add (new MainWindow (properties, 0));
  63. Desktop::getInstance().setScreenSaverEnabled (false);
  64. }
  65. void shutdown() override
  66. {
  67. mainWindows.clear();
  68. properties.saveIfNeeded();
  69. }
  70. void systemRequestedQuit() override
  71. {
  72. quit();
  73. }
  74. //==============================================================================
  75. struct MainWindow : public DocumentWindow
  76. {
  77. MainWindow (PropertiesFile& props)
  78. : DocumentWindow ("JUCE Networked Graphics Demo - Master", Colours::white, DocumentWindow::allButtons)
  79. {
  80. setUsingNativeTitleBar (true);
  81. setContentOwned (new MasterContentComponent (props), true);
  82. setBounds (100, 50, getWidth(), getHeight());
  83. setResizable (true, false);
  84. setVisible (true);
  85. glContext.attachTo (*this);
  86. }
  87. MainWindow (PropertiesFile& props, int windowIndex)
  88. : DocumentWindow ("JUCE Networked Graphics Demo", Colours::black, DocumentWindow::allButtons)
  89. {
  90. setUsingNativeTitleBar (true);
  91. setContentOwned (new SlaveCanvasComponent (props, windowIndex), true);
  92. setBounds (500, 100, getWidth(), getHeight());
  93. setResizable (true, false);
  94. setVisible (true);
  95. #if ! JUCE_IOS
  96. glContext.attachTo (*this);
  97. #endif
  98. #if JUCE_IOS || JUCE_ANDROID
  99. setFullScreen (true);
  100. #endif
  101. }
  102. ~MainWindow()
  103. {
  104. glContext.detach();
  105. }
  106. void closeButtonPressed() override
  107. {
  108. JUCEApplication::getInstance()->systemRequestedQuit();
  109. }
  110. OpenGLContext glContext;
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  112. };
  113. static PropertiesFile::Options getPropertyFileOptions()
  114. {
  115. PropertiesFile::Options o;
  116. o.applicationName = "JUCE Network Graphics Demo";
  117. o.filenameSuffix = ".settings";
  118. o.folderName = "JUCE Network Graphics Demo";
  119. o.osxLibrarySubFolder = "Application Support/JUCE Network Graphics Demo";
  120. o.millisecondsBeforeSaving = 2000;
  121. return o;
  122. }
  123. PropertiesFile properties;
  124. OwnedArray<MainWindow> mainWindows;
  125. };
  126. //==============================================================================
  127. // This macro generates the main() routine that launches the app.
  128. START_JUCE_APPLICATION (NetworkGraphicsDemoApplication)