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

xtFrontPanel.cpp (2070B)


      1 #include "xtFrontPanel.h"
      2 
      3 #include "xtController.h"
      4 #include "xtEditor.h"
      5 #include "xtLcd.h"
      6 
      7 #include "xtLib/xtMidiTypes.h"
      8 
      9 namespace xtJucePlugin
     10 {
     11 	constexpr const char* g_ledNames[] =
     12 	{
     13 		"midiLed"
     14 	};
     15 
     16 	FrontPanel::FrontPanel(const Editor& _editor, Controller& _controller) : m_controller(_controller)
     17 	{
     18 		m_leds.fill(nullptr);
     19 
     20 		for(size_t i=0; i<std::size(g_ledNames); ++i)
     21 			m_leds[i] = _editor.findComponentT<juce::Button>(g_ledNames[i], false);
     22 
     23 		auto *lcdArea = _editor.findComponentT<juce::Component>("lcdArea", false);
     24 
     25 		if (lcdArea)
     26 			m_lcd.reset(new XtLcd(*lcdArea, m_controller));
     27 
     28 		auto* shadow = _editor.findComponent("lcdshadow", false);
     29 
     30 		if(shadow)
     31 			shadow->setInterceptsMouseClicks(false, false);
     32 
     33 		_controller.sendSysEx(Controller::EmuRequestLcd);
     34 		_controller.sendSysEx(Controller::EmuRequestLeds);
     35 
     36 		_controller.setFrontPanel(this);
     37 	}
     38 
     39 	FrontPanel::~FrontPanel()
     40 	{
     41 		m_controller.setFrontPanel(nullptr);
     42 		m_lcd.reset();
     43 	}
     44 
     45 	void FrontPanel::processSysex(const std::vector<uint8_t>& _msg) const
     46 	{
     47 		if(_msg.size() < 5)
     48 			return;
     49 
     50 		const auto cmd = static_cast<xt::SysexCommand>(_msg[4]);
     51 
     52 		switch (cmd)
     53 		{
     54 		case xt::SysexCommand::EmuLCD:
     55 			processLCDUpdate(_msg);
     56 			break;
     57 		case xt::SysexCommand::EmuLEDs:
     58 			processLedUpdate(_msg);
     59 			break;
     60 		case xt::SysexCommand::EmuRotaries:
     61 		case xt::SysexCommand::EmuButtons:
     62 		default:
     63 			break;
     64 		}
     65 	}
     66 
     67 	void FrontPanel::processLCDUpdate(const std::vector<uint8_t>& _msg) const
     68 	{
     69 		const auto* data = &_msg[5];
     70 
     71 		std::array<uint8_t, 80> d{};
     72 
     73 		for(size_t i=0; i<d.size(); ++i)
     74 			d[i] = data[i];
     75 
     76 		m_lcd->setText(d);
     77 	}
     78 
     79 	void FrontPanel::processLedUpdate(const std::vector<uint8_t>& _msg) const
     80 	{
     81 		const uint32_t leds = 
     82 			(static_cast<uint32_t>(_msg[5]) << 24) |
     83 			(static_cast<uint32_t>(_msg[6]) << 16) |
     84 			(static_cast<uint32_t>(_msg[7]) << 8) |
     85 			static_cast<uint32_t>(_msg[8]);
     86 
     87 		for(size_t i=0; i<static_cast<uint32_t>(xt::LedType::Count); ++i)
     88 		{
     89 			if(m_leds[i])
     90 				m_leds[i]->setToggleState((leds & (1<<i)) != 0, juce::dontSendNotification);
     91 		}
     92 	}
     93 }