annotate Source/GUI/ControlWindowMainComponent.cpp @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 19650b4076ee
children
rev   line source
andrewm@55 1 /*
andrewm@55 2 ==============================================================================
andrewm@55 3
andrewm@55 4 This is an automatically generated GUI class created by the Introjucer!
andrewm@55 5
andrewm@55 6 Be careful when adding custom code to these files, as only the code within
andrewm@55 7 the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
andrewm@55 8 and re-saved.
andrewm@55 9
andrewm@55 10 Created with Introjucer version: 3.1.0
andrewm@55 11
andrewm@55 12 ------------------------------------------------------------------------------
andrewm@55 13
andrewm@55 14 The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
andrewm@55 15 Copyright 2004-13 by Raw Material Software Ltd.
andrewm@55 16
andrewm@55 17 ==============================================================================
andrewm@55 18 */
andrewm@55 19
andrewm@55 20
andrewm@55 21 //[Headers] You can add your own extra header files here...
andrewm@55 22 #ifndef TOUCHKEYS_NO_GUI
andrewm@55 23 #include "KeyboardZoneComponent.h"
andrewm@55 24 //[/Headers]
andrewm@55 25
andrewm@55 26 #include "ControlWindowMainComponent.h"
andrewm@55 27
andrewm@55 28
andrewm@55 29 //[MiscUserDefs] You can add your own user definitions and misc code here...
andrewm@55 30 //[/MiscUserDefs]
andrewm@55 31
andrewm@55 32 //==============================================================================
andrewm@55 33 ControlWindowMainComponent::ControlWindowMainComponent ()
andrewm@55 34 : controller_(0)
andrewm@55 35 {
andrewm@55 36 addAndMakeVisible (midiInputGroupComponent = new GroupComponent ("MIDI input group",
andrewm@55 37 "MIDI Input"));
andrewm@55 38
andrewm@55 39 addAndMakeVisible (midiInputDeviceComboBox = new ComboBox ("MIDI input combo box"));
andrewm@55 40 midiInputDeviceComboBox->setEditableText (false);
andrewm@55 41 midiInputDeviceComboBox->setJustificationType (Justification::centredLeft);
andrewm@55 42 midiInputDeviceComboBox->setTextWhenNothingSelected (String::empty);
andrewm@55 43 midiInputDeviceComboBox->setTextWhenNoChoicesAvailable ("(no choices)");
andrewm@55 44 midiInputDeviceComboBox->addListener (this);
andrewm@55 45
andrewm@55 46 addAndMakeVisible (label = new Label ("new label",
andrewm@55 47 "Keyboard:"));
andrewm@55 48 label->setFont (Font (15.00f, Font::plain));
andrewm@55 49 label->setJustificationType (Justification::centredLeft);
andrewm@55 50 label->setEditable (false, false, false);
andrewm@55 51 label->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 52 label->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 53
andrewm@55 54 addAndMakeVisible (groupComponent = new GroupComponent ("new group",
andrewm@55 55 "TouchKeys"));
andrewm@55 56
andrewm@55 57 addAndMakeVisible (label2 = new Label ("new label",
andrewm@55 58 "Device:\n"));
andrewm@55 59 label2->setFont (Font (15.00f, Font::plain));
andrewm@55 60 label2->setJustificationType (Justification::centredLeft);
andrewm@55 61 label2->setEditable (false, false, false);
andrewm@55 62 label2->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 63 label2->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 64
andrewm@55 65 addAndMakeVisible (touchkeyDeviceComboBox = new ComboBox ("TouchKeys combo box"));
andrewm@55 66 touchkeyDeviceComboBox->setEditableText (false);
andrewm@55 67 touchkeyDeviceComboBox->setJustificationType (Justification::centredLeft);
andrewm@55 68 touchkeyDeviceComboBox->setTextWhenNothingSelected (String::empty);
andrewm@55 69 touchkeyDeviceComboBox->setTextWhenNoChoicesAvailable ("(no choices)");
andrewm@55 70 touchkeyDeviceComboBox->addListener (this);
andrewm@55 71
andrewm@55 72 addAndMakeVisible (label3 = new Label ("new label",
andrewm@55 73 "Status:\n"));
andrewm@55 74 label3->setFont (Font (15.00f, Font::plain));
andrewm@55 75 label3->setJustificationType (Justification::centredLeft);
andrewm@55 76 label3->setEditable (false, false, false);
andrewm@55 77 label3->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 78 label3->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 79
andrewm@55 80 addAndMakeVisible (touchkeyStartButton = new TextButton ("TouchKeys start button"));
andrewm@55 81 touchkeyStartButton->setButtonText ("Start");
andrewm@55 82 touchkeyStartButton->addListener (this);
andrewm@55 83
andrewm@55 84 addAndMakeVisible (touchkeyStatusLabel = new Label ("TouchKeys status label",
andrewm@55 85 "not running"));
andrewm@55 86 touchkeyStatusLabel->setFont (Font (15.00f, Font::plain));
andrewm@55 87 touchkeyStatusLabel->setJustificationType (Justification::centredLeft);
andrewm@55 88 touchkeyStatusLabel->setEditable (false, false, false);
andrewm@55 89 touchkeyStatusLabel->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 90 touchkeyStatusLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 91
andrewm@55 92 addAndMakeVisible (oscGroupComponent = new GroupComponent ("OSC group",
andrewm@55 93 "OSC Output"));
andrewm@55 94
andrewm@55 95 addAndMakeVisible (label7 = new Label ("new label",
andrewm@55 96 "Host:"));
andrewm@55 97 label7->setFont (Font (15.00f, Font::plain));
andrewm@55 98 label7->setJustificationType (Justification::centredLeft);
andrewm@55 99 label7->setEditable (false, false, false);
andrewm@55 100 label7->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 101 label7->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 102
andrewm@55 103 addAndMakeVisible (oscHostTextEditor = new TextEditor ("new text editor"));
andrewm@55 104 oscHostTextEditor->setMultiLine (false);
andrewm@55 105 oscHostTextEditor->setReturnKeyStartsNewLine (false);
andrewm@55 106 oscHostTextEditor->setReadOnly (false);
andrewm@55 107 oscHostTextEditor->setScrollbarsShown (true);
andrewm@55 108 oscHostTextEditor->setCaretVisible (true);
andrewm@55 109 oscHostTextEditor->setPopupMenuEnabled (true);
andrewm@55 110 oscHostTextEditor->setText ("127.0.0.1");
andrewm@55 111
andrewm@55 112 addAndMakeVisible (label8 = new Label ("new label",
andrewm@55 113 "Port:"));
andrewm@55 114 label8->setFont (Font (15.00f, Font::plain));
andrewm@55 115 label8->setJustificationType (Justification::centredLeft);
andrewm@55 116 label8->setEditable (false, false, false);
andrewm@55 117 label8->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 118 label8->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 119
andrewm@55 120 addAndMakeVisible (oscPortTextEditor = new TextEditor ("new text editor"));
andrewm@55 121 oscPortTextEditor->setMultiLine (false);
andrewm@55 122 oscPortTextEditor->setReturnKeyStartsNewLine (false);
andrewm@55 123 oscPortTextEditor->setReadOnly (false);
andrewm@55 124 oscPortTextEditor->setScrollbarsShown (true);
andrewm@55 125 oscPortTextEditor->setCaretVisible (true);
andrewm@55 126 oscPortTextEditor->setPopupMenuEnabled (true);
andrewm@55 127 oscPortTextEditor->setText ("8000");
andrewm@55 128
andrewm@55 129 addAndMakeVisible (oscEnableButton = new ToggleButton ("OSC enable button"));
andrewm@55 130 oscEnableButton->setButtonText ("Enable OSC output");
andrewm@55 131 oscEnableButton->addListener (this);
andrewm@55 132
andrewm@55 133 addAndMakeVisible (oscEnableRawButton = new ToggleButton ("OSC enable raw button"));
andrewm@55 134 oscEnableRawButton->setButtonText ("Send raw frames");
andrewm@55 135 oscEnableRawButton->addListener (this);
andrewm@55 136
andrewm@55 137 addAndMakeVisible (label4 = new Label ("new label",
andrewm@55 138 "Lowest Octave:"));
andrewm@55 139 label4->setFont (Font (15.00f, Font::plain));
andrewm@55 140 label4->setJustificationType (Justification::centredLeft);
andrewm@55 141 label4->setEditable (false, false, false);
andrewm@55 142 label4->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 143 label4->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 144
andrewm@55 145 addAndMakeVisible (touchkeyOctaveComboBox = new ComboBox ("TouchKeys octave box"));
andrewm@55 146 touchkeyOctaveComboBox->setEditableText (false);
andrewm@55 147 touchkeyOctaveComboBox->setJustificationType (Justification::centredLeft);
andrewm@55 148 touchkeyOctaveComboBox->setTextWhenNothingSelected (String::empty);
andrewm@55 149 touchkeyOctaveComboBox->setTextWhenNoChoicesAvailable ("(no choices)");
andrewm@55 150 touchkeyOctaveComboBox->addListener (this);
andrewm@55 151
andrewm@55 152 addAndMakeVisible (oscInputGroupComponent = new GroupComponent ("MIDI input group",
andrewm@55 153 "OSC Input"));
andrewm@55 154
andrewm@55 155 addAndMakeVisible (oscInputEnableButton = new ToggleButton ("OSC input enable button"));
andrewm@55 156 oscInputEnableButton->setButtonText ("Enable OSC input");
andrewm@55 157 oscInputEnableButton->addListener (this);
andrewm@55 158
andrewm@55 159 addAndMakeVisible (label6 = new Label ("new label",
andrewm@55 160 "Port:"));
andrewm@55 161 label6->setFont (Font (15.00f, Font::plain));
andrewm@55 162 label6->setJustificationType (Justification::centredLeft);
andrewm@55 163 label6->setEditable (false, false, false);
andrewm@55 164 label6->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 165 label6->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 166
andrewm@55 167 addAndMakeVisible (oscInputPortTextEditor = new TextEditor ("new text editor"));
andrewm@55 168 oscInputPortTextEditor->setMultiLine (false);
andrewm@55 169 oscInputPortTextEditor->setReturnKeyStartsNewLine (false);
andrewm@55 170 oscInputPortTextEditor->setReadOnly (false);
andrewm@55 171 oscInputPortTextEditor->setScrollbarsShown (true);
andrewm@55 172 oscInputPortTextEditor->setCaretVisible (true);
andrewm@55 173 oscInputPortTextEditor->setPopupMenuEnabled (true);
andrewm@55 174 oscInputPortTextEditor->setText ("8001");
andrewm@55 175
andrewm@55 176 addAndMakeVisible (keyboardZoneTabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
andrewm@55 177 keyboardZoneTabbedComponent->setTabBarDepth (30);
andrewm@55 178 keyboardZoneTabbedComponent->setCurrentTabIndex (-1);
andrewm@55 179
andrewm@55 180 addAndMakeVisible (addZoneButton = new TextButton ("add zone button"));
andrewm@55 181 addZoneButton->setButtonText ("Add");
andrewm@55 182 addZoneButton->addListener (this);
andrewm@55 183
andrewm@55 184 addAndMakeVisible (removeZoneButton = new TextButton ("remove zone button"));
andrewm@55 185 removeZoneButton->setButtonText ("Del");
andrewm@55 186 removeZoneButton->addListener (this);
andrewm@55 187
andrewm@55 188 addAndMakeVisible (touchkeyAutodetectButton = new TextButton ("TouchKeys autodetect button"));
andrewm@55 189 touchkeyAutodetectButton->setButtonText ("Detect");
andrewm@55 190 touchkeyAutodetectButton->addListener (this);
andrewm@55 191
andrewm@55 192 addAndMakeVisible (midiInputAuxDeviceComboBox = new ComboBox ("MIDI input aux combo box"));
andrewm@55 193 midiInputAuxDeviceComboBox->setEditableText (false);
andrewm@55 194 midiInputAuxDeviceComboBox->setJustificationType (Justification::centredLeft);
andrewm@55 195 midiInputAuxDeviceComboBox->setTextWhenNothingSelected (String::empty);
andrewm@55 196 midiInputAuxDeviceComboBox->setTextWhenNoChoicesAvailable ("(no choices)");
andrewm@55 197 midiInputAuxDeviceComboBox->addListener (this);
andrewm@55 198
andrewm@55 199 addAndMakeVisible (label5 = new Label ("new label",
andrewm@55 200 "Aux:"));
andrewm@55 201 label5->setFont (Font (15.00f, Font::plain));
andrewm@55 202 label5->setJustificationType (Justification::centredRight);
andrewm@55 203 label5->setEditable (false, false, false);
andrewm@55 204 label5->setColour (TextEditor::textColourId, Colours::black);
andrewm@55 205 label5->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@55 206
andrewm@55 207
andrewm@55 208 //[UserPreSize]
andrewm@55 209 lastSelectedMidiInputID_ = -1;
andrewm@55 210 lastSelectedMidiAuxInputID_ = -1;
andrewm@55 211 lastSegmentUniqueIdentifier_ = -1;
andrewm@55 212
andrewm@55 213 // Add octave labels to combo box
andrewm@55 214 for(int i = 0; i <= kTouchkeysMaxOctave; i++) {
andrewm@55 215 touchkeyOctaveComboBox->addItem("C" + String(i), i + kTouchkeysComponentComboBoxOffset);
andrewm@55 216 }
andrewm@55 217 //[/UserPreSize]
andrewm@55 218
andrewm@55 219 setSize (872, 444);
andrewm@55 220
andrewm@55 221
andrewm@55 222 //[Constructor] You can add your own custom stuff here..
andrewm@55 223 oscHostTextEditor->addListener(this);
andrewm@55 224 oscPortTextEditor->addListener(this);
andrewm@55 225 oscInputPortTextEditor->addListener(this);
andrewm@55 226 //[/Constructor]
andrewm@55 227 }
andrewm@55 228
andrewm@55 229 ControlWindowMainComponent::~ControlWindowMainComponent()
andrewm@55 230 {
andrewm@55 231 //[Destructor_pre]. You can add your own custom destruction code here..
andrewm@55 232 //[/Destructor_pre]
andrewm@55 233
andrewm@55 234 midiInputGroupComponent = nullptr;
andrewm@55 235 midiInputDeviceComboBox = nullptr;
andrewm@55 236 label = nullptr;
andrewm@55 237 groupComponent = nullptr;
andrewm@55 238 label2 = nullptr;
andrewm@55 239 touchkeyDeviceComboBox = nullptr;
andrewm@55 240 label3 = nullptr;
andrewm@55 241 touchkeyStartButton = nullptr;
andrewm@55 242 touchkeyStatusLabel = nullptr;
andrewm@55 243 oscGroupComponent = nullptr;
andrewm@55 244 label7 = nullptr;
andrewm@55 245 oscHostTextEditor = nullptr;
andrewm@55 246 label8 = nullptr;
andrewm@55 247 oscPortTextEditor = nullptr;
andrewm@55 248 oscEnableButton = nullptr;
andrewm@55 249 oscEnableRawButton = nullptr;
andrewm@55 250 label4 = nullptr;
andrewm@55 251 touchkeyOctaveComboBox = nullptr;
andrewm@55 252 oscInputGroupComponent = nullptr;
andrewm@55 253 oscInputEnableButton = nullptr;
andrewm@55 254 label6 = nullptr;
andrewm@55 255 oscInputPortTextEditor = nullptr;
andrewm@55 256 keyboardZoneTabbedComponent = nullptr;
andrewm@55 257 addZoneButton = nullptr;
andrewm@55 258 removeZoneButton = nullptr;
andrewm@55 259 touchkeyAutodetectButton = nullptr;
andrewm@55 260 midiInputAuxDeviceComboBox = nullptr;
andrewm@55 261 label5 = nullptr;
andrewm@55 262
andrewm@55 263
andrewm@55 264 //[Destructor]. You can add your own custom destruction code here..
andrewm@55 265 //[/Destructor]
andrewm@55 266 }
andrewm@55 267
andrewm@55 268 //==============================================================================
andrewm@55 269 void ControlWindowMainComponent::paint (Graphics& g)
andrewm@55 270 {
andrewm@55 271 //[UserPrePaint] Add your own custom painting code here..
andrewm@55 272 //[/UserPrePaint]
andrewm@55 273
andrewm@55 274 g.fillAll (Colour (0xffd2d2d2));
andrewm@55 275
andrewm@55 276 //[UserPaint] Add your own custom painting code here..
andrewm@55 277 //[/UserPaint]
andrewm@55 278 }
andrewm@55 279
andrewm@55 280 void ControlWindowMainComponent::resized()
andrewm@55 281 {
andrewm@55 282 midiInputGroupComponent->setBounds (8, 144, 304, 96);
andrewm@55 283 midiInputDeviceComboBox->setBounds (80, 168, 216, 24);
andrewm@55 284 label->setBounds (16, 168, 64, 24);
andrewm@55 285 groupComponent->setBounds (8, 8, 304, 128);
andrewm@55 286 label2->setBounds (16, 32, 60, 24);
andrewm@55 287 touchkeyDeviceComboBox->setBounds (72, 32, 224, 24);
andrewm@55 288 label3->setBounds (16, 96, 60, 24);
andrewm@55 289 touchkeyStartButton->setBounds (216, 96, 79, 24);
andrewm@55 290 touchkeyStatusLabel->setBounds (72, 96, 136, 24);
andrewm@55 291 oscGroupComponent->setBounds (8, 320, 304, 96);
andrewm@55 292 label7->setBounds (16, 376, 55, 24);
andrewm@55 293 oscHostTextEditor->setBounds (64, 376, 128, 24);
andrewm@55 294 label8->setBounds (200, 376, 40, 24);
andrewm@55 295 oscPortTextEditor->setBounds (240, 376, 56, 24);
andrewm@55 296 oscEnableButton->setBounds (24, 344, 144, 24);
andrewm@55 297 oscEnableRawButton->setBounds (176, 344, 144, 24);
andrewm@55 298 label4->setBounds (16, 64, 104, 24);
andrewm@55 299 touchkeyOctaveComboBox->setBounds (120, 64, 88, 24);
andrewm@55 300 oscInputGroupComponent->setBounds (8, 248, 304, 64);
andrewm@55 301 oscInputEnableButton->setBounds (24, 272, 152, 24);
andrewm@55 302 label6->setBounds (200, 272, 40, 24);
andrewm@55 303 oscInputPortTextEditor->setBounds (240, 272, 56, 24);
andrewm@55 304 keyboardZoneTabbedComponent->setBounds (320, 0, 552, 464);
andrewm@55 305 addZoneButton->setBounds (776, 4, 38, 20);
andrewm@55 306 removeZoneButton->setBounds (824, 4, 38, 20);
andrewm@55 307 touchkeyAutodetectButton->setBounds (216, 64, 79, 24);
andrewm@55 308 midiInputAuxDeviceComboBox->setBounds (80, 200, 216, 24);
andrewm@55 309 label5->setBounds (24, 200, 55, 24);
andrewm@55 310 //[UserResized] Add your own custom resize handling here..
andrewm@55 311
andrewm@55 312 // Resize KeyboardZoneComponent to fit new bounds
andrewm@55 313 juce::Rectangle<int> const& ourBounds = getBounds();
andrewm@55 314 juce::Rectangle<int> keyboardZoneBounds = keyboardZoneTabbedComponent->getBounds();
andrewm@55 315 keyboardZoneBounds.setHeight(ourBounds.getHeight() - keyboardZoneBounds.getY());
andrewm@55 316 keyboardZoneTabbedComponent->setBounds(keyboardZoneBounds);
andrewm@55 317 //[/UserResized]
andrewm@55 318 }
andrewm@55 319
andrewm@55 320 void ControlWindowMainComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
andrewm@55 321 {
andrewm@55 322 //[UsercomboBoxChanged_Pre]
andrewm@55 323 if(controller_ == 0)
andrewm@55 324 return;
andrewm@55 325 //[/UsercomboBoxChanged_Pre]
andrewm@55 326
andrewm@55 327 if (comboBoxThatHasChanged == midiInputDeviceComboBox)
andrewm@55 328 {
andrewm@55 329 //[UserComboBoxCode_midiInputDeviceComboBox] -- add your combo box handling code here..
andrewm@55 330
andrewm@55 331 // Look up the selected ID, remembering that Juce indices start at 1 and the first of
andrewm@55 332 // these is "Disabled"
andrewm@55 333 int selection = midiInputDeviceComboBox->getSelectedId() - kMidiInputDeviceComboBoxOffset;
andrewm@55 334 if(selection == 1 - kMidiInputDeviceComboBoxOffset) { // Disabled
andrewm@55 335 if(controller_->midiTouchkeysStandaloneModeIsEnabled())
andrewm@55 336 controller_->midiTouchkeysStandaloneModeDisable();
andrewm@55 337 controller_->disablePrimaryMIDIInputPort();
andrewm@55 338 }
andrewm@55 339 else if(selection == 2 - kMidiInputDeviceComboBoxOffset) { // Standalone mode
andrewm@55 340 controller_->disablePrimaryMIDIInputPort();
andrewm@55 341 controller_->midiTouchkeysStandaloneModeEnable();
andrewm@55 342 }
andrewm@55 343 else if(selection >= 0 && selection < midiInputDeviceIDs_.size()) {
andrewm@55 344 int deviceId = midiInputDeviceIDs_[selection];
andrewm@55 345 if(controller_->midiTouchkeysStandaloneModeIsEnabled())
andrewm@55 346 controller_->midiTouchkeysStandaloneModeDisable();
andrewm@55 347 controller_->enableMIDIInputPort(deviceId, true);
andrewm@55 348 }
andrewm@55 349 //[/UserComboBoxCode_midiInputDeviceComboBox]
andrewm@55 350 }
andrewm@55 351 else if (comboBoxThatHasChanged == touchkeyDeviceComboBox)
andrewm@55 352 {
andrewm@55 353 //[UserComboBoxCode_touchkeyDeviceComboBox] -- add your combo box handling code here..
andrewm@55 354 // Nothing to do here right away -- wait until start button is pressed
andrewm@55 355 //[/UserComboBoxCode_touchkeyDeviceComboBox]
andrewm@55 356 }
andrewm@55 357 else if (comboBoxThatHasChanged == touchkeyOctaveComboBox)
andrewm@55 358 {
andrewm@55 359 //[UserComboBoxCode_touchkeyOctaveComboBox] -- add your combo box handling code here..
andrewm@55 360 int octave = touchkeyOctaveComboBox->getSelectedId() - kTouchkeysComponentComboBoxOffset;
andrewm@55 361
andrewm@55 362 // Convert octave number to MIDI note (C4 = 60)
andrewm@55 363 if(controller_ != 0)
andrewm@55 364 controller_->touchkeyDeviceSetLowestMidiNote((octave + 1)*12);
andrewm@55 365 //[/UserComboBoxCode_touchkeyOctaveComboBox]
andrewm@55 366 }
andrewm@55 367 else if (comboBoxThatHasChanged == midiInputAuxDeviceComboBox)
andrewm@55 368 {
andrewm@55 369 //[UserComboBoxCode_midiInputAuxDeviceComboBox] -- add your combo box handling code here..
andrewm@55 370
andrewm@55 371 // Look up the selected ID, remembering that Juce indices start at 1 and the first of
andrewm@55 372 // these is "Disabled"
andrewm@55 373 int selection = midiInputAuxDeviceComboBox->getSelectedId() - kMidiInputDeviceComboBoxOffset;
andrewm@55 374 if(selection == 1 - kMidiInputDeviceComboBoxOffset) { // Disabled
andrewm@55 375 // Disable all aux ports
andrewm@55 376 controller_->disableAllMIDIInputPorts(true);
andrewm@55 377 }
andrewm@55 378 else if(selection == 2 - kMidiInputDeviceComboBoxOffset) {
andrewm@55 379 // Shouldn't happen; standalone mode not an aux feature
andrewm@55 380 controller_->disableAllMIDIInputPorts(true);
andrewm@55 381 }
andrewm@55 382 else if(selection >= 0 && selection < midiInputDeviceIDs_.size()) {
andrewm@55 383 int deviceId = midiInputDeviceIDs_[selection];
andrewm@55 384 // Enable this aux port
andrewm@55 385 controller_->disableAllMIDIInputPorts(true);
andrewm@55 386 controller_->enableMIDIInputPort(deviceId, false);
andrewm@55 387 }
andrewm@55 388 //[/UserComboBoxCode_midiInputAuxDeviceComboBox]
andrewm@55 389 }
andrewm@55 390
andrewm@55 391 //[UsercomboBoxChanged_Post]
andrewm@55 392 //[/UsercomboBoxChanged_Post]
andrewm@55 393 }
andrewm@55 394
andrewm@55 395 void ControlWindowMainComponent::buttonClicked (Button* buttonThatWasClicked)
andrewm@55 396 {
andrewm@55 397 //[UserbuttonClicked_Pre]
andrewm@55 398 if(controller_ == 0)
andrewm@55 399 return;
andrewm@55 400 //[/UserbuttonClicked_Pre]
andrewm@55 401
andrewm@55 402 if (buttonThatWasClicked == touchkeyStartButton)
andrewm@55 403 {
andrewm@55 404 //[UserButtonCode_touchkeyStartButton] -- add your button handler code here..
andrewm@55 405 #ifdef ENABLE_TOUCHKEYS_SENSOR_TEST
andrewm@55 406 if(controller_->touchkeySensorTestIsRunning()) {
andrewm@55 407 // TouchKeys were performing a sensor test. Stop the test.
andrewm@55 408 controller_->touchkeySensorTestStop();
andrewm@55 409 }
andrewm@55 410 else if(controller_->touchkeyDeviceIsRunning()) {
andrewm@55 411 #else
andrewm@55 412 if(controller_->touchkeyDeviceIsRunning()) {
andrewm@55 413 #endif
andrewm@55 414 // TouchKeys were running. Stop and close.
andrewm@55 415 controller_->closeTouchkeyDevice();
andrewm@55 416 }
andrewm@55 417 else {
andrewm@55 418 // TouchKeys weren't running. Open and start.
andrewm@55 419 String devName = controller_->touchkeyDevicePrefix().c_str();
andrewm@55 420 devName += touchkeyDeviceComboBox->getText();
andrewm@55 421
andrewm@55 422 // This will attempt to start the device and update the state accordingly
andrewm@55 423 controller_->touchkeyDeviceStartupSequence(devName.toUTF8());
andrewm@55 424 }
andrewm@55 425 //[/UserButtonCode_touchkeyStartButton]
andrewm@55 426 }
andrewm@55 427 else if (buttonThatWasClicked == oscEnableButton)
andrewm@55 428 {
andrewm@55 429 //[UserButtonCode_oscEnableButton] -- add your button handler code here..
andrewm@55 430 controller_->oscTransmitSetEnabled(oscEnableButton->getToggleState());
andrewm@55 431 //[/UserButtonCode_oscEnableButton]
andrewm@55 432 }
andrewm@55 433 else if (buttonThatWasClicked == oscEnableRawButton)
andrewm@55 434 {
andrewm@55 435 //[UserButtonCode_oscEnableRawButton] -- add your button handler code here..
andrewm@55 436 controller_->oscTransmitSetRawDataEnabled(oscEnableRawButton->getToggleState());
andrewm@55 437 //[/UserButtonCode_oscEnableRawButton]
andrewm@55 438 }
andrewm@55 439 else if (buttonThatWasClicked == oscInputEnableButton)
andrewm@55 440 {
andrewm@55 441 //[UserButtonCode_oscInputEnableButton] -- add your button handler code here..
andrewm@55 442 controller_->oscReceiveSetEnabled(oscInputEnableButton->getToggleState());
andrewm@55 443 //[/UserButtonCode_oscInputEnableButton]
andrewm@55 444 }
andrewm@55 445 else if (buttonThatWasClicked == addZoneButton)
andrewm@55 446 {
andrewm@55 447 //[UserButtonCode_addZoneButton] -- add your button handler code here..
andrewm@55 448 controller_->midiSegmentAdd();
andrewm@55 449 //[/UserButtonCode_addZoneButton]
andrewm@55 450 }
andrewm@55 451 else if (buttonThatWasClicked == removeZoneButton)
andrewm@55 452 {
andrewm@55 453 //[UserButtonCode_removeZoneButton] -- add your button handler code here..
andrewm@55 454 int tabIndex = keyboardZoneTabbedComponent->getCurrentTabIndex();
andrewm@55 455 if(tabIndex != 0) {
andrewm@55 456 KeyboardZoneComponent* selectedComponent = static_cast<KeyboardZoneComponent*> (keyboardZoneTabbedComponent->getTabContentComponent(tabIndex));
andrewm@55 457 controller_->midiSegmentRemove(selectedComponent->keyboardSegment());
andrewm@55 458 }
andrewm@55 459 //[/UserButtonCode_removeZoneButton]
andrewm@55 460 }
andrewm@55 461 else if (buttonThatWasClicked == touchkeyAutodetectButton)
andrewm@55 462 {
andrewm@55 463 //[UserButtonCode_touchkeyAutodetectButton] -- add your button handler code here..
andrewm@55 464 if(controller_->touchkeyDeviceIsAutodetecting())
andrewm@55 465 controller_->touchkeyDeviceStopAutodetecting();
andrewm@55 466 else
andrewm@55 467 controller_->touchkeyDeviceAutodetectLowestMidiNote();
andrewm@55 468 //[/UserButtonCode_touchkeyAutodetectButton]
andrewm@55 469 }
andrewm@55 470
andrewm@55 471 //[UserbuttonClicked_Post]
andrewm@55 472 //[/UserbuttonClicked_Post]
andrewm@55 473 }
andrewm@55 474
andrewm@55 475
andrewm@55 476
andrewm@55 477 //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
andrewm@55 478
andrewm@55 479 void ControlWindowMainComponent::textEditorReturnKeyPressed(TextEditor &editor)
andrewm@55 480 {
andrewm@55 481 if(controller_ == 0)
andrewm@55 482 return;
andrewm@55 483 if(&editor == oscHostTextEditor || &editor == oscPortTextEditor)
andrewm@55 484 updateOscHostPort();
andrewm@55 485 else if(&editor == oscInputPortTextEditor) {
andrewm@55 486 int port = atoi(oscInputPortTextEditor->getText().toUTF8());
andrewm@55 487 controller_->oscReceiveSetPort(port);
andrewm@55 488 }
andrewm@55 489 }
andrewm@55 490
andrewm@55 491 void ControlWindowMainComponent::textEditorEscapeKeyPressed(TextEditor &editor)
andrewm@55 492 {
andrewm@55 493 // Nothing to do here
andrewm@55 494 }
andrewm@55 495
andrewm@55 496 void ControlWindowMainComponent::textEditorFocusLost(TextEditor &editor)
andrewm@55 497 {
andrewm@55 498 textEditorReturnKeyPressed(editor);
andrewm@55 499 }
andrewm@55 500
andrewm@55 501 // Update list of TouchKeys and MIDI input devices
andrewm@55 502 void ControlWindowMainComponent::updateInputDeviceList()
andrewm@55 503 {
andrewm@55 504 if(controller_ == 0)
andrewm@55 505 return;
andrewm@55 506
andrewm@55 507 // *** TouchKeys devices ***
andrewm@55 508 vector<string> tkdevices = controller_->availableTouchkeyDevices();
andrewm@55 509 vector<string>::iterator tkit;
andrewm@55 510 int counter;
andrewm@55 511
andrewm@55 512 touchkeyDeviceComboBox->clear();
andrewm@55 513
andrewm@55 514 if(tkdevices.size() == 0) {
andrewm@55 515 touchkeyDeviceComboBox->addItem("No devices", 1);
andrewm@55 516 touchkeyDeviceComboBox->setSelectedId(1, dontSendNotification);
andrewm@55 517 touchkeyDeviceComboBox->setEnabled(false);
andrewm@55 518 touchkeyStartButton->setEnabled(false);
andrewm@55 519 }
andrewm@55 520 else {
andrewm@55 521 counter = 1;
andrewm@55 522 for(tkit = tkdevices.begin(); tkit != tkdevices.end(); ++tkit) {
andrewm@55 523 touchkeyDeviceComboBox->addItem(tkit->c_str(), counter++);
andrewm@55 524 }
andrewm@55 525 touchkeyDeviceComboBox->setSelectedId(1, dontSendNotification);
andrewm@55 526 touchkeyDeviceComboBox->setEnabled(true);
andrewm@55 527 touchkeyStartButton->setEnabled(true);
andrewm@55 528 }
andrewm@55 529
andrewm@55 530 // *** MIDI input devices ***
andrewm@55 531 vector<pair<int, string> > devices = controller_->availableMIDIInputDevices();
andrewm@55 532 vector<pair<int, string> >::iterator it;
andrewm@55 533
andrewm@55 534 midiInputDeviceComboBox->clear();
andrewm@55 535 midiInputDeviceIDs_.clear();
andrewm@55 536 midiInputDeviceComboBox->addItem("Disabled", 1);
andrewm@55 537 midiInputDeviceComboBox->addItem("TouchKeys Standalone", 2);
andrewm@55 538
andrewm@55 539 midiInputAuxDeviceComboBox->clear();
andrewm@55 540 midiInputAuxDeviceComboBox->addItem("Disabled", 1);
andrewm@55 541
andrewm@55 542 counter = kMidiInputDeviceComboBoxOffset;
andrewm@55 543
andrewm@55 544 // Check whether the currently selected ID still exists while
andrewm@55 545 // we build the list
andrewm@55 546 bool lastSelectedDeviceExists = false;
andrewm@55 547 bool lastSelectedAuxDeviceExists = false;
andrewm@55 548 for(it = devices.begin(); it != devices.end(); ++it) {
andrewm@55 549 midiInputDeviceComboBox->addItem((*it).second.c_str(), counter);
andrewm@55 550 midiInputAuxDeviceComboBox->addItem((*it).second.c_str(), counter);
andrewm@55 551 midiInputDeviceIDs_.push_back(it->first);
andrewm@55 552 if(it->first == lastSelectedMidiInputID_)
andrewm@55 553 lastSelectedDeviceExists = true;
andrewm@55 554 if(it->first == lastSelectedMidiAuxInputID_)
andrewm@55 555 lastSelectedAuxDeviceExists = true;
andrewm@55 556 counter++;
andrewm@55 557 }
andrewm@55 558
andrewm@55 559 if(!lastSelectedDeviceExists && lastSelectedMidiInputID_ >= 0)
andrewm@55 560 controller_->disablePrimaryMIDIInputPort();
andrewm@55 561 if(!lastSelectedAuxDeviceExists && lastSelectedMidiAuxInputID_ >= 0)
andrewm@55 562 controller_->disableAllMIDIInputPorts(true);
andrewm@55 563 }
andrewm@55 564
andrewm@55 565 void ControlWindowMainComponent::updateOscHostPort()
andrewm@55 566 {
andrewm@55 567 if(controller_ == 0)
andrewm@55 568 return;
andrewm@55 569
andrewm@55 570 String oscHost = oscHostTextEditor->getText();
andrewm@55 571 String oscPort = oscPortTextEditor->getText();
andrewm@55 572 controller_->oscTransmitClearAddresses();
andrewm@55 573 controller_->oscTransmitAddAddress(oscHost.toUTF8(), oscPort.toUTF8());
andrewm@55 574 }
andrewm@55 575
andrewm@55 576 // Synchronize the UI state with the underlying state of the controller
andrewm@55 577 void ControlWindowMainComponent::synchronize() {
andrewm@55 578 if(controller_ == 0)
andrewm@55 579 return;
andrewm@55 580
andrewm@55 581 bool devicesUpdated = false;
andrewm@55 582
andrewm@55 583 if(controller_->devicesShouldUpdate() != lastControllerUpdateDeviceCount_) {
andrewm@55 584 lastControllerUpdateDeviceCount_ = controller_->devicesShouldUpdate();
andrewm@55 585 updateInputDeviceList();
andrewm@55 586 devicesUpdated = true;
andrewm@55 587 }
andrewm@55 588
andrewm@55 589 // Update TouchKeys status
andrewm@55 590 #ifdef ENABLE_TOUCHKEYS_SENSOR_TEST
andrewm@55 591 if(controller_->touchkeySensorTestIsRunning()) {
andrewm@55 592 touchkeyStartButton->setButtonText("Stop");
andrewm@55 593 touchkeyStatusLabel->setText("Testing", dontSendNotification);
andrewm@55 594 }
andrewm@55 595 else if(controller_->touchkeyDeviceIsRunning()) {
andrewm@55 596 #else
andrewm@55 597 if(controller_->touchkeyDeviceIsRunning()) {
andrewm@55 598 #endif
andrewm@55 599 touchkeyStartButton->setButtonText("Stop");
andrewm@55 600 touchkeyStatusLabel->setText("Running", dontSendNotification);
andrewm@55 601 }
andrewm@55 602 else if(controller_->touchkeyDeviceErrorOccurred()) {
andrewm@55 603 touchkeyStartButton->setButtonText("Start");
andrewm@55 604 touchkeyStatusLabel->setText(controller_->touchkeyDeviceErrorMessage().c_str(), dontSendNotification);
andrewm@55 605 }
andrewm@55 606 else {
andrewm@55 607 touchkeyStartButton->setButtonText("Start");
andrewm@55 608 touchkeyStatusLabel->setText("Not running", dontSendNotification);
andrewm@55 609 }
andrewm@55 610
andrewm@55 611 // Update MIDI input status
andrewm@55 612 if(controller_->midiTouchkeysStandaloneModeIsEnabled()) {
andrewm@55 613 midiInputDeviceComboBox->setSelectedId(2, dontSendNotification);
andrewm@55 614 }
andrewm@55 615 else {
andrewm@55 616 // First query the primary port
andrewm@55 617 int selectedPrimaryPort = controller_->selectedMIDIPrimaryInputPort();
andrewm@55 618 if(selectedPrimaryPort < 0) {
andrewm@55 619 midiInputDeviceComboBox->setSelectedId(1, dontSendNotification);
andrewm@55 620 }
andrewm@55 621 else if(selectedPrimaryPort != lastSelectedMidiInputID_ || devicesUpdated){
andrewm@55 622 // Input has changed from before. Find it in vector
andrewm@55 623 // If there is more than one selected ID, we will only take the first one for
andrewm@55 624 // the current UI. This affects the display but not the functionality.
andrewm@55 625 for(int i = 0; i < midiInputDeviceIDs_.size(); i++) {
andrewm@55 626 if(midiInputDeviceIDs_[i] == selectedPrimaryPort) {
andrewm@55 627 midiInputDeviceComboBox->setSelectedId(i + kMidiInputDeviceComboBoxOffset, dontSendNotification);
andrewm@55 628 break;
andrewm@55 629 }
andrewm@55 630 }
andrewm@55 631 // ...and cache this as the last ID so we don't search again next time
andrewm@55 632 lastSelectedMidiInputID_ = selectedPrimaryPort;
andrewm@55 633
andrewm@55 634 // Now disable this item in the auxiliary combo box
andrewm@55 635 for(int i = 0; i < midiInputAuxDeviceComboBox->getNumItems(); i++) {
andrewm@55 636 int itemId = midiInputAuxDeviceComboBox->getItemId(i) - kMidiInputDeviceComboBoxOffset;
andrewm@55 637 if(itemId >= 0) {
andrewm@55 638 midiInputAuxDeviceComboBox->setItemEnabled(midiInputAuxDeviceComboBox->getItemId(i),
andrewm@55 639 (itemId != selectedPrimaryPort));
andrewm@55 640 }
andrewm@55 641 }
andrewm@55 642 }
andrewm@55 643 }
andrewm@55 644
andrewm@55 645 // Then get all aux ports and display the first one
andrewm@55 646 const std::vector<int>& selectedMidiInputDevices(controller_->selectedMIDIAuxInputPorts());
andrewm@55 647 if(selectedMidiInputDevices.empty()) {
andrewm@55 648 midiInputAuxDeviceComboBox->setSelectedId(1, dontSendNotification);
andrewm@55 649 }
andrewm@55 650 else if(selectedMidiInputDevices.front() != lastSelectedMidiAuxInputID_ || devicesUpdated){
andrewm@55 651 // Input has changed from before. Find it in vector
andrewm@55 652 // If there is more than one selected ID, we will only take the first one for
andrewm@55 653 // the current UI. This affects the display but not the functionality.
andrewm@55 654 for(int i = 0; i < midiInputDeviceIDs_.size(); i++) {
andrewm@55 655 if(midiInputDeviceIDs_[i] == selectedMidiInputDevices.front()) {
andrewm@55 656 midiInputAuxDeviceComboBox->setSelectedId(i + kMidiInputDeviceComboBoxOffset, dontSendNotification);
andrewm@55 657 break;
andrewm@55 658 }
andrewm@55 659 }
andrewm@55 660 // ...and cache this as the last ID so we don't search again next time
andrewm@55 661 lastSelectedMidiAuxInputID_ = selectedMidiInputDevices.front();
andrewm@55 662 }
andrewm@55 663
andrewm@55 664 // Update OSC status
andrewm@55 665 oscEnableButton->setToggleState(controller_->oscTransmitEnabled(), dontSendNotification);
andrewm@55 666 oscEnableRawButton->setToggleState(controller_->oscTransmitRawDataEnabled(), dontSendNotification);
andrewm@55 667 oscInputEnableButton->setToggleState(controller_->oscReceiveEnabled(), dontSendNotification);
andrewm@55 668
andrewm@55 669 // Update the OSC fields only if the text editors aren't active
andrewm@55 670 if(!oscHostTextEditor->hasKeyboardFocus(true) && !oscPortTextEditor->hasKeyboardFocus(true)) {
andrewm@55 671 const std::vector<lo_address>& oscAddresses = controller_->oscTransmitAddresses();
andrewm@55 672 if(oscAddresses.empty()) {
andrewm@55 673 oscHostTextEditor->setText("", false);
andrewm@55 674 oscPortTextEditor->setText("", false);
andrewm@55 675 }
andrewm@55 676 else {
andrewm@55 677 // Take the first address to display in the text editor. As with MIDI input,
andrewm@55 678 // this doesn't affect the functionality, only the UI display.
andrewm@55 679 lo_address firstAddress = oscAddresses.front();
andrewm@55 680
andrewm@55 681 oscHostTextEditor->setText(lo_address_get_hostname(firstAddress), false);
andrewm@55 682 oscPortTextEditor->setText(lo_address_get_port(firstAddress), false);
andrewm@55 683 }
andrewm@55 684 }
andrewm@55 685 if(!oscInputPortTextEditor->hasKeyboardFocus(true)) {
andrewm@55 686 int port = controller_->oscReceivePort();
andrewm@55 687 oscInputPortTextEditor->setText(String(port), false);
andrewm@55 688 }
andrewm@55 689
andrewm@55 690 // Set the octave button
andrewm@55 691 int octave = (controller_->touchkeyDeviceLowestMidiNote() / 12) - 1;
andrewm@55 692 if(octave >= 0 && octave <= kTouchkeysMaxOctave)
andrewm@55 693 touchkeyOctaveComboBox->setSelectedId(octave + kTouchkeysComponentComboBoxOffset, dontSendNotification);
andrewm@55 694
andrewm@55 695 // Enable or disable the autodetect button depending on the device status
andrewm@55 696 if(!controller_->touchkeyDeviceIsRunning()) {
andrewm@55 697 touchkeyAutodetectButton->setEnabled(false);
andrewm@55 698 }
andrewm@55 699 else if(controller_->touchkeyDeviceIsAutodetecting()) {
andrewm@55 700 touchkeyAutodetectButton->setEnabled(true);
andrewm@55 701 touchkeyAutodetectButton->setButtonText("Cancel");
andrewm@55 702 }
andrewm@55 703 else {
andrewm@55 704 touchkeyAutodetectButton->setEnabled(true);
andrewm@55 705 touchkeyAutodetectButton->setButtonText("Detect");
andrewm@55 706 }
andrewm@55 707
andrewm@55 708 // Update segments list if it has changed
andrewm@55 709 if(lastSegmentUniqueIdentifier_ != controller_->midiSegmentUniqueIdentifier())
andrewm@55 710 updateKeyboardSegments();
andrewm@55 711
andrewm@55 712 // Synchronize every tab component
andrewm@55 713 for(int tab = 0; tab < keyboardZoneTabbedComponent->getNumTabs(); tab++) {
andrewm@55 714 KeyboardZoneComponent *component = static_cast<KeyboardZoneComponent*> (keyboardZoneTabbedComponent->getTabContentComponent(tab));
andrewm@55 715 component->synchronize(devicesUpdated);
andrewm@55 716 }
andrewm@55 717
andrewm@55 718 // Update add/remove buttons
andrewm@55 719 if(keyboardZoneTabbedComponent->getCurrentTabIndex() <= 0) {
andrewm@55 720 removeZoneButton->setEnabled(false);
andrewm@55 721 }
andrewm@55 722 else {
andrewm@55 723 removeZoneButton->setEnabled(true);
andrewm@55 724 }
andrewm@55 725 if(controller_->midiSegmentsCount() >= 8)
andrewm@55 726 addZoneButton->setEnabled(false);
andrewm@55 727 else
andrewm@55 728 addZoneButton->setEnabled(true);
andrewm@55 729 }
andrewm@55 730
andrewm@55 731 // Return the currently selected TouchKeys string
andrewm@55 732 String ControlWindowMainComponent::currentTouchkeysSelectedPath()
andrewm@55 733 {
andrewm@55 734 String devName = controller_->touchkeyDevicePrefix().c_str();
andrewm@55 735 devName += touchkeyDeviceComboBox->getText();
andrewm@55 736
andrewm@55 737 return devName;
andrewm@55 738 }
andrewm@55 739
andrewm@55 740 // Update the state of the keyboard segment tab bar. Called only when segments change
andrewm@55 741 void ControlWindowMainComponent::updateKeyboardSegments()
andrewm@55 742 {
andrewm@55 743 if(controller_ == 0)
andrewm@55 744 return;
andrewm@55 745 // Update the identifier to say we've matched the current state of the segments
andrewm@55 746 lastSegmentUniqueIdentifier_ = controller_->midiSegmentUniqueIdentifier();
andrewm@55 747
andrewm@55 748 // Save the current selected index in case we later remove it
andrewm@55 749 int currentlySelectedIndex = keyboardZoneTabbedComponent->getCurrentTabIndex();
andrewm@55 750
andrewm@55 751 KeyboardZoneComponent* currentlySelectedComponent = static_cast<KeyboardZoneComponent*> (keyboardZoneTabbedComponent->getTabContentComponent(currentlySelectedIndex));
andrewm@55 752 MidiKeyboardSegment* currentlySelectedSegment = 0;
andrewm@55 753 if(currentlySelectedComponent != 0)
andrewm@55 754 currentlySelectedSegment = currentlySelectedComponent->keyboardSegment();
andrewm@55 755 bool selectedNewTab = false;
andrewm@55 756
andrewm@55 757 // First, go through the segments and create tabs as needed
andrewm@55 758 int maxNumSegments = controller_->midiSegmentsCount();
andrewm@55 759 for(int i = 0; i < maxNumSegments; i++) {
andrewm@55 760 MidiKeyboardSegment* segment = controller_->midiSegment(i);
andrewm@55 761 bool matched = false;
andrewm@55 762 if(segment == 0)
andrewm@55 763 continue;
andrewm@55 764 // Look for this segment among the tabs we already have
andrewm@55 765 for(int tab = 0; tab < keyboardZoneTabbedComponent->getNumTabs(); tab++) {
andrewm@55 766 KeyboardZoneComponent *component = static_cast<KeyboardZoneComponent*> (keyboardZoneTabbedComponent->getTabContentComponent(tab));
andrewm@55 767 if(component->keyboardSegment() == segment && component->keyboardZone() == segment->outputPort()) {
andrewm@55 768 // Found it...
andrewm@55 769 matched = true;
andrewm@55 770 break;
andrewm@55 771 }
andrewm@55 772 }
andrewm@55 773 // If we didn't find it, add a tab for this segment
andrewm@55 774 if(!matched) {
andrewm@55 775 KeyboardZoneComponent *newComponent = new KeyboardZoneComponent();
andrewm@55 776 newComponent->setMainApplicationController(controller_);
andrewm@55 777 newComponent->setKeyboardSegment(segment, segment->outputPort());
andrewm@55 778
andrewm@55 779 char name[16];
andrewm@55 780 #ifdef _MSC_VER
andrewm@55 781 _snprintf_s(name, 16, _TRUNCATE, "Zone %d", segment->outputPort());
andrewm@55 782 #else
andrewm@55 783 snprintf(name, 16, "Zone %d", segment->outputPort());
andrewm@55 784 #endif
andrewm@55 785
andrewm@55 786 // Add the component, telling the tab manager to take charge of deleting it at the end
andrewm@55 787 keyboardZoneTabbedComponent->addTab(name, Colours::lightgrey, newComponent, true);
andrewm@55 788 keyboardZoneTabbedComponent->setCurrentTabIndex(keyboardZoneTabbedComponent->getNumTabs() - 1);
andrewm@55 789 selectedNewTab = true;
andrewm@55 790
andrewm@55 791 //std::cout << "Adding tab for segment " << segment << endl;
andrewm@55 792 }
andrewm@55 793 }
andrewm@55 794
andrewm@55 795 // Now go through the other way and remove tabs that are no longer needed
andrewm@55 796 // Iterate through each tab: find a match in the segments
andrewm@55 797 int tab = 0;
andrewm@55 798 while(tab < keyboardZoneTabbedComponent->getNumTabs()) {
andrewm@55 799 KeyboardZoneComponent *component = static_cast<KeyboardZoneComponent*> (keyboardZoneTabbedComponent->getTabContentComponent(tab));
andrewm@55 800 MidiKeyboardSegment *segment = component->keyboardSegment();
andrewm@55 801 bool matched = false;
andrewm@55 802
andrewm@55 803 for(int i = 0; i < maxNumSegments; i++) {
andrewm@55 804 if(segment == controller_->midiSegment(i) && component->keyboardZone() == segment->outputPort()) {
andrewm@55 805 matched = true;
andrewm@55 806 break;
andrewm@55 807 }
andrewm@55 808 }
andrewm@55 809 if(segment == 0 || !matched) {
andrewm@55 810 // This tab holds a nonexistent segment and should be removed
andrewm@55 811 keyboardZoneTabbedComponent->removeTab(tab);
andrewm@55 812
andrewm@55 813 if(currentlySelectedSegment == segment) {
andrewm@55 814 // The currently selected tab has been removed. Select the prior one.
andrewm@55 815 if(currentlySelectedIndex > 0) {
andrewm@55 816 int indexToSelect = currentlySelectedIndex - 1;
andrewm@55 817 if(indexToSelect >= keyboardZoneTabbedComponent->getNumTabs())
andrewm@55 818 indexToSelect = keyboardZoneTabbedComponent->getNumTabs() - 1;
andrewm@55 819 if(indexToSelect < 0)
andrewm@55 820 indexToSelect = 0;
andrewm@55 821 keyboardZoneTabbedComponent->setCurrentTabIndex(indexToSelect);
andrewm@55 822 }
andrewm@55 823 else
andrewm@55 824 keyboardZoneTabbedComponent->setCurrentTabIndex(0);
andrewm@55 825 }
andrewm@55 826
andrewm@55 827 // And we have to start over again since the tab indexing has changed
andrewm@55 828 tab = 0;
andrewm@55 829 }
andrewm@55 830 else // Found a match: check the next tab
andrewm@55 831 tab++;
andrewm@55 832 // Eventually, we get to the end of the list of tabs an we know every existing tab matches a segment
andrewm@55 833 }
andrewm@55 834 }
andrewm@55 835
andrewm@55 836 //[/MiscUserCode]
andrewm@55 837
andrewm@55 838
andrewm@55 839 //==============================================================================
andrewm@55 840 #if 0
andrewm@55 841 /* -- Introjucer information section --
andrewm@55 842
andrewm@55 843 This is where the Introjucer stores the metadata that describe this GUI layout, so
andrewm@55 844 make changes in here at your peril!
andrewm@55 845
andrewm@55 846 BEGIN_JUCER_METADATA
andrewm@55 847
andrewm@55 848 <JUCER_COMPONENT documentType="Component" className="ControlWindowMainComponent"
andrewm@55 849 componentName="" parentClasses="public Component, public TextEditor::Listener"
andrewm@55 850 constructorParams="" variableInitialisers="controller_(0)" snapPixels="8"
andrewm@55 851 snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="0"
andrewm@55 852 initialWidth="872" initialHeight="444">
andrewm@55 853 <BACKGROUND backgroundColour="ffd2d2d2"/>
andrewm@55 854 <GROUPCOMPONENT name="MIDI input group" id="ce80a86ee6475cd9" memberName="midiInputGroupComponent"
andrewm@55 855 virtualName="" explicitFocusOrder="0" pos="8 144 304 96" title="MIDI Input"/>
andrewm@55 856 <COMBOBOX name="MIDI input combo box" id="def32c74505cfa50" memberName="midiInputDeviceComboBox"
andrewm@55 857 virtualName="" explicitFocusOrder="0" pos="80 168 216 24" editable="0"
andrewm@55 858 layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
andrewm@55 859 <LABEL name="new label" id="ad7bc4640d8023b7" memberName="label" virtualName=""
andrewm@55 860 explicitFocusOrder="0" pos="16 168 64 24" edTextCol="ff000000"
andrewm@55 861 edBkgCol="0" labelText="Keyboard:" editableSingleClick="0" editableDoubleClick="0"
andrewm@55 862 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
andrewm@55 863 bold="0" italic="0" justification="33"/>
andrewm@55 864 <GROUPCOMPONENT name="new group" id="9106305fd2211185" memberName="groupComponent"
andrewm@55 865 virtualName="" explicitFocusOrder="0" pos="8 8 304 128" title="TouchKeys"/>
andrewm@55 866 <LABEL name="new label" id="944877a84dcfc602" memberName="label2" virtualName=""
andrewm@55 867 explicitFocusOrder="0" pos="16 32 60 24" edTextCol="ff000000"
andrewm@55 868 edBkgCol="0" labelText="Device:&#10;" editableSingleClick="0"
andrewm@55 869 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@55 870 fontsize="15" bold="0" italic="0" justification="33"/>
andrewm@55 871 <COMBOBOX name="TouchKeys combo box" id="871223bdcad0e693" memberName="touchkeyDeviceComboBox"
andrewm@55 872 virtualName="" explicitFocusOrder="0" pos="72 32 224 24" editable="0"
andrewm@55 873 layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
andrewm@55 874 <LABEL name="new label" id="1cdf89082d95c72c" memberName="label3" virtualName=""
andrewm@55 875 explicitFocusOrder="0" pos="16 96 60 24" edTextCol="ff000000"
andrewm@55 876 edBkgCol="0" labelText="Status:&#10;" editableSingleClick="0"
andrewm@55 877 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@55 878 fontsize="15" bold="0" italic="0" justification="33"/>
andrewm@55 879 <TEXTBUTTON name="TouchKeys start button" id="1bb1c69c957fc984" memberName="touchkeyStartButton"
andrewm@55 880 virtualName="" explicitFocusOrder="0" pos="216 96 79 24" buttonText="Start"
andrewm@55 881 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@55 882 <LABEL name="TouchKeys status label" id="c91b132696e6ba1d" memberName="touchkeyStatusLabel"
andrewm@55 883 virtualName="" explicitFocusOrder="0" pos="72 96 136 24" edTextCol="ff000000"
andrewm@55 884 edBkgCol="0" labelText="not running" editableSingleClick="0"
andrewm@55 885 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@55 886 fontsize="15" bold="0" italic="0" justification="33"/>
andrewm@55 887 <GROUPCOMPONENT name="OSC group" id="8268119e22809825" memberName="oscGroupComponent"
andrewm@55 888 virtualName="" explicitFocusOrder="0" pos="8 320 304 96" title="OSC Output"/>
andrewm@55 889 <LABEL name="new label" id="896c0c48a1cf50a" memberName="label7" virtualName=""
andrewm@55 890 explicitFocusOrder="0" pos="16 376 55 24" edTextCol="ff000000"
andrewm@55 891 edBkgCol="0" labelText="Host:" editableSingleClick="0" editableDoubleClick="0"
andrewm@55 892 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
andrewm@55 893 bold="0" italic="0" justification="33"/>
andrewm@55 894 <TEXTEDITOR name="new text editor" id="84778d0bbebedd36" memberName="oscHostTextEditor"
andrewm@55 895 virtualName="" explicitFocusOrder="0" pos="64 376 128 24" initialText="127.0.0.1"
andrewm@55 896 multiline="0" retKeyStartsLine="0" readonly="0" scrollbars="1"
andrewm@55 897 caret="1" popupmenu="1"/>
andrewm@55 898 <LABEL name="new label" id="157c85bf83a7f936" memberName="label8" virtualName=""
andrewm@55 899 explicitFocusOrder="0" pos="200 376 40 24" edTextCol="ff000000"
andrewm@55 900 edBkgCol="0" labelText="Port:" editableSingleClick="0" editableDoubleClick="0"
andrewm@55 901 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
andrewm@55 902 bold="0" italic="0" justification="33"/>
andrewm@55 903 <TEXTEDITOR name="new text editor" id="7c21f0c238812d11" memberName="oscPortTextEditor"
andrewm@55 904 virtualName="" explicitFocusOrder="0" pos="240 376 56 24" initialText="8000"
andrewm@55 905 multiline="0" retKeyStartsLine="0" readonly="0" scrollbars="1"
andrewm@55 906 caret="1" popupmenu="1"/>
andrewm@55 907 <TOGGLEBUTTON name="OSC enable button" id="ccd52591cfd0b632" memberName="oscEnableButton"
andrewm@55 908 virtualName="" explicitFocusOrder="0" pos="24 344 144 24" buttonText="Enable OSC output"
andrewm@55 909 connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
andrewm@55 910 <TOGGLEBUTTON name="OSC enable raw button" id="4aaf8f80edaff24" memberName="oscEnableRawButton"
andrewm@55 911 virtualName="" explicitFocusOrder="0" pos="176 344 144 24" buttonText="Send raw frames"
andrewm@55 912 connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
andrewm@55 913 <LABEL name="new label" id="c5873c6498f8156d" memberName="label4" virtualName=""
andrewm@55 914 explicitFocusOrder="0" pos="16 64 104 24" edTextCol="ff000000"
andrewm@55 915 edBkgCol="0" labelText="Lowest Octave:" editableSingleClick="0"
andrewm@55 916 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@55 917 fontsize="15" bold="0" italic="0" justification="33"/>
andrewm@55 918 <COMBOBOX name="TouchKeys octave box" id="36ace32027c81d30" memberName="touchkeyOctaveComboBox"
andrewm@55 919 virtualName="" explicitFocusOrder="0" pos="120 64 88 24" editable="0"
andrewm@55 920 layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
andrewm@55 921 <GROUPCOMPONENT name="MIDI input group" id="bb54712f78382055" memberName="oscInputGroupComponent"
andrewm@55 922 virtualName="" explicitFocusOrder="0" pos="8 248 304 64" title="OSC Input"/>
andrewm@55 923 <TOGGLEBUTTON name="OSC input enable button" id="22a196770a440560" memberName="oscInputEnableButton"
andrewm@55 924 virtualName="" explicitFocusOrder="0" pos="24 272 152 24" buttonText="Enable OSC input"
andrewm@55 925 connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
andrewm@55 926 <LABEL name="new label" id="c680c2da87cdcbf2" memberName="label6" virtualName=""
andrewm@55 927 explicitFocusOrder="0" pos="200 272 40 24" edTextCol="ff000000"
andrewm@55 928 edBkgCol="0" labelText="Port:" editableSingleClick="0" editableDoubleClick="0"
andrewm@55 929 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
andrewm@55 930 bold="0" italic="0" justification="33"/>
andrewm@55 931 <TEXTEDITOR name="new text editor" id="d4a91e8bff5b6bc9" memberName="oscInputPortTextEditor"
andrewm@55 932 virtualName="" explicitFocusOrder="0" pos="240 272 56 24" initialText="8001"
andrewm@55 933 multiline="0" retKeyStartsLine="0" readonly="0" scrollbars="1"
andrewm@55 934 caret="1" popupmenu="1"/>
andrewm@55 935 <TABBEDCOMPONENT name="keyboard zone tabbed component" id="33da3d6583cdacbf" memberName="keyboardZoneTabbedComponent"
andrewm@55 936 virtualName="" explicitFocusOrder="0" pos="320 0 552 464" orientation="top"
andrewm@55 937 tabBarDepth="30" initialTab="-1"/>
andrewm@55 938 <TEXTBUTTON name="add zone button" id="1d2fa7fd74f31315" memberName="addZoneButton"
andrewm@55 939 virtualName="" explicitFocusOrder="0" pos="776 4 38 20" buttonText="Add"
andrewm@55 940 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@55 941 <TEXTBUTTON name="remove zone button" id="7865f7787a191e0e" memberName="removeZoneButton"
andrewm@55 942 virtualName="" explicitFocusOrder="0" pos="824 4 38 20" buttonText="Del"
andrewm@55 943 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@55 944 <TEXTBUTTON name="TouchKeys autodetect button" id="6e19894bc11d0276" memberName="touchkeyAutodetectButton"
andrewm@55 945 virtualName="" explicitFocusOrder="0" pos="216 64 79 24" buttonText="Detect"
andrewm@55 946 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@55 947 <COMBOBOX name="MIDI input aux combo box" id="1b77c934a4790942" memberName="midiInputAuxDeviceComboBox"
andrewm@55 948 virtualName="" explicitFocusOrder="0" pos="80 200 216 24" editable="0"
andrewm@55 949 layout="33" items="" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
andrewm@55 950 <LABEL name="new label" id="7409cb92cfa3b9f2" memberName="label5" virtualName=""
andrewm@55 951 explicitFocusOrder="0" pos="24 200 55 24" edTextCol="ff000000"
andrewm@55 952 edBkgCol="0" labelText="Aux:" editableSingleClick="0" editableDoubleClick="0"
andrewm@55 953 focusDiscardsChanges="0" fontname="Default font" fontsize="15"
andrewm@55 954 bold="0" italic="0" justification="34"/>
andrewm@55 955 </JUCER_COMPONENT>
andrewm@55 956
andrewm@55 957 END_JUCER_METADATA
andrewm@55 958 */
andrewm@55 959 #endif
andrewm@55 960
andrewm@55 961
andrewm@55 962 //[EndFile] You can add extra defines here...
andrewm@55 963 #endif // TOUCHKEYS_NO_GUI
andrewm@55 964 //[/EndFile]