ConfigChannel.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 "LinJam.h"
  15. //[/Headers]
  16. #include "ConfigChannel.h"
  17. //[MiscUserDefs] You can add your own user definitions and misc code here...
  18. //[/MiscUserDefs]
  19. //==============================================================================
  20. ConfigChannel::ConfigChannel (ValueTree channel_store)
  21. : channelStore(channel_store)
  22. {
  23. addAndMakeVisible (nameLabel = new Label ("nameLabel",
  24. TRANS("channel name")));
  25. nameLabel->setFont (Font (15.00f, Font::plain));
  26. nameLabel->setJustificationType (Justification::centredTop);
  27. nameLabel->setEditable (false, false, false);
  28. nameLabel->setColour (Label::textColourId, Colours::white);
  29. nameLabel->setColour (TextEditor::textColourId, Colours::black);
  30. nameLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  31. addAndMakeVisible (nameText = new TextEditor ("nameText"));
  32. nameText->setExplicitFocusOrder (1);
  33. nameText->setMultiLine (false);
  34. nameText->setReturnKeyStartsNewLine (false);
  35. nameText->setReadOnly (false);
  36. nameText->setScrollbarsShown (false);
  37. nameText->setCaretVisible (true);
  38. nameText->setPopupMenuEnabled (false);
  39. nameText->setColour (TextEditor::textColourId, Colours::grey);
  40. nameText->setColour (TextEditor::backgroundColourId, Colours::black);
  41. nameText->setText (String());
  42. addAndMakeVisible (monoButton = new ToggleButton ("monoButton"));
  43. monoButton->setExplicitFocusOrder (2);
  44. monoButton->setButtonText (TRANS("mono"));
  45. monoButton->setRadioGroupId (1);
  46. monoButton->setToggleState (true, dontSendNotification);
  47. monoButton->setColour (ToggleButton::textColourId, Colours::white);
  48. addAndMakeVisible (stereoButton = new ToggleButton ("stereoButton"));
  49. stereoButton->setExplicitFocusOrder (3);
  50. stereoButton->setButtonText (TRANS("stereo"));
  51. stereoButton->setRadioGroupId (1);
  52. stereoButton->setColour (ToggleButton::textColourId, Colours::white);
  53. addAndMakeVisible (inputLabel = new Label ("inputLabel",
  54. TRANS("input channel")));
  55. inputLabel->setFont (Font (15.00f, Font::plain));
  56. inputLabel->setJustificationType (Justification::centredTop);
  57. inputLabel->setEditable (false, false, false);
  58. inputLabel->setColour (Label::textColourId, Colours::white);
  59. inputLabel->setColour (TextEditor::textColourId, Colours::black);
  60. inputLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  61. addAndMakeVisible (channelSelect = new ComboBox ("channelSelect"));
  62. channelSelect->setExplicitFocusOrder (4);
  63. channelSelect->setEditableText (false);
  64. channelSelect->setJustificationType (Justification::centredLeft);
  65. channelSelect->setTextWhenNothingSelected (TRANS("(select channel)"));
  66. channelSelect->setTextWhenNoChoicesAvailable (TRANS("(no free channels)"));
  67. channelSelect->addListener (this);
  68. addAndMakeVisible (okButton = new TextButton ("okButton"));
  69. okButton->setExplicitFocusOrder (5);
  70. okButton->setButtonText (TRANS("ok"));
  71. addAndMakeVisible (cancelButton = new TextButton ("cancelButton"));
  72. cancelButton->setExplicitFocusOrder (6);
  73. cancelButton->setButtonText (TRANS("cancel"));
  74. //[UserPreSize]
  75. //[/UserPreSize]
  76. setSize (200, 200);
  77. //[Constructor] You can add your own custom stuff here..
  78. this->nameText ->setColour(CaretComponent::caretColourId , Colours::white) ;
  79. this->channelSelect->setColour(ComboBox::textColourId , Colours::grey) ;
  80. this->channelSelect->setColour(ComboBox::backgroundColourId , Colours::black) ;
  81. // TODO: change option colors
  82. // set channel config state
  83. this->channelStore = channel_store ;
  84. this->isNewChannel = (channel_store.getType() == CONFIG::NEWCHANNEL_ID) ;
  85. String client_name = str(channel_store[CONFIG::CHANNEL_NAME_ID]) ;
  86. this->sourceN = int(channel_store[CONFIG::SOURCE_N_ID ]) ;
  87. this->isStereo = int(channel_store[CONFIG::STEREO_ID ]) != CONFIG::MONO ;
  88. // set GUI state and populate input select options
  89. this->nameText ->setText(LinJamConfig::TrimStereoName(client_name)) ;
  90. this->stereoButton->setToggleState(this->isStereo , juce::dontSendNotification) ;
  91. createChannelSelectOptions() ; populateChannelSelect() ;
  92. // local event handlers
  93. this->monoButton ->addListener(this) ;
  94. this->stereoButton->addListener(this) ;
  95. this->okButton ->addListener(this) ;
  96. this->cancelButton->addListener(this) ;
  97. //[/Constructor]
  98. }
  99. ConfigChannel::~ConfigChannel()
  100. {
  101. //[Destructor_pre]. You can add your own custom destruction code here..
  102. //[/Destructor_pre]
  103. nameLabel = nullptr;
  104. nameText = nullptr;
  105. monoButton = nullptr;
  106. stereoButton = nullptr;
  107. inputLabel = nullptr;
  108. channelSelect = nullptr;
  109. okButton = nullptr;
  110. cancelButton = nullptr;
  111. //[Destructor]. You can add your own custom destruction code here..
  112. //[/Destructor]
  113. }
  114. //==============================================================================
  115. void ConfigChannel::paint (Graphics& g)
  116. {
  117. //[UserPrePaint] Add your own custom painting code here..
  118. //[/UserPrePaint]
  119. g.setColour (Colour (0xff202020));
  120. g.fillRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), static_cast<float> (getHeight() - 0), 10.000f);
  121. g.setColour (Colours::white);
  122. g.drawRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), static_cast<float> (getHeight() - 0), 10.000f, 1.000f);
  123. //[UserPaint] Add your own custom painting code here..
  124. //[/UserPaint]
  125. }
  126. void ConfigChannel::resized()
  127. {
  128. //[UserPreResize] Add your own custom resize code here..
  129. //[/UserPreResize]
  130. nameLabel->setBounds (24, 24, 152, 16);
  131. nameText->setBounds (24, 44, 152, 16);
  132. monoButton->setBounds (34, 64, 64, 16);
  133. stereoButton->setBounds (102, 64, 64, 16);
  134. inputLabel->setBounds (24, 84, 152, 16);
  135. channelSelect->setBounds (24, 104, 152, 16);
  136. okButton->setBounds (34, 152, 64, 24);
  137. cancelButton->setBounds (102, 152, 64, 24);
  138. //[UserResized] Add your own custom resize handling here..
  139. //[/UserResized]
  140. }
  141. void ConfigChannel::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  142. {
  143. //[UsercomboBoxChanged_Pre]
  144. //[/UsercomboBoxChanged_Pre]
  145. if (comboBoxThatHasChanged == channelSelect)
  146. {
  147. //[UserComboBoxCode_channelSelect] -- add your combo box handling code here..
  148. //[/UserComboBoxCode_channelSelect]
  149. }
  150. //[UsercomboBoxChanged_Post]
  151. //[/UsercomboBoxChanged_Post]
  152. }
  153. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  154. void ConfigChannel::buttonClicked(Button* a_button)
  155. {
  156. if (a_button == this->monoButton || a_button == this->stereoButton)
  157. {
  158. bool was_selected_stereo = this->isStereo ;
  159. this->isStereo = this->stereoButton->getToggleState() ;
  160. bool has_stereo_selection_changed = (was_selected_stereo != this->isStereo) ;
  161. if (has_stereo_selection_changed) populateChannelSelect() ;
  162. }
  163. else if (a_button == this->okButton)
  164. {
  165. String gui_name = this->nameText ->getText() ;
  166. int selection_n = this->channelSelect->getSelectedItemIndex() ;
  167. int stereo_status = (!this->isStereo) ? CONFIG::MONO : CONFIG::STEREO_L ;
  168. int source_n = (!this->isStereo) ? this->freeAudioSourceNs [selection_n] :
  169. this->freeAudioSourcePairNs[selection_n] ;
  170. String client_name = LinJamConfig::MakeStereoName(gui_name , stereo_status) ;
  171. // update existing channel asynchronously
  172. this->channelStore.setProperty(CONFIG::CHANNEL_NAME_ID , client_name , nullptr)
  173. .setProperty(CONFIG::SOURCE_N_ID , source_n , nullptr)
  174. .setProperty(CONFIG::STEREO_ID , stereo_status , nullptr) ;
  175. // or create new local channel
  176. if (this->isNewChannel) LinJam::AddLocalChannel(this->channelStore) ;
  177. ((CallOutBox*)getParentComponent())->dismiss() ;
  178. }
  179. else if (a_button == this->cancelButton)
  180. ((CallOutBox*)getParentComponent())->dismiss() ;
  181. }
  182. String ConfigChannel::makeMonoSelectOption(int channel_n)
  183. {
  184. int display_channel_n = channel_n + 1 ;
  185. return "input " + String(display_channel_n) ;
  186. }
  187. String ConfigChannel::makeStereoSelectOption(int channel_n)
  188. {
  189. int display_channel_n = channel_n + 1 ;
  190. return "inputs " + String(display_channel_n) +
  191. " & " + String(display_channel_n + 1) ;
  192. }
  193. void ConfigChannel::createChannelSelectOptions()
  194. {
  195. this->freeAudioSourceNs = LinJam::GetFreeAudioSources() ;
  196. this->freeAudioSourcePairNs = LinJam::GetFreeAudioSourcePairs() ;
  197. int n_channels = this->freeAudioSourceNs.size() ;
  198. int n_channel_pairs = this->freeAudioSourcePairNs.size() ;
  199. for (int free_channel_n = 0 ; free_channel_n < n_channels ; ++free_channel_n)
  200. {
  201. int channel_n = this->freeAudioSourceNs.getUnchecked(free_channel_n) ;
  202. this->freeAudioSourceOptions.add(makeMonoSelectOption(channel_n)) ;
  203. }
  204. for (int free_pair_n = 0 ; free_pair_n < n_channel_pairs ; ++free_pair_n)
  205. {
  206. int channel_n = this->freeAudioSourcePairNs.getUnchecked(free_pair_n) ;
  207. this->freeAudioSourcePairOptions.add(makeStereoSelectOption(channel_n)) ;
  208. }
  209. }
  210. void ConfigChannel::populateChannelSelect()
  211. {
  212. this->channelSelect->clear() ;
  213. StringArray options = (!this->isStereo) ?
  214. this->freeAudioSourceOptions :
  215. this->freeAudioSourcePairOptions ;
  216. this->channelSelect->addItemList(options , 1) ;
  217. // pre-select current input option for existing channel
  218. int preselection_n = (this->isNewChannel) ? 0 :
  219. (!this->isStereo) ?
  220. this->freeAudioSourceNs .indexOf(this->sourceN) :
  221. this->freeAudioSourcePairNs.indexOf(this->sourceN) ;
  222. this->channelSelect->setSelectedItemIndex((~preselection_n) ? preselection_n : 0) ;
  223. }
  224. //[/MiscUserCode]
  225. //==============================================================================
  226. #if 0
  227. /* -- Introjucer information section --
  228. This is where the Introjucer stores the metadata that describe this GUI layout, so
  229. make changes in here at your peril!
  230. BEGIN_JUCER_METADATA
  231. <JUCER_COMPONENT documentType="Component" className="ConfigChannel" componentName=""
  232. parentClasses="public Component, public ButtonListener" constructorParams="ValueTree channel_store"
  233. variableInitialisers="channelStore(channel_store)" snapPixels="8"
  234. snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="1"
  235. initialWidth="200" initialHeight="200">
  236. <BACKGROUND backgroundColour="0">
  237. <ROUNDRECT pos="0 0 0M 0M" cornerSize="10" fill="solid: ff202020" hasStroke="1"
  238. stroke="1, mitered, butt" strokeColour="solid: ffffffff"/>
  239. </BACKGROUND>
  240. <LABEL name="nameLabel" id="eb57b2d805d2eff8" memberName="nameLabel"
  241. virtualName="" explicitFocusOrder="0" pos="24 24 152 16" textCol="ffffffff"
  242. edTextCol="ff000000" edBkgCol="0" labelText="channel name" editableSingleClick="0"
  243. editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
  244. fontsize="15" bold="0" italic="0" justification="12"/>
  245. <TEXTEDITOR name="nameText" id="f721d2f898b8b762" memberName="nameText" virtualName=""
  246. explicitFocusOrder="1" pos="24 44 152 16" textcol="ff808080"
  247. bkgcol="ff000000" initialText="" multiline="0" retKeyStartsLine="0"
  248. readonly="0" scrollbars="0" caret="1" popupmenu="0"/>
  249. <TOGGLEBUTTON name="monoButton" id="f830997aaae8295f" memberName="monoButton"
  250. virtualName="" explicitFocusOrder="2" pos="34 64 64 16" txtcol="ffffffff"
  251. buttonText="mono" connectedEdges="0" needsCallback="0" radioGroupId="1"
  252. state="1"/>
  253. <TOGGLEBUTTON name="stereoButton" id="f0fa912c23c0064f" memberName="stereoButton"
  254. virtualName="" explicitFocusOrder="3" pos="102 64 64 16" txtcol="ffffffff"
  255. buttonText="stereo" connectedEdges="0" needsCallback="0" radioGroupId="1"
  256. state="0"/>
  257. <LABEL name="inputLabel" id="9d36c2a259889270" memberName="inputLabel"
  258. virtualName="" explicitFocusOrder="0" pos="24 84 152 16" textCol="ffffffff"
  259. edTextCol="ff000000" edBkgCol="0" labelText="input channel" editableSingleClick="0"
  260. editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
  261. fontsize="15" bold="0" italic="0" justification="12"/>
  262. <COMBOBOX name="channelSelect" id="7a9c3a4f62832f42" memberName="channelSelect"
  263. virtualName="" explicitFocusOrder="4" pos="24 104 152 16" editable="0"
  264. layout="33" items="" textWhenNonSelected="(select channel)" textWhenNoItems="(no free channels)"/>
  265. <TEXTBUTTON name="okButton" id="504a4ad212ccb744" memberName="okButton" virtualName=""
  266. explicitFocusOrder="5" pos="34 152 64 24" buttonText="ok" connectedEdges="0"
  267. needsCallback="0" radioGroupId="0"/>
  268. <TEXTBUTTON name="cancelButton" id="4ec3eac10517595b" memberName="cancelButton"
  269. virtualName="" explicitFocusOrder="6" pos="102 152 64 24" buttonText="cancel"
  270. connectedEdges="0" needsCallback="0" radioGroupId="0"/>
  271. </JUCER_COMPONENT>
  272. END_JUCER_METADATA
  273. */
  274. #endif
  275. //[EndFile] You can add extra defines here...
  276. //[/EndFile]