Controls.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*\
  2. |*| Copyright 2015-2016 bill-auger <https://github.com/bill-auger/av-caster/issues>
  3. |*|
  4. |*| This file is part of the AvCaster program.
  5. |*|
  6. |*| AvCaster is free software: you can redistribute it and/or modify
  7. |*| it under the terms of the GNU General Public License version 3
  8. |*| as published by the Free Software Foundation.
  9. |*|
  10. |*| AvCaster is distributed in the hope that it will be useful,
  11. |*| but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. |*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. |*| GNU General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU General Public License
  16. |*| along with AvCaster. If not, see <http://www.gnu.org/licenses/>.
  17. \*/
  18. //[Headers] You can add your own extra header files here...
  19. #include "../Controllers/AvCaster.h"
  20. #include "../Trace/TraceControls.h"
  21. //[/Headers]
  22. #include "Controls.h"
  23. //[MiscUserDefs] You can add your own user definitions and misc code here...
  24. //[/MiscUserDefs]
  25. //==============================================================================
  26. Controls::Controls (MainContent* main_content)
  27. : mainContent(main_content)
  28. {
  29. //[Constructor_pre] You can add your own custom stuff here..
  30. //[/Constructor_pre]
  31. addAndMakeVisible (controlsGroup = new GroupComponent ("controlsGroup",
  32. TRANS("Controls")));
  33. controlsGroup->setColour (GroupComponent::outlineColourId, Colours::white);
  34. controlsGroup->setColour (GroupComponent::textColourId, Colours::white);
  35. addAndMakeVisible (screenToggle = new ToggleButton ("screenToggle"));
  36. screenToggle->setExplicitFocusOrder (1);
  37. screenToggle->setButtonText (TRANS("Screen"));
  38. screenToggle->addListener (this);
  39. screenToggle->setColour (ToggleButton::textColourId, Colours::white);
  40. addAndMakeVisible (cameraToggle = new ToggleButton ("cameraToggle"));
  41. cameraToggle->setExplicitFocusOrder (2);
  42. cameraToggle->setButtonText (TRANS("Camera"));
  43. cameraToggle->addListener (this);
  44. cameraToggle->setColour (ToggleButton::textColourId, Colours::white);
  45. addAndMakeVisible (textToggle = new ToggleButton ("textToggle"));
  46. textToggle->setExplicitFocusOrder (3);
  47. textToggle->setButtonText (TRANS("Text"));
  48. textToggle->addListener (this);
  49. textToggle->setColour (ToggleButton::textColourId, Colours::white);
  50. addAndMakeVisible (imageToggle = new ToggleButton ("imageToggle"));
  51. imageToggle->setExplicitFocusOrder (4);
  52. imageToggle->setButtonText (TRANS("Pause"));
  53. imageToggle->addListener (this);
  54. imageToggle->setColour (ToggleButton::textColourId, Colours::white);
  55. addAndMakeVisible (previewToggle = new ToggleButton ("previewToggle"));
  56. previewToggle->setExplicitFocusOrder (5);
  57. previewToggle->setButtonText (TRANS("Preview"));
  58. previewToggle->addListener (this);
  59. previewToggle->setColour (ToggleButton::textColourId, Colours::white);
  60. addAndMakeVisible (audioToggle = new ToggleButton ("audioToggle"));
  61. audioToggle->setExplicitFocusOrder (6);
  62. audioToggle->setButtonText (TRANS("Audio"));
  63. audioToggle->addListener (this);
  64. audioToggle->setColour (ToggleButton::textColourId, Colours::white);
  65. addAndMakeVisible (outputToggle = new ToggleButton ("outputToggle"));
  66. outputToggle->setExplicitFocusOrder (7);
  67. outputToggle->setButtonText (TRANS("Transmit"));
  68. outputToggle->addListener (this);
  69. outputToggle->setColour (ToggleButton::textColourId, Colours::white);
  70. addAndMakeVisible (presetsCombo = new ComboBox ("presetsCombo"));
  71. presetsCombo->setExplicitFocusOrder (8);
  72. presetsCombo->setEditableText (true);
  73. presetsCombo->setJustificationType (Justification::centredLeft);
  74. presetsCombo->setTextWhenNothingSelected (String());
  75. presetsCombo->setTextWhenNoChoicesAvailable (TRANS("(no choices)"));
  76. presetsCombo->addListener (this);
  77. addAndMakeVisible (configButton = new ImageButton ("configButton"));
  78. configButton->setExplicitFocusOrder (9);
  79. configButton->addListener (this);
  80. configButton->setImages (false, true, true,
  81. ImageCache::getFromMemory (BinaryData::config_png, BinaryData::config_pngSize), 1.000f, Colour (0x00000000),
  82. ImageCache::getFromMemory (BinaryData::confighover_png, BinaryData::confighover_pngSize), 1.000f, Colour (0x00000000),
  83. ImageCache::getFromMemory (BinaryData::configpushed_png, BinaryData::configpushed_pngSize), 1.000f, Colour (0x00000000));
  84. //[UserPreSize]
  85. //[/UserPreSize]
  86. setSize (1, 1);
  87. //[Constructor] You can add your own custom stuff here..
  88. this->mainContent->configureCombobox(this->presetsCombo) ;
  89. //[/Constructor]
  90. }
  91. Controls::~Controls()
  92. {
  93. //[Destructor_pre]. You can add your own custom destruction code here..
  94. //[/Destructor_pre]
  95. controlsGroup = nullptr;
  96. screenToggle = nullptr;
  97. cameraToggle = nullptr;
  98. textToggle = nullptr;
  99. imageToggle = nullptr;
  100. previewToggle = nullptr;
  101. audioToggle = nullptr;
  102. outputToggle = nullptr;
  103. presetsCombo = nullptr;
  104. configButton = nullptr;
  105. //[Destructor]. You can add your own custom destruction code here..
  106. //[/Destructor]
  107. }
  108. //==============================================================================
  109. void Controls::paint (Graphics& g)
  110. {
  111. //[UserPrePaint] Add your own custom painting code here..
  112. //[/UserPrePaint]
  113. g.setColour (Colour (0xff282828));
  114. g.fillRoundedRectangle (20.0f, 22.0f, static_cast<float> (getWidth() - 40), 52.0f, 4.000f);
  115. //[UserPaint] Add your own custom painting code here..
  116. //[/UserPaint]
  117. }
  118. void Controls::resized()
  119. {
  120. //[UserPreResize] Add your own custom resize code here..
  121. //[/UserPreResize]
  122. controlsGroup->setBounds (16, 12, getWidth() - 32, 64);
  123. screenToggle->setBounds (32, 36, 72, 24);
  124. cameraToggle->setBounds (108, 36, 76, 24);
  125. textToggle->setBounds (188, 36, 52, 24);
  126. imageToggle->setBounds (244, 36, 64, 24);
  127. previewToggle->setBounds (314, 36, 78, 24);
  128. audioToggle->setBounds (396, 36, 64, 24);
  129. outputToggle->setBounds (464, 36, 90, 24);
  130. presetsCombo->setBounds (560, 36, 128, 24);
  131. configButton->setBounds (696, 36, 24, 24);
  132. //[UserResized] Add your own custom resize handling here..
  133. //[/UserResized]
  134. }
  135. void Controls::buttonClicked (Button* buttonThatWasClicked)
  136. {
  137. //[UserbuttonClicked_Pre]
  138. Identifier key ;
  139. var value = var(buttonThatWasClicked->getToggleState()) ;
  140. //[/UserbuttonClicked_Pre]
  141. if (buttonThatWasClicked == screenToggle)
  142. {
  143. //[UserButtonCode_screenToggle] -- add your button handler code here..
  144. key = CONFIG::SCREEN_ID ;
  145. //[/UserButtonCode_screenToggle]
  146. }
  147. else if (buttonThatWasClicked == cameraToggle)
  148. {
  149. //[UserButtonCode_cameraToggle] -- add your button handler code here..
  150. key = CONFIG::CAMERA_ID ;
  151. //[/UserButtonCode_cameraToggle]
  152. }
  153. else if (buttonThatWasClicked == textToggle)
  154. {
  155. //[UserButtonCode_textToggle] -- add your button handler code here..
  156. key = CONFIG::TEXT_ID ;
  157. //[/UserButtonCode_textToggle]
  158. }
  159. else if (buttonThatWasClicked == imageToggle)
  160. {
  161. //[UserButtonCode_imageToggle] -- add your button handler code here..
  162. key = CONFIG::IMAGE_ID ;
  163. //[/UserButtonCode_imageToggle]
  164. }
  165. else if (buttonThatWasClicked == previewToggle)
  166. {
  167. //[UserButtonCode_previewToggle] -- add your button handler code here..
  168. key = CONFIG::PREVIEW_ID ;
  169. //[/UserButtonCode_previewToggle]
  170. }
  171. else if (buttonThatWasClicked == audioToggle)
  172. {
  173. //[UserButtonCode_audioToggle] -- add your button handler code here..
  174. key = CONFIG::AUDIO_ID ;
  175. //[/UserButtonCode_audioToggle]
  176. }
  177. else if (buttonThatWasClicked == outputToggle)
  178. {
  179. //[UserButtonCode_outputToggle] -- add your button handler code here..
  180. key = CONFIG::OUTPUT_ID ;
  181. //[/UserButtonCode_outputToggle]
  182. }
  183. else if (buttonThatWasClicked == configButton)
  184. {
  185. //[UserButtonCode_configButton] -- add your button handler code here..
  186. key = CONFIG::IS_PENDING_ID ;
  187. value = var(true) ;
  188. //[/UserButtonCode_configButton]
  189. }
  190. //[UserbuttonClicked_Post]
  191. AvCaster::SetValue(key , value) ;
  192. //[/UserbuttonClicked_Post]
  193. }
  194. void Controls::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  195. {
  196. //[UsercomboBoxChanged_Pre]
  197. //[/UsercomboBoxChanged_Pre]
  198. if (comboBoxThatHasChanged == presetsCombo)
  199. {
  200. //[UserComboBoxCode_presetsCombo] -- add your combo box handling code here..
  201. handlePresetsCombo() ; return ;
  202. //[/UserComboBoxCode_presetsCombo]
  203. }
  204. //[UsercomboBoxChanged_Post]
  205. //[/UsercomboBoxChanged_Post]
  206. }
  207. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  208. void Controls::broughtToFront() { loadConfig() ; }
  209. void Controls::initialize(ValueTree config_store , NamedValueSet& disabled_features)
  210. {
  211. this->configStore = config_store ;
  212. // disable controls per cli args
  213. this->screenToggle ->setEnabled(!disabled_features.contains(CONFIG::SCREEN_ID )) ;
  214. this->cameraToggle ->setEnabled(!disabled_features.contains(CONFIG::CAMERA_ID )) ;
  215. this->textToggle ->setEnabled(!disabled_features.contains(CONFIG::TEXT_ID )) ;
  216. this->imageToggle ->setEnabled(!disabled_features.contains(CONFIG::IMAGE_ID )) ;
  217. this->previewToggle->setEnabled(!disabled_features.contains(CONFIG::PREVIEW_ID)) ;
  218. this->audioToggle ->setEnabled(!disabled_features.contains(CONFIG::AUDIO_ID )) ;
  219. this->outputToggle ->setEnabled(!disabled_features.contains(CONFIG::OUTPUT_ID )) ;
  220. }
  221. void Controls::loadConfig()
  222. {
  223. bool is_screen_active = bool(this->configStore[CONFIG::SCREEN_ID ]) ;
  224. bool is_camera_active = bool(this->configStore[CONFIG::CAMERA_ID ]) ;
  225. bool is_text_active = bool(this->configStore[CONFIG::TEXT_ID ]) ;
  226. bool is_image_active = bool(this->configStore[CONFIG::IMAGE_ID ]) ;
  227. bool is_preview_active = bool(this->configStore[CONFIG::PREVIEW_ID ]) ;
  228. bool is_audio_active = bool(this->configStore[CONFIG::AUDIO_ID ]) ;
  229. bool is_output_active = bool(this->configStore[CONFIG::OUTPUT_ID ]) ;
  230. int sink_idx = int (this->configStore[CONFIG::OUTPUT_SINK_ID]) ;
  231. Colour screen_text_color = this->mainContent->btnTextColor(is_screen_active ) ;
  232. Colour screen_tick_color = this->mainContent->btnTickColor(is_screen_active ) ;
  233. Colour camera_text_color = this->mainContent->btnTextColor(is_camera_active ) ;
  234. Colour camera_tick_color = this->mainContent->btnTickColor(is_camera_active ) ;
  235. Colour text_text_color = this->mainContent->btnTextColor(is_text_active ) ;
  236. Colour text_tick_color = this->mainContent->btnTickColor(is_text_active ) ;
  237. Colour image_text_color = this->mainContent->btnTextColor(is_image_active ) ;
  238. Colour image_tick_color = this->mainContent->btnTickColor(is_image_active ) ;
  239. Colour preview_text_color = this->mainContent->btnTextColor(is_preview_active) ;
  240. Colour preview_tick_color = this->mainContent->btnTickColor(is_preview_active) ;
  241. Colour audio_text_color = this->mainContent->btnTextColor(is_audio_active ) ;
  242. Colour audio_tick_color = this->mainContent->btnTickColor(is_audio_active ) ;
  243. Colour output_text_color = this->mainContent->btnTextColor(is_output_active ) ;
  244. Colour output_tick_color = this->mainContent->btnTickColor(is_output_active ) ;
  245. String xmit_btn_text = (sink_idx == CONFIG::FILE_OUTPUT_IDX) ? GUI::FILE_XMIT_TEXT :
  246. (sink_idx == CONFIG::RTMP_OUTPUT_IDX) ? GUI::RTMP_XMIT_TEXT :
  247. String::empty ;
  248. DEBUG_TRACE_CONTROLS_LOAD_CONFIG
  249. this->screenToggle ->setToggleState (is_screen_active , juce::dontSendNotification) ;
  250. this->cameraToggle ->setToggleState (is_camera_active , juce::dontSendNotification) ;
  251. this->textToggle ->setToggleState (is_text_active , juce::dontSendNotification) ;
  252. this->imageToggle ->setToggleState (is_image_active , juce::dontSendNotification) ;
  253. this->previewToggle->setToggleState (is_preview_active , juce::dontSendNotification) ;
  254. this->audioToggle ->setToggleState (is_audio_active , juce::dontSendNotification) ;
  255. this->outputToggle ->setToggleState (is_output_active , juce::dontSendNotification) ;
  256. this->screenToggle ->setColour (ToggleButton::textColourId , screen_text_color ) ;
  257. this->screenToggle ->setColour (ToggleButton::tickColourId , screen_tick_color ) ;
  258. this->cameraToggle ->setColour (ToggleButton::textColourId , camera_text_color ) ;
  259. this->cameraToggle ->setColour (ToggleButton::tickColourId , camera_tick_color ) ;
  260. this->textToggle ->setColour (ToggleButton::textColourId , text_text_color ) ;
  261. this->textToggle ->setColour (ToggleButton::tickColourId , text_tick_color ) ;
  262. this->imageToggle ->setColour (ToggleButton::textColourId , image_text_color ) ;
  263. this->imageToggle ->setColour (ToggleButton::tickColourId , image_tick_color ) ;
  264. this->previewToggle->setColour (ToggleButton::textColourId , preview_text_color) ;
  265. this->previewToggle->setColour (ToggleButton::tickColourId , preview_tick_color) ;
  266. this->outputToggle ->setColour (ToggleButton::textColourId , output_text_color ) ;
  267. this->outputToggle ->setColour (ToggleButton::tickColourId , output_tick_color ) ;
  268. this->outputToggle ->setButtonText (xmit_btn_text) ;
  269. this->mainContent ->loadPresetsCombo(this->presetsCombo) ;
  270. this->presetsCombo ->setEditableText (false) ;
  271. }
  272. void Controls::handlePresetsCombo()
  273. {
  274. int option_n = this->presetsCombo->getSelectedItemIndex() ;
  275. // should loadConfig() asynchronously
  276. AvCaster::SetValue(CONFIG::PRESET_ID , option_n) ;
  277. }
  278. //[/MiscUserCode]
  279. //==============================================================================
  280. #if 0
  281. /* -- Projucer information section --
  282. This is where the Projucer stores the metadata that describe this GUI layout, so
  283. make changes in here at your peril!
  284. BEGIN_JUCER_METADATA
  285. <JUCER_COMPONENT documentType="Component" className="Controls" componentName=""
  286. parentClasses="public Component" constructorParams="MainContent* main_content"
  287. variableInitialisers="mainContent(main_content)" snapPixels="8"
  288. snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="0"
  289. initialWidth="1" initialHeight="1">
  290. <BACKGROUND backgroundColour="0">
  291. <ROUNDRECT pos="20 22 40M 52" cornerSize="4" fill="solid: ff282828" hasStroke="0"/>
  292. </BACKGROUND>
  293. <GROUPCOMPONENT name="controlsGroup" id="5f4ffe47101cb73b" memberName="controlsGroup"
  294. virtualName="" explicitFocusOrder="0" pos="16 12 32M 64" outlinecol="ffffffff"
  295. textcol="ffffffff" title="Controls"/>
  296. <TOGGLEBUTTON name="screenToggle" id="ccd6f9830703071b" memberName="screenToggle"
  297. virtualName="" explicitFocusOrder="1" pos="32 36 72 24" txtcol="ffffffff"
  298. buttonText="Screen" connectedEdges="0" needsCallback="1" radioGroupId="0"
  299. state="0"/>
  300. <TOGGLEBUTTON name="cameraToggle" id="844fe21cdd50ef0b" memberName="cameraToggle"
  301. virtualName="" explicitFocusOrder="2" pos="108 36 76 24" txtcol="ffffffff"
  302. buttonText="Camera" connectedEdges="0" needsCallback="1" radioGroupId="0"
  303. state="0"/>
  304. <TOGGLEBUTTON name="textToggle" id="a63786623ec66379" memberName="textToggle"
  305. virtualName="" explicitFocusOrder="3" pos="188 36 52 24" txtcol="ffffffff"
  306. buttonText="Text" connectedEdges="0" needsCallback="1" radioGroupId="0"
  307. state="0"/>
  308. <TOGGLEBUTTON name="imageToggle" id="6a66a5d35080c1cd" memberName="imageToggle"
  309. virtualName="" explicitFocusOrder="4" pos="244 36 64 24" txtcol="ffffffff"
  310. buttonText="Pause" connectedEdges="0" needsCallback="1" radioGroupId="0"
  311. state="0"/>
  312. <TOGGLEBUTTON name="previewToggle" id="692b72b8aa04c022" memberName="previewToggle"
  313. virtualName="" explicitFocusOrder="5" pos="314 36 78 24" txtcol="ffffffff"
  314. buttonText="Preview" connectedEdges="0" needsCallback="1" radioGroupId="0"
  315. state="0"/>
  316. <TOGGLEBUTTON name="audioToggle" id="36486443d32175e6" memberName="audioToggle"
  317. virtualName="" explicitFocusOrder="6" pos="396 36 64 24" txtcol="ffffffff"
  318. buttonText="Audio" connectedEdges="0" needsCallback="1" radioGroupId="0"
  319. state="0"/>
  320. <TOGGLEBUTTON name="outputToggle" id="22cf1f64bccae1df" memberName="outputToggle"
  321. virtualName="" explicitFocusOrder="7" pos="464 36 90 24" txtcol="ffffffff"
  322. buttonText="Transmit" connectedEdges="0" needsCallback="1" radioGroupId="0"
  323. state="0"/>
  324. <COMBOBOX name="presetsCombo" id="94d77976c2b2f37" memberName="presetsCombo"
  325. virtualName="" explicitFocusOrder="8" pos="560 36 128 24" editable="1"
  326. layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
  327. <IMAGEBUTTON name="configButton" id="19b48645d13bf310" memberName="configButton"
  328. virtualName="" explicitFocusOrder="9" pos="696 36 24 24" buttonText="configButton"
  329. connectedEdges="0" needsCallback="1" radioGroupId="0" keepProportions="1"
  330. resourceNormal="BinaryData::config_png" opacityNormal="1" colourNormal="0"
  331. resourceOver="BinaryData::confighover_png" opacityOver="1" colourOver="0"
  332. resourceDown="BinaryData::configpushed_png" opacityDown="1" colourDown="0"/>
  333. </JUCER_COMPONENT>
  334. END_JUCER_METADATA
  335. */
  336. #endif
  337. //[EndFile] You can add extra defines here...
  338. //[/EndFile]