void MainContentComponent::Init(std::shared_ptr<CommandMap>& command_map, std::weak_ptr<LR_IPC_IN>&& lr_ipc_in, std::weak_ptr<LR_IPC_OUT>&& lr_ipc_out, std::shared_ptr<MIDIProcessor>& midi_processor, //-V2009 std::shared_ptr<ProfileManager>& profile_manager, std::shared_ptr<SettingsManager>& settings_manager, std::shared_ptr<MIDISender>& midi_sender) { //copy the pointers command_map_ = command_map; lr_ipc_in_ = std::move(lr_ipc_in); lr_ipc_out_ = std::move(lr_ipc_out); settings_manager_ = settings_manager; midi_processor_ = midi_processor; midi_sender_ = midi_sender; //call the function of the sub component. command_table_model_.Init(command_map); if (midi_processor) { // Add ourselves as a listener for MIDI commands midi_processor->addMIDICommandListener(this); } if (const auto ptr = lr_ipc_out_.lock()) { // Add ourselves as a listener for LR_IPC_OUT events ptr->addListener(this); } if (profile_manager) { // Add ourselves as a listener for profile changes profile_manager->addListener(this); } //Set the component size setSize(kMainWidth, kMainHeight); // Main title title_label_.setFont(juce::Font{36.f, juce::Font::bold}); title_label_.setEditable(false); title_label_.setColour(juce::Label::textColourId, juce::Colours::darkgrey); title_label_.setComponentEffect(&title_shadow_); title_label_.setBounds(kMainLeft, 10, kFullWidth, 30); addToLayout(&title_label_, anchorMidLeft, anchorMidRight); addAndMakeVisible(title_label_); // Version label SetLabelSettings(version_label_); version_label_.setBounds(kMainLeft, 40, kFullWidth, 10); addToLayout(&version_label_, anchorMidLeft, anchorMidRight); addAndMakeVisible(version_label_); // Connection status connection_label_.setFont(juce::Font{12.f, juce::Font::bold}); connection_label_.setEditable(false); connection_label_.setColour(juce::Label::backgroundColourId, juce::Colours::red); connection_label_.setColour(juce::Label::textColourId, juce::Colours::black); connection_label_.setJustificationType(juce::Justification::centred); connection_label_.setBounds(200, 15, kConnectionLabelWidth, kStandardHeight); addToLayout(&connection_label_, anchorMidLeft, anchorMidRight); addAndMakeVisible(connection_label_); // Load button load_button_.addListener(this); load_button_.setBounds(kFirstButtonX, 60, kButtonWidth, kStandardHeight); addToLayout(&load_button_, anchorMidLeft, anchorMidRight); addAndMakeVisible(load_button_); // Save button save_button_.addListener(this); save_button_.setBounds(kSecondButtonX, 60, kButtonWidth, kStandardHeight); addToLayout(&save_button_, anchorMidLeft, anchorMidRight); addAndMakeVisible(save_button_); // Settings button settings_button_.addListener(this); settings_button_.setBounds(kThirdButtonX, 60, kButtonWidth, kStandardHeight); addToLayout(&settings_button_, anchorMidLeft, anchorMidRight); addAndMakeVisible(settings_button_); // Command Table command_table_.setModel(&command_table_model_); command_table_.setBounds(kMainLeft, 100, kFullWidth, kCommandTableHeight); addToLayout(&command_table_, anchorMidLeft, anchorMidRight); addAndMakeVisible(command_table_); // Profile name label SetLabelSettings(profile_name_label_); profile_name_label_.setBounds(kMainLeft, kProfileNameY, kLabelWidth, kStandardHeight); addToLayout(&profile_name_label_, anchorMidLeft, anchorMidRight); profile_name_label_.setJustificationType(juce::Justification::centred); addAndMakeVisible(profile_name_label_); // Last MIDI command command_label_.setFont(juce::Font{12.f, juce::Font::bold}); command_label_.setEditable(false); command_label_.setColour(juce::Label::textColourId, juce::Colours::darkgrey); command_label_.setBounds(kCommandLabelX, kCommandLabelY, kLabelWidth, kStandardHeight); addToLayout(&command_label_, anchorMidLeft, anchorMidRight); addAndMakeVisible(command_label_); // Remove row button remove_row_button_.addListener(this); remove_row_button_.setBounds(kMainLeft, kRemoveRowY, kFullWidth, kStandardHeight); addToLayout(&remove_row_button_, anchorMidLeft, anchorMidRight); addAndMakeVisible(remove_row_button_); // Rescan MIDI button rescan_button_.addListener(this); rescan_button_.setBounds(kMainLeft, kRescanY, kFullWidth, kStandardHeight); addToLayout(&rescan_button_, anchorMidLeft, anchorMidRight); addAndMakeVisible(rescan_button_); // adding the current status label, used for counting down. current_status_.setBounds(kMainLeft, kCurrentStatusY, kFullWidth, kStandardHeight); addToLayout(¤t_status_, anchorMidLeft, anchorMidRight); current_status_.setJustificationType(juce::Justification::centred); SetLabelSettings(current_status_); addAndMakeVisible(current_status_); if (settings_manager_) { // Try to load a default.xml if the user has not set a profile directory if (settings_manager_->getProfileDirectory().isEmpty()) { juce::File default_profile = juce::File::getSpecialLocation(juce::File::currentExecutableFile).getSiblingFile("default.xml"); std::unique_ptr<juce::XmlElement> xml_element{juce::XmlDocument::parse(default_profile)}; if (xml_element) { command_table_model_.buildFromXml(xml_element.get()); command_table_.updateContent(); } } else if (profile_manager) { // otherwise use the last profile from the profile directory profile_manager->switchToProfile(0); } } // turn it on activateLayout(); }
void MainContentComponent::Init(CommandMap *commandMap, LR_IPC_IN *in, LR_IPC_OUT *out, MIDIProcessor *midiProcessor, ProfileManager *profileManager, SettingsManager *settingsManager, MIDISender *midiSender) { //copy the pointers m_commandMap = commandMap; m_lr_IPC_IN = in; m_lr_IPC_OUT = out; m_settingsManager = settingsManager; m_midiProcessor = midiProcessor; m_midiSender = midiSender; //call the function of the sub component. _commandTableModel.Init(commandMap); if (midiProcessor) { // Add ourselves as a listener for MIDI commands midiProcessor->addMIDICommandListener(this); } if (m_lr_IPC_OUT) { // Add ourselves as a listener for LR_IPC_OUT events m_lr_IPC_OUT->addListener(this); } if (profileManager) { // Add ourselves as a listener for profile changes profileManager->addListener(this); } //Set the component size setSize(MAIN_WIDTH, MAIN_HEIGHT); // Main title _titleLabel.setFont(Font(36.f, Font::bold)); _titleLabel.setEditable(false); _titleLabel.setColour(Label::textColourId, Colours::darkgrey); _titleLabel.setComponentEffect(&_titleShadow); _titleLabel.setBounds(MAIN_LEFT, 10, MAIN_WIDTH - 2 * MAIN_LEFT, 30); addToLayout(&_titleLabel, anchorMidLeft, anchorMidRight); addAndMakeVisible(_titleLabel); // Version label SetLabelSettings(_versionLabel); _versionLabel.setBounds(MAIN_LEFT, 40, MAIN_WIDTH - 2 * MAIN_LEFT, 10); addToLayout(&_versionLabel, anchorMidLeft, anchorMidRight); addAndMakeVisible(_versionLabel); // Connection status _connectionLabel.setFont(Font(12.f, Font::bold)); _connectionLabel.setEditable(false); _connectionLabel.setColour(Label::backgroundColourId, Colours::red); _connectionLabel.setColour(Label::textColourId, Colours::black); _connectionLabel.setJustificationType(Justification::centred); _connectionLabel.setBounds(200, 15, MAIN_WIDTH - MAIN_LEFT - 200, 20); addToLayout(&_connectionLabel, anchorMidLeft, anchorMidRight); addAndMakeVisible(_connectionLabel); //get the button width long buttonWidth = (MAIN_WIDTH - 2 * MAIN_LEFT - SPACEBETWEENBUTTON * 2) / 3; // Load button _loadButton.addListener(this); _loadButton.setBounds(MAIN_LEFT, 60, buttonWidth, 20); addToLayout(&_loadButton, anchorMidLeft, anchorMidRight); addAndMakeVisible(_loadButton); // Save button _saveButton.addListener(this); _saveButton.setBounds(MAIN_LEFT + buttonWidth + SPACEBETWEENBUTTON, 60, buttonWidth, 20); addToLayout(&_saveButton, anchorMidLeft, anchorMidRight); addAndMakeVisible(_saveButton); // Settings button _settingsButton.addListener(this); _settingsButton.setBounds(MAIN_LEFT + buttonWidth * 2 + SPACEBETWEENBUTTON * 2, 60, buttonWidth, 20); addToLayout(&_settingsButton, anchorMidLeft, anchorMidRight); addAndMakeVisible(_settingsButton); // Command Table _commandTable.setModel(&_commandTableModel); _commandTable.setBounds(MAIN_LEFT, 100, MAIN_WIDTH - MAIN_LEFT * 2, MAIN_HEIGHT - 210); addToLayout(&_commandTable, anchorMidLeft, anchorMidRight); addAndMakeVisible(_commandTable); long labelWidth = (MAIN_WIDTH - MAIN_LEFT * 2) / 2; // Profile name label SetLabelSettings(_profileNameLabel); _profileNameLabel.setBounds(MAIN_LEFT, MAIN_HEIGHT - 100, labelWidth, 20); addToLayout(&_profileNameLabel, anchorMidLeft, anchorMidRight); _profileNameLabel.setJustificationType(Justification::centred); addAndMakeVisible(_profileNameLabel); // Last MIDI command _commandLabel.setFont(Font(12.f, Font::bold)); _commandLabel.setEditable(false); _commandLabel.setColour(Label::textColourId, Colours::darkgrey); _commandLabel.setBounds(MAIN_LEFT + labelWidth, MAIN_HEIGHT - 100, labelWidth, 20); addToLayout(&_commandLabel, anchorMidLeft, anchorMidRight); addAndMakeVisible(_commandLabel); // Remove row button _removeRowButton.addListener(this); _removeRowButton.setBounds(MAIN_LEFT, MAIN_HEIGHT - 75, MAIN_WIDTH - MAIN_LEFT * 2, 20); addToLayout(&_removeRowButton, anchorMidLeft, anchorMidRight); addAndMakeVisible(_removeRowButton); // Rescan MIDI button _rescanButton.addListener(this); _rescanButton.setBounds(MAIN_LEFT, MAIN_HEIGHT - 50, MAIN_WIDTH - MAIN_LEFT * 2, 20); addToLayout(&_rescanButton, anchorMidLeft, anchorMidRight); addAndMakeVisible(_rescanButton); // adding the current status label, used for counting down. m_currentStatus.setBounds(MAIN_LEFT, MAIN_HEIGHT - 30, MAIN_WIDTH - MAIN_LEFT * 2, 20); addToLayout(&m_currentStatus, anchorMidLeft, anchorMidRight); m_currentStatus.setJustificationType(Justification::centred); SetLabelSettings(m_currentStatus); addAndMakeVisible(m_currentStatus); _systemTrayComponent.setIconImage(ImageCache::getFromMemory(BinaryData::MIDI2LR_png, BinaryData::MIDI2LR_pngSize)); if (m_settingsManager) { // Try to load a default.xml if the user has not set a profile directory if (m_settingsManager->getProfileDirectory().isEmpty()) { File defaultProfile = File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("default.xml"); ScopedPointer<XmlElement> elem = XmlDocument::parse(defaultProfile); if (elem) { _commandTableModel.buildFromXml(elem); _commandTable.updateContent(); } } else if (profileManager) { // otherwise use the last profile from the profile directory profileManager->switchToProfile(0); } } // turn it on activateLayout(); }