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.

151 lines
5.1KB

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