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.

158 lines
5.4KB

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