void CtrlrPanelMIDISnapshot::gatherSnapshotData()
{
    buffer.clear();

    for (int i=0; i<owner.getModulators().size(); i++)
    {
        CtrlrModulator *m = owner.getModulators()[i];
        if (m->getMidiMessagePtr())
        {
            if (m->getComponent())
            {
                if ((int)m->getComponent()->getProperty(Ids::componentRadioGroupId) > 0)
                {
                    if (m->getComponent()->getToggleState() == false)
                        continue;
                    else if (!(bool)m->getProperty(Ids::modulatorExcludeFromSnapshot))
                        addCtrlrMidiMessageToBuffer (buffer, m->getMidiMessage());
                }
                else if (!(bool)m->getProperty(Ids::modulatorExcludeFromSnapshot))
                {
                    addCtrlrMidiMessageToBuffer (buffer, m->getMidiMessage());
                }
            }
        }
    }
}
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 #3
0
void CtrlrPanel::setProgram(ValueTree programTree, const bool sendSnapshotNow)
{
	ValueTree program;

	if (programTree.hasType(Ids::panelState))
	{
		program = programTree;
	}
	else
	{
		if (programTree.getChildWithName(Ids::panelState).isValid())
		{
			program = programTree.getChildWithName(Ids::panelState);
		}
	}

	setProgramState (true);
	if (program.isValid())
	{
		for (int i=0; i<program.getNumChildren(); i++)
		{
			if (program.getChild(i).hasType(Ids::value))
			{
				CtrlrModulator *m = getModulator (program.getChild(i).getProperty(Ids::name));
				if (m)
				{
					m->setRestoreState (true);
					m->getProcessor().setValueFromGUI (program.getChild(i).getProperty(Ids::value), true);
					if (m->getComponent())
					{
						m->getComponent()->setComponentValue (program.getChild(i).getProperty(Ids::value), false);
					}
					m->getProcessor().handleUpdateNowIfNeeded();
					m->setRestoreState (false);
				}
			}
		}

		if ((bool)getProperty (Ids::panelMidiSnapshotAfterProgramChange) == true)
		{
			snapshot.sendSnapshot();
		}

		if (luaPanelProgramChangedCbk && !luaPanelProgramChangedCbk.wasObjectDeleted())
		{
			if (luaPanelProgramChangedCbk->isValid())
			{
				getCtrlrLuaManager().getMethodManager().call (luaPanelProgramChangedCbk);
			}
		}
	}

	setProgramState (false);

	if (sendSnapshotNow)
	{
		_DBG("CtrlrPanel::setProgram sendSnapshotNow");
		sendSnapshot();
	}
}
void CtrlrPanelMIDISnapshot::gatherSnapshotData()
{
	buffer.clear();

	for (int i=0; i<owner.getModulators().size(); i++)
	{
		CtrlrModulator *m = owner.getModulators()[i];
		if (m->getMidiMessagePtr())
		{
			if (m->getComponent())
			{
				if ((int)m->getComponent()->getProperty(Ids::componentRadioGroupId) > 0)
				{
					if (m->getComponent()->getToggleState() == false)
						continue;
					else if (!(bool)m->getProperty(Ids::modulatorExcludeFromSnapshot))
						addCtrlrMidiMessageToBuffer (buffer, m->getMidiMessage());
				}
				else if (!(bool)m->getProperty(Ids::modulatorExcludeFromSnapshot))
				{
					addCtrlrMidiMessageToBuffer (buffer, m->getMidiMessage());
				}
			}
		}
	}

	showDialog = owner.getProperty(Ids::panelMidiSnapshotShowProgress);

	if (showDialog)
    {
        if (alertWindow == nullptr)
            alertWindow = LookAndFeel::getDefaultLookAndFeel().createAlertWindow ("MIDI Snapshot", String(), "Stop", String(), String(), AlertWindow::NoIcon, 1, nullptr);

        alertWindow->setEscapeKeyCancels (false);
        alertWindow->addProgressBarComponent (progress);
    }
    else
    {
        alertWindow = nullptr;
    }

    if (luaPanelMidiSnapshotPreCbk && !luaPanelMidiSnapshotPreCbk.wasObjectDeleted())
	{
		if (luaPanelMidiSnapshotPreCbk->isValid())
		{
			owner.getCtrlrLuaManager().getMethodManager().call (luaPanelMidiSnapshotPreCbk, &buffer);
		}
	}
}
void CtrlrPanelComponentProperties::refreshTargetModulationPropertyList (const ValueTree &sourceModulationTree)
{
	CtrlrModulator *target = owner.getOwner().getModulator (sourceModulationTree.getProperty (Ids::modulatorLinkedToModulator));

	if (target)
	{
		modulatorPropertyList.clear();
		modulatorPropertyList.add (COMBO_NONE_ITEM);

		if ((bool)sourceModulationTree.getProperty (Ids::modulatorLinkedToComponent) == true)
		{
			CtrlrComponent *c = target->getComponent();
			if (c)
			{
				for (int i=0; i<c->getComponentTree().getNumProperties(); i++)
				{
					modulatorPropertyList.add (c->getComponentTree().getPropertyName(i).toString());
				}
			}
		}
		else
		{
			for (int i=0; i<target->getModulatorTree().getNumProperties(); i++)
			{
				modulatorPropertyList.add (target->getModulatorTree().getPropertyName(i).toString());
			}
		}
	}
}
void CtrlrComponent::removeFromTab ()
{
	CtrlrModulator *tabsModulator = owner.getOwner().getModulator(getProperty(Ids::componentTabName));
	if (tabsModulator)
	{
		CtrlrTabsComponent *tabsComponent = dynamic_cast<CtrlrTabsComponent*>(tabsModulator->getComponent());
		if (tabsComponent)
		{
			tabsComponent->setOwned (this, getProperty(Ids::componentTabId), false);
		}
	}
}