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.

166 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../JuceLibraryCode/JuceHeader.h"
  20. namespace
  21. {
  22. String getIPAddress()
  23. {
  24. Array<IPAddress> addresses;
  25. IPAddress::findAllAddresses (addresses);
  26. return addresses[1].toString();
  27. }
  28. String getBroadcastIPAddress()
  29. {
  30. return getIPAddress().upToLastOccurrenceOf (".", false, false) + ".255";
  31. }
  32. static const int masterPortNumber = 9001; // the UDP port the master sends on / the clients receive.
  33. static const int clientPortNumber = 9002; // the UDP port the clients send on / the master receives.
  34. static const String canvasStateOSCAddress = "/juce/nfd/canvasState";
  35. static const String newClientOSCAddress = "/juce/nfd/newClient";
  36. static const String userInputOSCAddress = "/juce/nfd/userInput";
  37. };
  38. #include "SharedCanvas.h"
  39. #include "SlaveComponent.h"
  40. #include "Demos.h"
  41. #include "MasterComponent.h"
  42. //==============================================================================
  43. class NetworkGraphicsDemoApplication : public JUCEApplication
  44. {
  45. public:
  46. NetworkGraphicsDemoApplication() : properties (getPropertyFileOptions())
  47. {}
  48. const String getApplicationName() override { return ProjectInfo::projectName; }
  49. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  50. bool moreThanOneInstanceAllowed() override { return true; }
  51. void anotherInstanceStarted (const String&) override {}
  52. //==============================================================================
  53. void initialise (const String& commandLine) override
  54. {
  55. #if ! JUCE_IOS && ! JUCE_ANDROID
  56. // Run as the master if we have a command-line flag "master" or if the exe itself
  57. // has been renamed to include the word "master"..
  58. bool isMaster = commandLine.containsIgnoreCase ("master")
  59. || File::getSpecialLocation (File::currentApplicationFile)
  60. .getFileName().containsIgnoreCase ("master");
  61. if (isMaster)
  62. mainWindows.add (new MainWindow (properties));
  63. #endif
  64. mainWindows.add (new MainWindow (properties, 0));
  65. Desktop::getInstance().setScreenSaverEnabled (false);
  66. }
  67. void shutdown() override
  68. {
  69. mainWindows.clear();
  70. properties.saveIfNeeded();
  71. }
  72. void systemRequestedQuit() override
  73. {
  74. quit();
  75. }
  76. //==============================================================================
  77. struct MainWindow : public DocumentWindow
  78. {
  79. MainWindow (PropertiesFile& props)
  80. : DocumentWindow ("JUCE Networked Graphics Demo - Master", Colours::white, DocumentWindow::allButtons)
  81. {
  82. setUsingNativeTitleBar (true);
  83. setContentOwned (new MasterContentComponent (props), true);
  84. setBounds (100, 50, getWidth(), getHeight());
  85. setResizable (true, false);
  86. setVisible (true);
  87. glContext.attachTo (*this);
  88. }
  89. MainWindow (PropertiesFile& props, int windowIndex)
  90. : DocumentWindow ("JUCE Networked Graphics Demo", Colours::black, DocumentWindow::allButtons)
  91. {
  92. setUsingNativeTitleBar (true);
  93. setContentOwned (new SlaveCanvasComponent (props, windowIndex), true);
  94. setBounds (500, 100, getWidth(), getHeight());
  95. setResizable (true, false);
  96. setVisible (true);
  97. #if ! JUCE_IOS
  98. glContext.attachTo (*this);
  99. #endif
  100. #if JUCE_IOS || JUCE_ANDROID
  101. setFullScreen (true);
  102. #endif
  103. }
  104. ~MainWindow()
  105. {
  106. glContext.detach();
  107. }
  108. void closeButtonPressed() override
  109. {
  110. JUCEApplication::getInstance()->systemRequestedQuit();
  111. }
  112. OpenGLContext glContext;
  113. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  114. };
  115. static PropertiesFile::Options getPropertyFileOptions()
  116. {
  117. PropertiesFile::Options o;
  118. o.applicationName = "JUCE Network Graphics Demo";
  119. o.filenameSuffix = ".settings";
  120. o.folderName = "JUCE Network Graphics Demo";
  121. o.osxLibrarySubFolder = "Application Support/JUCE Network Graphics Demo";
  122. o.millisecondsBeforeSaving = 2000;
  123. return o;
  124. }
  125. PropertiesFile properties;
  126. OwnedArray<MainWindow> mainWindows;
  127. };
  128. //==============================================================================
  129. // This macro generates the main() routine that launches the app.
  130. START_JUCE_APPLICATION (NetworkGraphicsDemoApplication)