//=============MidiInputDeviceSelector============================================ MidiInputDeviceSelector::MidiInputDeviceSelector(String name) : ComboBox(name) { // get list of devices StringArray devices = MidiInput::getDevices(); addItemList(devices, 1); addListener(this); setSelectedItemIndex(MidiInput::getDefaultDeviceIndex()); }
void ComboBox::clear (const NotificationType notification) { items.clear(); separatorPending = false; if (! label->isEditable()) setSelectedItemIndex (-1, notification); }
void ComboBox::clear (const bool dontSendChangeMessage) { items.clear(); separatorPending = false; if (! label->isEditable()) setSelectedItemIndex (-1, dontSendChangeMessage); }
//============MidiOutputDeviceSelector=========================================== MidiOutputDeviceSelector::MidiOutputDeviceSelector(String name) : ComboBox(name) { // populate self with available devices StringArray options = MidiOutput::getDevices(); addItemList(options, 1); addListener(this); setSelectedItemIndex(MidiOutput::getDefaultDeviceIndex()); }
void ComboBoxImage::showPopup() { if ( !onPopup ) { onPopup = true; int idx = popup.show() - 1; onPopup = false; if ( idx < 0 ) return; setSelectedItemIndex(idx); } }
bool ComboBox::selectIfEnabled (const int index) { const ItemInfo* const item = getItemForIndex (index); if (item != nullptr && item->isEnabled) { setSelectedItemIndex (index); return true; } return false; }
void ItemContainer::mousePressed(gcn::MouseEvent &event) { const int button = event.getButton(); if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) { Item *item = getItem(event.getX(), event.getY()); if (item) setSelectedItemIndex(item->getInvIndex()); } }
Combo::Combo(const parameters::ParameterInfo& inParamInfo, juce::AudioProcessor* inProcessor) : Control(inParamInfo, inProcessor) { const int numValues = static_cast<int>(getPlainValue(1.f)) + 1; for (int i = 0; i < numValues; ++i) { addItem(getControlValueText(getNormalizedValue(float(i))), i + 1); } setJustificationType(juce::Justification::centred); setSelectedItemIndex(static_cast<int>(getPlainValue(getControlValue())), juce::dontSendNotification); addListener(this); }
//============================================================================== bool ComboBox::keyPressed (const KeyPress& key) { bool used = false; if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey)) { setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1)); used = true; } else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey)) { setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1)); used = true; } else if (key.isKeyCode (KeyPress::returnKey)) { showPopup(); used = true; } return used; }
void ComboBox::setSelectedItemIndex (const int index, const bool dontSendChange) { setSelectedItemIndex (index, dontSendChange ? dontSendNotification : sendNotification); }
void Combo::controlValueChanged(float inValue) { setSelectedItemIndex(static_cast<int>(getPlainValue(inValue)), juce::dontSendNotification); }
void ItemContainer::keyPressed(gcn::KeyEvent &event) { const int columns = std::max(1, getWidth() / gridWidth); const int gridSlot = getVisibleSlot(getSelectedItem()); int itemX = gridSlot % columns; int itemY = gridSlot / columns; // Handling direction keys: all of these set selectNewItem, and change // itemX or itemY checking only that the selection doesn't go off the top, // left or right of the grid. The block below the switch statement then // checks that there's an item in that slot (implictly bounds-checking that // the selection didn't go off the bottom of the grid). bool selectNewItem = false; switch (event.getKey().getValue()) { case Key::LEFT: if (itemX != 0) itemX--; selectNewItem = true; event.consume(); break; case Key::RIGHT: if (itemX < (columns - 1)) itemX++; selectNewItem = true; event.consume(); break; case Key::UP: if (itemY != 0) itemY--; selectNewItem = true; event.consume(); break; case Key::DOWN: itemY++; selectNewItem = true; event.consume(); break; case Key::ENTER: case Key::SPACE: if (event.isShiftPressed()) { const std::string actionEventId = getActionEventId(); setActionEventId("default"); distributeActionEvent(); setActionEventId(actionEventId); } else distributeActionEvent(); event.consume(); break; } if (selectNewItem) { Item* selection = getItemInVisibleSlot(itemX + columns * itemY); if (selection) setSelectedItemIndex(selection->getInvIndex()); } }