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

mqEditor.cpp (5826B)


      1 #include "mqEditor.h"
      2 
      3 #include "PluginProcessor.h"
      4 
      5 #include "mqController.h"
      6 #include "mqFrontPanel.h"
      7 #include "mqPartButton.h"
      8 #include "mqPartSelect.h"
      9 #include "mqPatchManager.h"
     10 
     11 #include "mqLib/mqbuildconfig.h"
     12 
     13 #include "jucePluginEditorLib/focusedParameter.h"
     14 
     15 #include "jucePluginLib/filetype.h"
     16 
     17 namespace mqJucePlugin
     18 {
     19 	static constexpr uint32_t PlayModeListenerId = 1;
     20 
     21 	Editor::Editor(jucePluginEditorLib::Processor& _processor, pluginLib::ParameterBinding& _binding, const jucePluginEditorLib::Skin& _skin)
     22 	: jucePluginEditorLib::Editor(_processor, _binding, _skin)
     23 	, m_controller(dynamic_cast<Controller&>(_processor.getController()))
     24 	{
     25 		create();
     26 
     27 		m_frontPanel.reset(new FrontPanel(*this, m_controller));
     28 
     29 		if(auto* container = findComponent("patchbrowser", false))
     30 		{
     31 			constexpr auto scale = 1.3f;
     32 			const float x = static_cast<float>(container->getX());
     33 			const float y = static_cast<float>(container->getY());
     34 			const float w = static_cast<float>(container->getWidth());
     35 			const float h = static_cast<float>(container->getHeight());
     36 			container->setTransform(juce::AffineTransform::scale(scale, scale));
     37 			container->setSize(static_cast<int>(w / scale),static_cast<int>(h / scale));
     38 			container->setTopLeftPosition(static_cast<int>(x / scale),static_cast<int>(y / scale));
     39 
     40 			setPatchManager(new PatchManager(*this, container));
     41 		}
     42 
     43 		auto disableButton = [](juce::Component* _comp)
     44 		{
     45 			_comp->setAlpha(0.5f);
     46 			_comp->setEnabled(false);
     47 		};
     48 
     49 		auto disableByName = [this, &disableButton](const std::string& _button)
     50 		{
     51 			if (auto* bt = findComponentT<juce::Button>(_button, false))
     52 				disableButton(bt);
     53 		};
     54 
     55 		m_btPlayModeMulti = findComponentT<juce::Button>("btPlayModeMulti", false);
     56 		if(m_btPlayModeMulti)
     57 		{
     58 			if constexpr(mqLib::g_pluginDemo)
     59 			{
     60 				disableButton(m_btPlayModeMulti);
     61 			}
     62 			else
     63 			{
     64 				m_btPlayModeMulti->onClick = [this]()
     65 				{
     66 					m_controller.setPlayMode(m_btPlayModeMulti->getToggleState());
     67 				};
     68 			}
     69 		}
     70 
     71 		m_btSave = findComponentT<juce::Button>("btSave", false);
     72 		if (m_btSave)
     73 		{
     74 			if constexpr (mqLib::g_pluginDemo)
     75 			{
     76 				disableButton(m_btSave);
     77 			}
     78 			else
     79 			{
     80 				m_btSave->onClick = [this]()
     81 				{
     82 					onBtSave();
     83 				};
     84 			}
     85 		}
     86 
     87 		if constexpr(mqLib::g_pluginDemo)
     88 		{
     89 			disableByName("btPageMulti");
     90 			disableByName("btPageDrum");
     91 		}
     92 
     93 		m_btPresetPrev = findComponentT<juce::Button>("btPresetPrev", false);
     94 		m_btPresetNext = findComponentT<juce::Button>("btPresetNext", m_btPresetPrev != nullptr);
     95 
     96 		if (m_btPresetPrev)
     97 		{
     98 			m_btPresetPrev->onClick = [this]			{ onBtPresetPrev();	};
     99 			m_btPresetNext->onClick = [this]			{ onBtPresetNext();	};
    100 		}
    101 
    102 		m_focusedParameter.reset(new jucePluginEditorLib::FocusedParameter(m_controller, _binding, *this));
    103 
    104 		if(!findComponents("partSelectButton", false).empty())
    105 			m_partSelect.reset(new mqPartSelect(*this, m_controller, _binding));
    106 
    107 		addMouseListener(this, true);
    108 
    109 		m_controller.onPlayModeChanged.addListener(PlayModeListenerId, [this](bool)
    110 		{
    111 			if(m_btPlayModeMulti)
    112 				m_btPlayModeMulti->setToggleState(m_controller.isMultiMode(), juce::dontSendNotification);
    113 			if(m_partSelect)
    114 				m_partSelect->onPlayModeChanged();
    115 		});
    116 	}
    117 
    118 	Editor::~Editor()
    119 	{
    120 		m_controller.onPlayModeChanged.removeListener(PlayModeListenerId);
    121 
    122 		m_partSelect.reset();
    123 		m_focusedParameter.reset();
    124 		m_frontPanel.reset();
    125 	}
    126 
    127 	std::pair<std::string, std::string> Editor::getDemoRestrictionText() const
    128 	{
    129 		return {"Vavra",
    130 			"Vavra runs in demo mode\n"
    131 			"\n"
    132 			"The following features are disabled:\n"
    133 			"- Saving/Exporting Presets\n"
    134 			"- Plugin state is not preserve"
    135 		};
    136 	}
    137 
    138 	genericUI::Button<juce::DrawableButton>* Editor::createJuceComponent(genericUI::Button<juce::DrawableButton>* _button, genericUI::UiObject& _object, const std::string& _name, juce::DrawableButton::ButtonStyle _buttonStyle)
    139 	{
    140 		if(_object.getName() == "partSelectButton")
    141 			return new mqPartButton(*this, _name, _buttonStyle);
    142 
    143 		return jucePluginEditorLib::Editor::createJuceComponent(_button, _object, _name, _buttonStyle);
    144 	}
    145 
    146 	void Editor::mouseEnter(const juce::MouseEvent& _event)
    147 	{
    148 		m_focusedParameter->onMouseEnter(_event);
    149 	}
    150 
    151 	void Editor::savePreset(const pluginLib::FileType& _type)
    152 	{
    153 		jucePluginEditorLib::Editor::savePreset(_type, [&](const juce::File& _file)
    154 		{
    155 			auto type = _type;
    156 			const auto file = createValidFilename(type, _file);
    157 
    158 			const auto part = m_controller.getCurrentPart();
    159 			const auto p = m_controller.createSingleDump(mqLib::MidiBufferNum::SingleBankA, static_cast<mqLib::MidiSoundLocation>(0), part, part);
    160 			if(!p.empty())
    161 			{
    162 				const std::vector<std::vector<uint8_t>> presets{p};
    163 				jucePluginEditorLib::Editor::savePresets(_type, file, presets);
    164 			}
    165 		});
    166 	}
    167 
    168 	void Editor::onBtSave()
    169 	{
    170 		juce::PopupMenu menu;
    171 
    172 		const auto countAdded = getPatchManager()->createSaveMenuEntries(menu);
    173 
    174 		if(countAdded)
    175 			menu.addSeparator();
    176 
    177 		auto addEntry = [&](juce::PopupMenu& _menu, const std::string& _name, const std::function<void(pluginLib::FileType)>& _callback)
    178 		{
    179 			juce::PopupMenu subMenu;
    180 
    181 			subMenu.addItem(".syx", [_callback]() {_callback(pluginLib::FileType::Syx); });
    182 			subMenu.addItem(".mid", [_callback]() {_callback(pluginLib::FileType::Mid); });
    183 
    184 			_menu.addSubMenu(_name, subMenu);
    185 		};
    186 
    187 		addEntry(menu, "Current Single (Edit Buffer)", [this](pluginLib::FileType _type)
    188 		{
    189 			savePreset(_type);
    190 		});
    191 
    192 		menu.showMenuAsync(juce::PopupMenu::Options());
    193 	}
    194 
    195 	void Editor::onBtPresetPrev()
    196 	{
    197 		if (getPatchManager() && getPatchManager()->selectPrevPreset(m_controller.getCurrentPart()))
    198 			return;
    199 		m_controller.selectPrevPreset();
    200 	}
    201 
    202 	void Editor::onBtPresetNext()
    203 	{
    204 		if (getPatchManager() && getPatchManager()->selectNextPreset(m_controller.getCurrentPart()))
    205 			return;
    206 		m_controller.selectNextPreset();
    207 	}
    208 }