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

mqPatchBrowser.cpp (2859B)


      1 #include "mqPatchBrowser.h"
      2 
      3 #include "mqController.h"
      4 
      5 #include "../mqLib/mqstate.h"
      6 
      7 namespace mqJucePlugin
      8 {
      9     enum Columns
     10 	{
     11         INDEX = 1,
     12         NAME = 2,
     13         CAT = 3,
     14 	};
     15 
     16 	constexpr std::initializer_list<jucePluginEditorLib::PatchBrowser::ColumnDefinition> g_columns =
     17 	{
     18 		{"#", INDEX, 32},
     19 		{"Name", NAME, 150},
     20 		{"Category", CAT, 70}
     21 	};
     22 
     23 	PatchBrowser::PatchBrowser(const jucePluginEditorLib::Editor& _editor, pluginLib::Controller& _controller, juce::PropertiesFile& _config) : jucePluginEditorLib::PatchBrowser(_editor, _controller, _config, g_columns)
     24 	{
     25 	}
     26 
     27 	jucePluginEditorLib::Patch* PatchBrowser::createPatch()
     28 	{
     29 		return new Patch();
     30 	}
     31 
     32 	bool PatchBrowser::initializePatch(jucePluginEditorLib::Patch& _patch)
     33 	{
     34 		if(_patch.sysex.size() < 5 || _patch.sysex[4] != 0x10)
     35 			return false;
     36 
     37 		auto& patch = static_cast<Patch&>(_patch);
     38 
     39 		const auto& dumpMq = mqLib::State::g_dumps[static_cast<uint32_t>(mqLib::State::DumpType::Single)];
     40 
     41 		if (patch.sysex.size() == dumpMq.dumpSize)
     42 		{
     43 			patch.name = std::string(reinterpret_cast<const char *>(&patch.sysex[dumpMq.firstParamIndex + 363]), 16);
     44 			patch.category = std::string(reinterpret_cast<const char *>(&patch.sysex[dumpMq.firstParamIndex + 379]), 4);
     45 
     46 			return true;
     47 		}
     48 
     49 		const auto &dumpQ = mqLib::State::g_dumps[static_cast<uint32_t>(mqLib::State::DumpType::SingleQ)];
     50 
     51 		if (patch.sysex.size() == dumpQ.dumpSize)
     52 		{
     53 			patch.name = std::string(reinterpret_cast<const char *>(&patch.sysex[dumpQ.firstParamIndex + 364]), 16);
     54 			patch.category = std::string(reinterpret_cast<const char *>(&patch.sysex[dumpQ.firstParamIndex + 380]), 4);
     55 
     56 			return true;
     57 		}
     58 		return false;
     59 	}
     60 
     61 	juce::MD5 PatchBrowser::getChecksum(jucePluginEditorLib::Patch& _patch)
     62 	{
     63 		const auto& dump = mqLib::State::g_dumps[static_cast<uint32_t>(mqLib::State::DumpType::Single)];
     64 
     65 		return {&_patch.sysex[dump.firstParamIndex], dump.dumpSize - 2 - dump.firstParamIndex};
     66 	}
     67 
     68 	bool PatchBrowser::activatePatch(jucePluginEditorLib::Patch& _patch)
     69 	{
     70 		auto& c = static_cast<Controller&>(m_controller);
     71 
     72 		c.sendSingle(_patch.sysex);
     73 
     74 		return true;
     75 	}
     76 
     77 	int PatchBrowser::comparePatches(int _columnId, const jucePluginEditorLib::Patch& _a, const jucePluginEditorLib::Patch& _b) const
     78 	{
     79 		auto& a = static_cast<const Patch&>(_a);
     80 		auto& b = static_cast<const Patch&>(_b);
     81 
     82 		switch(_columnId)
     83 		{
     84 			case INDEX:		return a.progNumber - b.progNumber;
     85 			case NAME:		return a.name.compare(b.name);
     86 			case CAT:		return a.category.compare(b.category);
     87 			default:		return 0;
     88 		}
     89 	}
     90 
     91 	std::string PatchBrowser::getCellText(const jucePluginEditorLib::Patch& _patch, int _columnId)
     92 	{
     93 		switch (_columnId)
     94 		{
     95 		case INDEX:		return std::to_string(_patch.progNumber);
     96 		case NAME:		return _patch.name;
     97 		case CAT:		return static_cast<const Patch&>(_patch).category;
     98 		default:		return "?";
     99 		}
    100 	}
    101 }