void CtrlrPanelCanvas::replaceComponent (CtrlrModulator &modulator, const String &targetComponentType)
{
	CtrlrComponent *oldComponent = modulator.getComponent();
	CtrlrComponent *newComponent = nullptr;

	/* detach the existing component so it doesn't get notified about anything, the pointer will be invalid */
    if (getOwner().getSelection())
    {
        getOwner().getSelection()->deselectAll();
        getOwner().getSelection()->dispatchPendingMessages();
        getOwner().getSelection()->removeChangeListener(oldComponent);
    }

	if (oldComponent)
	{
		/* keep a copy of the old properties, we need to find out if the component is in a group */
		ValueTree oldComponentProperties = oldComponent->getObjectTree().createCopy();

		modulator.setComponentType(targetComponentType, false);

		/* get the new component pointer and attach it */
		newComponent = modulator.getComponent();
        if (getOwner().getSelection())
            getOwner().getSelection()->addChangeListener (newComponent);

		addAndMakeVisibleNg (modulator.getComponent(), nullptr, true);

		/* attach the new component to any group components the old component was int */
		if (oldComponentProperties.hasProperty(Ids::componentGroupName))
		{
			CtrlrGroup *group = dynamic_cast<CtrlrGroup*>(owner.getOwner().getComponent(oldComponentProperties.getProperty(Ids::componentGroupName)));
			if (group)
			{
				group->setOwned (newComponent, true);
			}
		}

		if (oldComponentProperties.hasProperty(Ids::componentTabName))
		{
			CtrlrTabsComponent *tabs = dynamic_cast<CtrlrTabsComponent*>(owner.getOwner().getComponent(oldComponentProperties.getProperty(Ids::componentTabName)));
			if (tabs)
			{
				tabs->setOwned (newComponent, oldComponentProperties.getProperty(Ids::componentTabId), true);
			}
		}

		/* copy any old properties to the new component */
        for (int i=0; i<oldComponentProperties.getNumProperties(); i++)
		{
			const Identifier propName 	= oldComponentProperties.getPropertyName(i);
			const var propValue			= oldComponentProperties.getProperty(propName);

			if (propName != Ids::uiType)
			{
				if (newComponent->getObjectTree().hasProperty(propName))
					newComponent->setProperty (propName, propValue);
			}
		}
	}
}
Exemple #2
0
void Mixer::pruneRemotes(ValueTree active_users)
{
  // find GUI elements for parted users
  for (int user_n = GUI::FIRST_REMOTE_IDX ; user_n < getNumDynamicMixers() ; ++user_n)
  {
    RemoteChannels* channels        = (RemoteChannels*)getChildComponent(user_n) ;
    Identifier      user_id         = Identifier(channels->getComponentID()) ;
    Array<var>*     active_channels = active_users[user_id].getArray() ;

    if (active_users.hasProperty(user_id))
    {
      // find GUI elements for removed channels of active user (first is master)
      for (int channel_n = 1 ; channel_n < channels->getNumChannels() ; ++channel_n)
      {
        Component* channel    = channels->getChildComponent(channel_n) ;
        var        channel_id = var(channel->getComponentID()) ;

        if (active_channels->contains(channel_id)) continue ;

        // delete orphaned GUI elements for removed channel
        removeChannel(user_id , Identifier(channel_id.toString())) ; --channel_n ;
      }
    }
    // delete orphaned GUI elements for parted user
    else { removeChannels(channels) ; --user_n ; }
  }
}
bool MDLHelper::addOutputDSPVarIfNotExists(const MDLFile& mdlFile)
{
    ValueTree mdlRoot = mdlFile.getMDLRoot();
    bool outputDSPExists = false;

    ValueTree fcb = mdlRoot.getOrCreateChildWithName(Objects::faustcodeblock, nullptr);
    for (int i = 0; i < fcb.getNumChildren(); ++i)
    {
        ValueTree fc = fcb.getChild(i);
        if (fc.hasProperty(Ids::value))
        {
            String fcStr = fc[Ids::value].toString();
            if (fcStr.startsWith("outputDSP"))
            {
                outputDSPExists = true;
                break;
            }
        }
    }
    if (!outputDSPExists)
    {
        ValueTree fc(Ids::faustcode);
        fc.setProperty(Ids::value, "outputDSP=SAMlimiter:highpass(4,20.0);", nullptr);
        fcb.addChild(fc, -1, nullptr);
        return true;
    }
    return false;
}
void UnityProjectBuilder::updateBuildDirectories()
{
    if (buildDir.isEmpty())
        return;
    
    ValueTree exportsTree (project.getChildWithName (Ids::exportFormats));
    
    if (! exportsTree.isValid())
        return;
    
    const int numExports = exportsTree.getNumChildren();
    
    for (int i = 0; i < numExports; ++i)
    {
        ValueTree exporter (exportsTree.getChild (i));
        
        if (exporter.hasProperty (Ids::targetFolderProp))
        {
            logOutput ("Updating exporter " + exporter.getType().toString());
            const String oldTarget (exporter.getProperty (Ids::targetFolderProp).toString());
            String newTarget (buildDir);
            
            if (oldTarget.containsChar ('/'))
                 newTarget << oldTarget.fromLastOccurrenceOf ("/", true, false);
                
            exporter.setProperty (Ids::targetFolderProp, newTarget, nullptr);
        }
    }
}
void CtrlrTabsComponent::addTab(const ValueTree tabToAdd)
{
	ValueTree tabTree = tabToAdd;

	const int tabId = ctrlrTabs->getNumTabs();

	if (!tabTree.hasProperty(Ids::uiTabsTabIndex))
		tabTree.setProperty (Ids::uiTabsTabIndex, tabId, 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabName))
		tabTree.setProperty (Ids::uiTabsTabName, "Tab "+String(tabId), 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabContentBackgroundColour))
		tabTree.setProperty (Ids::uiTabsTabContentBackgroundColour, Colours::yellow.toString(), 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabBackgroundColour))
		tabTree.setProperty (Ids::uiTabsTabBackgroundColour, Colours::lightgrey.toString(), 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabBackgroundImage))
		tabTree.setProperty (Ids::uiTabsTabBackgroundImage, COMBO_NONE_ITEM, 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabBackgroundImageLayout))
		tabTree.setProperty (Ids::uiTabsTabBackgroundImageLayout, 36, 0);

	if (!tabTree.hasProperty(Ids::uiTabsTabBackgroundImageAlpha))
		tabTree.setProperty (Ids::uiTabsTabBackgroundImageAlpha, 255, 0);

	ctrlrTabs->addTab (	tabTree.getProperty(Ids::uiTabsTabName).toString(),
						VAR2COLOUR(tabTree.getProperty(Ids::uiTabsTabBackgroundColour)),
						new CtrlrTabsContentComponent(tabTree, *this),
						true,
						tabTree.getProperty(Ids::uiTabsTabIndex));
}
void CtrlrPanelComponentProperties::copyProperties(ValueTree &sourceTree, ValueTree &destinationTree)
{
	for (int i=0; i<sourceTree.getNumProperties(); i++)
	{
		if (!destinationTree.hasProperty (sourceTree.getPropertyName(i)))
		{
			if (sourceTree.getPropertyName(i) != Ids::vstIndex)
				destinationTree.setProperty (sourceTree.getPropertyName(i), sourceTree.getPropertyAsValue(sourceTree.getPropertyName(i), 0), 0);
		}
	}
}
//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void PageRemoteSensor::jobExecutionResult (const ValueTree jobResultData)
{
    MessageManagerLock mmlock;

    if (jobResultData.hasProperty(SunriseConfig::rsCurrent0))
    {
        current0Label->setValue ((int)jobResultData.getProperty(SunriseConfig::rsCurrent0), Amp);
    }

    if (jobResultData.hasProperty(SunriseConfig::rsCurrent1))
    {
        current1Label->setValue ((int)jobResultData.getProperty(SunriseConfig::rsCurrent1), Amp);
    }

    if (jobResultData.hasProperty(SunriseConfig::rsTemperature0))
    {
        temperatureLabel->setValue ((int)jobResultData.getProperty(SunriseConfig::rsTemperature0), Celsius);
    }

    if (jobResultData.hasProperty(SunriseConfig::rsPressure0))
    {
        pressureLabel->setValue ((int)jobResultData.getProperty(SunriseConfig::rsPressure0), HectoPascal);
    }

	if (jobResultData.hasProperty(SunriseConfig::rsTemperature1))
    {
        temperatureLabel2->setValue ((int)jobResultData.getProperty(SunriseConfig::rsTemperature1), Celsius);
    }

	if (jobResultData.hasProperty(SunriseConfig::rsHumidity0))
    {
        humidityLabel->setValue ((int)jobResultData.getProperty(SunriseConfig::rsHumidity0), Percent);
    }
}
void StoredSettings::RestoreProperty(const Identifier& CategoryName, const Identifier& PropertyName, Value& Val)
{
	ValueTree tree = (CategoryName == Identifiers::Category1) ? tree_root : tree_root.getOrCreateChildWithName(CategoryName, nullptr);
	if(!tree.hasProperty(PropertyName)){
		//If there isn't one then set a new one.
		//プロパティーが存在しなければ、設定する
		tree.setProperty(PropertyName, Val, nullptr);
	}else{
		//If the property already exists then just return it.
		//存在していれば、そのプロパティーを参照する
		Val.referTo(tree.getPropertyAsValue(PropertyName, nullptr));
	}
}