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

commandReader.cpp (1344B)


      1 #include "commandReader.h"
      2 
      3 #include "command.h"
      4 #include "dsp56300/source/dsp56kEmu/logging.h"
      5 #include "networkLib/stream.h"
      6 
      7 namespace bridgeLib
      8 {
      9 	CommandReader::CommandReader(CommandCallback&& _callback) : m_stream(512 * 1024), m_commandCallback(std::move(_callback))
     10 	{
     11 	}
     12 
     13 	void CommandReader::read(networkLib::Stream& _stream)
     14 	{
     15 		// read command (4 bytes)
     16 		char temp[5]{0,0,0,0,0};
     17 
     18 		_stream.read(temp, 4);
     19 		const auto command = static_cast<Command>(cmd(temp));
     20 
     21 		// read size (4 bytes)
     22 		uint32_t size;
     23 		_stream.read(&size, sizeof(size));
     24 
     25 		// read data (n bytes)
     26 		m_stream.getVector().resize(size);
     27 		_stream.read(m_stream.getVector().data(), size);
     28 
     29 //		LOG("Recv cmd " << commandToString(command) << ", len " << size);
     30 		m_stream.setReadPos(0);
     31 		handleCommand(command, m_stream);
     32 	}
     33 
     34 	void CommandReader::read(baseLib::BinaryStream& _in)
     35 	{
     36 		// read command (4 bytes)
     37 		char temp[5]{0,0,0,0,0};
     38 
     39 		_in.read(temp[0]);
     40 		_in.read(temp[1]);
     41 		_in.read(temp[2]);
     42 		_in.read(temp[3]);
     43 
     44 		const auto command = cmd(temp);
     45 
     46 		// read size (4 bytes)
     47 		const uint32_t size = _in.read<uint32_t>();
     48 
     49 		// read data (n bytes)
     50 		m_stream.getVector().resize(size);
     51 		for(size_t i=0; i<size; ++i)
     52 			m_stream.getVector()[i] = _in.read<uint8_t>();
     53 
     54 		m_stream.setReadPos(0);
     55 		handleCommand(static_cast<Command>(command), m_stream);
     56 	}
     57 }