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.

159 lines
5.4KB

  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 getBroadcastIPAddress()
  23. {
  24. return IPAddress::getLocalAddress().toString().upToLastOccurrenceOf (".", false, false) + ".255";
  25. }
  26. static const int masterPortNumber = 9001; // the UDP port the master sends on / the clients receive.
  27. static const int clientPortNumber = 9002; // the UDP port the clients send on / the master receives.
  28. static const String canvasStateOSCAddress = "/juce/nfd/canvasState";
  29. static const String newClientOSCAddress = "/juce/nfd/newClient";
  30. static const String userInputOSCAddress = "/juce/nfd/userInput";
  31. };
  32. #include "SharedCanvas.h"
  33. #include "SlaveComponent.h"
  34. #include "Demos.h"
  35. #include "MasterComponent.h"
  36. //==============================================================================
  37. class NetworkGraphicsDemoApplication : public JUCEApplication
  38. {
  39. public:
  40. NetworkGraphicsDemoApplication() : properties (getPropertyFileOptions())
  41. {}
  42. const String getApplicationName() override { return ProjectInfo::projectName; }
  43. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  44. bool moreThanOneInstanceAllowed() override { return true; }
  45. void anotherInstanceStarted (const String&) override {}
  46. //==============================================================================
  47. void initialise (const String& commandLine) override
  48. {
  49. #if ! JUCE_IOS && ! JUCE_ANDROID
  50. // Run as the master if we have a command-line flag "master" or if the exe itself
  51. // has been renamed to include the word "master"..
  52. bool isMaster = commandLine.containsIgnoreCase ("master")
  53. || File::getSpecialLocation (File::currentApplicationFile)
  54. .getFileName().containsIgnoreCase ("master");
  55. if (isMaster)
  56. mainWindows.add (new MainWindow (properties));
  57. #endif
  58. mainWindows.add (new MainWindow (properties, 0));
  59. Desktop::getInstance().setScreenSaverEnabled (false);
  60. }
  61. void shutdown() override
  62. {
  63. mainWindows.clear();
  64. properties.saveIfNeeded();
  65. }
  66. void systemRequestedQuit() override
  67. {
  68. quit();
  69. }
  70. //==============================================================================
  71. struct MainWindow : public DocumentWindow
  72. {
  73. MainWindow (PropertiesFile& props)
  74. : DocumentWindow ("JUCE Networked Graphics Demo - Master", Colours::white, DocumentWindow::allButtons)
  75. {
  76. setUsingNativeTitleBar (true);
  77. setContentOwned (new MasterContentComponent (props), true);
  78. setBounds (100, 50, getWidth(), getHeight());
  79. setResizable (true, false);
  80. setVisible (true);
  81. glContext.attachTo (*this);
  82. }
  83. MainWindow (PropertiesFile& props, int windowIndex)
  84. : DocumentWindow ("JUCE Networked Graphics Demo", Colours::black, DocumentWindow::allButtons)
  85. {
  86. setUsingNativeTitleBar (true);
  87. setContentOwned (new SlaveCanvasComponent (props, windowIndex), true);
  88. setBounds (500, 100, getWidth(), getHeight());
  89. setResizable (true, false);
  90. setVisible (true);
  91. #if ! JUCE_IOS
  92. glContext.attachTo (*this);
  93. #endif
  94. #if JUCE_IOS || JUCE_ANDROID
  95. setFullScreen (true);
  96. #endif
  97. }
  98. ~MainWindow()
  99. {
  100. glContext.detach();
  101. }
  102. void closeButtonPressed() override
  103. {
  104. JUCEApplication::getInstance()->systemRequestedQuit();
  105. }
  106. OpenGLContext glContext;
  107. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  108. };
  109. static PropertiesFile::Options getPropertyFileOptions()
  110. {
  111. PropertiesFile::Options o;
  112. o.applicationName = "JUCE Network Graphics Demo";
  113. o.filenameSuffix = ".settings";
  114. o.folderName = "JUCE Network Graphics Demo";
  115. o.osxLibrarySubFolder = "Application Support/JUCE Network Graphics Demo";
  116. o.millisecondsBeforeSaving = 2000;
  117. return o;
  118. }
  119. PropertiesFile properties;
  120. OwnedArray<MainWindow> mainWindows;
  121. };
  122. //==============================================================================
  123. // This macro generates the main() routine that launches the app.
  124. START_JUCE_APPLICATION (NetworkGraphicsDemoApplication)