DJMFix.cpp
branchv_0
changeset 5 ef8f4023e32e
parent 2 f34476ab597f
child 6 bddcf2bf29f2
     1.1 --- a/DJMFix.cpp	Fri Dec 18 23:58:03 2020 +0100
     1.2 +++ b/DJMFix.cpp	Sat Dec 19 17:33:16 2020 +0100
     1.3 @@ -15,7 +15,9 @@
     1.4   * along with this program. If not, see <http://www.gnu.org/licenses/>.
     1.5   */
     1.6  #include <iostream>
     1.7 +#include <iomanip>
     1.8  #include <thread>
     1.9 +#include <atomic>
    1.10  #include <chrono>
    1.11  #include <stdexcept>
    1.12  
    1.13 @@ -27,8 +29,8 @@
    1.14  private:
    1.15  	MidiSender* midiSender;
    1.16  	std::thread keepAliveThread;
    1.17 -	bool running = false;
    1.18 -	bool stopped = false;
    1.19 +	std::atomic<bool> running{false};
    1.20 +	std::atomic<bool> stopped{false};
    1.21  
    1.22  	void run() {
    1.23  		while (!stopped) {
    1.24 @@ -38,6 +40,13 @@
    1.25  		}
    1.26  	}
    1.27  
    1.28 +	// TODO: remove
    1.29 +	std::string toString(const MidiMessage& midiMessage) {
    1.30 +		std::stringstream result;
    1.31 +		for (uint8_t b : midiMessage) result << std::hex << std::setw(2) << std::setfill('0') << (int) b;
    1.32 +		return result.str();
    1.33 +	}
    1.34 +
    1.35  public:
    1.36  
    1.37  	virtual ~DJMFixImpl() override {
    1.38 @@ -51,13 +60,22 @@
    1.39  	}
    1.40  
    1.41  	virtual void receive(MidiMessage midiMessage) override {
    1.42 -		std::cerr << "DJMFixImpl::receive()" << std::endl; // TODO: do not mess STDIO
    1.43 +		std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO
    1.44 +
    1.45 +		if (midiMessage.size() == 54 && midiMessage[9] == 0x13) {
    1.46 +			std::cerr << "DJMFixImpl::receive(): got message with HashA and SeedE" << std::endl; // TODO: do not mess STDIO
    1.47 +		}
    1.48 +
    1.49  	}
    1.50  
    1.51  	void start() override {
    1.52  		std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO
    1.53 -		if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting");
    1.54 -		midiSender->send({0xf0, 0xf7});
    1.55 +		if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting DJMFix");
    1.56 +
    1.57 +		// TODO: methods for parsing and constructing messages from parts (TLV)
    1.58 +		midiSender->send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x50, 0x01, 0xf7});
    1.59 +		std::this_thread::sleep_for(std::chrono::milliseconds(10));
    1.60 +		midiSender->send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x12, 0x2a, 0x01, 0x0b, 0x50, 0x69, 0x6f, 0x6e, 0x65, 0x65, 0x72, 0x44, 0x4a, 0x02, 0x0b, 0x72, 0x65, 0x6b, 0x6f, 0x72, 0x64, 0x62, 0x6f, 0x78, 0x03, 0x12, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xf7});
    1.61  
    1.62  		keepAliveThread = std::thread(&DJMFixImpl::run, this);
    1.63  		running = true;