mt-32-display.cpp
branchv_0
changeset 0 a7af46af7903
child 1 6733bd832b61
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mt-32-display.cpp	Tue May 19 16:01:09 2020 +0200
     1.3 @@ -0,0 +1,45 @@
     1.4 +#include <iostream>
     1.5 +#include <iomanip>
     1.6 +
     1.7 +/**
     1.8 + * Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
     1.9 + * which instructs the unit to show given text on the display.
    1.10 + * 
    1.11 + * Roland MT-32 is capable to display 20 characters.
    1.12 + * Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
    1.13 + * 
    1.14 + * The SysEx message contains a checksum.
    1.15 + * If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
    1.16 + * and then returns back to the default screen.
    1.17 + * 
    1.18 + * Usage:
    1.19 + *     amidi --port="hw:2,0,0" --send-hex="$(echo -n '   Run GNU/Linux    ' | ./mt-32-display )"
    1.20 + * 
    1.21 + * @param argc
    1.22 + * @param argv
    1.23 + * @return 
    1.24 + */
    1.25 +int main(int argc, char**argv) {
    1.26 +	std::cout << "f0 41 10 16 12 20 00 00 ";
    1.27 +	std::cout << std::hex << std::setfill('0');
    1.28 +
    1.29 +	int sum = 0;
    1.30 +
    1.31 +	// 20 00 00 = display message
    1.32 +	sum += 0x20;
    1.33 +	sum += 0x00;
    1.34 +	sum += 0x00;
    1.35 +
    1.36 +	for (char ch; std::cin.read(&ch, 1).good();) {
    1.37 +		std::cout << std::setw(2) << ((int) ch) << " ";
    1.38 +		sum += ch;
    1.39 +	}
    1.40 +
    1.41 +	sum %= 128;
    1.42 +	sum = 128 - sum;
    1.43 +	std::cout << std::setw(2) << sum;
    1.44 +	std::cout << " f7";
    1.45 +
    1.46 +	std::cout << std::endl;
    1.47 +	return 0;
    1.48 +}