Channels.cpp 12 KB

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