Main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ==============================================================================
  3. This file was auto-generated by the Introjucer!
  4. It contains the basic startup code for a Juce application.
  5. ==============================================================================
  6. */
  7. // NOTE: in order to avoid "multiple definitions of WinMain()" compiler error
  8. // arrange that "windows.h" be included before "JuceHeader.h" in all contexts
  9. // also arrange to include "JuceHeader.h" before any "*Component.h"
  10. #include "LinJam.h" // includes "windows.h" and "JuceHeader.h"
  11. #include "Constants.h"
  12. #include "MainContent.h"
  13. #include "./Trace/TraceMain.h"
  14. class LinJamApplication : public JUCEApplication , public NJClient , MultiTimer
  15. {
  16. public:
  17. LinJamApplication() {}
  18. void initialise(const String& command_line) override
  19. {
  20. this->mainWindow = new MainWindow() ;
  21. MainContent* main_content = (MainContent*)this->mainWindow->mainContent ;
  22. if (LinJam::Initialize(this , main_content , command_line))
  23. {
  24. // start NJClient pump and GUI update timers
  25. startTimer(CLIENT::CLIENT_TIMER_ID , CLIENT::CLIENT_DRIVER_IVL) ;
  26. startTimer(CLIENT::GUI_TIMER_HI_ID , CLIENT::GUI_UPDATE_HI_IVL) ;
  27. startTimer(CLIENT::GUI_TIMER_LO_ID , CLIENT::GUI_UPDATE_LO_IVL) ;
  28. }
  29. else quit() ;
  30. }
  31. void anotherInstanceStarted(const String& command_line) override
  32. {
  33. // When another instance of the app is launched while this one is running,
  34. // this method is invoked, and the commandLine parameter tells you what
  35. // the other instance's command-line arguments were.
  36. }
  37. void shutdown() override
  38. {
  39. LinJam::Shutdown() ;
  40. this->mainWindow = nullptr ;
  41. DEBUG_TRACE_SHUTDOWN
  42. }
  43. void systemRequestedQuit() override { this->quit() ; }
  44. const String getApplicationName() override { return ProjectInfo::projectName ; }
  45. const String getApplicationVersion() override { return ProjectInfo::versionString ; }
  46. bool moreThanOneInstanceAllowed() override { return false ; }
  47. /*
  48. This class implements the desktop window that contains an instance of
  49. our MainContentComponent class.
  50. */
  51. class MainWindow : public DocumentWindow
  52. {
  53. friend class LinJamApplication ;
  54. public:
  55. MainWindow() : DocumentWindow(GUI::APP_NAME ,
  56. Colour(0xff202020) ,
  57. DocumentWindow::allButtons)
  58. {
  59. // config button (managed and handled by MainContent)
  60. this->configButton = new TextButton("configButton") ;
  61. Component::addAndMakeVisible(this->configButton) ;
  62. // main content
  63. this->mainContent = new MainContent(this , this->configButton) ;
  64. this->mainContent->setComponentID(GUI::CONTENT_GUI_ID) ;
  65. setContentOwned(this->mainContent , true) ;
  66. // this main desktop window
  67. #ifdef _MAC
  68. setTitleBarButtonsRequired(DocumentWindow::allButtons , true) ;
  69. #endif // _MAC
  70. setTitleBarHeight(GUI::TITLEBAR_H) ;
  71. // setIcon(const Image &imageToUse) ;
  72. centreWithSize(getWidth() , getHeight()) ;
  73. setVisible(true) ;
  74. }
  75. ~MainWindow()
  76. {
  77. this->mainContent = nullptr ;
  78. this->configButton = nullptr ;
  79. }
  80. void closeButtonPressed() { JUCEApplication::getInstance()->systemRequestedQuit() ; }
  81. private:
  82. ScopedPointer<MainContent> mainContent ;
  83. ScopedPointer<TextButton> configButton ;
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
  85. } ;
  86. private:
  87. ScopedPointer<MainWindow> mainWindow ;
  88. void timerCallback(int timer_id) override { LinJam::HandleTimer(timer_id) ; }
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinJamApplication)
  90. } ;
  91. START_JUCE_APPLICATION(LinJamApplication)