xtParts.cpp (1480B)
1 #include "xtParts.h" 2 3 #include "xtController.h" 4 #include "xtEditor.h" 5 #include "xtPartName.h" 6 7 namespace xtJucePlugin 8 { 9 Parts::Parts(Editor& _editor) : m_editor(_editor) 10 { 11 std::vector<PartButton*> buttons; 12 std::vector<PartName*> names; 13 std::vector<juce::Button*> leds; 14 15 _editor.findComponents<PartButton>(buttons, "PartButtonSmall", 8); 16 _editor.findComponents<PartName>(names, "PatchName", 8); 17 _editor.findComponents<juce::Button>(leds, "PartLedSmall", 8); 18 19 for(size_t i=0; i<m_parts.size(); ++i) 20 { 21 auto& part = m_parts[i]; 22 part.m_button = buttons[i]; 23 part.m_name = names[i]; 24 part.m_led = leds[i]; 25 26 part.m_button->initalize(static_cast<uint8_t>(i)); 27 part.m_name->initalize(static_cast<uint8_t>(i)); 28 } 29 30 updateUi(); 31 } 32 33 bool Parts::selectPart(const uint8_t _part) const 34 { 35 auto fail = [this]() 36 { 37 juce::MessageManager::callAsync([this] 38 { 39 updateUi(); 40 }); 41 return false; 42 }; 43 44 if(_part >= m_parts.size()) 45 return fail(); 46 if(_part > 0 && !m_editor.getXtController().isMultiMode()) 47 return fail(); 48 m_editor.setCurrentPart(_part); 49 50 updateUi(); 51 52 return true; 53 } 54 55 void Parts::updateUi() const 56 { 57 const auto currentPart = m_editor.getXtController().getCurrentPart(); 58 59 for(size_t i=0; i<m_parts.size(); ++i) 60 { 61 const auto& part = m_parts[i]; 62 63 part.m_led->setToggleState(i == currentPart, juce::dontSendNotification); 64 part.m_button->setToggleState(i == currentPart, juce::dontSendNotification); 65 } 66 } 67 }