Channels.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. ==============================================================================
  3. This is an automatically generated GUI class created by the Introjucer!
  4. Be careful when adding custom code to these files, as only the code within
  5. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  6. and re-saved.
  7. Created with Introjucer version: 3.1.1
  8. ------------------------------------------------------------------------------
  9. The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  10. Copyright 2004-13 by Raw Material Software Ltd.
  11. ==============================================================================
  12. */
  13. //[Headers] You can add your own extra header files here...
  14. #include "LinJamConfig.h"
  15. #include "Mixer.h"
  16. #include "ConfigChannel.h"
  17. #include "./Trace/TraceChannels.h"
  18. //[/Headers]
  19. #include "Channels.h"
  20. //[MiscUserDefs] You can add your own user definitions and misc code here...
  21. //[/MiscUserDefs]
  22. //==============================================================================
  23. Channels::Channels ()
  24. {
  25. //[Constructor_pre] You can add your own custom stuff here..
  26. //[/Constructor_pre]
  27. addAndMakeVisible (channelsLabel = new Label ("channelsLabel",
  28. String()));
  29. channelsLabel->setFont (Font (12.00f, Font::plain));
  30. channelsLabel->setJustificationType (Justification::centredBottom);
  31. channelsLabel->setEditable (false, false, false);
  32. channelsLabel->setColour (Label::backgroundColourId, Colour (0x00000000));
  33. channelsLabel->setColour (Label::textColourId, Colours::grey);
  34. channelsLabel->setColour (Label::outlineColourId, Colour (0x00000000));
  35. channelsLabel->setColour (TextEditor::textColourId, Colour (0x00000000));
  36. channelsLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  37. addAndMakeVisible (addButton = new TextButton ("addButton"));
  38. addButton->setButtonText (TRANS("+"));
  39. addButton->setColour (TextButton::buttonColourId, Colour (0xff004000));
  40. addButton->setColour (TextButton::buttonOnColourId, Colours::green);
  41. addButton->setColour (TextButton::textColourOnId, Colours::lime);
  42. addButton->setColour (TextButton::textColourOffId, Colours::lime);
  43. addAndMakeVisible (expandButton = new TextButton ("expandButton"));
  44. expandButton->setButtonText (TRANS("+"));
  45. expandButton->setColour (TextButton::buttonColourId, Colour (0xff404000));
  46. expandButton->setColour (TextButton::buttonOnColourId, Colours::olive);
  47. expandButton->setColour (TextButton::textColourOnId, Colours::yellow);
  48. expandButton->setColour (TextButton::textColourOffId, Colours::yellow);
  49. addAndMakeVisible (ignoreButton = new TextButton ("ignoreButton"));
  50. ignoreButton->setButtonText (TRANS("X"));
  51. ignoreButton->setColour (TextButton::buttonColourId, Colour (0xff400000));
  52. ignoreButton->setColour (TextButton::buttonOnColourId, Colours::maroon);
  53. ignoreButton->setColour (TextButton::textColourOnId, Colours::red);
  54. ignoreButton->setColour (TextButton::textColourOffId, Colours::red);
  55. //[UserPreSize]
  56. this->channelsLabel->setAlwaysOnTop(true) ;
  57. this->addButton ->setAlwaysOnTop(true) ;
  58. this->expandButton ->setAlwaysOnTop(true) ;
  59. this->ignoreButton ->setAlwaysOnTop(true) ;
  60. //[/UserPreSize]
  61. setSize (67, 276);
  62. //[Constructor] You can add your own custom stuff here..
  63. //[/Constructor]
  64. }
  65. Channels::~Channels()
  66. {
  67. //[Destructor_pre]. You can add your own custom destruction code here..
  68. //[/Destructor_pre]
  69. channelsLabel = nullptr;
  70. addButton = nullptr;
  71. expandButton = nullptr;
  72. ignoreButton = nullptr;
  73. //[Destructor]. You can add your own custom destruction code here..
  74. deleteAllChildren() ;
  75. //[/Destructor]
  76. }
  77. //==============================================================================
  78. void Channels::paint (Graphics& g)
  79. {
  80. //[UserPrePaint] Add your own custom painting code here..
  81. //[/UserPrePaint]
  82. g.setColour (Colour (0xff101010));
  83. g.fillRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), static_cast<float> (getHeight() - 0), 10.000f);
  84. g.setColour (Colours::white);
  85. g.drawRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), static_cast<float> (getHeight() - 0), 10.000f, 1.000f);
  86. //[UserPaint] Add your own custom painting code here..
  87. //[/UserPaint]
  88. }
  89. void Channels::resized()
  90. {
  91. //[UserPreResize] Add your own custom resize code here..
  92. //[/UserPreResize]
  93. channelsLabel->setBounds (4, 4, getWidth() - 8, 12);
  94. addButton->setBounds (getWidth() - 15, 0, 15, 16);
  95. expandButton->setBounds (getWidth() - 15, 0, 15, 16);
  96. ignoreButton->setBounds (getWidth() - 15, 16, 15, 16);
  97. //[UserResized] Add your own custom resize handling here..
  98. // position add/config/expand buttons
  99. int btn_x = getWidth() - GUI::HOVER_BTN_W ;
  100. int btn_y = 0 ;
  101. int btn_w = GUI::HOVER_BTN_W ;
  102. int btn_h = GUI::HOVER_BTN_H ;
  103. this->addButton ->setBounds(btn_x , btn_y , btn_w , btn_h) ;
  104. this->expandButton->setBounds(btn_x , btn_y , btn_w , btn_h) ;
  105. this->ignoreButton->setBounds(btn_x , btn_y , btn_w , btn_h) ;
  106. // resize this container
  107. int n_channels = getNumChannels() ;
  108. int channels_w = GUI::MIXERGROUP_W((n_channels)? n_channels : 1) ;
  109. int channels_h = GUI::MIXERGROUP_H ;
  110. setSize(channels_w , channels_h) ;
  111. // shift child channels
  112. for (int channel_n = 0 ; channel_n < n_channels ; ++channel_n)
  113. {
  114. int channel_x = GUI::MIXERGROUP_W(channel_n) ;
  115. getChildComponent(channel_n)->setTopLeftPosition(channel_x , GUI::CHANNEL_Y) ;
  116. }
  117. // update mixer layout
  118. Mixer* mixer = (Mixer*)getParentComponent() ; if (mixer) mixer->resized() ;
  119. //[/UserResized]
  120. }
  121. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  122. /* Channels class public instance methods */
  123. bool Channels::addChannel(ValueTree channel_store)
  124. {
  125. DEBUG_TRACE_ADD_CHANNEL_GUI_FAIL
  126. // ensure GUI for this channel does not already exist
  127. Identifier channel_id = channel_store.getType() ;
  128. if (!channel_store.isValid() || getChannel(channel_id)) return false ;
  129. // hide stereo slave channels
  130. if (int(channel_store[CONFIG::STEREO_ID]) == CONFIG::STEREO_R) return false ;
  131. // create channel GUI
  132. Channel* channel = newChannel(channel_store) ;
  133. addChildAndSetID(channel , STRING(channel_id)) ;
  134. channel->toFront(false) ;
  135. // resize and shift channel slices
  136. resized() ;
  137. DEBUG_TRACE_ADD_CHANNEL_GUI
  138. return true ;
  139. }
  140. void Channels::removeChannel(Identifier channel_id)
  141. {
  142. DEBUG_TRACE_REMOVE_CHANNEL_GUI
  143. // destroy channel , resize , and shift channel slices
  144. Component* channel = getChannel(channel_id) ;
  145. if (channel) { delete channel ; resized() ; }
  146. }
  147. int Channels::getNumChannels()
  148. {
  149. return getNumChildComponents() - GUI::N_STATIC_CHANNELS_CHILDREN ;
  150. }
  151. /* Channels class protected instance methods */
  152. Channel* Channels::getChannel(Identifier channel_id)
  153. {
  154. return (Channel*)findChildWithID(StringRef(STRING(channel_id))) ;
  155. }
  156. /* MasterChannels , LocalChannels , RemoteChannels classes public class methods */
  157. MasterChannels::MasterChannels()
  158. {
  159. this->channelsLabel->setText(GUI::MASTERS_LABEL_TEXT , juce::dontSendNotification) ;
  160. this->addButton ->setVisible(false) ;
  161. this->expandButton ->setVisible(false) ;
  162. this->ignoreButton ->setVisible(false) ;
  163. }
  164. LocalChannels::LocalChannels()
  165. {
  166. this->channelsLabel->setText(GUI::LOCALS_LABEL_TEXT , juce::dontSendNotification) ;
  167. this->addButton ->addListener(this) ;
  168. this->expandButton ->setVisible(false) ;
  169. this->ignoreButton ->setVisible(false) ;
  170. }
  171. RemoteChannels::RemoteChannels(ValueTree user_store , ValueTree blacklist_store)
  172. : userStore(user_store) , blacklistStore(blacklist_store)
  173. {
  174. this->channelsLabel->setText(STRING(user_store.getType()) , juce::dontSendNotification) ;
  175. this->expandButton ->addListener(this) ;
  176. this->ignoreButton ->addListener(this) ;
  177. this->addButton ->setVisible(false) ;
  178. this->isExpanded = false ;
  179. }
  180. /* MasterChannels , LocalChannels , RemoteChannels classes private instance methods */
  181. void LocalChannels::buttonClicked(Button* a_button)
  182. {
  183. if (a_button == this->addButton)
  184. {
  185. ConfigChannel* configChannel = new ConfigChannel(LinJamConfig::NewChannel()) ;
  186. Component* mixer = getParentComponent() ;
  187. Component* mainContent = mixer->getParentComponent() ;
  188. // compute CallOutBox arrow target posistion
  189. int modalX = mixer->getX() + getX() + this->addButton->getX() + GUI::HOVER_BTN_XC ;
  190. int modalY = mixer->getY() + getY() + this->addButton->getY() + GUI::HOVER_BTN_YC ;
  191. juce::Rectangle<int> modalRect = juce::Rectangle<int>(modalX , modalY , 1 , 1) ;
  192. // instantiate ConfigChannel as CallOutBox
  193. configChannel->setSize(GUI::CHANNEL_CONFIG_W , GUI::CHANNEL_CONFIG_H) ;
  194. CallOutBox::launchAsynchronously(configChannel , modalRect , mainContent) ;
  195. }
  196. }
  197. void RemoteChannels::buttonClicked(Button* a_button)
  198. {
  199. if (a_button == this->expandButton) toggleExpandChannels() ;
  200. else if (a_button == this->ignoreButton) addUserToBlacklist() ;
  201. }
  202. void RemoteChannels::toggleExpandChannels()
  203. {
  204. this->isExpanded = !this->isExpanded ;
  205. // TODO: (issue #45)
  206. DBG("RemoteChannels::toggleExpandChannels() this->isExpanded=" + String(this->isExpanded)) ;
  207. }
  208. void RemoteChannels::addUserToBlacklist()
  209. {
  210. ValueTree blacklist_entry_store = ValueTree(this->userStore.getType()) ;
  211. this->blacklistStore.addChild(blacklist_entry_store , -1 , nullptr) ;
  212. }
  213. Channel* MasterChannels::newChannel(ValueTree channel_store)
  214. {
  215. return new MasterChannel(channel_store) ;
  216. }
  217. Channel* LocalChannels::newChannel(ValueTree channel_store)
  218. {
  219. return new LocalChannel(channel_store) ;
  220. }
  221. Channel* RemoteChannels::newChannel(ValueTree channel_store)
  222. {
  223. return new RemoteChannel(channel_store) ;
  224. }
  225. //[/MiscUserCode]
  226. //==============================================================================
  227. #if 0
  228. /* -- Introjucer information section --
  229. This is where the Introjucer stores the metadata that describe this GUI layout, so
  230. make changes in here at your peril!
  231. BEGIN_JUCER_METADATA
  232. <JUCER_COMPONENT documentType="Component" className="Channels" componentName=""
  233. parentClasses="public Component" constructorParams="" variableInitialisers=""
  234. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
  235. fixedSize="0" initialWidth="67" initialHeight="276">
  236. <BACKGROUND backgroundColour="0">
  237. <ROUNDRECT pos="0 0 0M 0M" cornerSize="10" fill="solid: ff101010" hasStroke="1"
  238. stroke="1, mitered, butt" strokeColour="solid: ffffffff"/>
  239. </BACKGROUND>
  240. <LABEL name="channelsLabel" id="11f182b0c62d16d1" memberName="channelsLabel"
  241. virtualName="" explicitFocusOrder="0" pos="4 4 8M 12" bkgCol="0"
  242. textCol="ff808080" outlineCol="0" edTextCol="0" edBkgCol="0"
  243. labelText="" editableSingleClick="0" editableDoubleClick="0"
  244. focusDiscardsChanges="0" fontname="Default font" fontsize="12"
  245. bold="0" italic="0" justification="20"/>
  246. <TEXTBUTTON name="addButton" id="e6ac05f3ca896afc" memberName="addButton"
  247. virtualName="" explicitFocusOrder="0" pos="15R 0 15 16" bgColOff="ff004000"
  248. bgColOn="ff008000" textCol="ff00ff00" textColOn="ff00ff00" buttonText="+"
  249. connectedEdges="0" needsCallback="0" radioGroupId="0"/>
  250. <TEXTBUTTON name="expandButton" id="b034e593677d00a0" memberName="expandButton"
  251. virtualName="" explicitFocusOrder="0" pos="15R 0 15 16" bgColOff="ff404000"
  252. bgColOn="ff808000" textCol="ffffff00" textColOn="ffffff00" buttonText="+"
  253. connectedEdges="0" needsCallback="0" radioGroupId="0"/>
  254. <TEXTBUTTON name="ignoreButton" id="4e531501a9190ef5" memberName="ignoreButton"
  255. virtualName="" explicitFocusOrder="0" pos="15R 16 15 16" bgColOff="ff400000"
  256. bgColOn="ff800000" textCol="ffff0000" textColOn="ffff0000" buttonText="X"
  257. connectedEdges="0" needsCallback="0" radioGroupId="0"/>
  258. </JUCER_COMPONENT>
  259. END_JUCER_METADATA
  260. */
  261. #endif
  262. //[EndFile] You can add extra defines here...
  263. //[/EndFile]