gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

weTablesTree.cpp (2154B)


      1 #include "weTablesTree.h"
      2 
      3 #include "weTablesTreeItem.h"
      4 #include "weData.h"
      5 #include "xtController.h"
      6 #include "xtEditor.h"
      7 #include "xtWaveEditor.h"
      8 
      9 #include "xtLib/xtMidiTypes.h"
     10 
     11 namespace xtJucePlugin
     12 {
     13 	TablesTree::TablesTree(WaveEditor& _editor) : Tree(_editor)
     14 	{
     15 		for(uint16_t i=0; i<xt::wave::g_tableCount; ++i)
     16 		{
     17 			const xt::TableId tableId(i);
     18 
     19 			if(xt::wave::isAlgorithmicTable(tableId) && _editor.getTableName(tableId).empty())
     20 				continue;
     21 
     22 			getRootItem()->addSubItem(new TablesTreeItem(_editor, tableId));
     23 		}
     24 
     25 		setIndentSize(5);
     26 
     27 		auto* paramWave = getWaveParameter();
     28 
     29 		m_waveParamListener.set(paramWave, [this](pluginLib::Parameter* const&)
     30 		{
     31 			onWaveParamChanged();
     32 		});
     33 
     34 		m_partChangedListener.set(getWaveEditor().getEditor().getXtController().onCurrentPartChanged, [this](const uint8_t&)
     35 		{
     36 			onPartChanged();
     37 		});
     38 	}
     39 	
     40 	void TablesTree::setSelectedEntryFromCurrentPreset() const
     41 	{
     42 		const auto* paramWave = getWaveParameter();
     43 
     44 		const auto tableId = xt::TableId(static_cast<uint16_t>(paramWave->getUnnormalizedValue()));
     45 		getWaveEditor().setSelectedTable(tableId);
     46 	}
     47 
     48 	void TablesTree::setSelectedTable(const xt::TableId _id) const
     49 	{
     50 		for(int i=0; i<getRootItem()->getNumSubItems(); ++i)
     51 		{
     52 			auto* subItem = dynamic_cast<TablesTreeItem*>(getRootItem()->getSubItem(i));
     53 			if(!subItem)
     54 				continue;
     55 			if(subItem->getTableId() == _id)
     56 			{
     57 				subItem->setSelected(true, true, juce::dontSendNotification);
     58 				getRootItem()->getOwnerView()->scrollToKeepItemVisible(subItem);
     59 
     60 				auto* paramWave = getWaveParameter();
     61 				if(paramWave->getUnnormalizedValue() != _id.rawId())
     62 					paramWave->setUnnormalizedValueNotifyingHost(_id.rawId(), pluginLib::Parameter::Origin::Ui);
     63 
     64 				return;
     65 			}
     66 		}
     67 	}
     68 
     69 	void TablesTree::onWaveParamChanged() const
     70 	{
     71 		setSelectedEntryFromCurrentPreset();
     72 	}
     73 
     74 	void TablesTree::onPartChanged() const
     75 	{
     76 		setSelectedEntryFromCurrentPreset();
     77 	}
     78 
     79 	pluginLib::Parameter* TablesTree::getWaveParameter() const
     80 	{
     81 		const auto& c = getWaveEditor().getEditor().getXtController();
     82 		auto* param = c.getParameter("Wave", c.getCurrentPart());
     83 		assert(param);
     84 		return param;
     85 	}
     86 }