mt-32-display.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 19 May 2020 16:03:25 +0200
branchv_0
changeset 1 6733bd832b61
parent 0 a7af46af7903
child 2 a84830179027
permissions -rw-r--r--
license: GNU GPLv3

/**
 * SysEx message encoder for Roland MT-32
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <iostream>
#include <iomanip>

/**
 * Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
 * which instructs the unit to show given text on the display.
 * 
 * Roland MT-32 is capable to display 20 characters.
 * Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
 * 
 * The SysEx message contains a checksum.
 * If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
 * and then returns back to the default screen.
 * 
 * Usage:
 *     amidi --port="hw:2,0,0" --send-hex="$(echo -n '   Run GNU/Linux    ' | ./mt-32-display )"
 * 
 * @param argc
 * @param argv
 * @return 
 */
int main(int argc, char**argv) {
	std::cout << "f0 41 10 16 12 20 00 00 ";
	std::cout << std::hex << std::setfill('0');

	int sum = 0;

	// 20 00 00 = display message
	sum += 0x20;
	sum += 0x00;
	sum += 0x00;

	for (char ch; std::cin.read(&ch, 1).good();) {
		std::cout << std::setw(2) << ((int) ch) << " ";
		sum += ch;
	}

	sum %= 128;
	sum = 128 - sum;
	std::cout << std::setw(2) << sum;
	std::cout << " f7";

	std::cout << std::endl;
	return 0;
}